Archived
1
0

generalize LED_Port and LED_ShiftReg to LED_Port

This commit is contained in:
wolfv6 2016-10-30 19:46:23 -06:00
parent a45efab44f
commit 6dde737d23
7 changed files with 26 additions and 41 deletions

View File

@ -24,7 +24,9 @@ Keybrd library class inheritance diagram
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)

View File

@ -3,23 +3,29 @@
#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; PortWriteInterface& refPort;
const uint8_t pin; //bit pattern, 1 is IOE pin to LED 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();

View File

@ -1,11 +0,0 @@
#include "LED_ShiftReg.h"
void LED_ShiftReg::on()
{
refPort.write(pin, HIGH);
}
void LED_ShiftReg::off()
{
refPort.write(pin, LOW);
}

View File

@ -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

View File

@ -2,11 +2,15 @@
#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

View File

@ -3,6 +3,12 @@
#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:

View File

@ -6,12 +6,12 @@
#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);