已封存
1
0

remove portState from ReadPort

This commit is contained in:
wolfv6 2016-07-13 15:49:56 -06:00
父節點 f76ec3002d
當前提交 a7d1fc0b85
共有 9 個檔案被更改,包括 32 行新增34 行删除

查看文件

@ -7,7 +7,7 @@
#include "IOEPort.h"
/* A LED_PCA9655E object is an PCA9655E pin that is connected to an LED indicator light.
Input/Ouput Direction configuration is set to ouput in row_Port_PCA9655E.begin() and col_Port_PCA9655E.begin().
Input/Ouput Direction configuration are set to ouput in StrobePort_PCA9655E.begin() and ReadPort_PCA9655E.begin().
*/
class LED_PCA9655E: public LED
{

查看文件

@ -10,12 +10,11 @@ Port classes are the keybrd library's interface to microcontoller ports or I/O e
class ReadPort
{
protected:
const uint8_t readPins; //bitwise pin configuration, 1 means read column
uint8_t portState; //bitwise pin values, which is set in read()
const uint8_t READ_PINS; //bitwise pin configuration, 1 means read column
public:
ReadPort(const uint8_t readPins): readPins(readPins), portState(0) {}
ReadPort(const uint8_t READ_PINS): READ_PINS(READ_PINS) {}
//read port and store it's pins values in portState
//read port and return readState
virtual uint8_t read()=0;
};
#endif

查看文件

@ -3,15 +3,15 @@
/*
configures column port's configuration, input, and pins.
*/
ReadPort_PCA9655E::ReadPort_PCA9655E (IOEPort& port, const uint8_t readPins)
: ReadPort(readPins), port(port), configurationByteCommand(port.num + 6), inputByteCommand(port.num)
ReadPort_PCA9655E::ReadPort_PCA9655E (IOEPort& port, const uint8_t READ_PINS)
: ReadPort(READ_PINS), port(port), configurationByteCommand(port.num + 6), inputByteCommand(port.num)
{}
void ReadPort_PCA9655E::begin()
{
Wire.beginTransmission(port.ADDR);
Wire.write(configurationByteCommand);
Wire.write(readPins); //0=configure as output (for LED), 1=configure as input (for read)
Wire.write(READ_PINS); //0=configure as output (for LED), 1=configure as input (for read)
Wire.endTransmission();
}

查看文件

@ -11,7 +11,7 @@ PCA9655E does not have internal pull-up resistors (PCA9535E does).
Instantiation
------------
readPins parameter is port's bitwise pin configuration
READ_PINS parameter is port's bitwise pin configuration
1=configure as input (for pins connected to column)
0=configure as output (for LED or not connected to a column)
@ -22,7 +22,7 @@ Example instantiation for column port 1, with pins 2 and 3 connected to columns:
IOEPort port1(1, 0);
ReadPort_PCA9655E colPort1(port1, 2<<0 | 1<<3 );
readPins are read from pin 0 on up.
READ_PINS are read from pin 0 on up.
Diode orientation
----------------
@ -36,7 +36,7 @@ class ReadPort_PCA9655E : public ReadPort
const uint8_t inputByteCommand;
public:
//The constructor initialization list is in .cpp
ReadPort_PCA9655E(IOEPort& port, const uint8_t readPins);
ReadPort_PCA9655E(IOEPort& port, const uint8_t READ_PINS);
void begin();
//read port and store result in portState

查看文件

@ -3,11 +3,11 @@
void Row_ShiftRegisters::process()
{
//these variables are all bitwise, one bit per key
read_pins_t rowState; //1 means pressed, 0 means released
read_pins_t readState; //1 means pressed, 0 means released
read_pins_t debouncedChanged; //1 means debounced changed
rowState = scanner.scan();
debouncedChanged = debouncer.debounce(rowState, debounced);
readState = scanner.scan();
debouncedChanged = debouncer.debounce(readState, debounced);
pressRelease(READ_PIN_COUNT, debouncedChanged);
}

查看文件

@ -6,10 +6,10 @@ process() scans the row and calls any newly pressed or released keys.
void Row_uC::process()
{
//these variables are all bitwise, one bit per key
read_pins_t rowState; //1 means pressed, 0 means released
read_pins_t readState; //1 means pressed, 0 means released
read_pins_t debouncedChanged; //1 means debounced changed
rowState = scanner.scan();
debouncedChanged = debouncer.debounce(rowState, debounced);
readState = scanner.scan();
debouncedChanged = debouncer.debounce(readState, debounced);
pressRelease(READ_PIN_COUNT, debouncedChanged);
}

查看文件

@ -16,11 +16,11 @@ void Scanner_ShiftRegs74HC165::begin()
}
/*
Sets readPinCount and returns rowState.
returns readState.
*/
read_pins_t Scanner_ShiftRegs74HC165::scan()
{
read_pins_t rowState = 0;
read_pins_t readState = 0;
//strobe row on
digitalWrite(STROBE_PIN, STROBE_ON);
@ -29,16 +29,14 @@ read_pins_t Scanner_ShiftRegs74HC165::scan()
//read all the column pins
digitalWrite(SHIFT_LOAD, LOW); //load parallel inputs to the register
digitalWrite(SHIFT_LOAD, HIGH); //shift the data toward a serial output
SPI.transfer(&rowState, BYTE_COUNT);
SPI.transfer(&readState, BYTE_COUNT);
//strobe row off
digitalWrite(STROBE_PIN, STROBE_OFF);
// readPinCount = READ_PIN_COUNT;
//for testing on breadboard, clear unpowered pins
rowState &= 0b11110001000100010001000100010001; //todo
readState &= 0b11110001000100010001000100010001; //todo
return rowState;
return readState;
}

查看文件

@ -28,7 +28,7 @@ Scanner_uC::Scanner_uC(const uint8_t STROBE_PIN,
}
/* scan() Strobes the row and reads the columns.
Sets READ_PIN_COUNT and returns rowState.
Sets READ_PIN_COUNT and returns readState.
https://www.arduino.cc/en/Tutorial/DigitalPins
https://www.arduino.cc/en/Reference/PinMode
@ -38,7 +38,7 @@ https://www.arduino.cc/en/Reference/Constants > Digital Pins modes: INPUT, INPUT
*/
read_pins_t Scanner_uC::scan()
{
read_pins_t rowState = 0; //bitwise, one col per bit, 1 means key is pressed
read_pins_t readState = 0; //bitwise, one col per bit, 1 means key is pressed
read_pins_t readMask = 1; //bitwise, one col per bit, active col bit is 1
//strobe row on
@ -50,7 +50,7 @@ read_pins_t Scanner_uC::scan()
{
if ( digitalRead(READ_PINS[i]) == STROBE_ON )
{
rowState |= readMask;
readState |= readMask;
}
readMask <<= 1;
}
@ -59,5 +59,5 @@ read_pins_t Scanner_uC::scan()
digitalWrite(STROBE_PIN, STROBE_OFF);
// readPinCount = READ_PIN_COUNT;
return rowState;
return readState;
}

查看文件

@ -16,17 +16,18 @@ void StrobePort_PCA9655E::begin()
/*
pin is bitwise, where pin being strobed is 1.
level is HIGH or LOW.
value is HIGH or LOW.
Does not reset the other pins because LEDs could be using some of the pins.
*/
void StrobePort_PCA9655E::write(const uint8_t pin, const bool level)
void StrobePort_PCA9655E::write(const uint8_t pin, const bool value)
{
if (level == LOW)
if (value == LOW) //if active low
{
port.outputVal &= ~pin; //set pin output to low, do not reset the other pins because LEDs
port.outputVal &= ~pin; //set pin output to low
}
else
else //if active high
{
port.outputVal |= pin; //set pin output to high
port.outputVal |= pin; //set pin output to high
}
Wire.beginTransmission(port.ADDR);