Scanner_uC Scanner_IOE Scanner_ShiftRegsPISO | Scanner_uC Scanner_IOE Scanner_ShiftRegsPISO | ||||
PortInterface | |||||
PortWriteInterface | |||||
/ \ | |||||
PortInterface Port_ShiftRegs (Port class for MOSI shift registers) | |||||
/ \ | / \ | ||||
Port_PCA9655E Port_MCP23S17 (one Port class for each IOE type) | Port_PCA9655E Port_MCP23S17 (one Port class for each IOE type) | ||||
#include <Arduino.h> | #include <Arduino.h> | ||||
#include <inttypes.h> | #include <inttypes.h> | ||||
#include <LEDInterface.h> | #include <LEDInterface.h> | ||||
#include <PortInterface.h> | |||||
#include <PortWriteInterface.h> | |||||
/* An LED_Port object is an I/O expander pin that is connected to an LED indicator light. | /* An LED_Port object is an I/O expander pin that is connected to an LED indicator light. | ||||
LED_Port functions turn LED on and off. | |||||
Example initialization: | Example initialization: | ||||
const uint8_t IOE_ADDR = 0x20; | const uint8_t IOE_ADDR = 0x20; | ||||
Port_MCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 ); | Port_MCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 ); | ||||
LED_Port LED_fn(portA, 1<<5); | LED_Port LED_fn(portA, 1<<5); | ||||
Example initialization: | |||||
Port_ShiftRegs shiftRegs(8); | |||||
LED_Port LED_fn(shiftRegs, 1<<6); | |||||
*/ | */ | ||||
class LED_Port : public LEDInterface | class LED_Port : public LEDInterface | ||||
{ | { | ||||
private: | private: | ||||
PortInterface& refPort; | |||||
const uint8_t pin; //bit pattern, 1 is IOE pin to LED | |||||
PortWriteInterface& refPort; | |||||
const uint8_t pin; //bit pattern, 1 is pin connected to LED | |||||
public: | public: | ||||
LED_Port(PortInterface& refPort, const uint8_t pin) | |||||
LED_Port(PortWriteInterface& refPort, const uint8_t pin) | |||||
: refPort(refPort), pin(pin) {} | : refPort(refPort), pin(pin) {} | ||||
virtual void on(); | virtual void on(); | ||||
virtual void off(); | virtual void off(); |
#include "LED_ShiftReg.h" | |||||
void LED_ShiftReg::on() | |||||
{ | |||||
refPort.write(pin, HIGH); | |||||
} | |||||
void LED_ShiftReg::off() | |||||
{ | |||||
refPort.write(pin, LOW); | |||||
} |
#ifndef LED_SHIFTREG_H | |||||
#define LED_SHIFTREG_H | |||||
#include <Arduino.h> | |||||
#include <inttypes.h> | |||||
#include <LEDInterface.h> | |||||
#include <PortWriteInterface.h> | |||||
/* LED_ShiftReg turns LED on and off. | |||||
shift register RCLK pin a.k.a. SS or ST | |||||
*/ | |||||
class LED_ShiftReg: public LEDInterface | |||||
{ | |||||
private: | |||||
PortWriteInterface& refPort; | |||||
const uint8_t pin; //bit pattern, 1 is shift-register pin connected to an LED | |||||
public: | |||||
LED_ShiftReg(PortWriteInterface& refPort, uint8_t pin) | |||||
: refPort(refPort), pin(pin) {} | |||||
virtual void on(); | |||||
virtual void off(); | |||||
}; | |||||
#endif |
#define PORTINTERFACE_H | #define PORTINTERFACE_H | ||||
#include <Arduino.h> | #include <Arduino.h> | ||||
#include <inttypes.h> | #include <inttypes.h> | ||||
#include <PortWriteInterface.h> | |||||
/* | /* | ||||
Port classes are the keybrd library's interface to microcontroller ports or I/O expander ports. | Port classes are the keybrd library's interface to microcontroller ports or I/O expander ports. | ||||
Port classes that can read and write, inherit from PortInterface. | |||||
Port classes that can only write, inherit from PortWriteInterface. | |||||
*/ | */ | ||||
class PortInterface | |||||
class PortInterface : public PortWriteInterface | |||||
{ | { | ||||
public: | public: | ||||
virtual void beginProtocol()=0; //SPI bus or I2C bus | virtual void beginProtocol()=0; //SPI bus or I2C bus |
#include <Arduino.h> | #include <Arduino.h> | ||||
#include <inttypes.h> | #include <inttypes.h> | ||||
/* | |||||
Port classes are the keybrd library's interface to MOSI shift registers i.e. Port_ShiftRegs | |||||
Port classes that can read & write, inherit from PortInterface. | |||||
Port classes that can only write, inherit from PortWriteInterface. | |||||
*/ | |||||
class PortWriteInterface | class PortWriteInterface | ||||
{ | { | ||||
public: | public: |
#include <PortWriteInterface.h> | #include <PortWriteInterface.h> | ||||
/* Port_ShiftRegs | /* Port_ShiftRegs | ||||
shift register RCLK pin a.k.a. SS or ST | |||||
slaveSelect is controller-pin number connected to shift register RCLK pin a.k.a. SS or ST | |||||
*/ | */ | ||||
class Port_ShiftRegs : public PortWriteInterface | class Port_ShiftRegs : public PortWriteInterface | ||||
{ | { | ||||
private: | private: | ||||
const uint8_t slaveSelect; //controller-pin number connected to shift register RCLK | |||||
const uint8_t slaveSelect; //controller-pin number | |||||
uint8_t outputVal; //bit pattern for LEDs | uint8_t outputVal; //bit pattern for LEDs | ||||
public: | public: | ||||
Port_ShiftRegs(const uint8_t slaveSelect); | Port_ShiftRegs(const uint8_t slaveSelect); |