makes more senese like this
This commit is contained in:
64
src/main.c
64
src/main.c
@@ -43,6 +43,38 @@ struct sensors_t {
|
|||||||
double hass_state;
|
double hass_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void *sensors_thread(void *arg) {
|
||||||
|
applog(LOG_START, "sensors thread started, refresh interval is %dms", refresh_interval_ms);
|
||||||
|
struct sensors_t* sensors = arg;
|
||||||
|
|
||||||
|
struct timespec next;
|
||||||
|
clock_gettime(CLOCK_REALTIME, &next);
|
||||||
|
|
||||||
|
// set up paths for the sensors
|
||||||
|
strcpy(sensors->home.mountpoint, "/home/drath");
|
||||||
|
cpu_detect(&sensors->cpu, "0000:00:18.3");
|
||||||
|
|
||||||
|
while (control.g_running) { // NOLINT
|
||||||
|
pthread_mutex_lock(&control.sensors_mtx);
|
||||||
|
|
||||||
|
sys_get_load_avg(sensors->loadavg);
|
||||||
|
sys_get_time(&sensors->td);
|
||||||
|
sys_get_ram(&sensors->ram);
|
||||||
|
sys_get_disk(&sensors->home);
|
||||||
|
|
||||||
|
cpu_update(&sensors->cpu);
|
||||||
|
|
||||||
|
pthread_cond_signal(&control.sensors_ready);
|
||||||
|
pthread_mutex_unlock(&control.sensors_mtx);
|
||||||
|
|
||||||
|
timespec_add_ms(&next, refresh_interval_ms);
|
||||||
|
clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &next, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
applog(LOG_WRN, "sensors thread stopped");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
static void *display_thread(void *arg) {
|
static void *display_thread(void *arg) {
|
||||||
applog(LOG_START, "display thread started");
|
applog(LOG_START, "display thread started");
|
||||||
struct sensors_t* sensors = arg;
|
struct sensors_t* sensors = arg;
|
||||||
@@ -92,38 +124,6 @@ static void *display_thread(void *arg) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *sensors_thread(void *arg) {
|
|
||||||
applog(LOG_START, "sensors thread started, refresh interval is %dms", refresh_interval_ms);
|
|
||||||
struct sensors_t* sensors = arg;
|
|
||||||
|
|
||||||
struct timespec next;
|
|
||||||
clock_gettime(CLOCK_REALTIME, &next);
|
|
||||||
|
|
||||||
// set up paths for the sensors
|
|
||||||
strcpy(sensors->home.mountpoint, "/home/drath");
|
|
||||||
cpu_detect(&sensors->cpu, "0000:00:18.3");
|
|
||||||
|
|
||||||
while (control.g_running) { // NOLINT
|
|
||||||
pthread_mutex_lock(&control.sensors_mtx);
|
|
||||||
|
|
||||||
sys_get_load_avg(sensors->loadavg);
|
|
||||||
sys_get_time(&sensors->td);
|
|
||||||
sys_get_ram(&sensors->ram);
|
|
||||||
sys_get_disk(&sensors->home);
|
|
||||||
|
|
||||||
cpu_update(&sensors->cpu);
|
|
||||||
|
|
||||||
pthread_cond_signal(&control.sensors_ready);
|
|
||||||
pthread_mutex_unlock(&control.sensors_mtx);
|
|
||||||
|
|
||||||
timespec_add_ms(&next, refresh_interval_ms);
|
|
||||||
clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &next, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
applog(LOG_WRN, "sensors thread stopped");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
control.g_running = true;
|
control.g_running = true;
|
||||||
applog(LOG_START, "linuxSmartie started");
|
applog(LOG_START, "linuxSmartie started");
|
||||||
|
|||||||
Reference in New Issue
Block a user