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 getActuator(uint8_t actuatorId) -> Actuator *; // Returns a single actuator, or nullptr if the ID is unknown
57[[nodiscard]] auto getIndex(uint8_t actuatorId) -> uint8_t; // Returns a single actuator index, or UINT8_MAX if the ID is unknown
58[[nodiscard]] auto tryGetIndex(uint8_t actuatorId, uint8_t &actuatorIndex)
59 -> bool; // Returns true and writes the actuator index when the ID exists
60[[nodiscard]] auto actuatorExists(uint8_t actuatorId) -> bool; // Returns true if actuator exists
61void recordSwitchTime(uint8_t actuatorIndex, uint32_t now_ms); // Records a state-change time for compact actuator timer storage.
62#if CONFIG_USE_COMPACT_ACTUATOR_SWITCH_TIMES && LSH_STATIC_CONFIG_AUTO_OFF_ACTUATORS > 0
63[[nodiscard]] auto checkCompactAutoOffTimer(uint8_t autoOffIndex,
64 uint8_t actuatorIndex,
65 Actuator &actuator,
66 uint32_t now_ms,
67 uint32_t timer_ms) -> bool; // Checks one generated compact auto-off entry.
68#endif
69
76void updatePackedState(uint8_t actuatorIndex, bool state);
77
89template <uint8_t ActuatorIndex> __attribute__((always_inline)) inline void updatePackedStateStatic(bool state)
90{
91 static_assert(ActuatorIndex < CONFIG_MAX_ACTUATORS, "ActuatorIndex is outside the generated static profile.");
92 constexpr uint8_t byteIndex = static_cast<uint8_t>(ActuatorIndex >> 3U);
93 constexpr uint8_t bitMask = static_cast<uint8_t>(1U << (ActuatorIndex & 0x07U));
94 if (state)
95 {
96 packedActuatorStates[byteIndex] |= bitMask;
97 }
98 else
99 {
100 packedActuatorStates[byteIndex] &= static_cast<uint8_t>(~bitMask);
101 }
102}
103
109[[nodiscard]] auto getPackedStateByteCount() -> uint8_t;
110
117[[nodiscard]] auto getPackedStateByte(uint8_t byteIndex) -> uint8_t;
118
119void finalizeSetup(); // Final validation pass after configuration registration.
120} // namespace Actuators
121
122#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:124
__attribute__((always_inline)) inline void updatePackedStateStatic(bool state)
Keep the packed actuator-state shadow aligned using a generated index.
Definition actuator_manager.hpp:89
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:106
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:155
auto actuatorExists(uint8_t actuatorId) -> bool
Get if the actuator actually exists.
Definition actuator_manager.cpp:142
auto getActuator(uint8_t actuatorId) -> Actuator *
Get a single actuator.
Definition actuator_manager.cpp:84
void finalizeSetup()
Final validation after actuator registration.
Definition actuator_manager.cpp:253
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:228
void updatePackedState(uint8_t actuatorIndex, bool state)
Keep the compact actuator-state shadow aligned with one runtime state change.
Definition actuator_manager.cpp:204
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:239
Internal bridge that imports static profile resources into the library's scope.