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)
167 bool proceed_relay(
const int32_t currentAvgPower, uint16_t& overrideBitmask)
const
206 Serial.print(F(
"\tRelay configuration: #"));
207 Serial.println(idx + 1);
209 Serial.print(F(
"\t\tPin is "));
212 Serial.print(F(
"\t\tSurplus threshold: "));
215 Serial.print(F(
"\t\tImport threshold: "));
219 Serial.println(F(
" (import mode)"));
223 Serial.print(F(
" (surplus mode: turn OFF when surplus < "));
225 Serial.println(F(
"W)"));
228 Serial.print(F(
"\t\tMinimum working time in minutes: "));
231 Serial.print(F(
"\t\tMinimum stop time in minutes: "));
250 DBUGLN(F(
"Relay turned ON!"));
272 DBUGLN(F(
"Relay turned OFF!"));
313template< u
int8_t N, u
int8_t D = 10 >
384#if defined(__DOXYGEN__)
387 void inc_duration() const __attribute__((optimize(
"-O3")));
444 Serial.println(F(
"*** Relay(s) configuration ***"));
445 Serial.print(F(
"\tSliding average: "));
448 for (uint8_t
i = 0;
i < N; ++
i)
450 relay[
i].printRelayConfiguration(
i);
467 relay[--idx].inc_duration();
480template< 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
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 const auto & get_relay(uint8_t idx) const
Get the relay object.
constexpr RelayEngine(const relayOutput(&ref)[N])
Construct a list of relays.
constexpr auto size() const
Get the number of relays.
void proceed_relays(uint16_t &overrideBitmask) const
Proceed all relays in increasing order (surplus) or decreasing order (import).
void printRelayEngineConfiguration() const
Print the configuration of each relay.
constexpr RelayEngine(integral_constant< uint8_t, D >, const relayOutput(&ref)[N])
Construct a list of relays with a custom sliding average.
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, uint16_t &overrideBitmask) 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 uint8_t bit_read(const T &_src, const uint8_t bit)
Read the specified bit.
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 bit_clear(T &_dest, const uint8_t bit)
Clear the specified bit.
constexpr uint8_t unused_pin
RelayEngine(const relayOutput(&)[N]) -> RelayEngine< N, 10 >