/* 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 |
#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(); | ||||
}; | }; |
//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++) | ||||
{ | { |
#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 |
#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 |
#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 |
#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; |
#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 |
#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 |
*/ | */ | ||||
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); |
#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); |