LSH-Core
Deterministic firmware core for Controllino-based Labo Smart Home nodes
 
Loading...
Searching...
No Matches
actuator_manager.hpp
Go to the documentation of this file.
1
21#ifndef LSH_CORE_DEVICE_ACTUATOR_MANAGER_HPP
22#define LSH_CORE_DEVICE_ACTUATOR_MANAGER_HPP
23
24#include <stdint.h>
25
28class Actuator;
29
34namespace Actuators
35{
42using PackedActuatorStateBytes = etl::array<uint8_t, CONFIG_PACKED_ACTUATOR_STATE_STORAGE_CAPACITY>;
43
44#if defined(LSH_DEBUG) || defined(LSH_STATIC_CONFIG_RUNTIME_CHECKS)
45extern etl::array<Actuator *, CONFIG_MAX_ACTUATORS> actuators;
46#endif
54
55[[nodiscard]] auto getId(uint8_t actuatorIndex) -> uint8_t; // Returns the static actuator ID for one dense runtime index
56[[nodiscard]] auto getIndex(uint8_t actuatorId) -> uint8_t; // Returns a single actuator index, or UINT8_MAX if the ID is unknown
57[[nodiscard]] auto tryGetIndex(uint8_t actuatorId, uint8_t &actuatorIndex)
58 -> bool; // Returns true and writes the actuator index when the ID exists
59[[nodiscard]] auto actuatorExists(uint8_t actuatorId) -> bool; // Returns true if actuator exists
60void recordSwitchTime(uint8_t actuatorIndex, uint32_t now_ms); // Records a state-change time for compact actuator timer storage.
61#if CONFIG_USE_COMPACT_ACTUATOR_SWITCH_TIMES && LSH_STATIC_CONFIG_AUTO_OFF_ACTUATORS > 0
62[[nodiscard]] auto checkCompactAutoOffTimer(uint8_t autoOffIndex,
63 uint8_t actuatorIndex,
64 Actuator &actuator,
65 uint32_t now_ms,
66 uint32_t timer_ms) -> bool; // Checks one generated compact auto-off entry.
67#endif
68
75void updatePackedState(uint8_t actuatorIndex, bool state);
76
88template <uint8_t ActuatorIndex> __attribute__((always_inline)) inline void updatePackedStateStatic(bool state)
89{
90 static_assert(ActuatorIndex < CONFIG_MAX_ACTUATORS, "ActuatorIndex is outside the generated static profile.");
91 constexpr uint8_t byteIndex = static_cast<uint8_t>(ActuatorIndex >> 3U);
92 constexpr uint8_t bitMask = static_cast<uint8_t>(1U << (ActuatorIndex & 0x07U));
93 if (state)
94 {
95 packedActuatorStates[byteIndex] |= bitMask;
96 }
97 else
98 {
99 packedActuatorStates[byteIndex] &= static_cast<uint8_t>(~bitMask);
100 }
101}
102
108[[nodiscard]] auto getPackedStateByteCount() -> uint8_t;
109
116[[nodiscard]] auto getPackedStateByte(uint8_t byteIndex) -> uint8_t;
117
118void finalizeSetup(); // Final validation pass after configuration registration.
119} // namespace Actuators
120
121#endif // LSH_CORE_DEVICE_ACTUATOR_MANAGER_HPP
Represents an actuator (relay) attached to a digital pin.
Definition actuator.hpp:53
Safe wrapper for ETL array with Arduino min/max macros neutralized locally.
Globally stores all actuators (relays) and to operates over them.
Definition actuator_manager.cpp:32
auto tryGetIndex(uint8_t actuatorId, uint8_t &actuatorIndex) -> bool
Resolves an actuator ID to its dense runtime index with a single map lookup.
Definition actuator_manager.cpp:102
__attribute__((always_inline)) inline void updatePackedStateStatic(bool state)
Keep the packed actuator-state shadow aligned using a generated index.
Definition actuator_manager.hpp:88
etl::array< uint8_t, CONFIG_PACKED_ACTUATOR_STATE_STORAGE_CAPACITY > PackedActuatorStateBytes
Compact shadow of the full actuator runtime state in protocol bit order.
Definition actuator_manager.hpp:42
auto getIndex(uint8_t actuatorId) -> uint8_t
Get a single actuator index (in device vector of actuators).
Definition actuator_manager.cpp:84
void recordSwitchTime(uint8_t actuatorIndex, uint32_t now_ms)
Records the latest switch time for an actuator when compact actuator timer storage is enabled.
Definition actuator_manager.cpp:133
auto actuatorExists(uint8_t actuatorId) -> bool
Get if the actuator actually exists.
Definition actuator_manager.cpp:120
void finalizeSetup()
Final validation after actuator registration.
Definition actuator_manager.cpp:231
auto getId(uint8_t actuatorIndex) -> uint8_t
Return the static wire ID for one registered actuator index.
Definition actuator_manager.cpp:72
auto getPackedStateByteCount() -> uint8_t
Return the number of packed bytes required by the current topology.
Definition actuator_manager.cpp:206
void updatePackedState(uint8_t actuatorIndex, bool state)
Keep the compact actuator-state shadow aligned with one runtime state change.
Definition actuator_manager.cpp:182
PackedActuatorStateBytes packedActuatorStates
Canonical packed actuator-state shadow kept in sync with Actuator::setState().
Definition actuator_manager.cpp:37
auto getPackedStateByte(uint8_t byteIndex) -> uint8_t
Return one packed state byte in protocol wire order.
Definition actuator_manager.cpp:217
Internal bridge that imports static profile resources into the library's scope.