From e7af7cd3918a730ce23596e3e621a773ce24edf9 Mon Sep 17 00:00:00 2001 From: David Holdeman Date: Wed, 9 Sep 2020 16:18:54 -0500 Subject: [PATCH] Debounce pin state function (#1780) * add readpinstate * wrong var name --- firmware/hw_layer/debounce.cpp | 7 ++++++- firmware/hw_layer/debounce.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/firmware/hw_layer/debounce.cpp b/firmware/hw_layer/debounce.cpp index 4a69cd3374..7d3eb01508 100644 --- a/firmware/hw_layer/debounce.cpp +++ b/firmware/hw_layer/debounce.cpp @@ -68,13 +68,18 @@ void ButtonDebounce::updateConfiguration () { @returns true if the button is pressed, and will not return true again within the set timeout */ bool ButtonDebounce::readPinEvent() { + readValue = false; + return readPinState(); +} + +bool ButtonDebounce::readPinState() { if (!pin) { return false; } efitick_t timeNow = getTimeNowNt(); // If it's been less than the threshold since we were last called if ((timeNow - timeLast) < threshold) { - return false; + return readValue; } // readValue is a class variable, so it needs to be reset. // We don't actually need it to be a class variable in this method, diff --git a/firmware/hw_layer/debounce.h b/firmware/hw_layer/debounce.h index bfda7877e2..daaba08917 100644 --- a/firmware/hw_layer/debounce.h +++ b/firmware/hw_layer/debounce.h @@ -16,6 +16,7 @@ public: void init(int t, brain_pin_e *p, pin_input_mode_e *m); void updateConfiguration(); bool readPinEvent(); + bool readPinState(); static void updateConfigurationList(); private: int threshold;