Control Surface  1.1.1
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)
17  : GenericSelector<N, Callback>{selectable, callback},
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 
57 template <setting_t N>
59  public:
62  selectable,
63  {},
64  buttonPins,
65  } {}
66 };
67 
AH::ExtIO::pinMode
void pinMode(pin_t pin, uint8_t mode)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:36
INPUT_PULLUP
const uint8_t INPUT_PULLUP
Definition: ExtendedInputOutput.hpp:51
GenericSelector::begin
void begin() override
Initialize this updatable.
Definition: Selector.hpp:73
AH::ExtIO::digitalRead
int digitalRead(pin_t pin)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:60
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
SelectorBase::get
setting_t get() const
Get the current selection/setting.
Definition: Selector.hpp:47
GenericManyButtonsSelector
Definition: ManyButtonsSelector.hpp:10
GenericManyButtonsSelector::buttonPins
PinList< N > buttonPins
Definition: ManyButtonsSelector.hpp:38
Def.hpp
GenericSelector::update
void update() override
Update this updatable.
Definition: Selector.hpp:78
ExtendedInputOutput.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
Selectable
Definition: Selectable.hpp:11
GenericSelector::callback
Callback callback
Definition: Selector.hpp:140
GenericManyButtonsSelector::begin
void begin() override
Initialize this updatable.
Definition: ManyButtonsSelector.hpp:20
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
GenericSelector
Definition: Selector.hpp:57
LOW
const uint8_t LOW
Definition: ExtendedInputOutput.hpp:47
Selector.hpp
GenericSelector::set
void set(setting_t newSetting)
Select the given selection.
Definition: Selector.hpp:89
setting_t
uint8_t setting_t
The type used for Selectors.
Definition: Def.hpp:50
GenericSelector::selectable
Selectable< N > & selectable
Definition: Selector.hpp:137
ManyButtonsSelector
Selector that reads from buttons.
Definition: ManyButtonsSelector.hpp:58
ManyButtonsSelector::ManyButtonsSelector
ManyButtonsSelector(Selectable< N > &selectable, const PinList< N > &buttonPins)
Definition: ManyButtonsSelector.hpp:60
GenericManyButtonsSelector::GenericManyButtonsSelector
GenericManyButtonsSelector(Selectable< N > &selectable, const Callback &callback, const PinList< N > &buttonPins)
Definition: ManyButtonsSelector.hpp:14