21#ifndef ROTATION_GROUPS_H
22#define ROTATION_GROUPS_H
35 for (; mask; mask &= mask - 1)
55constexpr uint32_t
loadsOf(
const uint8_t code,
const uint8_t (&loadMap)[NL])
57 static_assert(NL <= 32,
"the load numbers of the rotation groups fit 32 bits");
62 return loadNum < NL ? (1UL << loadNum) : 0;
67 return loadNum < NL &&
Load::isLocal(loadMap[loadNum]) ? (1UL << loadNum) : 0;
77 for (uint8_t
i = 0;
i != NL; ++
i)
95 for (uint8_t
i = 0;
i != NL; ++
i)
105 for (uint8_t
i = 0;
i != NL; ++
i)
116template< u
int8_t NG, u
int8_t MaxPins, u
int8_t NL >
120 const auto& targets = groups.
getGroup(g);
121 for (uint8_t
i = 0;
i != targets.count; ++
i)
123 loads |=
loadsOf(targets.pins[
i], loadMap);
129template< u
int8_t NG, u
int8_t MaxPins, u
int8_t NL >
132 for (uint8_t g = 0; g != groups.
size(); ++g)
134 const auto& targets = groups.
getGroup(g);
135 for (uint8_t
i = 0;
i != targets.count; ++
i)
137 if (!
loadsOf(targets.pins[
i], loadMap))
147template< u
int8_t NG, u
int8_t MaxPins, u
int8_t NL >
150 for (uint8_t g = 0; g != groups.
size(); ++g)
161template< u
int8_t NG, u
int8_t MaxPins, u
int8_t NL >
165 for (uint8_t g = 0; g != groups.
size(); ++g)
167 const auto& targets = groups.
getGroup(g);
168 for (uint8_t
i = 0;
i != targets.count; ++
i)
170 const uint32_t loads =
loadsOf(targets.pins[
i], loadMap);
182template< u
int8_t NG, u
int8_t MaxPins, u
int8_t NL >
185 for (uint8_t g = 0; g != groups.
size(); ++g)
187 const uint32_t loads =
groupLoads(groups, g, loadMap);
190 for (uint8_t
i = 0;
i != NL; ++
i)
192 if (!(loads & (1UL <<
i)))
221template< u
int8_t NG, u
int8_t NL >
230 template< u
int8_t MaxPins >
235 for (uint8_t g = 0; g != NG; ++g)
238 for (uint8_t p = 0; p != NL; ++p)
240 if (priorities[p] < 32 && (
loads_[g] & (1UL << priorities[p])) && k < NL)
256 constexpr uint32_t
loads(
const uint8_t g)
const
262 template< u
int8_t N >
263 __attribute__((always_inline))
inline void rotate(uint8_t (&prio)[N])
const
266 for (uint8_t g = 0; g != NG; ++g)
268 const uint8_t end{
ends_[g] };
269 if (end - start >= 2)
271 const uint8_t last{ prio[
places_[end - 1]] };
272 for (uint8_t
i = end - 1;
i != start; --
i)
289template< u
int8_t NL >
293 template< u
int8_t MaxPins >
295 const uint8_t (& )[NL])
306 constexpr uint32_t
loads(uint8_t)
const
312 template< u
int8_t N >
319template< u
int8_t NG, u
int8_t MaxPins, u
int8_t NL >
The rotation groups, as in config.h: the loads that take turns at the top of the priority list,...
constexpr uint8_t size() const
Number of groups.
constexpr const PinList< MaxPins > & getGroup(const uint8_t index) const
The targets of group index, as codes.
void rotate(uint8_t(&)[N]) const
Nothing to rotate.
constexpr uint8_t size() const
Number of groups: none.
constexpr uint32_t loads(uint8_t) const
No loads: never called, there for the loops over size().
constexpr Table(const RotationGroups< 0, MaxPins > &, const uint8_t(&)[NL], const uint8_t(&)[NL])
The rotation groups, resolved: the priority places each group holds.
constexpr Table(const RotationGroups< NG, MaxPins > &groups, const uint8_t(&loadMap)[NL], const uint8_t(&priorities)[NL])
constexpr uint8_t size() const
Number of groups.
void rotate(uint8_t(&prio)[N]) const
Rotates each group by one among its places; each entry keeps its ON bit.
constexpr uint32_t loads(const uint8_t g) const
The loads of group g: bit n set for load n.
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.
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 pinOf(uint8_t entry)
The pin of the entry: TRIAC pin if local, status LED (0 = none) if remote.
constexpr uint8_t unitOf(uint8_t entry)
The owning unit of the entry: 0 for a local load, 1..3 for a remote one.
constexpr bool noLoadTwice(const RotationGroups< NG, MaxPins > &groups, const uint8_t(&loadMap)[NL])
No load is named twice, within a group or across groups.
constexpr bool targetsAreLoads(const RotationGroups< NG, MaxPins > &groups, const uint8_t(&loadMap)[NL])
Every code of every group stands for at least one load.
Table(const RotationGroups< NG, MaxPins > &, const uint8_t(&)[NL], const uint8_t(&)[NL]) -> Table< NG, NL >
Deduction guide: the groups and the loads from the arguments.
constexpr uint32_t loadsOf(const uint8_t code, const uint8_t(&loadMap)[NL])
The loads a target code stands for, by load number.
constexpr bool groupsHaveTwoLoads(const RotationGroups< NG, MaxPins > &groups, const uint8_t(&loadMap)[NL])
Every group holds at least 2 loads.
constexpr uint8_t countLoads(uint32_t mask)
Number of bits set in mask.
constexpr bool groupsAreConsistent(const RotationGroups< NG, MaxPins > &groups, const uint8_t(&loadMap)[NL])
In each group, every load is local, or every load is on the same remote unit.
constexpr uint32_t groupLoads(const RotationGroups< NG, MaxPins > &groups, const uint8_t g, const uint8_t(&loadMap)[NL])
The loads of group g, all its codes together.
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 LOCAL_LOAD