Archived
1
0

remove rowEnd, add KEY_COUNT, shift rowState

This commit is contained in:
wolfv6 2016-07-07 08:09:55 -06:00
parent 987f33e270
commit 4945f577a4
5 changed files with 15 additions and 12 deletions

View File

@ -4,7 +4,7 @@ pressRelease() calls key's press() or release() function if it was pressed or re
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
@ -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 //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

View File

@ -3,7 +3,7 @@
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)

View File

@ -21,6 +21,6 @@ class RowScanner_PinsBitwise : public RowScannerInterface
: 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

View File

@ -4,14 +4,15 @@ void Row_IOE::process()
{ {
//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); ptrColPort = scanner.scan();
rowState = getRowState(ptrColPort, rowEnd); //new rowState = getRowState(ptrColPort, KEY_COUNT); //new
debouncedChanged = debouncer.debounce(rowState, debounced); 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. 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();
@ -49,6 +51,7 @@ uint8_t Row_IOE::getRowState(ColPort* ptrColPort, read_pins_mask_t& rowEnd)
} }
rowEnd <<= 1; //shift rowEnd to next key rowEnd <<= 1; //shift rowEnd to next key
KEY_COUNT++;
} }
} }

View File

@ -39,9 +39,9 @@ class Row_IOE : public RowBase
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