generalize LED_Port and LED_ShiftReg to LED_Port
This commit is contained in:
parent
a45efab44f
commit
6dde737d23
@ -24,7 +24,9 @@ Keybrd library class inheritance diagram
|
||||
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)
|
||||
|
||||
|
@ -3,23 +3,29 @@
|
||||
#include <Arduino.h>
|
||||
#include <inttypes.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.
|
||||
LED_Port functions turn LED on and off.
|
||||
|
||||
Example initialization:
|
||||
const uint8_t IOE_ADDR = 0x20;
|
||||
Port_MCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 );
|
||||
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
|
||||
{
|
||||
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:
|
||||
LED_Port(PortInterface& refPort, const uint8_t pin)
|
||||
LED_Port(PortWriteInterface& refPort, const uint8_t pin)
|
||||
: refPort(refPort), pin(pin) {}
|
||||
virtual void on();
|
||||
virtual void off();
|
||||
|
@ -1,11 +0,0 @@
|
||||
#include "LED_ShiftReg.h"
|
||||
|
||||
void LED_ShiftReg::on()
|
||||
{
|
||||
refPort.write(pin, HIGH);
|
||||
}
|
||||
|
||||
void LED_ShiftReg::off()
|
||||
{
|
||||
refPort.write(pin, LOW);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#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
|
@ -2,11 +2,15 @@
|
||||
#define PORTINTERFACE_H
|
||||
#include <Arduino.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 that can read and write, inherit from PortInterface.
|
||||
Port classes that can only write, inherit from PortWriteInterface.
|
||||
*/
|
||||
class PortInterface
|
||||
class PortInterface : public PortWriteInterface
|
||||
{
|
||||
public:
|
||||
virtual void beginProtocol()=0; //SPI bus or I2C bus
|
||||
|
@ -3,6 +3,12 @@
|
||||
#include <Arduino.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
|
||||
{
|
||||
public:
|
||||
|
@ -6,12 +6,12 @@
|
||||
#include <PortWriteInterface.h>
|
||||
|
||||
/* 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
|
||||
{
|
||||
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
|
||||
public:
|
||||
Port_ShiftRegs(const uint8_t slaveSelect);
|
||||
|
Reference in New Issue
Block a user