Control Surface  1.1.0
MIDI Control Surface library for Arduino
ManyButtonsSelector.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Selector.hpp"
5 #include <Def/Def.hpp>
6 
8 
9 template <setting_t N, class Callback = EmptySelectorCallback>
10 class GenericManyButtonsSelector : public GenericSelector<N, Callback> {
12 
13  public:
15  const Callback &callback,
16  const PinList<N> &buttonPins)
18  buttonPins} {}
19 
20  void begin() override {
21  Parent::begin();
22  for (const pin_t &pin : buttonPins)
24  }
25 
26  void update() override {
28  for (setting_t i = 0; i < N; i++)
29  // TODO: invert?
31  if (AH::ExtIO::digitalRead(buttonPins[this->get()]) != LOW)
32  this->set(i);
33  break;
34  }
35  }
36 
37  private:
38  PinList<N> buttonPins;
39 };
40 
41 // -------------------------------------------------------------------------- //
42 
43 /**
44  * @brief Selector that reads from @f$ N @f$ buttons.
45  *
46  * Pressing the @f$ n @f$-th button selects the @f$ n @f$-th setting.
47  *
48  * @htmlonly
49  * <object type="image/svg+xml" data="../../selector-multiple-momentary-switches-LED.svg"></object>
50  * @endhtmlonly
51  *
52  * @ingroup Selectors
53  *
54  * @tparam N
55  * The number of settings.
56  */
57 template <setting_t N>
59  public:
62  selectable,
63  {},
64  buttonPins,
65  } {}
66 };
67 
ManyButtonsSelector::ManyButtonsSelector
ManyButtonsSelector(Selectable< N > &selectable, const PinList< N > &buttonPins)
Definition: ManyButtonsSelector.hpp:60
INPUT_PULLUP
const uint8_t INPUT_PULLUP
Definition: ExtendedInputOutput.hpp:51
GenericSelector::selectable
Selectable< N > & selectable
Definition: Selector.hpp:137
SelectorBase::get
setting_t get() const
Get the current selection/setting.
Definition: Selector.hpp:47
GenericManyButtonsSelector
Definition: ManyButtonsSelector.hpp:10
Def.hpp
AH::ExtIO::pinMode
void pinMode(pin_t pin, uint8_t mode)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:36
ExtendedInputOutput.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
Selectable
Definition: Selectable.hpp:11
GenericManyButtonsSelector::GenericManyButtonsSelector
GenericManyButtonsSelector(Selectable< N > &selectable, const Callback &callback, const PinList< N > &buttonPins)
Definition: ManyButtonsSelector.hpp:14
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
GenericSelector::set
void set(setting_t newSetting)
Select the given selection.
Definition: Selector.hpp:89
GenericSelector
Definition: Selector.hpp:57
GenericSelector::update
void update() override
Update this updatable.
Definition: Selector.hpp:78
GenericSelector::callback
Callback callback
Definition: Selector.hpp:140
LOW
const uint8_t LOW
Definition: ExtendedInputOutput.hpp:47
Selector.hpp
AH::pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Hardware-Types.hpp:17
GenericManyButtonsSelector::update
void update() override
Update this updatable.
Definition: ManyButtonsSelector.hpp:26
AH::ExtIO::digitalRead
int digitalRead(pin_t pin)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:58
GenericManyButtonsSelector::buttonPins
PinList< N > buttonPins
Definition: ManyButtonsSelector.hpp:38
setting_t
uint8_t setting_t
The type used for Selectors.
Definition: Def.hpp:50
GenericManyButtonsSelector::begin
void begin() override
Initialize this updatable.
Definition: ManyButtonsSelector.hpp:20
GenericSelector::begin
void begin() override
Initialize this updatable.
Definition: Selector.hpp:73
ManyButtonsSelector
Selector that reads from buttons.
Definition: ManyButtonsSelector.hpp:58