diff --git a/src/RowBase.cpp b/src/RowBase.cpp index 0eb840e..bf17f48 100644 --- a/src/RowBase.cpp +++ b/src/RowBase.cpp @@ -7,14 +7,14 @@ void RowBase::process(const bool activeHigh) //these variables are all bitwise, one bit per key uint8_t rowState; //1 means pressed, 0 means released uint16_t rowEnd; //1 bit marks positioned after last key of row - uint8_t newDebounced; //1 means pressed, 0 means released + uint8_t debounced; //1 means pressed, 0 means released uint8_t isFallingEdge; //1 means falling edge uint8_t isRisingEdge; //1 means rising edge scan(activeHigh); //save column-port-pin values to portState rowState = getRowState(rowEnd, activeHigh); - newDebounced = debounce(rowState); - detectEdge(newDebounced, isFallingEdge, isRisingEdge); + debounced = debounce(rowState); + detectEdge(debounced, isFallingEdge, isRisingEdge); pressRelease(rowEnd, isFallingEdge, isRisingEdge); } @@ -98,18 +98,18 @@ uint8_t RowBase::getRowState(uint16_t& rowEnd, const bool activeHigh) Computes isFallingEdge and isRisingEdge. All 3 parameters are bitwise. */ -void RowBase::detectEdge(uint8_t newDebounced, uint8_t& isFallingEdge, uint8_t& isRisingEdge) +void RowBase::detectEdge(uint8_t debounced, uint8_t& isFallingEdge, uint8_t& isRisingEdge) { uint8_t debouncedChanged; //bitwise - debouncedChanged = newDebounced xor debounced; - debounced = newDebounced; + debouncedChanged = debounced xor previousDebounced; + previousDebounced = debounced; //bit=1 if last debounced changed from 1 to 0, else bit=0 - isFallingEdge = debouncedChanged & ~debounced; + isFallingEdge = debouncedChanged & ~previousDebounced; //bit=1 if last debounced changed from 0 to 1, else bit=0 - isRisingEdge = debouncedChanged & debounced; + isRisingEdge = debouncedChanged & previousDebounced; } /* diff --git a/src/RowBase.h b/src/RowBase.h index 9c49d9d..98ab1ff 100644 --- a/src/RowBase.h +++ b/src/RowBase.h @@ -58,19 +58,19 @@ class RowBase void scan(const bool activeHigh); uint8_t getRowState(uint16_t& rowEnd, const bool activeHigh); virtual uint8_t debounce(const uint8_t rowState)=0; //debouncer and I2C error correction - void detectEdge(uint8_t newDebounced, uint8_t& isFallingEdge, uint8_t& isRisingEdge); + void detectEdge(uint8_t debounced, uint8_t& isFallingEdge, uint8_t& isRisingEdge); void pressRelease(const uint16_t rowEnd, const uint8_t isFallingEdge, const uint8_t isRisingEdge); virtual void keyWasPressed(); protected: - uint8_t debounced; //bitwise, one bit per key, debounced value of readings + uint8_t previousDebounced; //bitwise, one bit per key public: RowBase( RowPort &refRowPort, const uint8_t rowPin, ColPort *const ptrsColPorts[], const uint8_t colPortCount, Key *const ptrsKeys[]) : ptrsKeys(ptrsKeys), refRowPort(refRowPort), rowPin(rowPin), ptrsColPorts(ptrsColPorts), colPortCount(colPortCount), - debounced(0) { } + previousDebounced(0) { } //Key* getPtrKey(uint8_t col) const; todo delete, no longer needed 5/31/16 void process(const bool activeHigh); };