Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
IncrementDecrementButtons.cpp
Go to the documentation of this file.
2
4
5IncrementDecrementButtons::State
6IncrementDecrementButtons::updateImplementation() {
7 Button::State incrState = incrementButton.update();
8 Button::State decrState = decrementButton.update();
9
10 if (decrState == Button::Released && incrState == Button::Released) {
11 // Both released
12 } else if ((decrState == Button::Rising && incrState == Button::Released) ||
13 (incrState == Button::Rising && decrState == Button::Released) ||
14 (incrState == Button::Rising && decrState == Button::Rising)) {
15 // One released, the other rising → nothing
16 // now both released, so go to initial state
17 longPressState = Initial;
18 } else if (incrState == Button::Falling && decrState == Button::Falling) {
19 // Both falling → reset
20 // (rather unlikely, but just in case)
21 longPressState = AfterReset;
22 return Reset;
23 } else if (incrState == Button::Falling) {
24 if (decrState == Button::Pressed) {
25 // One pressed, the other falling → reset
26 longPressState = AfterReset;
27 return Reset;
28 } else {
29 // Increment falling, the other released → increment
30 return IncrementShort;
31 }
32 } else if (decrState == Button::Falling) {
33 if (incrState == Button::Pressed) {
34 // One pressed, the other falling → reset
35 longPressState = AfterReset;
36 return Reset;
37 } else {
38 // Decrement falling, the other released → decrement
39 return DecrementShort;
40 }
41 } else if (incrState == Button::Pressed && decrState == Button::Pressed) {
42 // Both pressed → nothing
43 } else if (longPressState != AfterReset && incrState == Button::Pressed) {
44 // Not reset and increment pressed → long press?
45 auto now = millis();
46 if (longPressState == LongPress) {
47 if (now - longPressRepeat >= LONG_PRESS_REPEAT_DELAY) {
48 longPressRepeat += LONG_PRESS_REPEAT_DELAY;
49 return IncrementHold;
50 }
51 } else if (incrementButton.stableTime() >= LONG_PRESS_DELAY) {
52 longPressState = LongPress;
53 longPressRepeat = now;
54 return IncrementLong;
55 }
56 } else if (longPressState != AfterReset && decrState == Button::Pressed) {
57 // Not reset and decrement pressed → long press?
58 auto now = millis();
59 if (longPressState == LongPress) {
60 if (now - longPressRepeat >= LONG_PRESS_REPEAT_DELAY) {
61 longPressRepeat += LONG_PRESS_REPEAT_DELAY;
62 return DecrementHold;
63 }
64 } else if (decrementButton.stableTime() >= LONG_PRESS_DELAY) {
65 longPressState = LongPress;
66 longPressRepeat = now;
67 return DecrementLong;
68 }
69 }
70 return Nothing;
71}
72
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
State
An enumeration of the different states a button can be in.
Definition Button.hpp:45
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