only:using higher level API which could matter for unit tests around time zero
This commit is contained in:
parent
a63265bffb
commit
86ce899026
|
@ -29,7 +29,6 @@ void ButtonDebounce::init (efitimems_t threshold, brain_pin_e &pin, pin_input_mo
|
|||
s_firstDebounce = this;
|
||||
}
|
||||
m_threshold = MS2NT(threshold);
|
||||
timeLast = 0;
|
||||
m_pin = &pin;
|
||||
m_mode = &mode;
|
||||
startConfiguration();
|
||||
|
@ -89,9 +88,9 @@ bool ButtonDebounce::readPinState() {
|
|||
if (!isBrainPinValid(*m_pin)) {
|
||||
return false;
|
||||
}
|
||||
efitick_t timeNow = getTimeNowNt();
|
||||
efitick_t timeNowNt = getTimeNowNt();
|
||||
// If it's been less than the threshold since we were last called
|
||||
if ((timeNow - timeLast) < m_threshold) {
|
||||
if (timeLast.getElapsedNt(timeNowNt) < m_threshold) {
|
||||
return storedValue;
|
||||
}
|
||||
// storedValue is a class variable, so it needs to be reset.
|
||||
|
@ -108,7 +107,7 @@ bool ButtonDebounce::readPinState() {
|
|||
storedValue = !storedValue;
|
||||
}
|
||||
if (storedValue) {
|
||||
timeLast = timeNow;
|
||||
timeLast.reset();
|
||||
}
|
||||
return storedValue;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
private:
|
||||
const char* const m_name;
|
||||
efitick_t m_threshold;
|
||||
efitick_t timeLast;
|
||||
Timer timeLast;
|
||||
brain_pin_e *m_pin;
|
||||
brain_pin_e active_pin = Gpio::Unassigned;
|
||||
pin_input_mode_e *m_mode;
|
||||
|
|
Loading…
Reference in New Issue