38#ifndef LOAD_PRIORITIES_H
39#define LOAD_PRIORITIES_H
56__attribute__((always_inline))
inline uint8_t
nextToAdd(
const uint8_t (&priorities)[N])
58 for (uint8_t index = 0; index < N; ++index)
75__attribute__((always_inline))
inline uint8_t
nextToRemove(
const uint8_t (&priorities)[N])
97__attribute__((always_inline))
inline void rotate(uint8_t (&priorities)[N])
101 uint8_t
i{
static_cast< uint8_t
>(N - 1) };
102 const auto temp{ priorities[
i] };
105 priorities[
i] = priorities[
i - 1];
108 priorities[0] = temp;
122template<
bool CALIBRATION, u
int8_t N,
typename IsOverr
idden >
123__attribute__((always_inline))
inline void toPhysical(
const uint8_t (&priorities)[N],
LoadStates (&physical)[N],
124 const bool diversionEnabled, IsOverridden isOverridden)
132 const bool bOn{ isOverridden(iLoad) || (diversionEnabled && (priorities[idx] &
loadStateOnBit)) };
173 __attribute__((noinline))
void onNewCycle(uint8_t (&priorities)[N],
const int32_t& energy,
const Bucket& bucket)
209 __attribute__((always_inline))
inline void onHighEnergy(uint8_t (&priorities)[N],
const int32_t& energy,
const int32_t capacity)
211 const auto tempLoad{
nextToAdd(priorities) };
218 bool bOK_toAddLoad{
true };
251 __attribute__((always_inline))
inline void onLowEnergy(uint8_t (&priorities)[N],
const int32_t& energy)
260 bool bOK_toRemoveLoad{
true };
278 if (bOK_toRemoveLoad)
Encoding of the load map: one packed byte per dump load.
constexpr uint8_t loadStateMask
constexpr uint8_t loadStateOnBit
uint8_t nextToRemove(const uint8_t(&priorities)[N])
The next logical load to switch OFF: the last one ON, in priority order.
uint8_t nextToAdd(const uint8_t(&priorities)[N])
The next logical load to switch ON: the first one OFF, in priority order.
void toPhysical(const uint8_t(&priorities)[N], LoadStates(&physical)[N], const bool diversionEnabled, IsOverridden isOverridden)
Maps the logical load states to the physical ones.
void rotate(uint8_t(&priorities)[N])
Rotates the priorities by one: the last load becomes the first, the others move down one place....
The fixed levels of the energy bucket, in bucket units.
The switching decision, once per mains cycle, and its state.
static constexpr uint8_t POST_TRANSITION_MAX_COUNT
void onNewCycle(uint8_t(&priorities)[N], const int32_t &energy, const Bucket &bucket)
The decision of one mains cycle: may switch one load ON or OFF.
void onLowEnergy(uint8_t(&priorities)[N], const int32_t &energy)
The energy level is low: may switch the last load ON to OFF.
uint8_t postTransitionCount
void onHighEnergy(uint8_t(&priorities)[N], const int32_t &energy, const int32_t capacity)
The energy level is high: may switch the next load ON.