51 constexpr relayOutput(uint8_t _relay_pin, int16_t _surplusThreshold, int16_t _importThreshold)
168 Serial.print(F(
"\tRelay configuration: #"));
169 Serial.println(idx + 1);
171 Serial.print(F(
"\t\tPin is "));
174 Serial.print(F(
"\t\tSurplus threshold: "));
177 Serial.print(F(
"\t\tImport threshold: "));
180 Serial.print(F(
"\t\tMinimum working time in minutes: "));
183 Serial.print(F(
"\t\tMinimum stop time in minutes: "));
202 DBUGLN(F(
"Relay turned ON!"));
224 DBUGLN(F(
"Relay turned OFF!"));
251template< u
int8_t N, u
int8_t D = 10 >
318#if defined(__DOXYGEN__)
321 void inc_duration() const __attribute__((optimize("-O3")));
373 pinMode(
relay[--idx].get_pin(), OUTPUT);
384 Serial.println(F(
"\t*** Relay(s) configuration ***"));
385 Serial.print(F(
"\t\tSliding average: "));
388 for (uint8_t
i = 0;
i < N; ++
i)
407 relay[--idx].inc_duration();
Exponentially Weighted Moving Average.
This class implements the relay management engine.
static EWMA_average< D *60/DATALOG_PERIOD_IN_SECONDS > ewma_average
constexpr auto get_size() const
Get the number of relays.
void proceed_relays() const
Proceed all relays in increasing order (surplus) or decreasing order (import)
static auto get_average()
Get the current average.
static void update_average(int16_t currentPower)
Update the sliding average.
const relayOutput relay[N]
void inc_duration() const
Increment the duration's state of each relay.
constexpr RelayEngine(integral_constant< uint8_t, D > ic, const relayOutput(&ref)[N])
Construct a list of relays with a custom sliding average.
constexpr const auto & get_relay(uint8_t idx) const
Get the relay object.
constexpr RelayEngine(const relayOutput(&ref)[N])
Construct a list of relays.
void printConfiguration() const
Print the configuration of each relay.
void initializePins() const
Initialize the pins used by the relays.
Relay diversion config and engine.
constexpr relayOutput()=delete
constexpr auto get_minOFF() const
Get the minimum OFF-time in seconds.
const int16_t importThreshold
const int16_t surplusThreshold
constexpr auto get_surplusThreshold() const
Get the surplus threshold which will turns ON the relay.
bool proceed_relay(const int32_t currentAvgPower) const
Proceed with the relay.
constexpr relayOutput(uint8_t _relay_pin, int16_t _surplusThreshold, int16_t _importThreshold, uint16_t _minON, uint16_t _minOFF)
Construct a new relay Config object with custom parameters.
bool try_turnOFF() const
Turn OFF the relay if the 'time' condition is met.
constexpr relayOutput(const uint8_t _relay_pin)
Construct a new relay Config object with default parameters.
constexpr auto get_importThreshold() const
Get the import threshold which will turns OFF the relay.
void printRelayConfiguration(uint8_t idx) const
Print the configuration of the current relay-diversion.
constexpr relayOutput(uint8_t _relay_pin, int16_t _surplusThreshold, int16_t _importThreshold)
Construct a new relay Config object with default/custom parameters.
auto isRelayON() const
Return the state.
constexpr auto get_pin() const
Get the control pin of the relay.
void inc_duration() const
Increment the duration of the current state.
bool try_turnON() const
Turn ON the relay if the 'time' condition is met.
constexpr auto get_minON() const
Get the minimum ON-time in seconds.
Basic configuration values to be set by the end-user.
constexpr uint8_t DATALOG_PERIOD_IN_SECONDS
Some macro for the Serial Output and Debugging.
This file implements an Exponentially Weighted Moving Average template class.
Code for sliding-window average.
Some useful but missing stl functions templates.
Some basics classes/types.
Some utility functions for pins manipulation.
constexpr void setPinON(const uint8_t pin)
Set the Pin state to ON for the specified pin.
constexpr void setPinOFF(const uint8_t pin)
Set the Pin state to OFF for the specified pin.