GCC Code Coverage Report


Directory: ./
File: firmware/hw_layer/signaldebounce.h
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 100.0% 13 0 13
Functions: 100.0% 3 0 3
Branches: 100.0% 4 0 4
Decisions: 100.0% 4 - 4

Line Branch Decision Exec Source
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 1 SignalDebounce(float debounceSeconds) :
15 1 period(debounceSeconds),
16 1 state(false)
17 1 { }
18
19 // feed it with raw value periodically
20 15 void set(bool newState)
21 {
22
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 9 times.
2/2
✓ Decision 'true' taken 6 times.
✓ Decision 'false' taken 9 times.
15 if (state == newState) {
23 6 timer.reset();
24 }
25
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 7 times.
2/2
✓ Decision 'true' taken 2 times.
✓ Decision 'false' taken 7 times.
9 else if (timer.hasElapsedSec(period)) {
26 2 state = newState;
27 2 timer.reset();
28 }
29 15 }
30
31 // get the 'smooth' value
32 14 bool get() const {
33 14 return state;
34 }
35
36 private:
37 Timer timer;
38 const float period;
39 bool state;
40 };
41