瀏覽代碼

generalize LED_Port and LED_ShiftReg to LED_Port

tags/v0.6.3
wolfv6 7 年之前
父節點
當前提交
6dde737d23
共有 7 個文件被更改,包括 26 次插入41 次删除
  1. 3
    1
      doc/keybrd_library_developer_guide.md
  2. 10
    4
      src/LED_Port.h
  3. 0
    11
      src/LED_ShiftReg.cpp
  4. 0
    22
      src/LED_ShiftReg.h
  5. 5
    1
      src/PortInterface.h
  6. 6
    0
      src/PortWriteInterface.h
  7. 2
    2
      src/Port_ShiftRegs.h

+ 3
- 1
doc/keybrd_library_developer_guide.md 查看文件

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

+ 10
- 4
src/LED_Port.h 查看文件

@@ -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();

+ 0
- 11
src/LED_ShiftReg.cpp 查看文件

@@ -1,11 +0,0 @@
#include "LED_ShiftReg.h"

void LED_ShiftReg::on()
{
refPort.write(pin, HIGH);
}

void LED_ShiftReg::off()
{
refPort.write(pin, LOW);
}

+ 0
- 22
src/LED_ShiftReg.h 查看文件

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

+ 5
- 1
src/PortInterface.h 查看文件

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

+ 6
- 0
src/PortWriteInterface.h 查看文件

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

+ 2
- 2
src/Port_ShiftRegs.h 查看文件

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