Archived
1
0

rename previousDebounced, debounced

This commit is contained in:
wolfv6 2016-06-01 09:58:03 -06:00
parent 51fb06939f
commit 25f66090e5
2 changed files with 11 additions and 11 deletions

View File

@ -7,14 +7,14 @@ void RowBase::process(const bool activeHigh)
//these variables are all bitwise, one bit per key //these variables are all bitwise, one bit per key
uint8_t rowState; //1 means pressed, 0 means released uint8_t rowState; //1 means pressed, 0 means released
uint16_t rowEnd; //1 bit marks positioned after last key of row 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 isFallingEdge; //1 means falling edge
uint8_t isRisingEdge; //1 means rising edge uint8_t isRisingEdge; //1 means rising edge
scan(activeHigh); //save column-port-pin values to portState scan(activeHigh); //save column-port-pin values to portState
rowState = getRowState(rowEnd, activeHigh); rowState = getRowState(rowEnd, activeHigh);
newDebounced = debounce(rowState); debounced = debounce(rowState);
detectEdge(newDebounced, isFallingEdge, isRisingEdge); detectEdge(debounced, isFallingEdge, isRisingEdge);
pressRelease(rowEnd, isFallingEdge, isRisingEdge); pressRelease(rowEnd, isFallingEdge, isRisingEdge);
} }
@ -98,18 +98,18 @@ uint8_t RowBase::getRowState(uint16_t& rowEnd, const bool activeHigh)
Computes isFallingEdge and isRisingEdge. Computes isFallingEdge and isRisingEdge.
All 3 parameters are bitwise. 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 uint8_t debouncedChanged; //bitwise
debouncedChanged = newDebounced xor debounced; debouncedChanged = debounced xor previousDebounced;
debounced = newDebounced; previousDebounced = debounced;
//bit=1 if last debounced changed from 1 to 0, else bit=0 //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 //bit=1 if last debounced changed from 0 to 1, else bit=0
isRisingEdge = debouncedChanged & debounced; isRisingEdge = debouncedChanged & previousDebounced;
} }
/* /*

View File

@ -58,19 +58,19 @@ class RowBase
void scan(const bool activeHigh); void scan(const bool activeHigh);
uint8_t getRowState(uint16_t& rowEnd, 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 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, void pressRelease(const uint16_t rowEnd,
const uint8_t isFallingEdge, const uint8_t isRisingEdge); const uint8_t isFallingEdge, const uint8_t isRisingEdge);
virtual void keyWasPressed(); virtual void keyWasPressed();
protected: protected:
uint8_t debounced; //bitwise, one bit per key, debounced value of readings uint8_t previousDebounced; //bitwise, one bit per key
public: public:
RowBase( RowPort &refRowPort, const uint8_t rowPin, RowBase( RowPort &refRowPort, const uint8_t rowPin,
ColPort *const ptrsColPorts[], const uint8_t colPortCount, ColPort *const ptrsColPorts[], const uint8_t colPortCount,
Key *const ptrsKeys[]) Key *const ptrsKeys[])
: ptrsKeys(ptrsKeys), refRowPort(refRowPort), rowPin(rowPin), : ptrsKeys(ptrsKeys), refRowPort(refRowPort), rowPin(rowPin),
ptrsColPorts(ptrsColPorts), colPortCount(colPortCount), ptrsColPorts(ptrsColPorts), colPortCount(colPortCount),
debounced(0) { } previousDebounced(0) { }
//Key* getPtrKey(uint8_t col) const; todo delete, no longer needed 5/31/16 //Key* getPtrKey(uint8_t col) const; todo delete, no longer needed 5/31/16
void process(const bool activeHigh); void process(const bool activeHigh);
}; };