-
-
Notifications
You must be signed in to change notification settings - Fork 314
Expand file tree
/
Copy pathDebouncedSwitchMatrixInput.hpp
More file actions
33 lines (28 loc) · 1.13 KB
/
DebouncedSwitchMatrixInput.hpp
File metadata and controls
33 lines (28 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef _INPUT_DEBOUNCEDSWITCHMATRIXINPUT_HPP
#define _INPUT_DEBOUNCEDSWITCHMATRIXINPUT_HPP
#include "input/SwitchMatrixInput.hpp"
#include "input/debounce.hpp"
template <size_t num_rows, size_t num_cols>
class DebouncedSwitchMatrixInput : public SwitchMatrixInput<num_rows, num_cols> {
public:
DebouncedSwitchMatrixInput(
const uint row_pins[num_rows],
const uint col_pins[num_cols],
const Button (&matrix)[num_rows][num_cols],
DiodeDirection direction,
uint32_t debounce_period_ms = 5
)
: SwitchMatrixInput<num_rows, num_cols>(row_pins, col_pins, matrix, direction) {
_debounce_period_ms = debounce_period_ms;
}
private:
DebounceState _debounce_state[num_rows][num_cols];
uint32_t _debounce_period_ms;
void UpdateButtonState(InputState &inputs, size_t col_index, size_t row_index, bool pressed) {
update_debounce_state(_debounce_state[col_index][row_index], pressed, _debounce_period_ms);
if (_debounce_state[col_index][row_index].pressed) {
set_button(inputs.buttons, this->_matrix[col_index][row_index], true);
}
};
};
#endif