Control Surface  1.1.1
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  } else if (incrState == Button::Rising) {
16  longPressState = Initial;
17  } else if (incrState == Button::Falling) {
18  return Increment;
19  } else { // if (incrState == Button::Pressed)
20  auto now = millis();
21  if (longPressState == LongPress) {
22  // still long pressed
23  if (now - longPressRepeat >= LONG_PRESS_REPEAT_DELAY) {
24  longPressRepeat += LONG_PRESS_REPEAT_DELAY;
25  return Increment;
26  }
27  } else if (button.stableTime(now) >= LONG_PRESS_DELAY) {
28  // long press starts
29  longPressState = LongPress;
30  longPressRepeat = now;
31  return Increment;
32  }
33  }
34  return Nothing;
35 }
36 
38 
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:17
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:49
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:16
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