rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
hw_layer
signaldebounce.h
Go to the documentation of this file.
1
#pragma once
2
3
// Very generic signal debounce
4
// Unlike ButtonDebounce, works with any arbitrary signal (from ADC, CAN, etc)
5
6
#include "rusefi/timer.h"
7
8
class
SignalDebounce
{
9
public
:
10
SignalDebounce
(
float
debounceSeconds,
bool
initialState) :
11
period
(debounceSeconds),
12
state
(initialState)
13
{ }
14
SignalDebounce
(
float
debounceSeconds) :
15
period
(debounceSeconds),
16
state
(false)
17
{ }
18
19
// feed it with raw value periodically
20
void
set
(
bool
newState)
21
{
22
if
(
state
== newState) {
23
timer
.reset();
24
}
25
else
if
(
timer
.hasElapsedSec(
period
)) {
26
state
= newState;
27
timer
.reset();
28
}
29
}
30
31
// get the 'smooth' value
32
bool
get
()
const
{
33
return
state
;
34
}
35
36
private
:
37
Timer
timer
;
38
const
float
period
;
39
bool
state
;
40
};
SignalDebounce
Definition
signaldebounce.h:8
SignalDebounce::SignalDebounce
SignalDebounce(float debounceSeconds)
Definition
signaldebounce.h:14
SignalDebounce::SignalDebounce
SignalDebounce(float debounceSeconds, bool initialState)
Definition
signaldebounce.h:10
SignalDebounce::state
bool state
Definition
signaldebounce.h:39
SignalDebounce::set
void set(bool newState)
Definition
signaldebounce.h:20
SignalDebounce::get
bool get() const
Definition
signaldebounce.h:32
SignalDebounce::timer
Timer timer
Definition
signaldebounce.h:37
SignalDebounce::period
const float period
Definition
signaldebounce.h:38
Generated on Sat Sep 27 2025 00:10:07 for rusEFI by
1.9.8