63 constexpr relayOutput(uint8_t _relay_pin, int16_t _surplusThreshold, int16_t _importThreshold)
77 constexpr relayOutput(uint8_t _relay_pin, int16_t _surplusThreshold, int16_t _importThreshold, uint16_t _minON, uint16_t _minOFF)
180 Serial.print(F(
"\tRelay configuration: #"));
181 Serial.println(idx + 1);
183 Serial.print(F(
"\t\tPin is "));
186 Serial.print(F(
"\t\tSurplus threshold: "));
189 Serial.print(F(
"\t\tImport threshold: "));
192 Serial.print(F(
"\t\tMinimum working time in minutes: "));
195 Serial.print(F(
"\t\tMinimum stop time in minutes: "));
214 DBUGLN(F(
"Relay turned ON!"));
236 DBUGLN(F(
"Relay turned OFF!"));
277template< u
int8_t N, u
int8_t D = 10 >
348#if defined(__DOXYGEN__)
351 void inc_duration() const __attribute__((optimize(
"-O3")));
405 Serial.println(F(
"\t*** Relay(s) configuration ***"));
406 Serial.print(F(
"\t\tSliding average: "));
409 for (uint8_t
i = 0;
i < N; ++
i)
411 relay[
i].printRelayConfiguration(
i);
428 relay[--idx].inc_duration();
Implements an Exponentially Weighted Moving Average (EWMA).
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.
Represents a single relay configuration and its behavior.
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(uint8_t pin)
Set the Pin state to ON for the specified pin.
constexpr void setPinOFF(uint8_t pin)
Set the Pin state to OFF for the specified pin.
constexpr uint8_t unused_pin