From a44b6f620d1f118b8925f5431167831461416002 Mon Sep 17 00:00:00 2001 From: wolfv6 Date: Tue, 7 Jun 2016 03:26:25 -0600 Subject: [PATCH] RowScanner_Arduino, move initialization to constructor --- src/RowBase.cpp | 5 +++-- src/RowScanner_Arduino.cpp | 26 +++++++------------------- src/RowScanner_Arduino.h | 20 +++++++++++++++----- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/RowBase.cpp b/src/RowBase.cpp index c999254..75acab9 100644 --- a/src/RowBase.cpp +++ b/src/RowBase.cpp @@ -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() { diff --git a/src/RowScanner_Arduino.cpp b/src/RowScanner_Arduino.cpp index edbdd05..a31e4e8 100644 --- a/src/RowScanner_Arduino.cpp +++ b/src/RowScanner_Arduino.cpp @@ -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; } diff --git a/src/RowScanner_Arduino.h b/src/RowScanner_Arduino.h index 6004a8d..3403751 100644 --- a/src/RowScanner_Arduino.h +++ b/src/RowScanner_Arduino.h @@ -5,23 +5,33 @@ #include #include #include -/* 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); };