diff --git a/src/Bounce.cpp b/src/Bounce.cpp index e78b81b..83ec937 100644 --- a/src/Bounce.cpp +++ b/src/Bounce.cpp @@ -1,7 +1,14 @@ -//////////// -// BOUNCE // -//////////// +/* + * Check Bounce2.h for licensing / authors. + */ + +#include "Bounce2.h" + + +/* + * Bounce + */ Bounce::Bounce() : pin(0) @@ -10,7 +17,8 @@ Bounce::Bounce() void Bounce::attach(int pin) { this->pin = pin; - // SET INITIAL STATE + // Set Initial State + begin(); } diff --git a/src/Debounce.cpp b/src/Debounce.cpp index b2b89bd..2bbae76 100644 --- a/src/Debounce.cpp +++ b/src/Debounce.cpp @@ -1,11 +1,14 @@ -// Please read Bounce2.h for information about the liscence and authors +/* + * Check Bounce2.h for licensing / authors. + */ #include "Bounce2.h" -////////////// -// DEBOUNCE // -////////////// + +/* + * Debounce + */ Debouncer::Debouncer():previous_millis(0) , interval_millis(10) @@ -36,6 +39,7 @@ bool Debouncer::update() #ifdef BOUNCE_LOCK_OUT // Ignore everything if we are locked out + if (millis() - previous_millis >= interval_millis) { bool currentState = readCurrentState(); if ( currentState != getStateFlag(DEBOUNCED_STATE) ) { @@ -46,44 +50,81 @@ bool Debouncer::update() #elif defined BOUNCE_WITH_PROMPT_DETECTION - // Read the state of the switch port into a temporary variable. + + /* + * Switch Port State 🠖 Temporary Variable + */ + bool readState = readCurrentState(); + // Check if the button state has changed + if ( readState != getStateFlag(DEBOUNCED_STATE) ) { - // We have seen a change from the current button state. + + + /* + * Enough time has passed + * ⤷ New state changes are allowed + * + * Set Flags: + * - STATE_CHANGED + * - DEBOUNCED_STATE + */ if ( millis() - previous_millis >= interval_millis ) { - // We have passed the time threshold, so a new change of state is allowed. - // set the STATE_CHANGED flag and the new DEBOUNCED_STATE. - // This will be prompt as long as there has been greater than interval_misllis ms since last change of input. - // Otherwise debounced state will not change again until bouncing is stable for the timeout period. changeState(); } } - // If the readState is different from previous readState, reset the debounce timer - as input is still unstable - // and we want to prevent new button state changes until the previous one has remained stable for the timeout. + + /* + * If readState ≠ to it's previous state + * ⤷ Reset the debounce timer + * + * This is done, as input is still unstable + * and we want to prevent new button state + * changes until the previous state has + * remained stable for the timeout. + */ + if ( readState != getStateFlag(UNSTABLE_STATE) ) { - // Update Unstable Bit to macth readState + + // Update unstable bit to match readState + toggleStateFlag(UNSTABLE_STATE); previous_millis = millis(); } #else - // Read the state of the switch in a temporary variable. + + /* + * Switch Port State 🠖 Temporary Variable + */ + bool currentState = readCurrentState(); - // If the reading is different from last reading, reset the debounce counter + /* + * If the reading ≠ to it's previous state + * ⤷ Reset the debounce counter + */ + if ( currentState != getStateFlag(UNSTABLE_STATE) ) { previous_millis = millis(); toggleStateFlag(UNSTABLE_STATE); } else if ( millis() - previous_millis >= interval_millis ) { - // We have passed the threshold time, so the input is now stable - // If it is different from last state, set the STATE_CHANGED flag + + /* + * We have passed the threshold time + * ⤷ The input is now stable + * + * If it is ≠ to it's previous state + * ⤷ Set the STATE_CHANGED flag + */ + if (currentState != getStateFlag(DEBOUNCED_STATE) ) { previous_millis = millis(); @@ -99,7 +140,13 @@ bool Debouncer::update() } -// WIP HELD + +// Work In Progress +/* + * Work In Progress + * HELD + */ + unsigned long Debouncer::previousDuration() const { return durationOfPreviousState; }