From 4d69fd2aed1f890fba971cb7b03898256c844b41 Mon Sep 17 00:00:00 2001 From: wolfv6 Date: Tue, 12 Jul 2016 08:31:17 -0600 Subject: [PATCH] remove readPinCount from Row_uC, Row_ShiftRegisters: process() and scan() --- src/Row_ShiftRegisters.cpp | 6 +++--- src/Row_ShiftRegisters.h | 3 ++- src/Row_uC.cpp | 6 +++--- src/Row_uC.h | 3 ++- src/Scanner_ShiftRegs74HC165.cpp | 6 +++--- src/Scanner_ShiftRegs74HC165.h | 4 ++-- src/Scanner_uC.cpp | 4 ++-- src/Scanner_uC.h | 4 ++-- 8 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Row_ShiftRegisters.cpp b/src/Row_ShiftRegisters.cpp index ebde054..670237e 100644 --- a/src/Row_ShiftRegisters.cpp +++ b/src/Row_ShiftRegisters.cpp @@ -4,12 +4,12 @@ void Row_ShiftRegisters::process() { //these variables are all bitwise, one bit per key read_pins_t rowState; //1 means pressed, 0 means released - uint8_t readPinCount; + //uint8_t readPinCount; read_pins_t debouncedChanged; //1 means debounced changed - rowState = scanner.scan(readPinCount); + rowState = scanner.scan(); debouncedChanged = debouncer.debounce(rowState, debounced); - pressRelease(readPinCount, debouncedChanged); + pressRelease(READ_PIN_COUNT, debouncedChanged); } void Row_ShiftRegisters::begin() diff --git a/src/Row_ShiftRegisters.h b/src/Row_ShiftRegisters.h index d017e36..630b753 100644 --- a/src/Row_ShiftRegisters.h +++ b/src/Row_ShiftRegisters.h @@ -30,9 +30,10 @@ class Row_ShiftRegisters : public Row Scanner_ShiftRegs74HC165 scanner; Debouncer_4Samples debouncer; //Debouncer_Not debouncer; //passed test + const uint8_t READ_PIN_COUNT; //number of read pins public: Row_ShiftRegisters(const uint8_t STROBE_PIN, uint8_t READ_PIN_COUNT, Key *const ptrsKeys[]) - : Row(ptrsKeys), scanner(STROBE_PIN, READ_PIN_COUNT) { } + : Row(ptrsKeys), scanner(STROBE_PIN, READ_PIN_COUNT), READ_PIN_COUNT(READ_PIN_COUNT) { } void begin(); void process(); }; diff --git a/src/Row_uC.cpp b/src/Row_uC.cpp index 996bc4d..6855044 100644 --- a/src/Row_uC.cpp +++ b/src/Row_uC.cpp @@ -7,10 +7,10 @@ void Row_uC::process() { //these variables are all bitwise, one bit per key read_pins_t rowState; //1 means pressed, 0 means released - uint8_t readPinCount; + //uint8_t readPinCount; read_pins_t debouncedChanged; //1 means debounced changed - rowState = scanner.scan(readPinCount); + rowState = scanner.scan(); debouncedChanged = debouncer.debounce(rowState, debounced); - pressRelease(readPinCount, debouncedChanged); + pressRelease(READ_PIN_COUNT, debouncedChanged); } diff --git a/src/Row_uC.h b/src/Row_uC.h index ca4482c..f269621 100644 --- a/src/Row_uC.h +++ b/src/Row_uC.h @@ -31,10 +31,11 @@ class Row_uC : public Row private: Scanner_uC scanner; Debouncer_4Samples debouncer; + const uint8_t READ_PIN_COUNT; //number of read pins public: Row_uC(const uint8_t strobePin, const uint8_t READ_PINS[], const uint8_t READ_PIN_COUNT, Key *const ptrsKeys[]) - : Row(ptrsKeys), scanner(strobePin, READ_PINS, READ_PIN_COUNT) { } + : Row(ptrsKeys), scanner(strobePin, READ_PINS, READ_PIN_COUNT), READ_PIN_COUNT(READ_PIN_COUNT) { } void process(); }; #endif diff --git a/src/Scanner_ShiftRegs74HC165.cpp b/src/Scanner_ShiftRegs74HC165.cpp index df625a4..656b0b6 100644 --- a/src/Scanner_ShiftRegs74HC165.cpp +++ b/src/Scanner_ShiftRegs74HC165.cpp @@ -2,7 +2,7 @@ //constructor Scanner_ShiftRegs74HC165::Scanner_ShiftRegs74HC165(const uint8_t STROBE_PIN, uint8_t READ_PIN_COUNT) - : STROBE_PIN(STROBE_PIN), BYTE_COUNT(ceil (float(READ_PIN_COUNT)/8)), READ_PIN_COUNT(READ_PIN_COUNT) + : STROBE_PIN(STROBE_PIN), BYTE_COUNT(ceil (float(READ_PIN_COUNT)/8)) { //configure controller to communicate with shift register matrix pinMode(STROBE_PIN, OUTPUT); @@ -18,7 +18,7 @@ void Scanner_ShiftRegs74HC165::begin() /* Sets readPinCount and returns rowState. */ -read_pins_t Scanner_ShiftRegs74HC165::scan(uint8_t& readPinCount) +read_pins_t Scanner_ShiftRegs74HC165::scan() { read_pins_t rowState = 0; @@ -34,7 +34,7 @@ read_pins_t Scanner_ShiftRegs74HC165::scan(uint8_t& readPinCount) //strobe row off digitalWrite(STROBE_PIN, STROBE_OFF); - readPinCount = READ_PIN_COUNT; + // readPinCount = READ_PIN_COUNT; //for testing on breadboard, clear unpowered pins rowState &= 0b11110001000100010001000100010001; //todo diff --git a/src/Scanner_ShiftRegs74HC165.h b/src/Scanner_ShiftRegs74HC165.h index 36d3b89..44b57aa 100644 --- a/src/Scanner_ShiftRegs74HC165.h +++ b/src/Scanner_ShiftRegs74HC165.h @@ -44,10 +44,10 @@ class Scanner_ShiftRegs74HC165 static const bool STROBE_OFF; //logic level of strobe off, complement of active state const uint8_t STROBE_PIN; //Arduino pin number connected to this row const uint8_t BYTE_COUNT; //number of bytes to read from shift registers - uint8_t READ_PIN_COUNT; + //uint8_t READ_PIN_COUNT; public: Scanner_ShiftRegs74HC165(const uint8_t STROBE_PIN, uint8_t READ_PIN_COUNT); - virtual read_pins_t scan(uint8_t& READ_PIN_COUNT); + virtual read_pins_t scan(); void begin(); }; #endif diff --git a/src/Scanner_uC.cpp b/src/Scanner_uC.cpp index 3ac8540..49f3464 100644 --- a/src/Scanner_uC.cpp +++ b/src/Scanner_uC.cpp @@ -36,7 +36,7 @@ https://www.arduino.cc/en/Reference/DigitalWrite https://www.arduino.cc/en/Reference/DigitalRead https://www.arduino.cc/en/Reference/Constants > Digital Pins modes: INPUT, INPUT_PULLUP, and OUTPUT */ -read_pins_t Scanner_uC::scan(uint8_t& readPinCount) +read_pins_t Scanner_uC::scan() { read_pins_t rowState = 0; //bitwise, one col per bit, 1 means key is pressed read_pins_t readMask = 1; //bitwise, one col per bit, active col bit is 1 @@ -58,6 +58,6 @@ read_pins_t Scanner_uC::scan(uint8_t& readPinCount) //strobe row off digitalWrite(STROBE_PIN, STROBE_OFF); - readPinCount = READ_PIN_COUNT; + // readPinCount = READ_PIN_COUNT; return rowState; } diff --git a/src/Scanner_uC.h b/src/Scanner_uC.h index 6b76e32..a6d4c44 100644 --- a/src/Scanner_uC.h +++ b/src/Scanner_uC.h @@ -19,8 +19,8 @@ class Scanner_uC const uint8_t READ_PIN_COUNT; //number of read pins public: Scanner_uC(const uint8_t STROBE_PIN, - const uint8_t READ_PINS[], const uint8_t READ_PIN_COUNT); //todo rename READ_PIN_COUNT to READ_PIN_COUNT ?? - virtual read_pins_t scan(uint8_t& READ_PIN_COUNT); + const uint8_t READ_PINS[], const uint8_t READ_PIN_COUNT); + virtual read_pins_t scan(); }; #endif