diff --git a/src/Bounce2.cpp b/src/Bounce2.cpp index 55712ba..049452c 100644 --- a/src/Bounce2.cpp +++ b/src/Bounce2.cpp @@ -107,12 +107,12 @@ bool Bounce::update() return getStateFlag(CHANGED_STATE); } -/* + // WIP HELD -unsigned long Bounce::held() { +unsigned long Bounce::previousDuration() { return durationOfPreviousState; } -*/ + unsigned long Bounce::duration() { return (millis() - stateChangeLastTime); } @@ -120,7 +120,7 @@ unsigned long Bounce::duration() { inline void Bounce::changeState() { toggleStateFlag(DEBOUNCED_STATE); setStateFlag(CHANGED_STATE) ; - // WIP HELD : durationOfPreviousState = millis() - stateChangeLastTime; + durationOfPreviousState = millis() - stateChangeLastTime; stateChangeLastTime = millis(); } diff --git a/src/Bounce2.h b/src/Bounce2.h index 2ed9403..7e0341b 100644 --- a/src/Bounce2.h +++ b/src/Bounce2.h @@ -164,8 +164,14 @@ class Bounce unsigned long duration(); + /** + @brief Returns the duration in milliseconds of the previous state. - // WIP HELD : unsigned long held(); // Returns the duration the previous state was held + Takes the values of duration() once the pin changes state. + + @return The duration in milliseconds (unsigned long) of the previous state. + */ + unsigned long previousDuration(); protected: unsigned long previous_millis; @@ -173,7 +179,7 @@ class Bounce uint8_t state; uint8_t pin; unsigned long stateChangeLastTime; - // WIP HELD : unsigned long durationOfPreviousState; + unsigned long durationOfPreviousState; virtual bool readCurrentState() { return digitalRead(pin); } virtual void setPinMode(int pin, int mode) { #if defined(ARDUINO_STM_NUCLEO_F103RB) || defined(ARDUINO_GENERIC_STM32F103C)