Archived
1
0

rename to rowEnd, document

This commit is contained in:
wolfv6 2016-06-07 20:24:50 -06:00
parent a44b6f620d
commit 514c326800
5 changed files with 26 additions and 23 deletions

View File

@ -29,7 +29,7 @@ Polling I2C may slow the scan rate enough so that no additional delay is needed:
const unsigned int Row::DELAY_MICROSECONDS = 0; const unsigned int Row::DELAY_MICROSECONDS = 0;
Slow-scan trick for debug messages that print too fast and not aligned, add this to sketch loop(): Slow-scan trick for debug messages that print too fast and not aligned, add this to sketch loop():
delay(1000); delay(500);
Keyboard.println(""); Keyboard.println("");
That way debug messages are printed at a managable rate, and each scan starts a new line. That way debug messages are printed at a managable rate, and each scan starts a new line.
*/ */
@ -41,6 +41,7 @@ void RowBase::wait()
/* /*
pressRelease() calls key's press() or release() function if it was pressed or released. pressRelease() calls key's press() or release() function if it was pressed or released.
Both parameters are bitwise. Both parameters are bitwise.
rowEnd bit marks positioned immediatly after last key of row.
*/ */
void RowBase::pressRelease(const uint16_t rowEnd, const uint8_t debouncedChanged) void RowBase::pressRelease(const uint16_t rowEnd, const uint8_t debouncedChanged)
{ {

View File

@ -2,11 +2,15 @@
/* /*
Strobes the row and reads the columns. Strobes the row and reads the columns.
Sets rowEnd and returns rowState.
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 RowScanner_Arduino::scan(uint16_t& rowEnd) uint8_t RowScanner_Arduino::scan(uint16_t& rowEnd)
{ {
uint8_t rowState = 0; uint8_t rowState = 0;
uint8_t col = 1; rowEnd = 1;
//strobe row on //strobe row on
if (activeHigh) if (activeHigh)
@ -24,9 +28,9 @@ uint8_t RowScanner_Arduino::scan(uint16_t& rowEnd)
{ {
if ( digitalRead(readPins[i]) == activeHigh ) if ( digitalRead(readPins[i]) == activeHigh )
{ {
rowState |= col; rowState |= rowEnd;
} }
col <<= 1; rowEnd <<= 1;
} }
//strobe row off //strobe row off
@ -39,6 +43,5 @@ uint8_t RowScanner_Arduino::scan(uint16_t& rowEnd)
digitalWrite(strobePin, HIGH); digitalWrite(strobePin, HIGH);
} }
rowEnd = col;
return rowState; return rowState;
} }

View File

@ -5,19 +5,16 @@
#include <RowScannerInterface.h> #include <RowScannerInterface.h>
#include <RowPort.h> #include <RowPort.h>
#include <ColPort.h> #include <ColPort.h>
/* rowPin > strobePins[]
replace port calls with /* RowScanner_Arduino class uses Arduino pin numbers (no port name).
x pass 1: hard code pins for row0 and col6, init in setup() */
x pass 2: readPins[] array
pass 3: move calls to IC classes - Strobe_uC, Read_uC
pass 4: add IC classes Strobe_MCP23018, Read_MCP23018 */
class RowScanner_Arduino : public RowScannerInterface class RowScanner_Arduino : public RowScannerInterface
{ {
private: private:
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
const uint8_t strobePin; //Arduino pin number connected to this row const uint8_t strobePin; //Arduino pin number connected to this row
const uint8_t* readPins; //array of read pins const uint8_t* readPins; //array of read pin numbers
const uint8_t READ_PIN_COUNT;//todo READ_PIN_COUNT const uint8_t READ_PIN_COUNT; //number of read pins
public: public:
RowScanner_Arduino(const uint8_t strobePin, RowScanner_Arduino(const uint8_t strobePin,
const uint8_t readPins[], const uint8_t READ_PIN_COUNT) const uint8_t readPins[], const uint8_t READ_PIN_COUNT)

View File

@ -37,14 +37,16 @@ uint8_t RowScanner_BitManipulation::scan(uint16_t& rowEnd)
/* /*
Copies column pins to rowState. Unused column pins are not copied. Copies column pins to rowState. Unused column pins are not copied.
Sets rowEnd and returns rowState. Sets rowEnd and returns rowState.
rowEnd is bitwise, where 1 bit corrsiponds to place immediatly after last key of row. rowEnd is a bitwise row mask, one col per bit, where active col bit is 1.
rowEnd and rowMask are larger type than portMask so that they can not overflow. 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 RowScanner_BitManipulation::getRowState(uint16_t& rowEnd) uint8_t RowScanner_BitManipulation::getRowState(uint16_t& rowEnd)
{ {
uint16_t rowMask = 1; //bitwise, one col per bit, active col bit is 1
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
rowEnd = 1;
for (uint8_t i=0; i < colPortCount; i++) //for each col port for (uint8_t i=0; i < colPortCount; i++) //for each col port
{ {
//bitwise colPins, 1 means pin is connected to column //bitwise colPins, 1 means pin is connected to column
@ -64,15 +66,13 @@ uint8_t RowScanner_BitManipulation::getRowState(uint16_t& rowEnd)
{ {
if (portMask & ~colPortState) //if pin detected a key press if (portMask & ~colPortState) //if pin detected a key press
{ {
rowState |= rowMask; //set rowState bit for that key rowState |= rowEnd; //set rowState bit for that key
} }
rowMask <<= 1; //shift rowMask to next key rowEnd <<= 1; //shift rowEnd to next key
} }
} }
} }
rowEnd = rowMask;
return rowState; return rowState;
} }

View File

@ -6,6 +6,8 @@
#include <RowPort.h> #include <RowPort.h>
#include <ColPort.h> #include <ColPort.h>
/* RowScanner_BitManipulation uses bit manipulation to read all pins of one port.
*/
class RowScanner_BitManipulation : public RowScannerInterface class RowScanner_BitManipulation : public RowScannerInterface
{ {
private: private: