@@ -4,7 +4,7 @@ pressRelease() calls key's press() or release() function if it was pressed or re | |||
Both parameters are bitwise. | |||
rowEnd bit marks positioned immediatly after last key of row. | |||
*/ | |||
void RowBase::pressRelease(const read_pins_mask_t rowEnd, const read_pins_t debouncedChanged) | |||
void RowBase::pressRelease(const uint8_t KEY_COUNT, const read_pins_t debouncedChanged) | |||
{ | |||
read_pins_t isFallingEdge; //bitwise, 1 means falling edge | |||
read_pins_t isRisingEdge; //bitwise, 1 means rising edge | |||
@@ -17,7 +17,7 @@ void RowBase::pressRelease(const read_pins_mask_t rowEnd, const read_pins_t debo | |||
//bit=1 if last debounced changed from 0 to 1, else bit=0 | |||
isRisingEdge = debouncedChanged & debounced; | |||
for (rowMask=1, col=0; rowMask<rowEnd; rowMask<<=1, col++) //for each key in row | |||
for (rowMask=1, col=0; col < KEY_COUNT; rowMask<<=1, col++) //for each key in row | |||
{ | |||
//release before press avoids impossible key sequence | |||
if (rowMask & isFallingEdge) //if key was released |
@@ -3,7 +3,7 @@ | |||
Strobes the row and reads the columns. | |||
Sets rowEnd and returns rowState. | |||
*/ | |||
ColPort* const RowScanner_PinsBitwise::scan(read_pins_mask_t& rowEnd) | |||
ColPort* const RowScanner_PinsBitwise::scan() | |||
{ | |||
//strobe row on | |||
if (activeHigh) |
@@ -21,6 +21,6 @@ class RowScanner_PinsBitwise : public RowScannerInterface | |||
: refRowPort(refRowPort), strobePin(strobePin), | |||
refColPort(refColPort) {} | |||
static const bool activeHigh; //logic level of strobe pin: 0=activeLow, 1=activeHigh | |||
virtual ColPort* const scan(read_pins_mask_t& rowEnd); | |||
virtual ColPort* const scan(); | |||
}; | |||
#endif |
@@ -4,14 +4,15 @@ void Row_IOE::process() | |||
{ | |||
//these variables are all bitwise, one bit per key | |||
uint8_t rowState; //1 means pressed, 0 means released | |||
read_pins_mask_t rowEnd; //1 bit marks positioned after last key of row | |||
//read_pins_mask_t rowEnd; //1 bit marks positioned after last key of row | |||
uint8_t debouncedChanged; //1 means debounced changed | |||
ColPort* ptrColPort; //new | |||
uint8_t KEY_COUNT; //new | |||
ptrColPort = scanner.scan(rowEnd); | |||
rowState = getRowState(ptrColPort, rowEnd); //new | |||
ptrColPort = scanner.scan(); | |||
rowState = getRowState(ptrColPort, KEY_COUNT); //new | |||
debouncedChanged = debouncer.debounce(rowState, debounced); | |||
pressRelease(rowEnd, debouncedChanged); | |||
pressRelease(KEY_COUNT, debouncedChanged); | |||
} | |||
/* | |||
@@ -21,12 +22,13 @@ rowEnd is a bitwise row mask, one col per bit, where active col bit is 1. | |||
At end of function, 1 bit marks place immediatly after last key of row. | |||
rowEnd is a larger type than portMask so that it can not overflow. | |||
*/ | |||
uint8_t Row_IOE::getRowState(ColPort* ptrColPort, read_pins_mask_t& rowEnd) | |||
uint8_t Row_IOE::getRowState(ColPort* ptrColPort, uint8_t& KEY_COUNT) | |||
{ | |||
uint8_t rowState = 0; //bitwise, one key per bit, 1 means key is pressed | |||
uint8_t portMask; //bitwise, 1 bit is a colPortState position | |||
uint8_t rowEnd; //1 bit marks positioned after last key of row todo rename | |||
rowEnd = 1; | |||
KEY_COUNT = 0; | |||
//bitwise colPins, 1 means pin is connected to column | |||
uint8_t colPins = ptrColPort->getColPins(); | |||
@@ -49,6 +51,7 @@ uint8_t Row_IOE::getRowState(ColPort* ptrColPort, read_pins_mask_t& rowEnd) | |||
} | |||
rowEnd <<= 1; //shift rowEnd to next key | |||
KEY_COUNT++; | |||
} | |||
} | |||
@@ -39,9 +39,9 @@ class Row_IOE : public RowBase | |||
Debouncer_4Samples debouncer; | |||
public: | |||
Row_IOE( RowPort& refRowPort, const uint8_t strobePin, | |||
ColPort& refColPort, Key *const ptrsKeys[]) | |||
ColPort& refColPort, Key *const ptrsKeys[], const uint8_t KEY_COUNT) | |||
: RowBase(ptrsKeys), scanner(refRowPort, strobePin, refColPort) { } | |||
void process(); | |||
uint8_t getRowState(ColPort* refColPort, read_pins_mask_t& rowEnd); | |||
uint8_t getRowState(ColPort* ptrColPort, uint8_t& KEY_COUNT); | |||
}; | |||
#endif |