From aa48937a096bee3cb979b8d307e6b0bf0dd9b4a8 Mon Sep 17 00:00:00 2001 From: wolfv6 Date: Mon, 6 Jun 2016 19:37:48 -0600 Subject: [PATCH] RowScanner_Arduino, add readPins[] array --- src/Row.h | 3 ++- src/RowBase.cpp | 4 +--- src/RowScanner_Arduino.cpp | 32 +++++++++++++++----------------- src/RowScanner_Arduino.h | 13 ++++++------- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/Row.h b/src/Row.h index a316c40..4f42209 100644 --- a/src/Row.h +++ b/src/Row.h @@ -24,7 +24,8 @@ class Row : public RowBase Debouncer_4Samples debouncer; public: //Row constructor was like Row_DH constructor - Row(const uint8_t rowPin, Key *const ptrsKeys[]) : RowBase(ptrsKeys), scanner(rowPin) { } + Row(const uint8_t strobePin, const uint8_t readPins[], const uint8_t READ_PIN_COUNT, Key *const ptrsKeys[]) + : RowBase(ptrsKeys), scanner(strobePin, readPins, READ_PIN_COUNT) { } virtual void process(); }; #endif diff --git a/src/RowBase.cpp b/src/RowBase.cpp index 50b5272..c999254 100644 --- a/src/RowBase.cpp +++ b/src/RowBase.cpp @@ -28,15 +28,13 @@ 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: +Slow-scan trick for debug messages that print too fast, add delay to sketch loop(): delay(1000); That way debug messages are printed at a managable rate. */ void RowBase::wait() { delayMicroseconds(DELAY_MICROSECONDS); //delay between Row scans to debounce switches -delay(500); -Keyboard.print(" w "); } /* diff --git a/src/RowScanner_Arduino.cpp b/src/RowScanner_Arduino.cpp index 07c7353..edbdd05 100644 --- a/src/RowScanner_Arduino.cpp +++ b/src/RowScanner_Arduino.cpp @@ -1,11 +1,11 @@ #include "RowScanner_Arduino.h" /* Strobes the row and reads the columns. -Strobe is on for shortest possible time. */ uint8_t RowScanner_Arduino::scan(uint16_t& rowEnd) { uint8_t rowState = 0; + uint8_t col = 1; //strobe row on if (activeHigh) @@ -18,28 +18,26 @@ uint8_t RowScanner_Arduino::scan(uint16_t& rowEnd) } delayMicroseconds(3); //time to stablize voltage -/* - uint8_t col = 1; - //read all the column ports - for (uint8_t i=0; i < readPinCount; i++) + for (uint8_t i=0; i < READ_PIN_COUNT; i++) { - if (digitalRead(6)) + if ( digitalRead(readPins[i]) == activeHigh ) { rowState |= col; - //ptrsColPorts[i]->read(); } +/* +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; } -*/ - if (digitalRead(6) == 0) - { - rowState |= 1<<0; - } - if (digitalRead(7) == 0) - { - rowState |= 1<<1; - } //strobe row off if (activeHigh) @@ -53,6 +51,6 @@ uint8_t RowScanner_Arduino::scan(uint16_t& rowEnd) rowEnd = 4; //only read first two col, a1 b2 4 -Keyboard.print(rowState); // prints 2b, not 1a, what happened to col0? +//Keyboard.print(rowState); return rowState; } diff --git a/src/RowScanner_Arduino.h b/src/RowScanner_Arduino.h index 3328810..6004a8d 100644 --- a/src/RowScanner_Arduino.h +++ b/src/RowScanner_Arduino.h @@ -8,7 +8,7 @@ /* rowPin > stobePins[] replace port calls with x pass 1: hard code pins for row0 and col6, init in setup() - pass 2: pins[] array - first strobe, then read + x pass 2: pins[] array - first strobe, then read 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 @@ -16,13 +16,12 @@ 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* readPins; //array of read pins - //const uint8_t readPinCount; + 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) - : stobePin(stobePin) - // readPinCount(readPinCount) - {} + RowScanner_Arduino(const uint8_t stobePin, + const uint8_t readPins[], const uint8_t READ_PIN_COUNT) + : stobePin(stobePin), readPins(readPins), READ_PIN_COUNT(READ_PIN_COUNT) {} virtual uint8_t scan(uint16_t& rowEnd); uint8_t getRowState(uint16_t& rowEnd); };