fork/GramFirmware

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

CarVacrebase to configurator818d962

gram
1.0 KiB35 linesraw
1#ifndef _INPUT_DEBOUNCEDGPIOBUTTONINPUT_HPP
2#define _INPUT_DEBOUNCEDGPIOBUTTONINPUT_HPP
3
4#include "core/state.hpp"
5#include "input/GpioButtonInput.hpp"
6#include "input/debounce.hpp"
7#include "util/state_util.hpp"
8
9template <size_t button_count> class DebouncedGpioButtonInput : public GpioButtonInput {
10  public:
11    DebouncedGpioButtonInput(
12        const GpioButtonMapping button_mappings[button_count],
13        uint32_t debounce_period_ms = 5
14    )
15        : GpioButtonInput(button_mappings, button_count) {
16        _debounce_period_ms = debounce_period_ms;
17    }
18
19  private:
20    DebounceState _debounce_state[button_count];
21    uint32_t _debounce_period_ms;
22
23    void UpdateButtonState(InputState &inputs, size_t button_mapping_index, bool pressed) {
24        bool state_changed = update_debounce_state(
25            _debounce_state[button_mapping_index],
26            pressed,
27            _debounce_period_ms
28        );
29        if (state_changed) {
30            set_button(inputs.buttons, _button_mappings[button_mapping_index].button, pressed);
31        }
32    }
33};
34
35#endif