@@ -39,7 +39,7 @@ Returns bitwise debouncedChanged. | |||
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 all_1 = ~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 | |||
} | |||
previousDebounced = debounced; | |||
// update newDebounce if all the samples agree with one another | |||
// if all samples=1 then debounced=1 | |||
// 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); | |||
debouncedChanged = debounced xor previousDebounced; | |||
previousDebounced = debounced; | |||
return debouncedChanged; | |||
} |
@@ -140,10 +140,10 @@ void RowBase::pressRelease(const uint16_t rowEnd, const uint8_t debouncedChanged | |||
uint8_t col; //index for ptrsKeys[col] array | |||
//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 | |||
isRisingEdge = debouncedChanged & previousDebounced; | |||
isRisingEdge = debouncedChanged & debounced; | |||
for (rowMask=1, col=0; rowMask<rowEnd; rowMask<<=1, col++) //for each key in row | |||
{ |
@@ -27,14 +27,14 @@ class RowBase | |||
void pressRelease(const uint16_t rowEnd, const uint8_t debouncedChanged); | |||
virtual void keyWasPressed(); | |||
protected: | |||
uint8_t previousDebounced; //bitwise, one bit per key | |||
uint8_t debounced; //bitwise, 1 means pressed, 0 means released | |||
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), | |||
previousDebounced(0) { } | |||
debounced(0) { } | |||
//Key* getPtrKey(uint8_t col) const; todo delete, no longer needed 5/31/16 | |||
void process(const bool activeHigh); | |||
}; |