Control Surface  1.1.0
MIDI Control Surface library for Arduino
SwitchSelector.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Selector.hpp"
4 #include <AH/Hardware/Button.hpp>
5 
7 
8 template <class Callback = EmptySelectorCallback>
9 class GenericSwitchSelector : public GenericSelector<2, Callback> {
11 
12  public:
14  const AH::Button &button)
15  : GenericSelector<2, Callback>{selectable, callback}, button{button} {}
16 
17  void begin() override {
18  Parent::begin();
19  button.begin();
20  }
21 
22  void update() override {
25  if (state == AH::Button::Falling)
26  this->set(1);
27  else if (state == AH::Button::Rising)
28  this->set(0);
29  }
30 
32 
33 #ifdef INDIVIDUAL_BUTTON_INVERT
34  void invert() { button.invert(); }
35 #endif
36 
37  private:
39 };
40 
41 /**
42  * @brief Selector that selects one of two settings, based on the state of a
43  * toggle or momentary switch.
44  *
45  * @htmlonly
46  * <object type="image/svg+xml" data="../../selector-one-toggle-switch-LED.svg"></object>
47  * @endhtmlonly
48  *
49  * @ingroup Selectors
50  */
52  public:
55  selectable,
56  {},
57  button,
58  } {}
59 };
60 
AH::Button::Rising
< Input went from high to low (1,0)
Definition: Button.hpp:57
GenericSelector< 2, Callback >::selectable
Selectable< N > & selectable
Definition: Selector.hpp:137
Button.hpp
GenericSwitchSelector::update
void update() override
Update this updatable.
Definition: SwitchSelector.hpp:22
GenericSwitchSelector
Definition: SwitchSelector.hpp:9
AH::Button
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:18
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
Selectable
Definition: Selectable.hpp:11
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
AH::Button::getState
State getState() const
Get the state of the button, without updating it.
Definition: Button.cpp:36
AH::Button::begin
void begin()
Initialize (enable the internal pull-up resistor).
Definition: Button.cpp:11
GenericSelector< 2, Callback >::set
void set(setting_t newSetting)
Select the given selection.
Definition: Selector.hpp:89
GenericSelector
Definition: Selector.hpp:57
GenericSelector< 2, Callback >::update
void update() override
Definition: Selector.hpp:78
GenericSelector< 2, Callback >::callback
Callback callback
Definition: Selector.hpp:140
AH::Button::update
State update()
Read the button and return its new state.
Definition: Button.cpp:19
SwitchSelector
Selector that selects one of two settings, based on the state of a toggle or momentary switch.
Definition: SwitchSelector.hpp:51
Selector.hpp
AH::Button::invert
AH_INDIVIDUAL_BUTTON_INVERT_STATIC void invert()
Invert the state of all buttons, or of this specific button (button pressed is HIGH instead of LOW).
Definition: Button.cpp:13
GenericSwitchSelector::GenericSwitchSelector
GenericSwitchSelector(Selectable< 2 > &selectable, const Callback &callback, const AH::Button &button)
Definition: SwitchSelector.hpp:13
AH::Button::State
State
An enumeration of the different states a button can be in.
Definition: Button.hpp:53
GenericSwitchSelector::begin
void begin() override
Initialize this updatable.
Definition: SwitchSelector.hpp:17
GenericSelector< 2, Callback >::begin
void begin() override
Definition: Selector.hpp:73
SwitchSelector::SwitchSelector
SwitchSelector(Selectable< 2 > &selectable, const AH::Button &button)
Definition: SwitchSelector.hpp:53
GenericSwitchSelector::button
AH::Button button
Definition: SwitchSelector.hpp:38
GenericSwitchSelector::getButtonState
AH::Button::State getButtonState() const
Definition: SwitchSelector.hpp:31
AH::Button::Falling
< Input went from high to high (1,1)
Definition: Button.hpp:56