diff --git a/Mk2_3phase_RFdatalog_temp/utils_relay.h b/Mk2_3phase_RFdatalog_temp/utils_relay.h index 3a25727b..e0f37b89 100644 --- a/Mk2_3phase_RFdatalog_temp/utils_relay.h +++ b/Mk2_3phase_RFdatalog_temp/utils_relay.h @@ -19,8 +19,9 @@ #include "utils_pins.h" /** - * @brief Config parameters for relay diversion + * @brief Relay diversion config and engine * + * @tparam T Duration in minutes of the sliding average */ template< uint8_t T = 1 > class relayOutput { @@ -105,11 +106,15 @@ template< uint8_t T = 1 > class relayOutput /** * @brief Increment the duration of the current state + * @details This function must be called every second. * */ void inc_duration() { - ++duration; + if (duration < UINT16_MAX) + { + ++duration; + } } /** @@ -177,8 +182,8 @@ template< uint8_t T = 1 > class relayOutput 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 */ + 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; };