Archived
1
0
This repo is archived. You can view files and clone it, but cannot push or open issues or pull requests.
keybrd/src/Scanner_IOE.cpp

44 lines
1.1 KiB
C++
Raw Normal View History

#include "Scanner_IOE.h"
/* init() is called once for each row from Row constructor.
*/
void Scanner_IOE::init(const uint8_t strobePin)
{
//empty
}
/* begin() should be called once from sketch setup().
2016-09-12 06:28:27 +00:00
Initiates communication protocal and configs ports.
*/
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);
}
/* scan() is called on every iteration of sketch loop().
strobePin is a bit pattern, 1 means that row pin is active.
scan() strobes the row's strobePin and retuns state of port's input pins.
*/
read_pins_t Scanner_IOE::scan(const uint8_t strobePin)
{
uint8_t readState; //bits, 1 means key is pressed, 0 means released
//strobe on
2016-11-06 09:41:56 +00:00
refPortWrite.write(strobePin, activeState);
delayMicroseconds(3); //time to stabilize voltage
//read the port pins
readState = refPortRead.read();
//strobe off
2016-11-06 09:41:56 +00:00
refPortWrite.write(strobePin, !activeState);
2016-11-06 09:41:56 +00:00
if (activeState == LOW) //if active low
{
readState = ~readState;
}
return readState;
}