Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
IncrementButton.cpp
Go to the documentation of this file.
1#include "IncrementButton.hpp"
2
4
5IncrementButton::State IncrementButton::updateImplementation() {
6 Button::State incrState = button.update();
7
8 if (incrState == Button::Released) {
9 // Button released, don't do anything
10 // This one is first to minimize overhead
11 // because most of the time, the button will
12 // be released
13 return Nothing;
14 } else if (incrState == Button::Rising) {
15 auto res = longPressState == LongPress ? ReleasedLong : ReleasedShort;
16 longPressState = Initial;
17 return res;
18 } else if (incrState == Button::Falling) {
19 return IncrementShort;
20 } else { // if (incrState == Button::Pressed)
21 auto now = millis();
22 if (longPressState == LongPress) {
23 // still long pressed
24 if (now - longPressRepeat >= LONG_PRESS_REPEAT_DELAY) {
25 longPressRepeat += LONG_PRESS_REPEAT_DELAY;
26 return IncrementHold;
27 }
28 } else if (button.stableTime(now) >= LONG_PRESS_DELAY) {
29 // long press starts
30 longPressState = LongPress;
31 longPressRepeat = now;
32 return IncrementLong;
33 }
34 }
35 return Nothing;
36}
37
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
State
An enumeration of the different states a button can be in.
Definition Button.hpp:45
State
An enumeration of the different actions to be performed by the counter.
constexpr unsigned long LONG_PRESS_REPEAT_DELAY
The time between increments/decremnets during a long press.
constexpr unsigned long LONG_PRESS_DELAY
The time in milliseconds before a press is registered as a long press.
An array wrapper for easy copying, comparing, and iterating.
Definition Array.hpp:32