LSH-Core
A robust C++ framework for Arduino-based home automation nodes
Loading...
Searching...
No Matches
indicator.hpp
Go to the documentation of this file.
1
21#ifndef LSHCORE_PERIPHERALS_OUTPUT_INDICATOR_HPP
22#define LSHCORE_PERIPHERALS_OUTPUT_INDICATOR_HPP
23
24#include <etl/vector.h>
25#include <stdint.h>
26
29
35{
36private:
37#ifndef CONFIG_USE_FAST_INDICATORS
38 const uint8_t pinNumber;
39#else
40 const uint8_t pinMask;
41 volatile uint8_t *const pinPort;
42#endif
43 uint8_t index = 0U;
45 etl::vector<uint8_t, CONFIG_MAX_ACTUATORS> controlledActuators{};
46 bool actualState = false;
47
48public:
49#ifndef CONFIG_USE_FAST_INDICATORS
54 explicit constexpr Indicator(uint8_t pin) noexcept : pinNumber(pin)
55 {
56 pinMode(pin, OUTPUT); // PinMode to Output
57 }
58#else
63 explicit Indicator(uint8_t pin) noexcept : pinMask(digitalPinToBitMask(pin)), pinPort(portOutputRegister(digitalPinToPort(pin)))
64 {
65 // PinMode to OUTPUT
66 uint8_t port = digitalPinToPort(pin);
67 volatile uint8_t *const reg = portModeRegister(port);
68 const uint8_t oldSREG = SREG;
69 cli();
70 *reg |= this->pinMask;
71 SREG = oldSREG;
72 }
73#endif
74
75#if (__cplusplus >= 201703L) && (__GNUC__ >= 7)
76 Indicator(const Indicator &) = delete;
77 Indicator(Indicator &&) = delete;
78 auto operator=(const Indicator &) -> Indicator & = delete;
79 auto operator=(Indicator &&) -> Indicator & = delete;
80#endif // (__cplusplus >= 201703L) && (__GNUC__ >= 7)
81
82 void setState(bool stateToSet); // Set the new state
83 void setIndex(uint8_t indexToSet); // Set the indicator index on Indicators namespace Array
84 auto addActuator(uint8_t actuatorIndex) -> Indicator &; // Add one actuator to controlled actuators vector
85 auto setMode(constants::IndicatorMode indicatorMode) -> Indicator &; // Set indicator mode
86 void check(); // Perform the actual check
87 void resizeVectors(); // Resize controlled actuators vector to its actual size.
88 [[nodiscard]] auto getIndex() const -> uint8_t; // Get the indicator index on Indicators namespace Array
89};
90
91#endif // LSHCORE_PERIPHERALS_OUTPUT_INDICATOR_HPP
Represents a state indicator for one or more attached actuators, indicators are normally connected to...
Definition indicator.hpp:35
constexpr Indicator(uint8_t pin) noexcept
Construct a new Indicator object using standard I/O.
Definition indicator.hpp:54
auto addActuator(uint8_t actuatorIndex) -> Indicator &
Add one actuator to controlled controlledActuators vector.
Definition indicator.cpp:62
auto setMode(constants::IndicatorMode indicatorMode) -> Indicator &
Set the mode of the indicator.
Definition indicator.cpp:74
void setIndex(uint8_t indexToSet)
Set the indicator index on Indicators namespace Array.
Definition indicator.cpp:51
void resizeVectors()
Resize controlled actuators vector to its actual size.
Definition indicator.cpp:170
auto getIndex() const -> uint8_t
Get the indicator index on Indicators namespace Array.
Definition indicator.cpp:180
void setState(bool stateToSet)
Set the state of the indicator.
Definition indicator.cpp:30
void check()
Switch the indicator based on controlled actuators status.
Definition indicator.cpp:100
Defines the IndicatorMode enum for indicator light behavior.
IndicatorMode
Indicator mode for an indicator.
Definition indicatormodes.hpp:36
@ ANY
If any controlled actuators is ON turn on the indicator.
Internal bridge that imports user-defined macros into the library's scope.