2016-07-12 13:23:24 +00:00
|
|
|
#include "ReadPort_PCA9655E.h"
|
2016-05-09 14:05:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
configures column port's configuration, input, and pins.
|
|
|
|
*/
|
2016-07-12 13:23:24 +00:00
|
|
|
ReadPort_PCA9655E::ReadPort_PCA9655E (IOEPort& port, const uint8_t readPins)
|
|
|
|
: ReadPort(readPins), port(port), configurationByteCommand(port.num + 6), inputByteCommand(port.num)
|
2016-05-09 14:05:08 +00:00
|
|
|
{}
|
|
|
|
|
2016-07-12 13:23:24 +00:00
|
|
|
void ReadPort_PCA9655E::begin()
|
2016-05-09 14:05:08 +00:00
|
|
|
{
|
|
|
|
Wire.beginTransmission(port.ADDR);
|
|
|
|
Wire.write(configurationByteCommand);
|
2016-07-12 13:23:24 +00:00
|
|
|
Wire.write(readPins); //0=configure as output (for LED), 1=configure as input (for read)
|
2016-05-09 14:05:08 +00:00
|
|
|
Wire.endTransmission();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Saves all port-pin values to portState.
|
|
|
|
*/
|
2016-07-13 13:17:35 +00:00
|
|
|
uint8_t ReadPort_PCA9655E::read()
|
2016-05-09 14:05:08 +00:00
|
|
|
{
|
|
|
|
Wire.beginTransmission(port.ADDR);
|
|
|
|
Wire.write(inputByteCommand); //input immediately before requestFrom
|
|
|
|
Wire.endTransmission(false); //PCA9655E needs false to send a restart
|
|
|
|
|
|
|
|
Wire.requestFrom(port.ADDR, 1u); //request one byte from input port
|
|
|
|
|
2016-07-13 13:17:35 +00:00
|
|
|
return Wire.read();
|
2016-05-09 14:05:08 +00:00
|
|
|
}
|