3-phase PV router
Loading...
Searching...
No Matches
utils_relay.h
Go to the documentation of this file.
1
16
17#ifndef UTILS_RELAY_H
18#define UTILS_RELAY_H
19
20#include "types.h"
21#include "type_traits.hpp"
22#include "debug.h"
23
24#include "relay_engine.h"
25#include "utils_pins.h"
26
32{
39 __attribute__((always_inline)) static void switched(const uint8_t pin, const bool on)
40 {
41 setPinState(pin, on);
42
43 statusln(on ? F("Relay turned ON!") : F("Relay turned OFF!"));
44 }
45};
46
56class relayOutput : public RelayLogic::Relay< RelayPinOutput >
57{
58public:
60
65 void printRelayConfiguration(uint8_t idx) const
66 {
67 info(F("\tRelay configuration: #"));
68 infoln(idx + 1);
69
70 info(F("\t\tPin is "));
71 infoln(get_pin());
72
73 info(F("\t\tSurplus threshold: "));
75
76 info(F("\t\tImport threshold: "));
78 if (get_importThreshold() >= 0)
79 {
80 infoln(F(" (import mode)"));
81 }
82 else
83 {
84 info(F(" (surplus mode: turn OFF when surplus < "));
86 infoln(F("W)"));
87 }
88
89 info(F("\t\tMinimum working time in minutes: "));
90 infoln(get_minON() / 60);
91
92 info(F("\t\tMinimum stop time in minutes: "));
93 infoln(get_minOFF() / 60);
94 }
95};
96
110template< uint8_t N, uint8_t D = 10 >
111class RelayDiverter : public RelayLogic::Engine< relayOutput, N, D >
112{
114
115public:
120 explicit constexpr RelayDiverter(const relayOutput (&ref)[N])
121 : Base(ref)
122 {
123 }
124
133 constexpr RelayDiverter(integral_constant< uint8_t, D > /* ic */, const relayOutput (&ref)[N])
134 : Base(ref)
135 {
136 }
137
144 template< uint16_t V >
145 constexpr RelayDiverter(integral_constant< uint16_t, V > /* ic */, const relayOutput (&ref)[N])
146 : Base(ref)
147 {
148 static_assert(V <= UINT8_MAX, "******** RELAY_FILTER_DELAY cannot exceed 255 minutes ! Please check your config.h ! ********");
149 static_assert(V == D, "******** The MINUTES() given to RelayDiverter differs from its template parameter D (RELAY_FILTER_DELAY) ! Please check your config.h ! ********");
150 }
151
157 explicit constexpr RelayDiverter(const RelayEngine< N, D >& relays)
159 {
160 }
161
169 {
170 infoln(F("*** Relay(s) configuration ***"));
171 info(F("\tSliding average: "));
172 infoln(D);
173
174 for (uint8_t i = 0; i < N; ++i)
175 {
176 Base::relay[i].printRelayConfiguration(i);
177 }
178 }
179
180private:
181 template< uint8_t... I >
183 : Base({ relayOutput{ relays.get_relay(I).pin, relays.get_relay(I).surplusThreshold, relays.get_relay(I).importThreshold,
184 relays.get_relay(I).minON, relays.get_relay(I).minOFF }... })
185 {
186 }
187};
188
189// Deduction guides for automatic template parameter deduction
190template< uint8_t N >
192
193template< uint8_t N, uint8_t D >
195
196template< uint8_t N, uint16_t D >
198
199template< uint8_t N, uint8_t D >
201
202#endif /* UTILS_RELAY_H */
Manages a collection of relays and their behavior based on surplus and import thresholds.
constexpr RelayDiverter(integral_constant< uint8_t, D >, const relayOutput(&ref)[N])
Construct a list of relays with a custom sliding average.
constexpr RelayDiverter(integral_constant< uint16_t, V >, const relayOutput(&ref)[N])
Construct a list of relays with a custom sliding average, given with MINUTES().
constexpr RelayDiverter(const relayOutput(&ref)[N])
Construct a list of relays.
void printRelayEngineConfiguration() const
Print the configuration of each relay.
constexpr RelayDiverter(const RelayEngine< N, D > &relays)
The relays of config.h.
RelayLogic::Engine< relayOutput, N, D > Base
constexpr RelayDiverter(const RelayEngine< N, D > &relays, index_sequence< I... >)
The relays, as in config.h: the sliding average and the settings of each relay.
A collection of relays, switched one at a time from a sliding average.
The state of one relay, and its decisions.
constexpr auto get_minON() const
constexpr auto get_minOFF() const
constexpr auto get_surplusThreshold() const
constexpr auto get_importThreshold() const
Represents a single relay configuration and its behavior.
Definition utils_relay.h:57
void printRelayConfiguration(uint8_t idx) const
Print the configuration of the current relay-diversion.
Definition utils_relay.h:65
constexpr RelayEngine relays
Definition config.h:130
The text output: informational messages (info) and debug messages (debug)
void infoln(const Args &... args)
Print an informational message and a line end, as Serial.println() does.
Definition debug.h:67
void statusln(const Args &... args)
Print a status message and a line end, as Serial.println() does (human-readable output only).
Definition debug.h:131
void info(const Args &... args)
Print an informational message, as Serial.print() does.
Definition debug.h:57
uint8_t i
typename make_index_sequence_impl< N >::type make_index_sequence
index_sequence< 0, 1, ..., N - 1 >.
Decisions of the relay diversion: which relay switches, and when.
The output of a relay in the firmware: its pin, and a status message.
Definition utils_relay.h:32
static void switched(const uint8_t pin, const bool on)
Called on each change of a relay, before its state changes.
Definition utils_relay.h:39
The indexes I..., as a type.
Some useful but missing stl functions templates.
Some basics classes/types.
Some utility functions for pins manipulation.
void setPinState(const uint8_t pin, const bool bState)
Set the Pin state for the specified pin.
Definition utils_pins.h:84
RelayDiverter(const relayOutput(&)[N]) -> RelayDiverter< N, 10 >