cooking continues

This commit is contained in:
2026-05-04 23:04:43 +02:00
parent a82fdd3d33
commit cab3c32c63
2 changed files with 26 additions and 31 deletions

View File

@@ -4,9 +4,9 @@
#include "log.h"
#include <unistd.h>
#include <stdatomic.h>
#include <stdio.h>
#include <sys/signalfd.h>
#include "lcd.h"
#include "sys.h"
static void timespec_add_ms(struct timespec *ts, const uint16_t ms) {
ts->tv_nsec += ms * 1000000L;
@@ -26,7 +26,7 @@ struct control_t {
} control;
struct sensors_t {
// sys::TimeDate td;
struct time_date_t td;
double loadavg[3];
// sys::Memory ram;
// sys::Disk home;
@@ -62,22 +62,20 @@ static void *display_thread(void *arg) {
lcd_flush_buf(&lcd);
lcd_clear_buf(&lcd);
static int i = 0;
while (g_running) { // NOLINT its updated globally bud
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
timespec_add_ms(&ts, (uint16_t)(refresh_interval_ms * 1.25));
pthread_mutex_lock(&control.sensors_mtx);
pthread_cond_timedwait(&control.sensors_ready, &control.sensors_mtx, &ts);
pthread_mutex_lock(&control.sensors_mtx); // lock sensor struct
pthread_cond_timedwait(&control.sensors_ready, &control.sensors_mtx, &ts); // wait until data ready
lcd_clear_buf(&lcd);
lcd_writef(&lcd, 0, 0, "%s %s", sensors->td.date, sensors->td.time);
lcd_writef(&lcd, 26, 0, "%.2f %.2f %.2f", sensors->loadavg[0], sensors->loadavg[1], sensors->loadavg[2]);
lcd_writef(&lcd, 44, "write %6d", i);
lcd_flush_buf(&lcd);
pthread_mutex_unlock(&control.sensors_mtx);
applog(LOG_WRN, "disp tock");
pthread_mutex_unlock(&control.sensors_mtx); // unlock sensor struct
}
lcd_close(&lcd);
@@ -95,12 +93,14 @@ static void *sensors_thread(void *arg) {
while (g_running) { // NOLINT
timespec_add_ms(&next, refresh_interval_ms);
pthread_mutex_lock(&control.sensors_mtx);
sensors->hass_state = 2.3;
sys_get_load_avg(sensors->loadavg);
sys_get_time(&sensors->td);
pthread_cond_signal(&control.sensors_ready);
pthread_mutex_unlock(&control.sensors_mtx);
clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &next, nullptr);
applog(LOG_WRN, "sensors tick");
}