| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | /** | |||
| 2 | * @file debounce.h | |||
| 3 | * @brief Generic button debounce class | |||
| 4 | * https://en.wikipedia.org/wiki/Switch#Contact_bounce | |||
| 5 | * If we don't 'debounce' our button inputs, we may mistakenly | |||
| 6 | * read a single button press as multiple events. | |||
| 7 | * | |||
| 8 | * @date Aug 31, 2020 | |||
| 9 | * @author David Holdeman, (c) 2020 | |||
| 10 | */ | |||
| 11 | #pragma once | |||
| 12 | ||||
| 13 | #include "io_pins.h" | |||
| 14 | #include <rusefi/timer.h> | |||
| 15 | ||||
| 16 | class ButtonDebounce { | |||
| 17 | public: | |||
| 18 | explicit ButtonDebounce(const char* name); | |||
| 19 | void init(efitimems_t threshold, brain_pin_e &pin, pin_input_mode_e &mode, bool inverted = false); | |||
| 20 | void stopConfiguration(); | |||
| 21 | void startConfiguration(); | |||
| 22 | bool readPinEvent(); | |||
| 23 | bool readPinState(); | |||
| 24 | bool readPinState2(bool valueWithinThreshold); | |||
| 25 | static void stopConfigurationList(); | |||
| 26 | static void startConfigurationList(); | |||
| 27 | static void debug(); | |||
| 28 | bool getPhysicalState(); | |||
| 29 | #if EFI_UNIT_TEST | |||
| 30 | 678 | static void resetForUnitTests() { | ||
| 31 | 678 | s_firstDebounce = nullptr; | ||
| 32 | 678 | } | ||
| 33 | #endif | |||
| 34 | private: | |||
| 35 | const char* const m_name; | |||
| 36 | efidur_t m_threshold; | |||
| 37 | Timer timeLast; | |||
| 38 | brain_pin_e *m_pin; | |||
| 39 | brain_pin_e active_pin = Gpio::Unassigned; | |||
| 40 | pin_input_mode_e *m_mode; | |||
| 41 | pin_input_mode_e active_mode = PI_DEFAULT; | |||
| 42 | bool storedValue = false; | |||
| 43 | bool m_inverted = false; | |||
| 44 | bool isInstanceRegisteredInGlobalList = false; | |||
| 45 | bool needsPinInitialization = true; | |||
| 46 | ButtonDebounce *nextDebounce = nullptr; | |||
| 47 | static ButtonDebounce* s_firstDebounce; | |||
| 48 | }; | |||
| 49 | ||||
| 50 | void initButtonDebounce(); | |||
| 51 |