fork/GramFirmware

git clone https://git.julia.blue/fork/GramFirmware

CarVacrebase to configurator818d962

gram
1.2 KiB38 linesraw
1#ifndef _INPUT_DEBOUNCEDSWITCHMATRIXINPUT_HPP
2#define _INPUT_DEBOUNCEDSWITCHMATRIXINPUT_HPP
3
4#include "input/SwitchMatrixInput.hpp"
5#include "input/debounce.hpp"
6
7template <size_t num_rows, size_t num_cols>
8class DebouncedSwitchMatrixInput : public SwitchMatrixInput<num_rows, num_cols> {
9  public:
10    DebouncedSwitchMatrixInput(
11        const uint row_pins[num_rows],
12        const uint col_pins[num_cols],
13        const Button (&matrix)[num_rows][num_cols],
14        DiodeDirection direction,
15        uint32_t debounce_period_ms = 5
16    )
17        : SwitchMatrixInput<num_rows, num_cols>(row_pins, col_pins, matrix, direction) {
18        _debounce_period_ms = debounce_period_ms;
19    }
20
21  private:
22    DebounceState _debounce_state[num_rows][num_cols];
23    uint32_t _debounce_period_ms;
24
25    void UpdateButtonState(InputState &inputs, size_t col_index, size_t row_index, bool pressed) {
26        bool state_changed = update_debounce_state(
27            _debounce_state[col_index][row_index],
28            pressed,
29            _debounce_period_ms
30        );
31        if (state_changed) {
32            Button button = this->_matrix[col_index][row_index];
33            set_button(inputs.buttons, button, pressed);
34        }
35    };
36};
37
38#endif