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

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()
{ {

+ 7
- 19
src/RowScanner_Arduino.cpp View File

#include "RowScanner_Arduino.h" #include "RowScanner_Arduino.h"

/* /*
Strobes the row and reads the columns. Strobes the row and reads the columns.
*/ */
//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
//read all the column ports //read all the column ports
for (uint8_t i=0; i < READ_PIN_COUNT; i++) for (uint8_t i=0; i < READ_PIN_COUNT; i++)
{ {
{ {
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

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

+ 15
- 5
src/RowScanner_Arduino.h View File

#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);
}; };