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
63 struct ClickableConfigFlags
65 uint8_t isShortClickable : 1 =
true;
66 uint8_t isLongClickable : 1 =
false;
67 uint8_t isSuperLongClickable : 1 =
false;
68 uint8_t isNetworkLongClickable : 1 =
false;
69 uint8_t isNetworkSuperLongClickable : 1 =
false;
70 uint8_t isQuickClickable : 1 =
false;
71 uint8_t isValid : 1 =
false;
72 uint8_t isChecked : 1 =
false;
75#ifndef CONFIG_USE_FAST_CLICKABLES
76 const uint8_t pinNumber;
78 const uint8_t pinMask;
79 const volatile uint8_t *
const pinPort;
84 ClickableConfigFlags configFlags;
93 State currentState = State::IDLE;
94 uint32_t stateChangeTime = 0U;
95 ActionFired lastActionFired = ActionFired::NONE;
98 etl::vector<uint8_t, CONFIG_MAX_ACTUATORS> actuatorsShort{};
99 etl::vector<uint8_t, CONFIG_MAX_ACTUATORS> actuatorsLong{};
100 etl::vector<uint8_t, CONFIG_MAX_ACTUATORS> actuatorsSuperLong{};
103 uint16_t longClick_ms = constants::timings::CLICKABLE_LONG_CLICK_TIME_MS;
104 uint16_t superLongClick_ms = constants::timings::CLICKABLE_SUPER_LONG_CLICK_TIME_MS;
107 uint8_t
debounce_ms = constants::timings::CLICKABLE_DEBOUNCE_TIME_MS;
110#ifndef CONFIG_USE_FAST_CLICKABLES
117 explicit constexpr Clickable(uint8_t pin, uint8_t uniqueId) noexcept : pinNumber(pin), id(uniqueId) {}
125 explicit Clickable(uint8_t pin, uint8_t uniqueId) noexcept : pinMask(digitalPinToBitMask(pin)), pinPort(portInputRegister(digitalPinToPort(pin))), id(uniqueId) {}
129#if (__cplusplus >= 201703L) && (__GNUC__ >= 7)
136 [[nodiscard]]
auto getState() -> bool;
144 bool networkClickable =
false,
148 bool networkClickable =
false,
163 [[nodiscard]]
auto getIndex() const -> uint8_t;
164 [[nodiscard]] auto
getId() const -> uint8_t;
165 [[nodiscard]] auto
getActuators(
constants::ClickType actuatorType) const -> const etl::ivector<uint8_t> *;
173 auto
check() ->
bool;
174 [[nodiscard]] auto
shortClick() const ->
bool;
175 [[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:226
uint8_t debounce_ms
Debounce time in ms.
Definition clickable.hpp:107
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:93
auto longClick() const -> bool
Perform a long click action.
Definition clickable.cpp:385
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:75
auto isNetworkClickable(constants::ClickType clickType) const -> bool
Get if the clickable performs network clicks.
Definition clickable.cpp:279
auto setClickableShort(bool shortClickable) -> Clickable &
Set clickable short clickability.
Definition clickable.cpp:60
auto getState() -> bool
Get the state of the clickable if configured as INPUT with its external pulldown resistor (PIN -> BUT...
Definition clickable.cpp:35
auto getId() const -> uint8_t
Get the unique ID of the clickable.
Definition clickable.cpp:215
constexpr Clickable(uint8_t pin, uint8_t uniqueId) noexcept
Construct a new Clickable object, conventional IO version.
Definition clickable.hpp:117
void setIndex(uint8_t indexToSet)
Store the Clickable index on Clickables namespace Array.
Definition clickable.cpp:49
auto addActuatorLong(uint8_t actuatorIndex) -> Clickable &
Add a long click actuator.
Definition clickable.cpp:146
auto getSuperLongClickType() const -> constants::SuperLongClickType
Get the type of super long click.
Definition clickable.cpp:317
auto setSuperLongClickTime(uint16_t timeToSet_ms) -> Clickable &
Set super long click time.
Definition clickable.cpp:194
auto setDebounceTime(uint8_t timeToSet_ms) -> Clickable &
Set debounce time.
Definition clickable.cpp:170
auto addActuatorSuperLong(uint8_t actuatorIndex) -> Clickable &
Add a super long click actuator.
Definition clickable.cpp:158
auto setLongClickTime(uint16_t timeToSet_ms) -> Clickable &
Set long click time.
Definition clickable.cpp:182
auto shortClick() const -> bool
Perform a short click action.
Definition clickable.cpp:358
auto clickDetection() -> constants::ClickResult
Perform the clickable state detection.
Definition clickable.cpp:465
auto addActuatorShort(uint8_t actuatorIndex) -> Clickable &
Add a short click actuator.
Definition clickable.cpp:134
void resizeVectors()
Resize vectors to actual needed size.
Definition clickable.cpp:569
auto superLongClickSelective() const -> bool
Perform a super long click selective action.
Definition clickable.cpp:441
auto getIndex() const -> uint8_t
Get the Clickable index on Clickables namespace Array.
Definition clickable.cpp:205
auto getNetworkFallback(constants::ClickType clickType) const -> constants::NoNetworkClickType
Get the fallback type for a network click type.
Definition clickable.cpp:298
auto getTotalActuators(constants::ClickType actuatorType) const -> uint8_t
Get the number of attached actuators of one kind.
Definition clickable.cpp:247
auto check() -> bool
Validates the clickable's configuration.
Definition clickable.cpp:331
auto getLongClickType() const -> constants::LongClickType
Get the type of long click.
Definition clickable.cpp:267
auto addActuator(uint8_t actuatorIndex, constants::ClickType actuatorType) -> Clickable &
Add an actuator to a list of actuators controlled by the clickable.
Definition clickable.cpp:109
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.