From 515cab788114fc1f130180c3e9a0fb9a4eea583b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Metrich?= <45318189+FredM67@users.noreply.github.com> Date: Fri, 5 May 2023 22:50:10 +0200 Subject: [PATCH] Set some members const --- Mk2_3phase_RFdatalog_temp/utils_relay.h | 40 +++++++++++-------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/Mk2_3phase_RFdatalog_temp/utils_relay.h b/Mk2_3phase_RFdatalog_temp/utils_relay.h index 8cad2fcd..3a25727b 100644 --- a/Mk2_3phase_RFdatalog_temp/utils_relay.h +++ b/Mk2_3phase_RFdatalog_temp/utils_relay.h @@ -142,17 +142,15 @@ template< uint8_t T = 1 > class relayOutput */ void try_turnON() { - if (relayState) + if (relayState || duration < minOFF) { return; } - if (duration > minOFF) - { - setPinON(relay_pin); - relayState = true; - duration = 0; - } + setPinON(relay_pin); + + relayState = true; + duration = 0; } /** @@ -161,28 +159,26 @@ template< uint8_t T = 1 > class relayOutput */ void try_turnOFF() { - if (!relayState) + if (!relayState || duration < minON) { return; } - if (duration > minON) - { - setPinOFF(relay_pin); - relayState = false; - duration = 0; - } + setPinOFF(relay_pin); + + relayState = false; + duration = 0; } private: - uint8_t relay_pin{ 0xff }; /**< Pin associated with the relay */ - int16_t surplusThreshold{ 1000 }; /**< Surplus threshold to turn relay ON */ - int16_t importThreshold{ 200 }; /**< Import threshold to turn relay OFF */ - uint16_t minON{ 5 * 60 }; /**< Minimum duration in seconds the relay is turned ON */ - uint16_t minOFF{ 5 * 60 }; /**< Minimum duration in seconds the relay is turned OFF */ - - uint16_t duration{ 0 }; /**< Duration of the current state */ - bool relayState{ false }; /**< State of the relay */ + const uint8_t relay_pin{ 0xff }; /**< Pin associated with the relay */ + const int16_t surplusThreshold{ 1000 }; /**< Surplus threshold to turn relay ON */ + const int16_t importThreshold{ 200 }; /**< Import threshold to turn relay OFF */ + const uint16_t minON{ 5 * 60 }; /**< Minimum duration in seconds the relay is turned ON */ + const uint16_t minOFF{ 5 * 60 }; /**< Minimum duration in seconds the relay is turned OFF */ + + uint16_t duration{ 0 }; /**< Duration of the current state */ + bool relayState{ false }; /**< State of the relay */ static inline movingAvg< int16_t, T * 60 / DATALOG_PERIOD_IN_SECONDS > sliding_Average; };