2016-09-06 07:08:26 +00:00
|
|
|
#include "Scanner_IOE.h"
|
|
|
|
|
2016-09-11 15:54:10 +00:00
|
|
|
/* init() is called once for each row from Row constructor.
|
2016-09-06 07:08:26 +00:00
|
|
|
*/
|
|
|
|
void Scanner_IOE::init(const uint8_t strobePin)
|
|
|
|
{
|
2016-09-11 15:54:10 +00:00
|
|
|
//empty
|
2016-09-06 07:08:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* begin() should be called once from sketch setup().
|
2016-09-12 06:28:27 +00:00
|
|
|
Initiates communication protocal and configs ports.
|
2016-09-06 07:08:26 +00:00
|
|
|
*/
|
|
|
|
void Scanner_IOE::begin()
|
|
|
|
{
|
2016-09-24 14:56:02 +00:00
|
|
|
refPortWrite.beginProtocol();
|
2016-11-06 09:41:56 +00:00
|
|
|
refPortWrite.begin(activeState);
|
|
|
|
refPortRead.begin(activeState);
|
2016-09-06 07:08:26 +00:00
|
|
|
}
|
|
|
|
|
2016-09-11 15:54:10 +00:00
|
|
|
/* scan() is called on every iteration of sketch loop().
|
2016-09-17 21:47:37 +00:00
|
|
|
strobePin is a bit pattern, 1 means that row pin is active.
|
2016-09-11 15:54:10 +00:00
|
|
|
scan() strobes the row's strobePin and retuns state of port's input pins.
|
2016-09-06 07:08:26 +00:00
|
|
|
*/
|
2016-09-07 04:51:36 +00:00
|
|
|
read_pins_t Scanner_IOE::scan(const uint8_t strobePin)
|
2016-09-06 07:08:26 +00:00
|
|
|
{
|
2016-09-17 21:47:37 +00:00
|
|
|
uint8_t readState; //bits, 1 means key is pressed, 0 means released
|
2016-09-06 07:08:26 +00:00
|
|
|
|
|
|
|
//strobe on
|
2016-11-14 07:29:29 +00:00
|
|
|
if (activeState == LOW) //if active low
|
|
|
|
{
|
2016-11-16 01:47:23 +00:00
|
|
|
refPortWrite.writeLow(strobePin);
|
2016-11-14 07:29:29 +00:00
|
|
|
}
|
|
|
|
else //if active high
|
|
|
|
{
|
2016-11-16 01:47:23 +00:00
|
|
|
refPortWrite.writeHigh(strobePin);
|
2016-11-14 07:29:29 +00:00
|
|
|
}
|
2016-09-06 07:08:26 +00:00
|
|
|
delayMicroseconds(3); //time to stabilize voltage
|
|
|
|
|
|
|
|
//read the port pins
|
|
|
|
readState = refPortRead.read();
|
|
|
|
|
|
|
|
//strobe off
|
2016-11-06 09:41:56 +00:00
|
|
|
if (activeState == LOW) //if active low
|
2016-09-11 15:54:10 +00:00
|
|
|
{
|
2016-11-16 01:47:23 +00:00
|
|
|
refPortWrite.writeHigh(strobePin);
|
2016-09-11 15:54:10 +00:00
|
|
|
readState = ~readState;
|
|
|
|
}
|
2016-11-14 07:29:29 +00:00
|
|
|
else //if active high
|
|
|
|
{
|
2016-11-16 01:47:23 +00:00
|
|
|
refPortWrite.writeLow(strobePin);
|
2016-11-14 07:29:29 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 07:08:26 +00:00
|
|
|
return readState;
|
|
|
|
}
|