2020-09-02 12:39:50 -07:00
|
|
|
/**
|
|
|
|
* @file debounce.h
|
|
|
|
* @brief Generic button debounce class
|
2020-09-20 11:01:00 -07:00
|
|
|
* https://en.wikipedia.org/wiki/Switch#Contact_bounce
|
|
|
|
* If we don't 'debounce' our button inputs, we may mistakenly
|
|
|
|
* read a single button press as multiple events.
|
2020-09-02 12:39:50 -07:00
|
|
|
*
|
|
|
|
* @date Aug 31, 2020
|
|
|
|
* @author David Holdeman, (c) 2020
|
|
|
|
*/
|
2020-09-20 11:01:00 -07:00
|
|
|
#pragma once
|
2020-09-08 08:29:38 -07:00
|
|
|
|
2020-09-02 12:39:50 -07:00
|
|
|
#include "globalaccess.h"
|
|
|
|
#include "io_pins.h"
|
|
|
|
|
|
|
|
class ButtonDebounce {
|
|
|
|
public:
|
2020-12-24 04:30:56 -08:00
|
|
|
explicit ButtonDebounce(const char* name);
|
2020-09-28 16:17:17 -07:00
|
|
|
void init(efitimems_t threshold, brain_pin_e &pin, pin_input_mode_e &mode);
|
2020-09-20 11:01:00 -07:00
|
|
|
void stopConfiguration();
|
|
|
|
void startConfiguration();
|
2020-09-02 12:39:50 -07:00
|
|
|
bool readPinEvent();
|
2020-09-09 14:18:54 -07:00
|
|
|
bool readPinState();
|
2020-09-20 11:01:00 -07:00
|
|
|
static void stopConfigurationList();
|
|
|
|
static void startConfigurationList();
|
2020-11-06 20:48:35 -08:00
|
|
|
static void debug();
|
2020-09-02 12:39:50 -07:00
|
|
|
private:
|
2020-12-24 04:30:56 -08:00
|
|
|
const char* const m_name;
|
2020-09-20 11:01:00 -07:00
|
|
|
efitick_t m_threshold;
|
2020-09-02 12:39:50 -07:00
|
|
|
efitick_t timeLast;
|
2020-09-20 11:01:00 -07:00
|
|
|
brain_pin_e *m_pin;
|
2022-04-28 14:32:39 -07:00
|
|
|
brain_pin_e active_pin = Gpio::Unassigned;
|
2020-09-20 11:01:00 -07:00
|
|
|
pin_input_mode_e *m_mode;
|
|
|
|
pin_input_mode_e active_mode = PI_DEFAULT;
|
|
|
|
bool storedValue = false;
|
2020-12-16 19:24:19 -08:00
|
|
|
bool isInstanceRegisteredInGlobalList = false;
|
|
|
|
bool needsPinInitialization = true;
|
2020-09-08 08:29:38 -07:00
|
|
|
ButtonDebounce *nextDebounce = nullptr;
|
|
|
|
static ButtonDebounce* s_firstDebounce;
|
2020-09-02 12:39:50 -07:00
|
|
|
};
|
2020-11-06 20:48:35 -08:00
|
|
|
|
2021-04-21 09:53:13 -07:00
|
|
|
void initButtonDebounce();
|