From 83cdd2f26f168076e0ea0ea94e762d301d02a08d Mon Sep 17 00:00:00 2001 From: Javier Arigita Date: Sun, 26 Apr 2020 08:48:03 +0200 Subject: [PATCH] Correction overflow protection --- tasmota/xdrv_39_thermostat.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasmota/xdrv_39_thermostat.ino b/tasmota/xdrv_39_thermostat.ino index e62322d01..85a1b245b 100644 --- a/tasmota/xdrv_39_thermostat.ino +++ b/tasmota/xdrv_39_thermostat.ino @@ -402,10 +402,10 @@ void ThermostatCalculatePI(void) aux_time_error = (int32_t)(Thermostat.temp_target_level_ctr - Thermostat.temp_measured) * 10; // Protect overflow - if (aux_time_error >= (int32_t)(INT16_MIN)) { + if (aux_time_error <= (int32_t)(INT16_MIN)) { Thermostat.temp_pi_error = (int16_t)(INT16_MIN); } - else if (aux_time_error <= (int32_t)INT16_MAX) { + else if (aux_time_error >= (int32_t)INT16_MAX) { Thermostat.temp_pi_error = (int16_t)INT16_MAX; } else { @@ -459,10 +459,10 @@ void ThermostatCalculatePI(void) aux_time_error = (int32_t)Thermostat.temp_pi_accum_error + (int32_t)Thermostat.temp_pi_error; // Protect overflow - if (aux_time_error >= (int32_t)INT16_MIN) { + if (aux_time_error <= (int32_t)INT16_MIN) { Thermostat.temp_pi_accum_error = INT16_MIN; } - else if (aux_time_error <= (int32_t)INT16_MAX) { + else if (aux_time_error >= (int32_t)INT16_MAX) { Thermostat.temp_pi_accum_error = INT16_MAX; } else {