Key __ | Key __ | ||||
| \ | | \ | ||||
| Key_LayeredKeysArray | | Key_LayeredKeysArray | ||||
| | |||||
Code | |||||
|_____________________ | |_____________________ | ||||
| \ \ | | \ \ | ||||
| Code_LayerLock Code_LayerHold | | Code_LayerLock Code_LayerHold | ||||
| | | | ||||
|___________________________ | |___________________________ | ||||
| \ \ | | \ \ | ||||
| Code_LayeredScScBase Code_LayeredCodeScBase | |||||
| Key_LayeredScScBase Key_LayeredCodeScBase | |||||
| | | | | | | | ||||
| Code_LayeredScSc Code_LayeredCodeSc | |||||
| Key_LayeredScSc Key_LayeredCodeSc | |||||
| | | | ||||
|_________________________________________________________ | |||||
Code | |||||
\________________________________________________________ | |||||
\ \ \ \ \ | \ \ \ \ \ | ||||
Code_Sc Code_Shift Code_AutoShift Code_LEDLock Code_Null | Code_Sc Code_Shift Code_AutoShift Code_LEDLock Code_Null | ||||
/ \ | / \ | ||||
* LayerState_DH - main LayerState for the keybrd_DH library | * LayerState_DH - main LayerState for the keybrd_DH library | ||||
* LayerState_MF - LayerState for Mouse Function sub-layers in the keybrd_DH library | * LayerState_MF - LayerState for Mouse Function sub-layers in the keybrd_DH library | ||||
*Code_Layered* class names start with "Code_Layered" and end with a descriptive name. | |||||
Example Code_Layered class names: | |||||
* Code_LayeredScSc | |||||
*Key_Layered* class names start with "Key_Layered" and end with a descriptive name. | |||||
Example Key_Layered class names: | |||||
* Key_LayeredScSc | |||||
* Key_LayeredKeysArray | * Key_LayeredKeysArray | ||||
Style guide | Style guide |
#include "Code_LayeredCodeSc.h" | |||||
#include "Key_LayeredCodeSc.h" | |||||
void Code_LayeredCodeSc::press() | |||||
void Key_LayeredCodeSc::press() | |||||
{ | { | ||||
layer = refLayerState.getActiveLayer(); | layer = refLayerState.getActiveLayer(); | ||||
pressCode(); | pressCode(); |
#ifndef CODE_LAYEREDCODESC_H | |||||
#define CODE_LAYEREDCODESC_H | |||||
#ifndef KEY_LAYEREDCODESC_H | |||||
#define KEY_LAYEREDCODESC_H | |||||
#include <Arduino.h> | #include <Arduino.h> | ||||
#include <inttypes.h> | #include <inttypes.h> | ||||
#include <Code_LayeredCodeScBase.h> | |||||
#include <Key_LayeredCodeScBase.h> | |||||
#include <LayerStateInterface.h> | #include <LayerStateInterface.h> | ||||
/* Class Code_LayeredCodeSc is a 2-layer code, one object for each layer e.g. | |||||
/* Class Key_LayeredCodeSc is a 2-layer code, one object for each layer e.g. | |||||
layer0: ms_up //mouse up | layer0: ms_up //mouse up | ||||
layer1: KEY_UP //up arrow | layer1: KEY_UP //up arrow | ||||
When the key is pressed, the active layer is retrieved from refLayerState, | When the key is pressed, the active layer is retrieved from refLayerState, | ||||
and the object for the active layer is sent to USB. | and the object for the active layer is sent to USB. | ||||
*/ | */ | ||||
class Code_LayeredCodeSc : public Code_LayeredCodeScBase | |||||
class Key_LayeredCodeSc : public Key_LayeredCodeScBase | |||||
{ | { | ||||
private: | private: | ||||
static LayerStateInterface& refLayerState; | static LayerStateInterface& refLayerState; | ||||
public: | public: | ||||
Code_LayeredCodeSc(Code& refCode0, const uint16_t scancode1) | |||||
: Code_LayeredCodeScBase(refCode0, scancode1, 0) { } | |||||
Key_LayeredCodeSc(Code& refCode0, const uint16_t scancode1) | |||||
: Key_LayeredCodeScBase(refCode0, scancode1, 0) { } | |||||
virtual void press(); | virtual void press(); | ||||
}; | }; | ||||
#endif | #endif |
#include "Code_LayeredCodeScBase.h" | |||||
#include "Key_LayeredCodeScBase.h" | |||||
void Code_LayeredCodeScBase::pressCode() | |||||
void Key_LayeredCodeScBase::pressCode() | |||||
{ | { | ||||
if (layer) | if (layer) | ||||
{ | { | ||||
} | } | ||||
} | } | ||||
void Code_LayeredCodeScBase::release() | |||||
void Key_LayeredCodeScBase::release() | |||||
{ | { | ||||
if (layer) | if (layer) | ||||
{ | { |
#ifndef CODE_LAYEREDCODESCBASE_H | |||||
#define CODE_LAYEREDCODESCBASE_H | |||||
#ifndef KEY_LAYEREDCODESCBASE_H | |||||
#define KEY_LAYEREDCODESCBASE_H | |||||
#include <Arduino.h> | #include <Arduino.h> | ||||
#include <inttypes.h> | #include <inttypes.h> | ||||
#include "Code.h" | #include "Code.h" | ||||
/* Class Code_LayeredCodeScBase is a 2-layer code, with one object for each layer e.g. | |||||
/* Class Key_LayeredCodeScBase is a 2-layer code, with one object for each layer e.g. | |||||
layer0: ms_up //mouse up | layer0: ms_up //mouse up | ||||
layer1: KEY_UP //up arrow | layer1: KEY_UP //up arrow | ||||
When the key is pressed, the active layer is retrieved from refLayerState, | When the key is pressed, the active layer is retrieved from refLayerState, | ||||
and the object for the active layer is sent to USB. | and the object for the active layer is sent to USB. | ||||
*/ | */ | ||||
class Code_LayeredCodeScBase : public Code | |||||
class Key_LayeredCodeScBase : public Code | |||||
{ | { | ||||
private: | private: | ||||
Code& refCode0; | Code& refCode0; | ||||
protected: | protected: | ||||
bool layer; | bool layer; | ||||
public: | public: | ||||
Code_LayeredCodeScBase(Code& refCode0, const uint16_t scancode1, uint8_t layer): | |||||
Key_LayeredCodeScBase(Code& refCode0, const uint16_t scancode1, uint8_t layer): | |||||
refCode0(refCode0), scancode1(scancode1), layer(layer) { } | refCode0(refCode0), scancode1(scancode1), layer(layer) { } | ||||
virtual void press()=0; | virtual void press()=0; | ||||
virtual void release(); | virtual void release(); |
#include "Code_LayeredScSc.h" | |||||
#include "Key_LayeredScSc.h" | |||||
void Code_LayeredScSc::press() | |||||
void Key_LayeredScSc::press() | |||||
{ | { | ||||
layer = refLayerState.getActiveLayer(); | layer = refLayerState.getActiveLayer(); | ||||
pressScancode(); | pressScancode(); |
#ifndef CODE_LAYEREDSCSC_H | |||||
#define CODE_LAYEREDSCSC_H | |||||
#ifndef KEY_LAYEREDSCSC_H | |||||
#define KEY_LAYEREDSCSC_H | |||||
#include <Arduino.h> | #include <Arduino.h> | ||||
#include <inttypes.h> | #include <inttypes.h> | ||||
#include <LayerStateInterface.h> | #include <LayerStateInterface.h> | ||||
#include <Code_LayeredScScBase.h> | |||||
#include <Key_LayeredScScBase.h> | |||||
/* Class Code_LayeredScSc is composed of two scancodes; "S" stands for Scancode. | |||||
/* Class Key_LayeredScSc is composed of two scancodes; "S" stands for Scancode. | |||||
layer is retreived from refLayerState. | layer is retreived from refLayerState. | ||||
when layer=0, press sends scancode0 | when layer=0, press sends scancode0 | ||||
when layer=1, press sends scancode1 | when layer=1, press sends scancode1 | ||||
*/ | */ | ||||
class Code_LayeredScSc : public Code_LayeredScScBase | |||||
class Key_LayeredScSc : public Key_LayeredScScBase | |||||
{ | { | ||||
private: | private: | ||||
static LayerStateInterface& refLayerState; | static LayerStateInterface& refLayerState; | ||||
public: | public: | ||||
Code_LayeredScSc(const uint16_t scancode0, const uint16_t scancode1) | |||||
: Code_LayeredScScBase(scancode0, scancode1) { } | |||||
Key_LayeredScSc(const uint16_t scancode0, const uint16_t scancode1) | |||||
: Key_LayeredScScBase(scancode0, scancode1) { } | |||||
virtual void press(); | virtual void press(); | ||||
}; | }; | ||||
#endif | #endif |
#include "Code_LayeredScScBase.h" | |||||
#include "Key_LayeredScScBase.h" | |||||
void Code_LayeredScScBase::pressScancode() | |||||
void Key_LayeredScScBase::pressScancode() | |||||
{ | { | ||||
if (layer) | if (layer) | ||||
{ | { | ||||
Keyboard.press(scancode); | Keyboard.press(scancode); | ||||
} | } | ||||
void Code_LayeredScScBase::release() | |||||
void Key_LayeredScScBase::release() | |||||
{ | { | ||||
Keyboard.release(scancode); | Keyboard.release(scancode); | ||||
} | } |
#ifndef CODE_LAYERED2SCANCODES_H | |||||
#define CODE_LAYERED2SCANCODES_H | |||||
#ifndef KEY_LAYERED2SCANCODES_H | |||||
#define KEY_LAYERED2SCANCODES_H | |||||
#include <Arduino.h> | #include <Arduino.h> | ||||
#include <inttypes.h> | #include <inttypes.h> | ||||
#include "Code.h" | #include "Code.h" | ||||
/* Class Code_LayeredScScBase is an abstract base class. It is composed of two scancodes: | |||||
/* Class Key_LayeredScScBase is an abstract base class. It is composed of two scancodes: | |||||
if layer=0, send scancode0 | if layer=0, send scancode0 | ||||
if layer=1, send scancode1 | if layer=1, send scancode1 | ||||
*/ | */ | ||||
class Code_LayeredScScBase : public Code | |||||
class Key_LayeredScScBase : public Code | |||||
{ | { | ||||
private: | private: | ||||
const uint16_t scancode0; | const uint16_t scancode0; | ||||
protected: | protected: | ||||
bool layer; //0 or 1 | bool layer; //0 or 1 | ||||
public: | public: | ||||
Code_LayeredScScBase(const uint16_t scancode0, const uint16_t scancode1): | |||||
Key_LayeredScScBase(const uint16_t scancode0, const uint16_t scancode1): | |||||
scancode0(scancode0), scancode1(scancode1), layer(0) { } | scancode0(scancode0), scancode1(scancode1), layer(0) { } | ||||
virtual void press()=0; | virtual void press()=0; | ||||
virtual void release(); | virtual void release(); |
Key_Layered classes include: | Key_Layered classes include: | ||||
* Key_LayeredKeysArray | * Key_LayeredKeysArray | ||||
* Code_LayeredScSc | |||||
* Code_LayeredCodeSc | |||||
* Key_LayeredScSc | |||||
* Key_LayeredCodeSc | |||||
The basic LayerState provided by the keybrd library is sufficient for implementing ordinary layer schemes. | The basic LayerState provided by the keybrd library is sufficient for implementing ordinary layer schemes. | ||||
For experimental layer schemes, you would need to create a custom LayerState class, and possibly custom Code_Layer and Key_Layered classes as well. | For experimental layer schemes, you would need to create a custom LayerState class, and possibly custom Code_Layer and Key_Layered classes as well. |