rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
debounce.h
Go to the documentation of this file.
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
17public:
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();
24 bool readPinState2(bool valueWithinThreshold);
25 static void stopConfigurationList();
26 static void startConfigurationList();
27 static void debug();
29#if EFI_UNIT_TEST
30 static void resetForUnitTests() {
31 s_firstDebounce = nullptr;
32 }
33#endif
34private:
35 const char* const m_name;
37 Timer timeLast;
42 bool storedValue = false;
43 bool m_inverted = false;
48};
49
void stopConfiguration()
Definition debounce.cpp:59
bool isInstanceRegisteredInGlobalList
Definition debounce.h:44
static void resetForUnitTests()
Definition debounce.h:30
pin_input_mode_e active_mode
Definition debounce.h:41
const char *const m_name
Definition debounce.h:35
bool storedValue
Definition debounce.h:42
pin_input_mode_e * m_mode
Definition debounce.h:40
void startConfiguration()
bool readPinEvent()
Timer timeLast
Definition debounce.h:37
void init(efitimems_t threshold, brain_pin_e &pin, pin_input_mode_e &mode, bool inverted=false)
Definition debounce.cpp:23
bool getPhysicalState()
brain_pin_e active_pin
Definition debounce.h:39
bool readPinState2(bool valueWithinThreshold)
static void debug()
static void startConfigurationList()
Definition debounce.cpp:49
static ButtonDebounce * s_firstDebounce
Definition debounce.h:47
ButtonDebounce * nextDebounce
Definition debounce.h:46
static void stopConfigurationList()
Definition debounce.cpp:39
bool needsPinInitialization
Definition debounce.h:45
efidur_t m_threshold
Definition debounce.h:36
brain_pin_e * m_pin
Definition debounce.h:38
bool m_inverted
Definition debounce.h:43
bool readPinState()
@ Unassigned
void initButtonDebounce()
this file is about general input/output utility methods, not much EFI-specifics
pin_input_mode_e
uint32_t efitimems_t
efitick_t efidur_t
brain_pin_e pin
Definition stm32_adc.cpp:15