Both parameters are bitwise. | Both parameters are bitwise. | ||||
rowEnd bit marks positioned immediatly after last key of row. | 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 isFallingEdge; //bitwise, 1 means falling edge | ||||
read_pins_t isRisingEdge; //bitwise, 1 means rising edge | read_pins_t isRisingEdge; //bitwise, 1 means rising edge | ||||
//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 & 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 | //release before press avoids impossible key sequence | ||||
if (rowMask & isFallingEdge) //if key was released | if (rowMask & isFallingEdge) //if key was released |
Strobes the row and reads the columns. | Strobes the row and reads the columns. | ||||
Sets rowEnd and returns rowState. | Sets rowEnd and returns rowState. | ||||
*/ | */ | ||||
ColPort* const RowScanner_PinsBitwise::scan(read_pins_mask_t& rowEnd) | |||||
ColPort* const RowScanner_PinsBitwise::scan() | |||||
{ | { | ||||
//strobe row on | //strobe row on | ||||
if (activeHigh) | if (activeHigh) |
: refRowPort(refRowPort), strobePin(strobePin), | : refRowPort(refRowPort), strobePin(strobePin), | ||||
refColPort(refColPort) {} | refColPort(refColPort) {} | ||||
static const bool activeHigh; //logic level of strobe pin: 0=activeLow, 1=activeHigh | 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 | #endif |
{ | { | ||||
//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 | ||||
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 | uint8_t debouncedChanged; //1 means debounced changed | ||||
ColPort* ptrColPort; //new | 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); | debouncedChanged = debouncer.debounce(rowState, debounced); | ||||
pressRelease(rowEnd, debouncedChanged); | |||||
pressRelease(KEY_COUNT, debouncedChanged); | |||||
} | } | ||||
/* | /* | ||||
At end of function, 1 bit marks place immediatly after last key of row. | 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. | 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 rowState = 0; //bitwise, one key per bit, 1 means key is pressed | ||||
uint8_t portMask; //bitwise, 1 bit is a colPortState position | 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 | //bitwise colPins, 1 means pin is connected to column | ||||
uint8_t colPins = ptrColPort->getColPins(); | uint8_t colPins = ptrColPort->getColPins(); | ||||
} | } | ||||
rowEnd <<= 1; //shift rowEnd to next key | rowEnd <<= 1; //shift rowEnd to next key | ||||
KEY_COUNT++; | |||||
} | } | ||||
} | } | ||||
Debouncer_4Samples debouncer; | Debouncer_4Samples debouncer; | ||||
public: | public: | ||||
Row_IOE( RowPort& refRowPort, const uint8_t strobePin, | 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) { } | : RowBase(ptrsKeys), scanner(refRowPort, strobePin, refColPort) { } | ||||
void process(); | void process(); | ||||
uint8_t getRowState(ColPort* refColPort, read_pins_mask_t& rowEnd); | |||||
uint8_t getRowState(ColPort* ptrColPort, uint8_t& KEY_COUNT); | |||||
}; | }; | ||||
#endif | #endif |