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
87 inline void setState(bool stateToSet)
88 {
89#ifdef CONFIG_USE_FAST_INDICATORS
90 if (!stateToSet)
91 {
92 *this->pinPort &= ~this->pinMask;
93 }
94 else
95 {
96 *this->pinPort |= this->pinMask;
97 }
98#else
99 digitalWrite(this->pinNumber, static_cast<uint8_t>(stateToSet));
100#endif
101 }
102 void setIndex(uint8_t indexToSet); // Set the indicator index on Indicators namespace Array
103 auto addActuator(uint8_t actuatorIndex) -> Indicator &; // Add one actuator to controlled actuators vector
104 auto setMode(constants::IndicatorMode indicatorMode) -> Indicator &; // Set indicator mode
105 void check(); // Perform the actual check
106
107 [[nodiscard]] auto getIndex() const -> uint8_t; // Get the indicator index on Indicators namespace Array
108};
109
110#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:43
auto setMode(constants::IndicatorMode indicatorMode) -> Indicator &
Set the mode of the indicator.
Definition indicator.cpp:55
void setIndex(uint8_t indexToSet)
Set the indicator index on Indicators namespace Array.
Definition indicator.cpp:32
auto getIndex() const -> uint8_t
Get the indicator index on Indicators namespace Array.
Definition indicator.cpp:154
void setState(bool stateToSet)
Set the state of the indicator.
Definition indicator.hpp:87
void check()
Switch the indicator based on controlled actuators status.
Definition indicator.cpp:81
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.