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:
66 {},
67 buttonPins,
68 } {}
69};
70
uint8_t setting_t
The type used for Selectors.
Definition Def.hpp:53
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
@ Pressed
Input went from low to low (0,0).
Definition Button.hpp:48
@ Falling
Input went from high to low (1,0).
Definition Button.hpp:50
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.
GenericSelector< N, Callback > Parent
GenericSelector(Selectable< N > &selectable, const EmptySelectorCallback &callback)
Definition Selector.hpp:69
ManyButtonsSelector(Selectable< N > &selectable, const PinList< N > &buttonPins)
Array< T, N > copyAs(const Array< U, N > &src)
Copy an Array to an Array of a different type.
Array< pin_t, N > PinList
An easy alias for arrays of pins.
An array wrapper for easy copying, comparing, and iterating.
Definition Array.hpp:32