Control Surface  1.2.0
MIDI Control Surface library for Arduino
IncrementButton.cpp
Go to the documentation of this file.
1 #include "IncrementButton.hpp"
2 
3 AH_DIAGNOSTIC_WERROR() // Enable errors on warnings
4 
6 
7 IncrementButton::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 
AH::Button::State
State
An enumeration of the different states a button can be in.
Definition: Button.hpp:53
AH::IncrementButton::State
State
An enumeration of the different actions to be performed by the counter.
Definition: IncrementButton.hpp:41
AH_DIAGNOSTIC_POP
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:36
AH::LONG_PRESS_REPEAT_DELAY
constexpr unsigned long LONG_PRESS_REPEAT_DELAY
The time between increments/decremnets during a long press.
Definition: AH/Settings/Settings.hpp:80
AH::IncrementButton::update
State update()
Update and return the state of the increment button.
Definition: IncrementButton.hpp:53
AH::LONG_PRESS_DELAY
constexpr unsigned long LONG_PRESS_DELAY
The time in milliseconds before a press is registered as a long press.
Definition: AH/Settings/Settings.hpp:77
IncrementButton.hpp
AH_DIAGNOSTIC_WERROR
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:35
AH::IncrementButton
A class for buttons that increment some counter or setting.
Definition: IncrementButton.hpp:22
BEGIN_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
Definition: AH/Settings/NamespaceSettings.hpp:9
END_AH_NAMESPACE
#define END_AH_NAMESPACE
Definition: AH/Settings/NamespaceSettings.hpp:10