Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
ManyButtonsSelector.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Selector.hpp"
6#include <Def/Def.hpp>
7
9
10template <setting_t N, class Callback = EmptySelectorCallback>
11class GenericManyButtonsSelector : public GenericSelector<N, Callback> {
13
14 public:
16 const Callback &callback,
17 const PinList<N> &buttonPins)
18 : GenericSelector<N, Callback> {selectable, callback},
19 buttons(AH::copyAs<AH::Button>(buttonPins)) {}
20
21 void begin() override {
23 for (auto &btn : buttons)
24 btn.begin();
25 }
26
27 void update() override {
29 for (setting_t i = 0; i < N; i++)
31 buttons[this->get()].getState() != AH::Button::Pressed)
32 this->set(i);
33 }
34
35 void invert() {
36 for (auto &btn : buttons)
37 btn.invert();
38 }
39
40 private:
42};
43
44// -------------------------------------------------------------------------- //
45
60template <setting_t N>
62 public:
63 ManyButtonsSelector(Selectable<N> &selectable, const PinList<N> &buttonPins)
66 {},
67 buttonPins,
68 } {}
69};
70
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
@ Pressed
Input went from low to low (0,0)
Definition Button.hpp:46
@ Falling
Input went from high to low (1,0)
Definition Button.hpp:48
A class that reads and filters an analog input.
void update() override
Update this updatable.
AH::Array< AH::Button, N > buttons
GenericManyButtonsSelector(Selectable< N > &selectable, const Callback &callback, const PinList< N > &buttonPins)
void begin() override
Initialize this updatable.
void set(setting_t newSetting)
Select the given selection.
Definition Selector.hpp:93
Callback callback
Definition Selector.hpp:144
void update() override
Update this updatable.
Definition Selector.hpp:77
Selectable< N > & selectable
Definition Selector.hpp:141
void begin() override
Initialize this updatable.
Definition Selector.hpp:72
Selector that reads from buttons.
ManyButtonsSelector(Selectable< N > &selectable, const PinList< N > &buttonPins)
setting_t get() const
Get the current selection/setting.
Definition Selector.hpp:46