Archived
1
0

rename StateLayers to LayerState

This commit is contained in:
wolfv6 2016-05-28 15:16:32 -06:00
parent f97ae6d23d
commit 0f511d5229
21 changed files with 91 additions and 91 deletions

View File

@ -12,7 +12,7 @@ keybrd version 1.0.0 will be released when the public API is stable.
* Restructured the project directory to conform to Arduino library manager specifications
* Moved keybrd_DH library extension (for DodoHand) to its own repository
* Moved sketches to examples directory
* Replaced Key_Layered dependency on LayerManager with StateLayers class
* Replaced Key_Layered dependency on LayerManager with LayerState class
### Added
* Tutorials

View File

@ -34,9 +34,9 @@ Keybrd library class inheritance diagram
LED_AVR LED_MCP23018 LED_PCA9655E (one LED class for each type of IC)
StateLayersInterface
LayerStateInterface
|
StateLayers
LayerState
Key __
@ -81,7 +81,7 @@ single-layer dependency diagram with LEDs
multi-layer dependency diagram with LEDs and I/O Expander
```
matrix[1..*]
| stateLayers[1..*]
| layerStates[1..*]
row[1..*]_________________________________________/__ | \
| \ \ \ / \ | \
rowPort[1] rowPin[1] colPort[1] keys[1] / code_layer[1..*] LED[0..*]
@ -116,11 +116,11 @@ Example Code_Layer class names:
* Code_LayerHold
* Code_LayerLock
*StateLayer* class names start with "StateLayer" and end with a descriptive name.
Example StateLayer class names:
* StateLayer - basic StateLayer class in keybrd library
* StateLayer_DH - main StateLayer for the keybrd_DH library
* StateLayer_MF - StateLayer for Mouse Function sub-layers in the keybrd_DH library
*LayerState* class names start with "LayerState" and end with a descriptive name.
Example LayerState class names:
* LayerState - basic LayerState class in keybrd library
* LayerState_DH - main LayerState for 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:

View File

@ -19,7 +19,7 @@ Uses the same variable naming convention as keybrd_DH.
#include <Code_ScS.h>
#include <Code_Shift.h>
#include <StateLayers.h>
#include <LayerState.h>
//#include <Code_LayerLock.h>
#include <Code_LayerHold.h>
@ -49,9 +49,9 @@ const uint8_t COL_PORT_L_COUNT = sizeof(ptrsColPorts_L)/sizeof(*ptrsColPorts_L);
// ================= CODES =====================
// -------------- LAYER CODES ------------------
StateLayers stateLayer;
//Code_LayerLock l_alpha(0, stateLayer);
Code_LayerHold l_fn(1, stateLayer);
LayerState layerState;
//Code_LayerLock l_alpha(0, layerState);
Code_LayerHold l_fn(1, layerState);
// --------------- SHIFT CODE ------------------
Code_Shift s_shift(MODIFIERKEY_LEFT_SHIFT);
@ -65,7 +65,7 @@ Code_Sc s_b(KEY_B);
Code_ScS s_exclamation(KEY_1);
Code_ScS s_at(KEY_2);
StateLayersInterface& Key_LayeredKeysArray::refStateLayers = stateLayer;
LayerStateInterface& Key_LayeredKeysArray::refLayerState = layerState;
// ============== LEFT MATRIX ==================
// --------------- LEFT KEYS -------------------

View File

@ -2,10 +2,10 @@
void Code_LayerHold::press()
{
refStateLayers.hold(layer);
refLayerState.hold(layer);
}
void Code_LayerHold::release()
{
refStateLayers.unhold(layer);
refLayerState.unhold(layer);
}

View File

@ -3,18 +3,18 @@
#include <inttypes.h>
#include <Code.h>
#include "StateLayers.h"
#include "LayerState.h"
/* Code_LayerHold calls StateLayers when pressed to change activeLayer.
/* Code_LayerHold calls LayerState when pressed to change activeLayer.
*/
class Code_LayerHold : public Code
{
private:
const uint8_t layer;
StateLayers& refStateLayers;
LayerState& refLayerState;
public:
Code_LayerHold(const uint8_t layer, StateLayers& refStateLayers)
: layer(layer), refStateLayers(refStateLayers) {}
Code_LayerHold(const uint8_t layer, LayerState& refLayerState)
: layer(layer), refLayerState(refLayerState) {}
virtual void press();
virtual void release();
};

View File

@ -2,7 +2,7 @@
void Code_LayerLock::press()
{
refStateLayers.lock(layer);
refLayerState.lock(layer);
}
void Code_LayerLock::release()

View File

@ -3,18 +3,18 @@
#include <inttypes.h>
#include <Code.h>
#include "StateLayers.h"
#include "LayerState.h"
/* Code_LayerLock calls StateLayers when pressed to change activeLayer.
/* Code_LayerLock calls LayerState when pressed to change activeLayer.
*/
class Code_LayerLock : public Code
{
private:
const uint8_t layer;
StateLayers& refStateLayers;
LayerState& refLayerState;
public:
Code_LayerLock(const uint8_t layer, StateLayers& refStateLayers)
: layer(layer), refStateLayers(refStateLayers) {}
Code_LayerLock(const uint8_t layer, LayerState& refLayerState)
: layer(layer), refLayerState(refLayerState) {}
virtual void press();
virtual void release();
};

View File

@ -2,6 +2,6 @@
void Code_LayeredCodeSc::press()
{
layer = refStateLayers.getActiveLayer();
layer = refLayerState.getActiveLayer();
pressCode();
}

View File

@ -3,18 +3,18 @@
#include <Arduino.h>
#include <inttypes.h>
#include <Code_LayeredCodeScBase.h>
#include <StateLayersInterface.h>
#include <LayerStateInterface.h>
/* Class Code_LayeredCodeSc is a 2-layer code, one object for each layer e.g.
layer0: ms_up //mouse up
layer1: KEY_UP //up arrow
When the key is pressed, the active layer is retrieved from refStateLayers,
When the key is pressed, the active layer is retrieved from refLayerState,
and the object for the active layer is sent to USB.
*/
class Code_LayeredCodeSc : public Code_LayeredCodeScBase
{
private:
static StateLayersInterface& refStateLayers;
static LayerStateInterface& refLayerState;
public:
Code_LayeredCodeSc(Code& refCode0, const uint16_t scancode1)
: Code_LayeredCodeScBase(refCode0, scancode1, 0) { }

View File

@ -7,7 +7,7 @@
/* Class Code_LayeredCodeScBase is a 2-layer code, one object for each layer e.g.
layer0: ms_up //mouse up
layer1: KEY_UP //up arrow
When the key is pressed, the active layer is retrieved from refStateLayers,
When the key is pressed, the active layer is retrieved from refLayerState,
and the object for the active layer is sent to USB.
*/
class Code_LayeredCodeScBase : public Code

View File

@ -2,6 +2,6 @@
void Code_LayeredScSc::press()
{
layer = refStateLayers.getActiveLayer();
layer = refLayerState.getActiveLayer();
pressScancode();
}

View File

@ -2,18 +2,18 @@
#define CODE_LAYEREDSCSC_H
#include <Arduino.h>
#include <inttypes.h>
#include <StateLayersInterface.h>
#include <LayerStateInterface.h>
#include <Code_LayeredScScBase.h>
/* Class Code_LayeredScSc is composed of two scancodes; "S" stands for Scancode.
layer is retreived from refStateLayers.
layer is retreived from refLayerState.
when layer=0, press sends scancode0
when layer=1, press sends scancode1
*/
class Code_LayeredScSc : public Code_LayeredScScBase
{
private:
static StateLayersInterface& refStateLayers;
static LayerStateInterface& refLayerState;
public:
Code_LayeredScSc(const uint16_t scancode0, const uint16_t scancode1)
: Code_LayeredScScBase(scancode0, scancode1) { }

View File

@ -2,7 +2,7 @@
void Key_LayeredKeysArray::press()
{
layer = refStateLayers.getActiveLayer();
layer = refLayerState.getActiveLayer();
ptrsKeys[layer]->press();
}

View File

@ -2,13 +2,13 @@
#define KEY_LAYEREDKEYSARRAY_H
#include <Arduino.h>
#include <inttypes.h>
#include <StateLayersInterface.h>
#include <LayerStateInterface.h>
#include <Key.h>
/* Class Key_LayeredKeysArray contains an array of Key pointers, one pointer per layer.
Codes are a kind of Key, so the Key pointers can point to Codes as well.
When the key is pressed, active layer is retreived from refStateLayers and
When the key is pressed, active layer is retreived from refLayerState and
the Key object of the active layer is called.
*/
class Key_LayeredKeysArray : public Key
@ -16,7 +16,7 @@ class Key_LayeredKeysArray : public Key
private:
Key *const *const ptrsKeys; //array of Key pointers, one Key per layer
uint8_t layer; //active layer when key was pressed
static StateLayersInterface& refStateLayers;
static LayerStateInterface& refLayerState;
public:
Key_LayeredKeysArray(Key *const ptrsKeys[]): ptrsKeys(ptrsKeys) {}
virtual void press();

View File

@ -1,11 +1,11 @@
#include "StateLayers.h"
#include "LayerState.h"
void StateLayers::hold(const uint8_t layer)
void LayerState::hold(const uint8_t layer)
{
setActiveLayer(layer);
}
void StateLayers::unhold(const uint8_t layer)
void LayerState::unhold(const uint8_t layer)
{
if (layer == activeLayer);
{
@ -13,19 +13,19 @@ void StateLayers::unhold(const uint8_t layer)
}
}
void StateLayers::lock(const uint8_t layer)
void LayerState::lock(const uint8_t layer)
{
setActiveLayer(layer);
lockedLayer = layer;
}
//Derived classes override setActiveLayer() to also set LED indicator lights.
void StateLayers::setActiveLayer(const uint8_t layer)
void LayerState::setActiveLayer(const uint8_t layer)
{
activeLayer = layer;
}
uint8_t StateLayers::getActiveLayer()
uint8_t LayerState::getActiveLayer()
{
return activeLayer;
}

View File

@ -2,20 +2,20 @@
#define LAYERSTATE_H
#include <inttypes.h>
#include <StateLayersInterface.h>
#include <LayerStateInterface.h>
/* basic StateLayers for keyboard.
When pressed, Code_Layer objects call StateLayers functions lock() or hold().
When pressed, Layered objects call StateLayers function getActiveLayer().
/* basic LayerState for keyboard.
When pressed, Code_Layer objects call LayerState functions lock() or hold().
When pressed, Layered objects call LayerState function getActiveLayer().
*/
class StateLayers : public StateLayersInterface
class LayerState : public LayerStateInterface
{
protected:
uint8_t activeLayer; //currently active layer
uint8_t lockedLayer; //most recently pressed lock layer
virtual void setActiveLayer(const uint8_t layer);
public:
StateLayers() : activeLayer(0), lockedLayer(0) {}
LayerState() : activeLayer(0), lockedLayer(0) {}
virtual void hold(uint8_t layer); //set activeLayer
virtual void unhold(const uint8_t layer); //restore activeLayer to lockedLayer
virtual void lock(uint8_t layer); //set activeLayer and lock it

11
src/LayerStateInterface.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef LAYERSTATEINTERFACE_H
#define LAYERSTATEINTERFACE_H
/* LayerStateInterface in an interface class
*/
class LayerStateInterface
{
public:
virtual uint8_t getActiveLayer()=0;
};
#endif

View File

@ -1,11 +0,0 @@
#ifndef STATELAYERSINTERFACE_H
#define STATELAYERSINTERFACE_H
/* StateLayersInterface in an interface class
*/
class StateLayersInterface
{
public:
virtual uint8_t getActiveLayer()=0;
};
#endif

View File

@ -26,7 +26,7 @@ Holding the fn key down makes it the active layer. Releasing the fn key restore
//Codes
#include <Code_Sc.h>
#include <StateLayers.h>
#include <LayerState.h>
#include <Code_LayerHold.h>
#include <Key_LayeredKeysArray.h>
@ -57,15 +57,15 @@ enum assings Id numbers to the layers.
*/
enum layers { NORMAL, FN };
/*
stateLayer keeps track of the active layer. The default layer number is 0.
layerState keeps track of the active layer. The default layer number is 0.
*/
StateLayers stateLayer;
LayerState layerState;
/*
The Code_LayerHold constructor parameter specifies a layer Id number and a StateLayer.
When l_fn is pressed, it tells stateLayer to change the active layer to 1.
When l_fn is released, it tells stateLayer to restore the normal layer.
The Code_LayerHold constructor parameter specifies a layer Id number and a LayerState.
When l_fn is pressed, it tells layerState to change the active layer to 1.
When l_fn is released, it tells layerState to restore the normal layer.
*/
Code_LayerHold l_fn(FN, stateLayer);
Code_LayerHold l_fn(FN, layerState);
// ---------------- SCAN CODES -----------------
Code_Sc s_a(KEY_A);
@ -102,15 +102,15 @@ Key* const ptrsCodes_01[] = { &s_b, &s_2 };
Key_LayeredKeysArray k_01(ptrsCodes_01);
/*
Key_LayeredKeysArray has a static variable refStateLayers defined here.
It is a reference to stateLayer.
Key_LayeredKeysArray has a static variable refLayerState defined here.
It is a reference to layerState.
*/
StateLayersInterface& Key_LayeredKeysArray::refStateLayers = stateLayer;
LayerStateInterface& Key_LayeredKeysArray::refLayerState = layerState;
/*
HOW LAYERED OBJECTS WORK
When a Key_LayeredKeysArray object is pressed,
it gets the active layer from stateLayer and then sends the scancode for the active layer.
it gets the active layer from layerState and then sends the scancode for the active layer.
*/
// ------------------- ROWS --------------------

View File

@ -26,7 +26,7 @@ Holding the fn key down makes it the active layer. Releasing the fn key restore
#include <Code_Sc.h>
#include <Code_ScS.h>
#include <Code_Shift.h>
#include <StateLayers.h>
#include <LayerState.h>
#include <Code_LayerHold.h>
#include <Key_LayeredKeysArray.h>
@ -54,8 +54,8 @@ The CODES section instantiates six codes, one for each item in the layout:
// ---------------- LAYER CODE -----------------
enum layers { NORMAL, FN };
StateLayers stateLayer;
Code_LayerHold l_fn(FN, stateLayer);
LayerState layerState;
Code_LayerHold l_fn(FN, layerState);
// ---------------- SCAN CODES -----------------
/*
@ -115,7 +115,7 @@ Key_LayeredKeysArray k_00(ptrsCodes_00);
Key* const ptrsCodes_01[] = { &s_b, &s_at };
Key_LayeredKeysArray k_01(ptrsCodes_01);
StateLayersInterface& Key_LayeredKeysArray::refStateLayers = stateLayer;
LayerStateInterface& Key_LayeredKeysArray::refLayerState = layerState;
// ------------------- ROWS --------------------
Key* const ptrsKeys_0[] = { &k_00, &k_01 };

View File

@ -19,20 +19,20 @@ The following pseudo code has just enough detail to show how layer schemes work.
**Key_Layer** objects select the active layer.
The "layer" variable is a layer id number.
When a Key_Layer object is pressed, it tells StateLayer to update the active layer.
When a Key_Layer object is pressed, it tells LayerState to update the active layer.
```
class Key_Layer
{
int layer
StateLayer& refStateLayer
press() { refStateLayer.setActiveLayer(layer) }
LayerState& refLayerState
press() { refLayerState.setActiveLayer(layer) }
}
```
**StateLayer** objects keep track of the active layer.
A StateLayer's activeLayer is always up to date.
**LayerState** objects keep track of the active layer.
A LayerState's activeLayer is always up to date.
```
class StateLayer
class LayerState
{
int activeLayer
setActiveLayer(int layer) { activeLayer = layer }
@ -42,13 +42,13 @@ class StateLayer
**Key_Layered** objects contain multiple Key pointers, one Key pointer for each layer.
Layer ids are used like indexes to select the appropriate key.
When a Key_Layered object is pressed, it gets the active layer from StateLayer, and then sends the key of the active layer.
When a Key_Layered object is pressed, it gets the active layer from LayerState, and then sends the key of the active layer.
```
class Key_Layered
{
Key** ptrsKeys //array of Key pointers, one Key pointer per layer
StateLayer& refStateLayer
press() { layer = refStateLayer.getActiveLayer()
LayerState& refLayerState
press() { layer = refLayerState.getActiveLayer()
ptrsKeys[layer]->press() }
}
```
@ -63,7 +63,7 @@ Dependency diagram
|
v
+------------+
| StateLayer |
| LayerState |
+------------+
^
|
@ -81,8 +81,8 @@ Key_Layer classes include:
* Code_LayerHold
* Code_LayerLock
A basic StateLayer class is:
* StateLayer
A basic LayerState class is:
* LayerState
Key_Layered classes include:
* Code_LayeredScSc
@ -108,7 +108,7 @@ Example single-layer Code classes include:
## A simple multi-layer keybrd sketch
The [keybrd_3a_multi-layer_annotated.ino](keybrd_3a_multi-layer_annotated/keybrd_3a_multi-layer_annotated.ino)
sketch uses three layer-scheme classes:
* StateLayers
* LayerState
* Code_LayerHold
* Key_LayeredKeysArray