Control Surface  1.1.0
MIDI Control Surface library for Arduino
IncrementButton.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
6 AH_DIAGNOSTIC_WERROR() // Enable errors on warnings
7 
8 #include "Button.hpp"
9 
11 
12 /**
13  * @brief A class for buttons that increment some counter or setting.
14  *
15  * It behaves the same way as a computer keyboard: when you press the button,
16  * it increments the counter once. If you keep on pressing it for longer than
17  * a certain threshold, it keeps on incrementing at a faster rate, until you
18  * release it.
19  *
20  * @ingroup AH_HardwareUtils
21  */
23  public:
24  /**
25  * @brief Create a IncrementButton.
26  *
27  * @param button
28  * The button to read from.
29  * The button is copied.
30  */
31  IncrementButton(const Button &button) : button(button) {}
32 
33  /// @see Button::begin
34  void begin() { button.begin(); }
35 
36  /**
37  * @brief An enumeration of the different actions to be performed by the
38  * counter.
39  * @todo Add states for initial press.
40  */
41  enum State {
42  Nothing = 0, ///< The counter must not be incremented.
43  Increment, ///< The counter must be incremented.
44  };
45 
46  /**
47  * @brief Update and return the state of the increment button.
48  */
49  State update() { return state = updateImplementation(); }
50 
51  /**
52  * @brief Return the state of the increment button without updating it.
53  *
54  * Returns the same value as the last @ref update call.
55  */
56  State getState() const { return state; }
57 
58 #ifdef AH_INDIVIDUAL_BUTTON_INVERT
59  /// @see Button::invert
60  void invert() { button.invert(); }
61 #endif
62 
63  protected:
64  State updateImplementation();
65 
66  private:
68 
69  enum {
72  } longPressState = Initial;
73  unsigned long longPressRepeat;
74 
75  State state = Nothing;
76 };
77 
79 
AH::IncrementButton::update
State update()
Update and return the state of the increment button.
Definition: IncrementButton.hpp:49
Warnings.hpp
AH::IncrementButton::LongPress
Definition: IncrementButton.hpp:71
AH::Button
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:18
AH_DIAGNOSTIC_POP
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:17
AH::IncrementButton::IncrementButton
IncrementButton(const Button &button)
Create a IncrementButton.
Definition: IncrementButton.hpp:31
AH::IncrementButton::Initial
Definition: IncrementButton.hpp:70
AH::IncrementButton::State
State
An enumeration of the different actions to be performed by the counter.
Definition: IncrementButton.hpp:41
AH::IncrementButton::longPressRepeat
unsigned long longPressRepeat
Definition: IncrementButton.hpp:73
AH::IncrementButton::begin
void begin()
Definition: IncrementButton.hpp:34
AH_DIAGNOSTIC_WERROR
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:16
AH::IncrementButton::button
Button button
Definition: IncrementButton.hpp:67
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
AH::IncrementButton::getState
State getState() const
Return the state of the increment button without updating it.
Definition: IncrementButton.hpp:56
AH::IncrementButton::Increment
The counter must be incremented.
Definition: IncrementButton.hpp:43
END_AH_NAMESPACE
#define END_AH_NAMESPACE
Definition: AH/Settings/NamespaceSettings.hpp:10