77inline constexpr uint8_t
LOAD{ 0x40 };
79inline constexpr uint8_t
RELAY{ 0x70 };
93constexpr uint8_t
LOAD(
const uint8_t loadNum)
95 return loadNum < TargetCode::MAX_LOADS ? static_cast< uint8_t >(
TargetCode::LOAD + loadNum) : 0;
101 return loadNum < TargetCode::MAX_LOCAL_LOADS ? static_cast< uint8_t >(
TargetCode::LOCAL_LOAD + loadNum) : 0;
110 return loadNum < REMOTE_MASK_BITS ? static_cast< uint8_t >(
REMOTE_PIN_BASE + loadNum) : 0;
114constexpr uint8_t
RELAY(
const uint8_t relayNum)
116 return relayNum < TargetCode::MAX_RELAYS ? static_cast< uint8_t >(
TargetCode::RELAY + relayNum) : 0;
156template< u
int8_t MaxPins >
175 for (uint8_t pin = 0; pin < 16 &&
count < MaxPins; ++pin)
177 if (bitmask & (1U << pin))
194 for (uint8_t pin = 0; pin < 16 &&
count < MaxPins; ++pin)
196 if (bitmask & (1UL << pin))
202 for (uint8_t
i = 0;
i < 8 &&
count < MaxPins; ++
i)
204 if (bitmask & (1UL << (16 +
i)))
215 template<
typename... Args >
217 :
pins{ static_cast< uint8_t >(args)... },
count(sizeof...(args)) {}
225 uint16_t result{ 0 };
230 result |= (1U <<
pins[
i]);
251 result |= (1U << remoteIndex);
263template< u
int8_t MaxPins >
304template< u
int8_t N, u
int8_t MaxPins = 16 >
321 constexpr uint8_t
getPin(
const uint8_t index)
const
323 return index < N ?
entries_[index].pin : 0;
333 template< uint8_t... I >
343template< u
int8_t MaxPins, u
int8_t N >
360 template< u
int16_t V >
424template< u
int8_t MaxPins = 16 >
451template< u
int8_t N, u
int8_t MaxPins = 16 >
480 template< uint8_t... I >
490template< u
int8_t MaxPins >
516template< u
int8_t MaxPins, u
int8_t N >
536template< u
int8_t N, u
int8_t MaxPins = 16 >
539 static_assert(N >= 1 && N <= 10,
"rotationGroups holds 1 to 10 groups");
545 const PinList< MaxPins >& g4 = {},
const PinList< MaxPins >& g5 = {},
546 const PinList< MaxPins >& g6 = {},
const PinList< MaxPins >& g7 = {},
547 const PinList< MaxPins >& g8 = {},
const PinList< MaxPins >& g9 = {})
548 :
RotationGroups(
Ten{ { g0, g1, g2, g3, g4, g5, g6, g7, g8, g9 } },
make_index_sequence< N >{})
570 template< uint8_t... I >
580template< u
int8_t MaxPins >
632 constexpr RelaySetting(
const uint8_t p,
const int16_t surplus = 1000,
const int16_t
import = 200,
const uint16_t on = 5,
const uint16_t off = 5)
646template< u
int8_t N, u
int8_t D = 10 >
663 template< u
int16_t V >
667 static_assert(V <= UINT8_MAX,
"******** RELAY_FILTER_DELAY cannot exceed 255 minutes ! Please check your config.h ! ********");
668 static_assert(V == D,
"******** The MINUTES() given to RelayEngine differs from its template parameter D (RELAY_FILTER_DELAY) ! Please check your config.h ! ********");
690 template< uint8_t... I >
704template< u
int8_t N, u
int8_t D >
708template< u
int8_t N, u
int16_t D >
768 template< uint8_t... I >
The override pins, as in config.h: each pin with the targets it forces.
constexpr OverridePins(const KeyIndexPair< MaxPins >(&pairs)[N])
The override pins, from a list of { pin, targets }.
constexpr uint8_t getPin(const uint8_t index) const
The override pin at index (0 if out of range).
constexpr uint8_t size() const
Number of override pins.
constexpr const PinList< MaxPins > & getTargets(const uint8_t index) const
The targets of the override pin at index, as codes.
const KeyIndexPair< MaxPins > entries_[N]
constexpr OverridePins(const KeyIndexPair< MaxPins >(&pairs)[N], index_sequence< I... >)
The relays, as in config.h: the sliding average and the settings of each relay.
constexpr uint8_t size() const
Number of relays.
constexpr RelayEngine(integral_constant< uint16_t, V >, const RelaySetting(&ref)[N])
The relays, with a sliding average given with MINUTES().
const RelaySetting relay_[N]
constexpr RelayEngine(const RelaySetting(&ref)[N], index_sequence< I... >)
constexpr RelayEngine(const RelaySetting(&ref)[N])
The relays, with the default sliding average.
constexpr const RelaySetting & get_relay(const uint8_t idx) const
The settings of relay idx.
static constexpr uint8_t filterDelay()
Duration of the sliding average, in minutes: D, the one the relay engine uses.
constexpr RelayEngine(integral_constant< uint8_t, D >, const RelaySetting(&ref)[N])
The relays, with a sliding average given as an integral_constant< uint8_t >.
constexpr RotationGroups()=default
constexpr PinList< MaxPins > getGroup(uint8_t) const
No targets: never called, there for the loops over size().
constexpr uint8_t size() const
Number of groups: none.
The rotation groups, as in config.h: the loads that take turns at the top of the priority list,...
constexpr RotationGroups(const PinList< MaxPins > &g0, const PinList< MaxPins > &g1={}, const PinList< MaxPins > &g2={}, const PinList< MaxPins > &g3={}, const PinList< MaxPins > &g4={}, const PinList< MaxPins > &g5={}, const PinList< MaxPins > &g6={}, const PinList< MaxPins > &g7={}, const PinList< MaxPins > &g8={}, const PinList< MaxPins > &g9={})
The groups, one list of targets each.
const PinList< MaxPins > groups_[N]
constexpr uint8_t size() const
Number of groups.
constexpr RotationGroups(const Ten &ten, index_sequence< I... >)
constexpr const PinList< MaxPins > & getGroup(const uint8_t index) const
The targets of group index, as codes.
constexpr PinList< MaxPins > getTargets(uint8_t) const
No targets: never called, there for the loops over size().
constexpr BoostWindow getWindow(uint8_t) const
No window: never called, there for the loops over size().
constexpr uint8_t size() const
Number of boosts: none.
constexpr ScheduledBoosts()=default
The scheduled boosts, as in config.h: each window with the targets it forces.
constexpr ScheduledBoosts(const BoostEntry< MaxPins >(&boosts)[N])
The boosts, from a list of { window, targets }.
const BoostEntry< MaxPins > entries_[N]
constexpr const PinList< MaxPins > & getTargets(const uint8_t i) const
The targets of boost i, as codes.
constexpr uint8_t size() const
Number of boosts.
constexpr ScheduledBoosts(const BoostEntry< MaxPins >(&boosts)[N], index_sequence< I... >)
constexpr BoostWindow getWindow(const uint8_t i) const
The window of boost i.
constexpr TemperatureSensing()=delete
constexpr TemperatureSensing(const uint8_t pin, const DeviceAddress(&ref)[N], index_sequence< I... >)
const DeviceAddress sensorAddrs[N]
constexpr uint8_t get_pin() const
The pin of the bus.
constexpr TemperatureSensing(const uint8_t pin, const DeviceAddress(&ref)[N])
The sensors on pin, from their addresses.
constexpr uint8_t size() const
Number of sensors.
RotationGroups() -> RotationGroups< 0 >
Deduction guides: the number of groups is the number of lists.
constexpr BoostStart BEFORE_END(const Minutes m)
A start m before the end of the off-peak period.
constexpr uint8_t REMOTE_PIN_BASE
Base value for virtual pins representing remote loads.
constexpr BoostLength FOR(const Minutes m)
A boost lasting m.
constexpr uint8_t ALL_REMOTE_LOADS()
Every remote load.
constexpr uint8_t LOCAL_LOAD(const uint8_t loadNum)
Same as LOAD(), for a load known to be local.
constexpr BoostWindow FIRST(const Minutes d)
The first d of the off-peak period.
constexpr uint8_t ALL_RELAYS()
Every relay (none without relay diversion).
PinList< 16 > RotationGroupTargets
constexpr BoostWindow LAST(const Minutes d)
The last d of the off-peak period, until the end.
constexpr BoostStart FROM_START(const Minutes m)
A start m after the beginning of the off-peak period.
constexpr uint8_t REMOTE_MASK_BITS
constexpr uint16_t UNTIL_THE_END
The length of a boost that only the meter ends: the end of the off-peak period stops it anyway.
constexpr uint8_t ALL_LOCAL_LOADS()
Every local load.
RelayEngine(const RelaySetting(&)[N]) -> RelayEngine< N, 10 >
Deduction guide: the default sliding average.
constexpr uint8_t RELAY(const uint8_t relayNum)
Relay relayNum of relays (0, no relay, if out of range or without relay diversion).
constexpr uint8_t ALL_LOADS()
Every load, local and remote.
OverridePins(const KeyIndexPair< MaxPins >(&)[N]) -> OverridePins< N, MaxPins >
Deduction guide: N and MaxPins from the list.
ScheduledBoosts() -> ScheduledBoosts< 0 >
Deduction guide: no argument, no boost.
constexpr uint8_t LOAD(const uint8_t loadNum)
Load loadNum of physicalLoadPin[], local or remote (0, no load, if out of range).
constexpr uint8_t ALL_LOADS_AND_RELAYS()
Every load and every relay.
constexpr uint8_t LOCAL_MASK_BITS
typename make_index_sequence_impl< N >::type make_index_sequence
index_sequence< 0, 1, ..., N - 1 >.
Encoding of the load map: one packed byte per dump load.
The codes LOAD(), RELAY() and ALL_...() put in a target list.
constexpr uint8_t MAX_LOCAL_LOADS
constexpr uint8_t MAX_LOADS
constexpr uint8_t ALL_LOADS
constexpr uint8_t ALL_LOCAL_LOADS
constexpr uint8_t MAX_RELAYS
constexpr uint8_t ALL_REMOTE_LOADS
constexpr uint8_t ALL_RELAYS
constexpr uint8_t ALL_LOADS_AND_RELAYS
constexpr uint8_t LOCAL_LOAD
When a set of loads is boosted: a window and the targets.
constexpr BoostEntry(const BoostStart &s, const PinList< MaxPins > &t)
A boost from s until the end of the off-peak period.
constexpr BoostEntry(const BoostStart &s, const BoostLength &l, const PinList< MaxPins > &t)
A boost from s, lasting l.
constexpr BoostEntry(const BoostWindow &w, const PinList< MaxPins > &t)
A boost with its window and targets.
PinList< MaxPins > targets
How long a boost lasts, in minutes, or UNTIL_THE_END.
Where a boost starts: minutes after the start of the off-peak period, or before its end if fromEnd.
When a load is boosted during the off-peak period.
Structure representing the address of a device.
Structure holding a pin and its associated index list.
constexpr uint16_t getLocalBitmask() const
Returns the bitmask for local pins in the index list.
PinList< MaxPins > indexList
constexpr KeyIndexPair(uint8_t k, const PinList< MaxPins > &list)
Constructor.
constexpr uint8_t getRemoteBitmask() const
Returns the bitmask for remote loads in the index list.
A number of minutes: the unit of the scheduled boosts, built with HOURS() or MINUTES().
constexpr Minutes(integral_constant< uint16_t, V >)
From MINUTES() or HOURS() (type_traits.hpp), the same macros as for the relays.
constexpr Minutes(const uint16_t v)
v minutes: explicit, so that a bare number is not taken for a duration.
Wrapper for a list of pins, constructible from variadic arguments.
constexpr uint16_t toLocalBitmask() const
Converts the pin list to a bitmask for local/physical pins only.
constexpr PinList(uint32_t bitmask)
Constructor from combined bitmask. Extracts both local and remote pins.
constexpr PinList()
Default constructor. Initializes with zero pins.
constexpr uint8_t toRemoteBitmask() const
Converts the pin list to a bitmask for remote loads only.
constexpr PinList(uint16_t bitmask)
Constructor from local-only bitmask.
constexpr PinList(Args... args)
Variadic constructor. Initializes with provided pins.
The settings of one relay, as in config.h: { pin, surplus, import, minON, minOFF }...
constexpr RelaySetting(const uint8_t p, const int16_t surplus=1000, const int16_t import=200, const uint16_t on=5, const uint16_t off=5)
A relay on p; what is left out takes its default.
PinList< MaxPins > groups[10]
The indexes I..., as a type.
Some useful but missing stl functions templates.
#define MINUTES(value)
A compile-time number of minutes, as an integral_constant.
Bit manipulation utility functions.
constexpr uint8_t unused_pin