Arduino Filters master
Filter library for Arduino
IncrementButton.cpp
Go to the documentation of this file.
1#include "IncrementButton.hpp"
2
3AH_DIAGNOSTIC_WERROR() // Enable errors on warnings
4
6
7IncrementButton::State IncrementButton::updateImplementation() {
8 Button::State incrState = button.update();
9
10 if (incrState == Button::Released) {
11 // Button released, don't do anything
12 // This one is first to minimize overhead
13 // because most of the time, the button will
14 // be released
15 return Nothing;
16 } else if (incrState == Button::Rising) {
17 auto res = longPressState == LongPress ? ReleasedLong : ReleasedShort;
18 longPressState = Initial;
19 return res;
20 } else if (incrState == Button::Falling) {
21 return IncrementShort;
22 } else { // if (incrState == Button::Pressed)
23 auto now = millis();
24 if (longPressState == LongPress) {
25 // still long pressed
26 if (now - longPressRepeat >= LONG_PRESS_REPEAT_DELAY) {
27 longPressRepeat += LONG_PRESS_REPEAT_DELAY;
28 return IncrementHold;
29 }
30 } else if (button.stableTime(now) >= LONG_PRESS_DELAY) {
31 // long press starts
32 longPressState = LongPress;
33 longPressRepeat = now;
34 return IncrementLong;
35 }
36 }
37 return Nothing;
38}
39
41
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
constexpr unsigned long LONG_PRESS_REPEAT_DELAY
The time between increments/decremnets during a long press.
Definition: Settings.hpp:82
constexpr unsigned long LONG_PRESS_DELAY
The time in milliseconds before a press is registered as a long press.
Definition: Settings.hpp:79
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:36
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:35
State
An enumeration of the different states a button can be in.
Definition: Button.hpp:48
@ Rising
Input went from low to high (0,1)
Definition: Button.hpp:52
@ Falling
Input went from high to low (1,0)
Definition: Button.hpp:51
@ Released
Input went from high to high (1,1)
Definition: Button.hpp:50
A class for buttons that increment some counter or setting.
State
An enumeration of the different actions to be performed by the counter.
State update()
Update and return the state of the increment button.