diff -r 6d97eb820cc1 -r 3518c07737d8 thermferm/thermferm.c --- a/thermferm/thermferm.c Sat Apr 20 11:48:20 2024 +0200 +++ b/thermferm/thermferm.c Mon Apr 22 11:33:04 2024 +0200 @@ -1033,18 +1033,15 @@ unit->alarm_flag = 0; if (unit->air_address) { - rc = device_in(unit->air_address, &temp); + unit->air_state = rc = device_in(unit->air_address, &temp); if (rc == DEVPRESENT_YES) { if (unit->air_temperature != temp) { unit->mqtt_flag |= MQTT_FLAG_DATA; } unit->air_temperature = temp; - unit->air_state = 0; - } else if (rc == DEVPRESENT_ERROR) { - unit->air_state = 1; - } else { - unit->air_state = 2; } + } else { + unit->air_state = DEVPRESENT_NO; } if (unit->beer_address) { @@ -1053,32 +1050,27 @@ /* Read alternative sensor */ rc = device_in(unit->beer_address2, &temp); } + unit->beer_state = rc; if (rc == DEVPRESENT_YES) { if (unit->beer_temperature != temp) { unit->mqtt_flag |= MQTT_FLAG_DATA; } unit->beer_temperature = temp; - unit->beer_state = 0; - } else if (rc == DEVPRESENT_ERROR) { - unit->beer_state = 1; - } else { - unit->beer_state = 2; } + } else { + unit->beer_state = DEVPRESENT_NO; } if (unit->chiller_address) { - rc = device_in(unit->chiller_address, &temp); + unit->chiller_state = rc = device_in(unit->chiller_address, &temp); if (rc == DEVPRESENT_YES) { if (unit->chiller_temperature != temp) { unit->mqtt_flag |= MQTT_FLAG_DATA; } unit->chiller_temperature = temp; - unit->chiller_state = 0; - } else if (rc == DEVPRESENT_ERROR) { - unit->chiller_state = 1; - } else { - unit->chiller_state = 2; } + } else { + unit->chiller_state = DEVPRESENT_NO; } /* @@ -1733,20 +1725,15 @@ lcd_buf_write(row, "Room temp N/A "); pthread_mutex_unlock(&mutexes[LOCK_LCD]); int updateHT = 0; - if (Config.temp_address) { - rc = device_in(Config.temp_address, &temp); + if (Config.temp_uuid) { + Config.temp_state = rc = device_in(Config.temp_uuid, &temp); if (rc == DEVPRESENT_YES) { if (Config.temp_value != temp) updateHT = 1; Config.temp_value = temp; - Config.temp_state = 0; pthread_mutex_lock(&mutexes[LOCK_LCD]); lcd_buf_write(row, "Room temp %.1f%c ", Config.temp_value / 1000.0, 0x01); pthread_mutex_unlock(&mutexes[LOCK_LCD]); - } else if (rc == DEVPRESENT_ERROR) { - Config.temp_state = 1; - } else { - Config.temp_state = 2; } mDelay(10); } @@ -1755,20 +1742,15 @@ pthread_mutex_lock(&mutexes[LOCK_LCD]); lcd_buf_write(row, " Humidity N/A "); pthread_mutex_unlock(&mutexes[LOCK_LCD]); - if (Config.hum_address) { - rc = device_in(Config.hum_address, &temp); + if (Config.hum_uuid) { + Config.hum_state = rc = device_in(Config.hum_uuid, &temp); if (rc == DEVPRESENT_YES) { if (Config.hum_value != temp) updateHT = 1; Config.hum_value = temp; - Config.hum_state = 0; pthread_mutex_lock(&mutexes[LOCK_LCD]); lcd_buf_write(row, " Humidity %.1f%% ", Config.hum_value / 1000.0); pthread_mutex_unlock(&mutexes[LOCK_LCD]); - } else if (rc == DEVPRESENT_ERROR) { - Config.hum_state = 1; - } else { - Config.hum_state = 2; } mDelay(10); }