Show loading if temp hasn't yet been read

This commit is contained in:
Alexander Rosenberg 2024-04-13 15:09:05 -07:00
parent 8f4fd1958d
commit da9a2acf4e
Signed by: school-rpi4
GPG Key ID: 5CCFC80B0B47B04B
2 changed files with 5 additions and 2 deletions

View File

@ -69,7 +69,8 @@ void start_update_thread(pthread_t *thread);
// cross thread variables // cross thread variables
sqlite3 *DATABASE; sqlite3 *DATABASE;
pthread_mutex_t STAT_MUTEX; 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; _Atomic bool RUNNING = true;
/* /*
* Lock the cross thread variables above. * Lock the cross thread variables above.

View File

@ -152,6 +152,8 @@ static bool stats_screen_dispatch(StatsScreen *screen, SensorState *state) {
int cur_len; int cur_len;
if (state->temp == UINT32_MAX || state->humid == UINT32_MAX) { 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 { } else {
cur_len = snprintf(buff, sizeof(buff), "%-4.1f%c %3" PRIu32 "%% ", cur_len = snprintf(buff, sizeof(buff), "%-4.1f%c %3" PRIu32 "%% ",
convert_temperature(state->temp), convert_temperature(state->temp),