From d5cd8e958b3fd01429cc68989c27516b467914ad Mon Sep 17 00:00:00 2001 From: wolfv6 Date: Wed, 13 Jul 2016 07:17:35 -0600 Subject: [PATCH] add StrobePort_PCA9655E::write() and const bool Scanner_Port::STROBE_OFF --- src/ReadPort.cpp | 4 ---- src/ReadPort.h | 3 +-- src/ReadPort_PCA9655E.cpp | 9 ++------- src/ReadPort_PCA9655E.h | 2 +- src/Scanner_Port.cpp | 19 ++++++++++++------- src/Scanner_Port.h | 7 ++++--- src/StrobePort.h | 1 + src/StrobePort_PCA9655E.cpp | 16 ++++++++++++++++ src/StrobePort_PCA9655E.h | 5 +++-- 9 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/ReadPort.cpp b/src/ReadPort.cpp index 4109cc9..68141c8 100644 --- a/src/ReadPort.cpp +++ b/src/ReadPort.cpp @@ -5,7 +5,3 @@ uint8_t ReadPort::getColPins() return readPins; } -uint8_t ReadPort::getPortState() -{ - return portState; -} diff --git a/src/ReadPort.h b/src/ReadPort.h index b3d6b87..f607e47 100644 --- a/src/ReadPort.h +++ b/src/ReadPort.h @@ -16,8 +16,7 @@ class ReadPort ReadPort(const uint8_t readPins): readPins(readPins), portState(0) {} //read port and store it's pins values in portState - virtual void read()=0; + virtual uint8_t read()=0; uint8_t getColPins(); - uint8_t getPortState(); }; #endif diff --git a/src/ReadPort_PCA9655E.cpp b/src/ReadPort_PCA9655E.cpp index d83fb82..36c2578 100644 --- a/src/ReadPort_PCA9655E.cpp +++ b/src/ReadPort_PCA9655E.cpp @@ -18,7 +18,7 @@ void ReadPort_PCA9655E::begin() /* Saves all port-pin values to portState. */ -void ReadPort_PCA9655E::read() +uint8_t ReadPort_PCA9655E::read() { Wire.beginTransmission(port.ADDR); Wire.write(inputByteCommand); //input immediately before requestFrom @@ -26,10 +26,5 @@ void ReadPort_PCA9655E::read() Wire.requestFrom(port.ADDR, 1u); //request one byte from input port - portState = Wire.read(); -/*if (portState)//todo -{ - Keyboard.print(" portState="); - Keyboard.print(portState); -}*/ + return Wire.read(); } diff --git a/src/ReadPort_PCA9655E.h b/src/ReadPort_PCA9655E.h index 5de8355..7839673 100644 --- a/src/ReadPort_PCA9655E.h +++ b/src/ReadPort_PCA9655E.h @@ -40,6 +40,6 @@ class ReadPort_PCA9655E : public ReadPort void begin(); //read port and store result in portState - virtual void read(); + virtual uint8_t read(); }; #endif diff --git a/src/Scanner_Port.cpp b/src/Scanner_Port.cpp index 20a3542..d0503ee 100644 --- a/src/Scanner_Port.cpp +++ b/src/Scanner_Port.cpp @@ -4,29 +4,34 @@ Strobes the row and reads the columns. */ uint8_t Scanner_Port::scan() { - //strobe row on - if (STROBE_ON == LOW) //if activeLow + uint8_t readState; + + /*if (STROBE_ON == LOW) //if activeLow { refStrobePort.setActivePinLow(strobePin); } else //if activeHigh { refStrobePort.setActivePinHigh(strobePin); - } + }*/ + //strobe row on + refStrobePort.write(STROBE_PIN, STROBE_ON); delayMicroseconds(3); //time to stablize voltage //read the port pins - refReadPort.read(); + readState = refReadPort.read(); //strobe row off - if (STROBE_ON == LOW) //if activeLow + refStrobePort.write(STROBE_PIN, STROBE_OFF); + /*if (STROBE_ON == LOW) //if activeLow { refStrobePort.setActivePinHigh(strobePin); } else //if activeHigh { refStrobePort.setActivePinLow(strobePin); - } + }*/ - return refReadPort.getPortState(); + //return refReadPort.getPortState(); + return readState; } diff --git a/src/Scanner_Port.h b/src/Scanner_Port.h index 25049ea..bdbf425 100644 --- a/src/Scanner_Port.h +++ b/src/Scanner_Port.h @@ -12,12 +12,13 @@ class Scanner_Port { private: static const bool STROBE_ON; //HIGH or LOW logic level of strobe on, active state + static const bool STROBE_OFF; //logic level of strobe off, complement of STROBE_ON StrobePort& refStrobePort; //this row's IC port - const uint8_t strobePin; //bitwise, 1 indicates IC pin connected to this row + const uint8_t STROBE_PIN; //bitwise, 1 indicates IC pin connected to this row ReadPort& refReadPort; public: - Scanner_Port(StrobePort &refStrobePort, const uint8_t strobePin, ReadPort& refReadPort) - : refStrobePort(refStrobePort), strobePin(strobePin), refReadPort(refReadPort) {} + Scanner_Port(StrobePort &refStrobePort, const uint8_t STROBE_PIN, ReadPort& refReadPort) + : refStrobePort(refStrobePort), STROBE_PIN(STROBE_PIN), refReadPort(refReadPort) {} uint8_t scan(); }; #endif diff --git a/src/StrobePort.h b/src/StrobePort.h index f5cd215..8bd5212 100644 --- a/src/StrobePort.h +++ b/src/StrobePort.h @@ -12,5 +12,6 @@ class StrobePort public: virtual void setActivePinHigh(const uint8_t activePin)=0; virtual void setActivePinLow(const uint8_t activePin)=0; + virtual void write(const uint8_t pin, const bool level)=0; }; #endif diff --git a/src/StrobePort_PCA9655E.cpp b/src/StrobePort_PCA9655E.cpp index 133b202..be31dd8 100644 --- a/src/StrobePort_PCA9655E.cpp +++ b/src/StrobePort_PCA9655E.cpp @@ -38,3 +38,19 @@ void StrobePort_PCA9655E::setActivePinHigh(const uint8_t activePin) Wire.endTransmission(); //todo delayMicroseconds(1500); still 4*bb w/o debouncer prints IOE rows sporadically } +void StrobePort_PCA9655E::write(const uint8_t pin, const bool level) +{ + if (level == LOW) + { + port.outputVal &= ~pin; + } + else + { + port.outputVal |= pin; + } + + Wire.beginTransmission(port.ADDR); + Wire.write(outputByteCommand); + Wire.write(port.outputVal); + Wire.endTransmission(); +} diff --git a/src/StrobePort_PCA9655E.h b/src/StrobePort_PCA9655E.h index 70ba164..d000929 100644 --- a/src/StrobePort_PCA9655E.h +++ b/src/StrobePort_PCA9655E.h @@ -44,7 +44,8 @@ class StrobePort_PCA9655E : public StrobePort StrobePort_PCA9655E(IOEPort& port); void begin(); - virtual void setActivePinLow(const uint8_t activePin); //activePin is a port mask - virtual void setActivePinHigh(const uint8_t activePin); + virtual void setActivePinLow(const uint8_t activePin); //activePin is a port mask todo delete + virtual void setActivePinHigh(const uint8_t activePin); //todo delete also in StrobePort.h + virtual void write(const uint8_t pin, const bool level); }; #endif