return readPins; | return readPins; | ||||
} | } | ||||
uint8_t ReadPort::getPortState() | |||||
{ | |||||
return portState; | |||||
} |
ReadPort(const uint8_t readPins): readPins(readPins), portState(0) {} | ReadPort(const uint8_t readPins): readPins(readPins), portState(0) {} | ||||
//read port and store it's pins values in portState | //read port and store it's pins values in portState | ||||
virtual void read()=0; | |||||
virtual uint8_t read()=0; | |||||
uint8_t getColPins(); | uint8_t getColPins(); | ||||
uint8_t getPortState(); | |||||
}; | }; | ||||
#endif | #endif |
/* | /* | ||||
Saves all port-pin values to portState. | Saves all port-pin values to portState. | ||||
*/ | */ | ||||
void ReadPort_PCA9655E::read() | |||||
uint8_t ReadPort_PCA9655E::read() | |||||
{ | { | ||||
Wire.beginTransmission(port.ADDR); | Wire.beginTransmission(port.ADDR); | ||||
Wire.write(inputByteCommand); //input immediately before requestFrom | Wire.write(inputByteCommand); //input immediately before requestFrom | ||||
Wire.requestFrom(port.ADDR, 1u); //request one byte from input port | 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(); | |||||
} | } |
void begin(); | void begin(); | ||||
//read port and store result in portState | //read port and store result in portState | ||||
virtual void read(); | |||||
virtual uint8_t read(); | |||||
}; | }; | ||||
#endif | #endif |
*/ | */ | ||||
uint8_t Scanner_Port::scan() | 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); | refStrobePort.setActivePinLow(strobePin); | ||||
} | } | ||||
else //if activeHigh | else //if activeHigh | ||||
{ | { | ||||
refStrobePort.setActivePinHigh(strobePin); | refStrobePort.setActivePinHigh(strobePin); | ||||
} | |||||
}*/ | |||||
//strobe row on | |||||
refStrobePort.write(STROBE_PIN, STROBE_ON); | |||||
delayMicroseconds(3); //time to stablize voltage | delayMicroseconds(3); //time to stablize voltage | ||||
//read the port pins | //read the port pins | ||||
refReadPort.read(); | |||||
readState = refReadPort.read(); | |||||
//strobe row off | //strobe row off | ||||
if (STROBE_ON == LOW) //if activeLow | |||||
refStrobePort.write(STROBE_PIN, STROBE_OFF); | |||||
/*if (STROBE_ON == LOW) //if activeLow | |||||
{ | { | ||||
refStrobePort.setActivePinHigh(strobePin); | refStrobePort.setActivePinHigh(strobePin); | ||||
} | } | ||||
else //if activeHigh | else //if activeHigh | ||||
{ | { | ||||
refStrobePort.setActivePinLow(strobePin); | refStrobePort.setActivePinLow(strobePin); | ||||
} | |||||
}*/ | |||||
return refReadPort.getPortState(); | |||||
//return refReadPort.getPortState(); | |||||
return readState; | |||||
} | } |
{ | { | ||||
private: | private: | ||||
static const bool STROBE_ON; //HIGH or LOW logic level of strobe on, active state | 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 | 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; | ReadPort& refReadPort; | ||||
public: | 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(); | uint8_t scan(); | ||||
}; | }; | ||||
#endif | #endif |
public: | public: | ||||
virtual void setActivePinHigh(const uint8_t activePin)=0; | virtual void setActivePinHigh(const uint8_t activePin)=0; | ||||
virtual void setActivePinLow(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 | #endif |
Wire.endTransmission(); | Wire.endTransmission(); | ||||
//todo delayMicroseconds(1500); still 4*bb w/o debouncer prints IOE rows sporadically | //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(); | |||||
} |
StrobePort_PCA9655E(IOEPort& port); | StrobePort_PCA9655E(IOEPort& port); | ||||
void begin(); | 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 | #endif |