Skip to content

Commit

Permalink
Set some members const
Browse files Browse the repository at this point in the history
  • Loading branch information
FredM67 committed May 5, 2023
1 parent 9854dd0 commit 515cab7
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions Mk2_3phase_RFdatalog_temp/utils_relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
};
Expand Down

0 comments on commit 515cab7

Please sign in to comment.