Archived
1
0

swap places of debounced and previousDebounced

This commit is contained in:
wolfv6 2016-06-02 15:51:42 -06:00
parent 05b4f875eb
commit 84fc616916
3 changed files with 7 additions and 6 deletions

View File

@ -39,7 +39,7 @@ Returns bitwise debouncedChanged.
uint8_t Row::debounce(const uint8_t rowState) uint8_t Row::debounce(const uint8_t rowState)
{ {
uint8_t debounced; //bitwise, 1 means pressed, 0 means released uint8_t previousDebounced; //bitwise, one bit per key
uint8_t debouncedChanged; //bitwise, 1 means debounced changed uint8_t debouncedChanged; //bitwise, 1 means debounced changed
uint8_t all_1 = ~0; //bitwise uint8_t all_1 = ~0; //bitwise
uint8_t all_0 = 0; //bitwise uint8_t all_0 = 0; //bitwise
@ -57,6 +57,8 @@ uint8_t Row::debounce(const uint8_t rowState)
all_0 |= samples[j]; //0 if all samples are 0 all_0 |= samples[j]; //0 if all samples are 0
} }
previousDebounced = debounced;
// update newDebounce if all the samples agree with one another // update newDebounce if all the samples agree with one another
// if all samples=1 then debounced=1 // if all samples=1 then debounced=1
// elseif all samples=0 then debounced=0 // elseif all samples=0 then debounced=0
@ -64,6 +66,5 @@ uint8_t Row::debounce(const uint8_t rowState)
debounced = all_1 | (all_0 & previousDebounced); debounced = all_1 | (all_0 & previousDebounced);
debouncedChanged = debounced xor previousDebounced; debouncedChanged = debounced xor previousDebounced;
previousDebounced = debounced;
return debouncedChanged; return debouncedChanged;
} }

View File

@ -140,10 +140,10 @@ void RowBase::pressRelease(const uint16_t rowEnd, const uint8_t debouncedChanged
uint8_t col; //index for ptrsKeys[col] array uint8_t col; //index for ptrsKeys[col] array
//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 & ~previousDebounced; isFallingEdge = debouncedChanged & ~debounced;
//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 & previousDebounced; isRisingEdge = debouncedChanged & debounced;
for (rowMask=1, col=0; rowMask<rowEnd; rowMask<<=1, col++) //for each key in row for (rowMask=1, col=0; rowMask<rowEnd; rowMask<<=1, col++) //for each key in row
{ {

View File

@ -27,14 +27,14 @@ class RowBase
void pressRelease(const uint16_t rowEnd, const uint8_t debouncedChanged); void pressRelease(const uint16_t rowEnd, const uint8_t debouncedChanged);
virtual void keyWasPressed(); virtual void keyWasPressed();
protected: protected:
uint8_t previousDebounced; //bitwise, one bit per key uint8_t debounced; //bitwise, 1 means pressed, 0 means released
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),
previousDebounced(0) { } debounced(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);
}; };