Browse Source

RowScanner_Arduino, move initialization to constructor

tags/v0.5.0
wolfv6 8 years ago
parent
commit
a44b6f620d
3 changed files with 25 additions and 26 deletions
  1. 3
    2
      src/RowBase.cpp
  2. 7
    19
      src/RowScanner_Arduino.cpp
  3. 15
    5
      src/RowScanner_Arduino.h

+ 3
- 2
src/RowBase.cpp 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:
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);
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()
{

+ 7
- 19
src/RowScanner_Arduino.cpp View File

@@ -1,4 +1,5 @@
#include "RowScanner_Arduino.h"

/*
Strobes the row and reads the columns.
*/
@@ -10,14 +11,14 @@ uint8_t RowScanner_Arduino::scan(uint16_t& rowEnd)
//strobe row on
if (activeHigh)
{
digitalWrite(stobePin, HIGH);
digitalWrite(strobePin, HIGH);
}
else //activeLow
{
digitalWrite(stobePin, LOW);
digitalWrite(strobePin, LOW);
}
delayMicroseconds(3); //time to stablize voltage
//read all the column ports
for (uint8_t i=0; i < READ_PIN_COUNT; i++)
{
@@ -25,32 +26,19 @@ uint8_t RowScanner_Arduino::scan(uint16_t& rowEnd)
{
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;
}

//strobe row off
if (activeHigh)
{
digitalWrite(0, LOW);
digitalWrite(strobePin, LOW);
}
else //activeLow
{
digitalWrite(0, HIGH);
digitalWrite(strobePin, HIGH);
}
rowEnd = 4; //only read first two col, a1 b2 4

//Keyboard.print(rowState);
rowEnd = col;
return rowState;
}

+ 15
- 5
src/RowScanner_Arduino.h View File

@@ -5,23 +5,33 @@
#include <RowScannerInterface.h>
#include <RowPort.h>
#include <ColPort.h>
/* rowPin > stobePins[]
/* rowPin > strobePins[]
replace port calls with
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 4: add IC classes Strobe_MCP23018, Read_MCP23018 */
class RowScanner_Arduino : public RowScannerInterface
{
private:
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 READ_PIN_COUNT;//todo READ_PIN_COUNT
public:
RowScanner_Arduino(const uint8_t stobePin,
RowScanner_Arduino(const uint8_t strobePin,
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);
uint8_t getRowState(uint16_t& rowEnd);
};