Archived
1
0

RowScanner_Arduino, move initialization to constructor

This commit is contained in:
wolfv6 2016-06-07 03:26:25 -06:00
parent aa48937a09
commit a44b6f620d
3 changed files with 25 additions and 26 deletions

View File

@ -28,9 +28,10 @@ The largest allowabl DELAY_MICROSECONDS is 65535 (.065535 second).
Polling I2C may slow the scan rate enough so that no additional delay is needed: 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, add delay to sketch loop(): Slow-scan trick for debug messages that print too fast and not aligned, add this to sketch loop():
delay(1000); delay(1000);
That way debug messages are printed at a managable rate. Keyboard.println("");
That way debug messages are printed at a managable rate, and each scan starts a new line.
*/ */
void RowBase::wait() void RowBase::wait()
{ {

View File

@ -1,4 +1,5 @@
#include "RowScanner_Arduino.h" #include "RowScanner_Arduino.h"
/* /*
Strobes the row and reads the columns. Strobes the row and reads the columns.
*/ */
@ -10,11 +11,11 @@ uint8_t RowScanner_Arduino::scan(uint16_t& rowEnd)
//strobe row on //strobe row on
if (activeHigh) if (activeHigh)
{ {
digitalWrite(stobePin, HIGH); digitalWrite(strobePin, HIGH);
} }
else //activeLow else //activeLow
{ {
digitalWrite(stobePin, LOW); digitalWrite(strobePin, LOW);
} }
delayMicroseconds(3); //time to stablize voltage delayMicroseconds(3); //time to stablize voltage
@ -25,32 +26,19 @@ uint8_t RowScanner_Arduino::scan(uint16_t& rowEnd)
{ {
rowState |= col; rowState |= col;
} }
/*
Keyboard.print(" stobePin");
Keyboard.print(stobePin);
Keyboard.print(" readPins[");
Keyboard.print(i);
Keyboard.print("]");
Keyboard.print((int)readPins[i]);
Keyboard.print(" col");
Keyboard.print(col);
Keyboard.print(" ");
*/
col <<= 1; col <<= 1;
} }
//strobe row off //strobe row off
if (activeHigh) if (activeHigh)
{ {
digitalWrite(0, LOW); digitalWrite(strobePin, LOW);
} }
else //activeLow else //activeLow
{ {
digitalWrite(0, HIGH); digitalWrite(strobePin, HIGH);
} }
rowEnd = 4; //only read first two col, a1 b2 4 rowEnd = col;
//Keyboard.print(rowState);
return rowState; return rowState;
} }

View File

@ -5,23 +5,33 @@
#include <RowScannerInterface.h> #include <RowScannerInterface.h>
#include <RowPort.h> #include <RowPort.h>
#include <ColPort.h> #include <ColPort.h>
/* rowPin > stobePins[] /* rowPin > strobePins[]
replace port calls with replace port calls with
x pass 1: hard code pins for row0 and col6, init in setup() x pass 1: hard code pins for row0 and col6, init in setup()
x pass 2: pins[] array - first strobe, then read x pass 2: readPins[] array
pass 3: move calls to IC classes - Strobe_uC, Read_uC pass 3: move calls to IC classes - Strobe_uC, Read_uC
pass 4: add IC classes Strobe_MCP23018, Read_MCP23018 */ 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 stobePin; //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 pins
const uint8_t READ_PIN_COUNT;//todo READ_PIN_COUNT const uint8_t READ_PIN_COUNT;//todo READ_PIN_COUNT
public: public:
RowScanner_Arduino(const uint8_t stobePin, 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)
: stobePin(stobePin), readPins(readPins), READ_PIN_COUNT(READ_PIN_COUNT) {} : strobePin(strobePin), readPins(readPins), READ_PIN_COUNT(READ_PIN_COUNT)
{
//row
pinMode(strobePin, OUTPUT);
//cols
for (uint8_t i=0; i < READ_PIN_COUNT; i++)
{
pinMode(readPins[i], INPUT_PULLUP);
}
}
virtual uint8_t scan(uint16_t& rowEnd); virtual uint8_t scan(uint16_t& rowEnd);
uint8_t getRowState(uint16_t& rowEnd); uint8_t getRowState(uint16_t& rowEnd);
}; };