14#ifndef ISF15ACP4_BUTTON_HPP
15#define ISF15ACP4_BUTTON_HPP
67 constexpr void Reset() noexcept {
72 repeat_armed_ =
false;
88 pressed_at_ms_ = now_ms;
92 if (down != pressed_) {
95 changed_at_ms_ = now_ms;
97 if ((now_ms - changed_at_ms_) >= config_.
debounce_ms) {
98 return accept(down, now_ms);
104 return holdEvent(now_ms);
110 [[nodiscard]]
constexpr bool IsDown() const noexcept {
114 [[nodiscard]]
constexpr uint32_t
PressCount() const noexcept {
119 constexpr ButtonUpdate accept(
bool down, uint32_t now_ms)
noexcept {
125 pressed_at_ms_ = changed_at_ms_;
129 press_count_ = press_count_ + 1U;
133 u.held_ms = changed_at_ms_ - pressed_at_ms_;
134 u.was_long = long_sent_;
135 repeat_armed_ =
false;
137 static_cast<void>(now_ms);
141 constexpr ButtonUpdate holdEvent(uint32_t now_ms)
noexcept {
143 u.timestamp_ms = now_ms;
144 const uint32_t held = now_ms - pressed_at_ms_;
149 }
else if (repeat_armed_ && (held >= repeat_due_ms_)) {
159 ButtonConfig config_;
160 uint32_t pressed_at_ms_{0};
161 uint32_t changed_at_ms_{0};
162 uint32_t repeat_due_ms_{0};
163 uint32_t press_count_{0};
164 bool started_{
false};
165 bool pressed_{
false};
166 bool changing_{
false};
167 bool long_sent_{
false};
168 bool repeat_armed_{
false};
173constexpr bool DebounceSelfCheck() noexcept {
175 cfg.debounce_ms = 10;
176 ButtonDebouncer d(cfg);
177 static_cast<void>(d.Update(
false, 0U));
178 static_cast<void>(d.Update(
true, 100U));
179 const ButtonUpdate early = d.Update(
true, 109U);
180 const ButtonUpdate edge = d.Update(
true, 110U);
182 (edge.timestamp_ms == 100U);
184static_assert(DebounceSelfCheck(),
185 "debounce: accepted after debounce_ms, stamped at the first sample");
ButtonEvent
What a switch poll can report.
Definition isf15acp4_types.hpp:215
@ LongPress
Held for long_press_ms; once per press.
@ Repeat
Held on: one per repeat_interval_ms after repeat_delay_ms.
@ Pressed
The switch closed and stayed closed for the debounce time.
@ Released
The switch opened and stayed open for the debounce time.
Public types of the ISF15ACP4 driver: errors, Result<T>, the display and button configuration,...
The ISF15ACP4 driver: everything it declares lives here; internals in detail.
Definition isf15acp4.hpp:31