10#ifndef M5_UTILITY_BUTTON_STATUS_HPP
11#define M5_UTILITY_BUTTON_STATUS_HPP
30 enum class button_state_t : uint8_t { state_nochange, state_clicked, state_hold, state_decide_click_count };
37 Status(
const uint16_t hold_ms = 500,
const uint16_t debounce_ms = 10)
38 : _msecHold{hold_ms}, _msecDebounce{debounce_ms}
86 return !_oldPress && _press;
91 return _oldPress && !_press;
96 return _currentState == button_state_t::state_clicked;
101 return _currentState == button_state_t::state_hold;
106 return _currentState == button_state_t::state_decide_click_count && _clickCount == 1;
111 return _currentState == button_state_t::state_decide_click_count && _clickCount == 2;
116 return _currentState == button_state_t::state_decide_click_count;
126 return ((
bool)_press) != ((bool)_oldPress);
131 return !_press && _oldPress == 2;
136 return _oldPress && !_press && _lastHoldPeriod >= ms;
141 return (_press && _lastMsec - _lastChange >= ms);
146 return (!_press && _lastMsec - _lastChange >= ms);
152 void setRawState(
const uint32_t msec,
const bool press);
156 return _currentState;
158 inline uint32_t lastChange(
void)
const
162 inline uint32_t getUpdateMsec(
void)
const
169 uint16_t _msecHold{500}, _msecDebounce{10};
170 uint32_t _lastMsec{}, _lastChange{}, _lastRawChange{}, _lastClicked{};
171 uint16_t _lastHoldPeriod{};
175 uint8_t _press{}, _oldPress{}, _clickCount{};
Top level namespace of M5.
Definition bit_segment.hpp:17