65 constexpr relayOutput(uint8_t _relay_pin, int16_t _surplusThreshold, int16_t _importThreshold)
82 constexpr relayOutput(uint8_t _relay_pin, int16_t _surplusThreshold, int16_t _importThreshold, uint16_t _minON, uint16_t _minOFF)
200 Serial.print(F(
"\tRelay configuration: #"));
201 Serial.println(idx + 1);
203 Serial.print(F(
"\t\tPin is "));
206 Serial.print(F(
"\t\tSurplus threshold: "));
209 Serial.print(F(
"\t\tImport threshold: "));
213 Serial.println(F(
" (import mode)"));
217 Serial.print(F(
" (surplus mode: turn OFF when surplus < "));
219 Serial.println(F(
"W)"));
222 Serial.print(F(
"\t\tMinimum working time in minutes: "));
225 Serial.print(F(
"\t\tMinimum stop time in minutes: "));
244 DBUGLN(F(
"Relay turned ON!"));
266 DBUGLN(F(
"Relay turned OFF!"));
307template< u
int8_t N, u
int8_t D = 10 >
378#if defined(__DOXYGEN__)
381 void inc_duration() const __attribute__((optimize(
"-O3")));
435 Serial.println(F(
"\t*** Relay(s) configuration ***"));
436 Serial.print(F(
"\t\tSliding average: "));
439 for (uint8_t
i = 0;
i < N; ++
i)
441 relay[
i].printRelayConfiguration(
i);
458 relay[--idx].inc_duration();
471template< u
int8_t N, u
int8_t D >
Implements an Exponentially Weighted Moving Average (EWMA).
Manages a collection of relays and their behavior based on surplus and import thresholds.
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.
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
RelayEngine(const relayOutput(&)[N]) -> RelayEngine< N, 10 >