31#ifndef UTILS_OVERRIDE_H
32#define UTILS_OVERRIDE_H
54constexpr uint8_t
overridePinOf(
const uint8_t (&loadMap)[N], uint8_t loadNum)
68 for (
const auto& entry : loadMap)
100template< uint8_t... Pins >
110#define VALIDATE_PINS(...) static_assert(are_pins_valid< __VA_ARGS__ >(), "Invalid pin(s) specified")
117template< uint8_t... Pins >
120 return ((1U << Pins) | ...);
136template< u
int8_t NL, u
int8_t NR, u
int8_t D >
151 constexpr uint8_t
pinOf(
const uint8_t code)
const
172 static constexpr bool isGroup(
const uint8_t code)
198 template< u
int8_t MaxPins >
201 uint16_t result{ 0 };
202 for (uint8_t
i = 0;
i < targets.
count; ++
i)
204 const uint8_t code{ targets.
pins[
i] };
211 template< u
int8_t MaxPins >
215 for (uint8_t
i = 0;
i < targets.
count; ++
i)
217 const uint8_t code{ targets.
pins[
i] };
230 for (uint8_t
i = 0;
i < NR; ++
i)
254template< u
int8_t N, u
int8_t MaxPins = 16 >
288 for (uint8_t
i = 0;
i < N; ++
i)
290 temp[
i] = { pairs[
i].pin, pairs[
i].getLocalBitmask(), pairs[
i].getRemoteBitmask() };
292 for (uint8_t
i = 0;
i < N; ++
i)
304 template<
typename Map >
309 for (uint8_t
i = 0;
i < N; ++
i)
313 for (uint8_t
i = 0;
i < N; ++
i)
333 constexpr uint8_t
getPin(uint8_t index)
const
335 return index < N ?
entries_[index].pin : 0;
345 return index < N ?
entries_[index].localBitmask : 0;
355 return index < N ?
entries_[index].remoteBitmask : 0;
365 for (uint8_t
i = 0;
i < N; ++
i)
382 for (uint8_t
i = 0;
i < N; ++
i)
398 void printOverrideConfig()
const
400 infoln(F(
"*** Override Pins Configuration ***"));
401 for (uint8_t
i = 0;
i < N; ++
i)
405 info(F(
"\tLocal: 0b"));
407 info(F(
"\tRemote: 0b"));
418template< u
int8_t MaxPins, u
int8_t N >
The override pins, as in config.h: each pin with the targets it forces.
constexpr uint8_t getPin(const uint8_t index) const
The override pin at index (0 if out of range).
constexpr const PinList< MaxPins > & getTargets(const uint8_t index) const
The targets of the override pin at index, as codes.
Manages override pins and their associated bitmasks for forced operation.
constexpr uint8_t findRemoteBitmask(uint8_t pin) const
Finds the remote bitmask associated with a given pin number.
constexpr uint8_t getRemoteBitmask(uint8_t index) const
Returns the remote bitmask for the specified entry index.
constexpr OverrideTable(const KeyIndexPair< MaxPins >(&pairs)[N])
Constructor. Initializes the override pin mapping from pin-index pairs.
constexpr uint8_t getPin(uint8_t index) const
Returns the pin number at the specified entry index.
constexpr uint16_t getLocalBitmask(uint8_t index) const
Returns the local bitmask for the specified entry index.
constexpr uint16_t findLocalBitmask(uint8_t pin) const
Finds the local bitmask associated with a given pin number.
constexpr uint8_t size() const
Returns the number of override pin entries.
constexpr OverrideTable(const OverridePins< N, MaxPins > &pins, const Map &map)
Constructor. The override pins of config.h, their codes turned into pins by map.
const uint8_t(& loadMap_)[NL]
constexpr uint8_t pinOf(const uint8_t code) const
The pin that a single code stands for (any code but ALL_...()).
constexpr TargetMap(const uint8_t(&loadMap)[NL], const RelayEngine< NR, D > &relays, const bool relayDiversion)
constexpr uint8_t remoteBitmask(const PinList< MaxPins > &targets) const
The remote loads that targets force, as a bitmask (bit 0 = remote load 0).
const RelayEngine< NR, D > & relays_
static constexpr bool isGroup(const uint8_t code)
Whether code is one of ALL_...(): several pins.
constexpr uint32_t groupMask(const uint8_t code) const
The pins of an ALL_...() code: local pins in the lower 16 bits, remote loads from bit 16.
constexpr uint32_t relaysMask() const
The pins of the relays, none without relay diversion.
constexpr uint16_t localBitmask(const PinList< MaxPins > &targets) const
The local loads and relays that targets force, as a bitmask of pins.
const bool relayDiversion_
constexpr RelayEngine relays
What config.h is written with: its types, constants and helpers.
constexpr uint8_t REMOTE_PIN_BASE
Base value for virtual pins representing remote loads.
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.
void info(const Args &... args)
Print an informational message, as Serial.print() does.
Encoding of the load map: one packed byte per dump load.
constexpr bool isLocal(uint8_t entry)
True if the entry describes a locally driven load.
constexpr uint8_t remoteOrdinal(const uint8_t(&map)[N], uint8_t loadNum)
Rank of a remote load among the remote loads, in ascending map order.
constexpr uint8_t pinOf(uint8_t entry)
The pin of the entry: TRIAC pin if local, status LED (0 = none) if remote.
constexpr uint8_t countRemoteLoads(const uint8_t(&map)[N])
Number of entries of the map that are driven remotely.
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
Structure holding a pin and its associated index list.
Internal structure representing a pin and its associated bitmasks.
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 uint8_t toRemoteBitmask() const
Converts the pin list to a bitmask for remote loads only.
Some useful but missing stl functions templates.
Bit manipulation utility functions.
constexpr void bit_set(T &_dest, const uint8_t bit)
Set the specified bit to 1.
constexpr uint32_t remoteLoadsMask(const uint8_t(&loadMap)[N])
Bitmask of every remote load (bit 16 + remote rank).
constexpr uint16_t validPinMask
constexpr bool are_pins_valid()
Compile-time validation function for pin values.
constexpr uint16_t indicesToBitmask()
Helper to convert pins to a bitmask at compile-time.
OverrideTable(const KeyIndexPair< MaxPins >(&)[N]) -> OverrideTable< N, MaxPins >
Deduction guide for OverrideTable, from plain pins. Allows template argument deduction from construct...
constexpr uint8_t overridePinOf(const uint8_t(&loadMap)[N], uint8_t loadNum)
Override pin of a load: its physical pin if local, a virtual pin if remote.
constexpr uint32_t localLoadsMask(const uint8_t(&loadMap)[N])
Bitmask of the pins of every local load (lower 16 bits).