From b26e37d65212b490c75cf6624f61dca589d809c4 Mon Sep 17 00:00:00 2001 From: Joshua Henderson Date: Tue, 30 Aug 2022 01:09:53 -0400 Subject: [PATCH] AP_BattMonitor: fix Rotoye Temperature Monitoring --- .../AP_BattMonitor_SMBus_Rotoye.cpp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/libraries/AP_BattMonitor/AP_BattMonitor_SMBus_Rotoye.cpp b/libraries/AP_BattMonitor/AP_BattMonitor_SMBus_Rotoye.cpp index 3ab3dc1e03..d05cc7a11d 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor_SMBus_Rotoye.cpp +++ b/libraries/AP_BattMonitor/AP_BattMonitor_SMBus_Rotoye.cpp @@ -3,20 +3,25 @@ #include // Specific to Rotoye Batmon -#define BATTMONITOR_SMBUS_TEMP_EXT 0x07 +#define BATTMONITOR_SMBUS_TEMP_EXT 0x48 // return the maximum of the internal and external temperature sensors void AP_BattMonitor_SMBus_Rotoye::read_temp(void) { - - uint16_t t_int, t_ext; - - /* Both internal and external values will always be sent by Batmon. + uint16_t t_int = 0; + uint16_t t_ext = 0; + + /* Both internal and external values will always be sent by Batmon. If no external thermistor is used, a zero-value is sent. */ - if (read_word(BATTMONITOR_SMBUS_TEMP, t_int) && - read_word(BATTMONITOR_SMBUS_TEMP_EXT, t_ext)) { - uint16_t t; - _state.temperature_time = AP_HAL::millis(); - t = ((t_ext > t_int) ? t_ext : t_int); - _state.temperature = KELVIN_TO_C(0.1f * (float)t); + const bool have_temp_internal = read_word(BATTMONITOR_SMBUS_TEMP, t_int); + const bool have_temp_external = read_word(BATTMONITOR_SMBUS_TEMP_EXT, t_ext); + + if (!have_temp_internal && !have_temp_external) { + _has_temperature = (AP_HAL::millis() - _state.temperature_time) <= AP_BATT_MONITOR_TIMEOUT; + return; } + + _has_temperature = true; + + _state.temperature_time = AP_HAL::millis(); + _state.temperature = KELVIN_TO_C(0.1f * float(MAX(t_int, t_ext))); }