Archived
1
0

add StrobePort_PCA9655E::write() and const bool Scanner_Port::STROBE_OFF

This commit is contained in:
wolfv6 2016-07-13 07:17:35 -06:00
parent 37186b7586
commit d5cd8e958b
9 changed files with 40 additions and 26 deletions

View File

@ -5,7 +5,3 @@ uint8_t ReadPort::getColPins()
return readPins;
}
uint8_t ReadPort::getPortState()
{
return portState;
}

View File

@ -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

View File

@ -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();
}

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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();
}

View File

@ -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