diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/Core/fsm.c | 10 | ||||
-rw-r--r-- | src/common/Core/main.c | 4 | ||||
-rw-r--r-- | src/common/GPIO/temperature.c | 25 | ||||
-rw-r--r-- | src/common/GPIO/temperature.h | 9 |
4 files changed, 27 insertions, 21 deletions
diff --git a/src/common/Core/fsm.c b/src/common/Core/fsm.c index 52ec8cb..47c349d 100644 --- a/src/common/Core/fsm.c +++ b/src/common/Core/fsm.c @@ -520,10 +520,11 @@ void fsm_update() { " %d AH %c ", capacity_bat_ah, supply_trend); } - if (temperature_valid()) { + float temp = 0; + if (temperature_get(&temp)) { len += snprintf(balise_message + len, BALISE_MESSAGE_LEN-len-1, " T %d ", - (int)(round_float_to_half_steps(temperature_get()))); + (int)(round_float_to_half_steps(temp))); } snprintf(balise_message + len, BALISE_MESSAGE_LEN-len-1, @@ -639,10 +640,11 @@ void fsm_update() { " %d AH ", capacity_bat_ah); } - if (temperature_valid()) { + float temp = 0; + if (temperature_get(&temp)) { len += snprintf(balise_message + len, BALISE_MESSAGE_LEN-len-1, " T %d ", - (int)(round_float_to_half_steps(temperature_get()))); + (int)(round_float_to_half_steps(temp))); } len += snprintf(balise_message+len, BALISE_MESSAGE_LEN-len-1, diff --git a/src/common/Core/main.c b/src/common/Core/main.c index ea393ab..f525221 100644 --- a/src/common/Core/main.c +++ b/src/common/Core/main.c @@ -502,8 +502,8 @@ static void gps_monit_task(void __attribute__ ((unused))*pvParameters) { stats_battery_at_full_hour(time.tm_hour, u_bat, capacity_bat); } - if (temperature_valid()) { - float temp = temperature_get(); + float temp = 0; + if (temperature_get(&temp)) { stats_temp(temp); const char *sign = ""; diff --git a/src/common/GPIO/temperature.c b/src/common/GPIO/temperature.c index f9e43cb..54fba80 100644 --- a/src/common/GPIO/temperature.c +++ b/src/common/GPIO/temperature.c @@ -30,7 +30,9 @@ float _temperature_last_value; -int _temperature_valid; +int _temperature_valid_since; + +#define TEMP_VALID_DURATION (60*15) // 15 minutes void temperature_task(void *pvParameters); @@ -47,16 +49,17 @@ void temperature_init() { NULL); } -// Return the current temperature -float temperature_get() { - if (_temperature_valid) { - return _temperature_last_value; - } else { - return 0.0f; - } +int temperature_valid() { + const uint64_t now = timestamp_now(); + return _temperature_valid_since > 0 && _temperature_valid_since + TEMP_VALID_DURATION < now; } -// Return 1 if the temperature is valid -int temperature_valid() { - return _temperature_valid; +// Return 1 if the the current temperature is valid, and write it into temp +int temperature_get(float *temp) { + if (temperature_valid()) { + *temp = _temperature_last_value; + return 1; + } + return 0; } + diff --git a/src/common/GPIO/temperature.h b/src/common/GPIO/temperature.h index f49cc26..8d8216f 100644 --- a/src/common/GPIO/temperature.h +++ b/src/common/GPIO/temperature.h @@ -26,15 +26,16 @@ #include <stdint.h> extern float _temperature_last_value; -extern int _temperature_valid; +extern int _temperature_valid_since; // Setup communication and temperature void temperature_init(void); -// Return 1 if the temperature is valid +// Return 1 if the the current temperature is valid int temperature_valid(void); -// Get current temperature -float temperature_get(void); +// Return 1 if the the current temperature is valid, and write it into temp +int temperature_get(float *temp); + void temperature_task(void *); |