Browse Source

rename LED LEDInterface

tags/v0.6.0
wolfv6 7 years ago
parent
commit
d24705d0cb

+ 1
- 1
src/Code_LEDLock.cpp View File

/* USB_LED_bit are codes from http://www.usb.org/developers/hidpage/HID1_11.pdf keyboard output report /* USB_LED_bit are codes from http://www.usb.org/developers/hidpage/HID1_11.pdf keyboard output report
*/ */
Code_LEDLock::Code_LEDLock(const uint16_t scancode, LED& refLED)
Code_LEDLock::Code_LEDLock(const uint16_t scancode, LEDInterface& refLED)
: scancode(scancode), refLED(refLED) : scancode(scancode), refLED(refLED)
{ {
switch (scancode) //initilize USB_LED_bit for given scancode switch (scancode) //initilize USB_LED_bit for given scancode

+ 3
- 3
src/Code_LEDLock.h View File

#include <Arduino.h> #include <Arduino.h>
#include <inttypes.h> #include <inttypes.h>
#include <Code.h> #include <Code.h>
#include <LED.h>
#include <LEDInterface.h>
extern volatile uint8_t keyboard_leds; extern volatile uint8_t keyboard_leds;
private: private:
const uint16_t scancode; const uint16_t scancode;
uint8_t USB_LED_bit; //codes used by keyboard output report uint8_t USB_LED_bit; //codes used by keyboard output report
LED& refLED; //indicator on keyboard
LEDInterface& refLED; //indicator on keyboard
void updateLED() const; void updateLED() const;
public: public:
Code_LEDLock(const uint16_t scancode, LED& refLED);
Code_LEDLock(const uint16_t scancode, LEDInterface& refLED);
virtual void press(); virtual void press();
virtual void release(); virtual void release();
}; };

+ 1
- 1
src/Debug.cpp View File

//Sometimes OS takes 6 seconds to recongnize keyboard. //Sometimes OS takes 6 seconds to recongnize keyboard.
//wait_for_OS() will blink LED and count up once per second for specified number of seconds. //wait_for_OS() will blink LED and count up once per second for specified number of seconds.
void Debug::wait_for_OS(LED& led, const uint8_t seconds)
void Debug::wait_for_OS(LEDInterface& led, const uint8_t seconds)
{ {
for (uint8_t elapsed = 0; elapsed < seconds; elapsed++) for (uint8_t elapsed = 0; elapsed < seconds; elapsed++)
{ {

+ 2
- 2
src/Debug.h View File

#ifndef DEBUG_H #ifndef DEBUG_H
#define DEBUG_H #define DEBUG_H
#include <Arduino.h> #include <Arduino.h>
#include <LED.h>
#include <LEDInterface.h>


class Debug class Debug
{ {
public: public:
void printMicrosecondsPerScan(); //print microseconds per scan every second void printMicrosecondsPerScan(); //print microseconds per scan every second
void printScansPerSecond(); //print scans per second every second void printScansPerSecond(); //print scans per second every second
void wait_for_OS(LED& led, uint8_t seconds); //wait for OS to recongnize keyboard
void wait_for_OS(LEDInterface& led, uint8_t seconds); //wait for OS to recongnize keyboard
}; };
#endif #endif

+ 0
- 13
src/LED.h View File

#ifndef LED_H
#define LED_H
/* LED is an interface class
Each LED object is an IC pin that is used to power an LED on and off.
*/
class LED
{
public:
virtual void on()=0;
virtual void off()=0;
};
#endif

+ 12
- 0
src/LEDInterface.h View File

#ifndef LEDINTERFACE_H
#define LEDINTERFACE_H
/* Each LED object is an IC pin that is used to power an LED on and off.
*/
class LEDInterface
{
public:
virtual void on()=0;
virtual void off()=0;
};
#endif

+ 2
- 2
src/LED_IOE.h View File

#include <Arduino.h> #include <Arduino.h>
#include <inttypes.h> #include <inttypes.h>
#include <Wire.h> #include <Wire.h>
#include <LED.h>
#include <LEDInterface.h>
#include <PortInterface.h> #include <PortInterface.h>
/* A LED_IOE object is an I/O expander pin that is connected to an LED indicator light. /* A LED_IOE object is an I/O expander pin that is connected to an LED indicator light.
Input/Ouput Direction configuration are set to ouput in PortWrite_*.begin() and PortRead_*.begin(). todo PortRead_*?? Input/Ouput Direction configuration are set to ouput in PortWrite_*.begin() and PortRead_*.begin(). todo PortRead_*??
*/ */
class LED_IOE : public LED
class LED_IOE : public LEDInterface
{ {
private: private:
PortInterface& refPort; PortInterface& refPort;

+ 2
- 2
src/LED_uC.h View File

#define LED_UC_H #define LED_UC_H
#include <Arduino.h> #include <Arduino.h>
#include <inttypes.h> #include <inttypes.h>
#include <LED.h>
#include <LEDInterface.h>
/* A LED_uC turns LED on and off. /* A LED_uC turns LED on and off.
*/ */
class LED_uC: public LED
class LED_uC: public LEDInterface
{ {
private: private:
const uint8_t pin; //Aduino pin that is connected to an LED const uint8_t pin; //Aduino pin that is connected to an LED

+ 3
- 3
src/LayerState_LED.h View File

#include <Arduino.h> #include <Arduino.h>
#include <inttypes.h> #include <inttypes.h>
#include <LayerState.h> #include <LayerState.h>
#include <LED.h>
#include <LEDInterface.h>


/* Basic LayerState with layer LED indictor lights. /* Basic LayerState with layer LED indictor lights.
begin() should be called once to turn on LED for initial active layer. begin() should be called once to turn on LED for initial active layer.
class LayerState_LED : public LayerState class LayerState_LED : public LayerState
{ {
private: private:
LED*const *const ptrsLEDs; //array of LEDs, where layerId is array index
LEDInterface*const *const ptrsLEDs; //array of LEDs, where layerId is array index
virtual void setActiveLayer(const uint8_t layerId);//set active layerId and turn on it's LED virtual void setActiveLayer(const uint8_t layerId);//set active layerId and turn on it's LED
public: public:
LayerState_LED(LED*const ptrsLEDs[]): ptrsLEDs(ptrsLEDs) {}
LayerState_LED(LEDInterface*const ptrsLEDs[]): ptrsLEDs(ptrsLEDs) {}
void begin(); void begin();
}; };
#endif #endif

+ 1
- 1
tutorials/keybrd_5a_LED_on_uC/keybrd_5a_LED_on_uC.ino View File

*/ */
enum layers { NORMAL, FN }; enum layers { NORMAL, FN };


LED* prtsLayerLEDs[] = { &LED_normal, &LED_fn }; //array index matches enum layerIds
LEDInterface* prtsLayerLEDs[] = { &LED_normal, &LED_fn }; //array index matches enum layerIds
LayerState_LED layerState(prtsLayerLEDs); LayerState_LED layerState(prtsLayerLEDs);


Code_LayerHold l_fn(FN, layerState); Code_LayerHold l_fn(FN, layerState);

+ 4
- 4
tutorials/keybrd_5b_LED_on_IOE/keybrd_5b_LED_on_IOE.ino View File

#include <LED_uC.h> #include <LED_uC.h>


//right matrix //right matrix
#include <PortMCP23S17.h>
#include <Port_MCP23S17.h>
#include <Scanner_IOE.h> #include <Scanner_IOE.h>
#include <LED_IOE.h> #include <LED_IOE.h>




// --------------- RIGHT SCANNER --------------- // --------------- RIGHT SCANNER ---------------
const uint8_t IOE_ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded const uint8_t IOE_ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded
PortMCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 ); //for read and LED
PortMCP23S17 portB(IOE_ADDR, 1, 0); //for strobe and LED
Port_MCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 ); //for read and LED
Port_MCP23S17 portB(IOE_ADDR, 1, 0); //for strobe and LED


Scanner_IOE scanner_R(LOW, portB, portA); Scanner_IOE scanner_R(LOW, portB, portA);


// ---------------- LAYER CODE ----------------- // ---------------- LAYER CODE -----------------
enum layers { NORMAL, FN }; enum layers { NORMAL, FN };


LED* prtsLayerLEDs[] = { &LED_normal, &LED_fn }; //array index matches enum layerIds
LEDInterface* prtsLayerLEDs[] = { &LED_normal, &LED_fn }; //array index matches enum layerIds
LayerState_LED layerState(prtsLayerLEDs); LayerState_LED layerState(prtsLayerLEDs);


Code_LayerHold l_fn(FN, layerState); Code_LayerHold l_fn(FN, layerState);