From da9a2acf4eba00652941aece573bec553890fb17 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Sat, 13 Apr 2024 15:09:05 -0700 Subject: [PATCH] Show loading if temp hasn't yet been read --- src/main.c | 3 ++- src/ui/screen.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index fd66369..f53449b 100644 --- a/src/main.c +++ b/src/main.c @@ -69,7 +69,8 @@ void start_update_thread(pthread_t *thread); // cross thread variables sqlite3 *DATABASE; pthread_mutex_t STAT_MUTEX; -uint32_t LAST_TEMP, LAST_HUMID; +// these values mean that we haven't yet read the temperature +uint32_t LAST_TEMP = UINT32_MAX - 1, LAST_HUMID = UINT32_MAX - 1; _Atomic bool RUNNING = true; /* * Lock the cross thread variables above. diff --git a/src/ui/screen.c b/src/ui/screen.c index b1aa39c..06b9d04 100644 --- a/src/ui/screen.c +++ b/src/ui/screen.c @@ -151,7 +151,9 @@ static bool stats_screen_dispatch(StatsScreen *screen, SensorState *state) { char buff[17]; int cur_len; if (state->temp == UINT32_MAX || state->humid == UINT32_MAX) { - cur_len = snprintf(buff, sizeof(buff), "ERROR! "); + cur_len = snprintf(buff, sizeof(buff), "ERROR! "); + } else if (state->temp == UINT_MAX - 1 || state->humid == UINT32_MAX - 1) { + cur_len = snprintf(buff, sizeof(buff), "LOADING! "); } else { cur_len = snprintf(buff, sizeof(buff), "%-4.1f%c %3" PRIu32 "%% ", convert_temperature(state->temp),