21#ifndef LSHCORE_PERIPHERALS_INPUT_CLICKABLE_HPP
22#define LSHCORE_PERIPHERALS_INPUT_CLICKABLE_HPP
24#include <etl/vector.h>
43 enum class State : uint8_t
55 enum class ActionFired : uint8_t
64 struct ClickableConfigFlags
66 uint8_t isShortClickable : 1 =
true;
67 uint8_t isLongClickable : 1 =
false;
68 uint8_t isSuperLongClickable : 1 =
false;
69 uint8_t isNetworkLongClickable : 1 =
false;
70 uint8_t isNetworkSuperLongClickable : 1 =
false;
71 uint8_t isQuickClickable : 1 =
false;
72 uint8_t isValid : 1 =
false;
73 uint8_t isChecked : 1 =
false;
77 ClickableConfigFlags configFlags;
79#ifndef CONFIG_USE_FAST_CLICKABLES
80 const uint8_t pinNumber;
82 const uint8_t pinMask;
83 const volatile uint8_t *
const pinPort;
89 State currentState = State::IDLE;
90 uint32_t stateChangeTime = 0U;
91 ActionFired lastActionFired = ActionFired::NONE;
94 uint16_t longClick_ms = constants::timings::CLICKABLE_LONG_CLICK_TIME_MS;
95 uint16_t superLongClick_ms = constants::timings::CLICKABLE_SUPER_LONG_CLICK_TIME_MS;
97 uint8_t
debounce_ms = constants::timings::CLICKABLE_DEBOUNCE_TIME_MS;
108 etl::vector<uint8_t, CONFIG_MAX_ACTUATORS> actuatorsShort{};
109 etl::vector<uint8_t, CONFIG_MAX_ACTUATORS> actuatorsLong{};
110 etl::vector<uint8_t, CONFIG_MAX_ACTUATORS> actuatorsSuperLong{};
113#ifndef CONFIG_USE_FAST_CLICKABLES
120 explicit constexpr Clickable(uint8_t pin, uint8_t uniqueId) noexcept : pinNumber(pin), id(uniqueId) {}
128 explicit Clickable(uint8_t pin, uint8_t uniqueId) noexcept : pinMask(digitalPinToBitMask(pin)), pinPort(portInputRegister(digitalPinToPort(pin))), id(uniqueId) {}
132#if (__cplusplus >= 201703L) && (__GNUC__ >= 7)
147#ifdef CONFIG_USE_FAST_CLICKABLES
148 return (*this->pinPort & this->pinMask) != 0U;
150 return (
static_cast<bool>(digitalRead(this->pinNumber)));
160 bool networkClickable =
false,
164 bool networkClickable =
false,
179 [[nodiscard]]
auto getIndex() const -> uint8_t;
180 [[nodiscard]] auto
getId() const -> uint8_t;
181 [[nodiscard]] auto
getActuators(
constants::ClickType actuatorType) const -> const etl::ivector<uint8_t> *;
189 auto
check() ->
bool;
190 [[nodiscard]] auto
shortClick() const ->
bool;
191 [[nodiscard]] auto
longClick() const ->
bool;
A class that represents a clickable object, like a button, and its associated logic.
Definition clickable.hpp:37
auto getActuators(constants::ClickType actuatorType) const -> const etl::ivector< uint8_t > *
Get the const vector of attached actuators.
Definition clickable.cpp:213
uint8_t debounce_ms
Debounce time in ms.
Definition clickable.hpp:97
auto setClickableSuperLong(bool superLongClickable, constants::SuperLongClickType clickType=constants::SuperLongClickType::NORMAL, bool networkClickable=false, constants::NoNetworkClickType fallback=constants::NoNetworkClickType::LOCAL_FALLBACK) -> Clickable &
Set clickable super long clickability locally and over network.
Definition clickable.cpp:80
auto longClick() const -> bool
Perform a long click action.
Definition clickable.cpp:372
auto setClickableLong(bool longClickable, constants::LongClickType clickType=constants::LongClickType::NORMAL, bool networkClickable=false, constants::NoNetworkClickType fallback=constants::NoNetworkClickType::LOCAL_FALLBACK) -> Clickable &
Set clickable long clickability locally and over network.
Definition clickable.cpp:62
auto isNetworkClickable(constants::ClickType clickType) const -> bool
Get if the clickable performs network clicks.
Definition clickable.cpp:266
auto setClickableShort(bool shortClickable) -> Clickable &
Set clickable short clickability.
Definition clickable.cpp:47
auto getId() const -> uint8_t
Get the unique ID of the clickable.
Definition clickable.cpp:202
constexpr Clickable(uint8_t pin, uint8_t uniqueId) noexcept
Construct a new Clickable object, conventional IO version.
Definition clickable.hpp:120
void setIndex(uint8_t indexToSet)
Store the Clickable index on Clickables namespace Array.
Definition clickable.cpp:36
auto addActuatorLong(uint8_t actuatorIndex) -> Clickable &
Add a long click actuator.
Definition clickable.cpp:133
auto getSuperLongClickType() const -> constants::SuperLongClickType
Get the type of super long click.
Definition clickable.cpp:304
auto setSuperLongClickTime(uint16_t timeToSet_ms) -> Clickable &
Set super long click time.
Definition clickable.cpp:181
auto setDebounceTime(uint8_t timeToSet_ms) -> Clickable &
Set debounce time.
Definition clickable.cpp:157
auto addActuatorSuperLong(uint8_t actuatorIndex) -> Clickable &
Add a super long click actuator.
Definition clickable.cpp:145
auto setLongClickTime(uint16_t timeToSet_ms) -> Clickable &
Set long click time.
Definition clickable.cpp:169
auto shortClick() const -> bool
Perform a short click action.
Definition clickable.cpp:345
auto clickDetection() -> constants::ClickResult
Perform the clickable state detection.
Definition clickable.cpp:452
auto addActuatorShort(uint8_t actuatorIndex) -> Clickable &
Add a short click actuator.
Definition clickable.cpp:121
auto superLongClickSelective() const -> bool
Perform a super long click selective action.
Definition clickable.cpp:428
auto getIndex() const -> uint8_t
Get the Clickable index on Clickables namespace Array.
Definition clickable.cpp:192
auto getNetworkFallback(constants::ClickType clickType) const -> constants::NoNetworkClickType
Get the fallback type for a network click type.
Definition clickable.cpp:285
auto getTotalActuators(constants::ClickType actuatorType) const -> uint8_t
Get the number of attached actuators of one kind.
Definition clickable.cpp:234
auto getState() const -> bool
Get the state of the clickable if configured as INPUT with its external pulldown resistor (PIN -> BUT...
Definition clickable.hpp:145
auto check() -> bool
Validates the clickable's configuration.
Definition clickable.cpp:318
auto getLongClickType() const -> constants::LongClickType
Get the type of long click.
Definition clickable.cpp:254
auto addActuator(uint8_t actuatorIndex, constants::ClickType actuatorType) -> Clickable &
Add an actuator to a list of actuators controlled by the clickable.
Definition clickable.cpp:96
Defines the ClickResult enum for the clickable state machine.
Defines enums for various click types and fallback behaviors.
namespace for constants.
Definition config.hpp:33
SuperLongClickType
Super long click behaviors.
Definition clicktypes.hpp:60
@ NORMAL
Turns off all controllino unprotected actuators.
@ NONE
Never use this, it's just a default parameter.
LongClickType
Long click behaviors.
Definition clicktypes.hpp:48
@ NORMAL
Turns on or off secondary attached actuators based on how many are on or off.
@ NONE
Never use this, it's just a default parameter.
NoNetworkClickType
Fallback for a network click that expired or receives a failover.
Definition clicktypes.hpp:71
@ LOCAL_FALLBACK
Apply local logic.
@ NONE
Never use this, it's just a default parameter.
ClickType
Clickable (like button) click types.
Definition clicktypes.hpp:36
Centralizes all build-time configurable timing constants for the framework.
Internal bridge that imports user-defined macros into the library's scope.