diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 074b7ec..7ff3188 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -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 diff --git a/doc/keybrd_library_developer_guide.md b/doc/keybrd_library_developer_guide.md index 40b5624..2f90823 100644 --- a/doc/keybrd_library_developer_guide.md +++ b/doc/keybrd_library_developer_guide.md @@ -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: diff --git a/examples/keybrd_mapping_bb/keybrd_mapping_bb.ino b/examples/keybrd_mapping_bb/keybrd_mapping_bb.ino index 3c0d7e4..a119139 100644 --- a/examples/keybrd_mapping_bb/keybrd_mapping_bb.ino +++ b/examples/keybrd_mapping_bb/keybrd_mapping_bb.ino @@ -19,7 +19,7 @@ Uses the same variable naming convention as keybrd_DH. #include #include -#include +#include //#include #include @@ -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 ------------------- diff --git a/src/Code_LayerHold.cpp b/src/Code_LayerHold.cpp index 1923dbf..55d8b0a 100644 --- a/src/Code_LayerHold.cpp +++ b/src/Code_LayerHold.cpp @@ -2,10 +2,10 @@ void Code_LayerHold::press() { - refStateLayers.hold(layer); + refLayerState.hold(layer); } void Code_LayerHold::release() { - refStateLayers.unhold(layer); + refLayerState.unhold(layer); } diff --git a/src/Code_LayerHold.h b/src/Code_LayerHold.h index 69d4366..23e0b1e 100644 --- a/src/Code_LayerHold.h +++ b/src/Code_LayerHold.h @@ -3,18 +3,18 @@ #include #include -#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(); }; diff --git a/src/Code_LayerLock.cpp b/src/Code_LayerLock.cpp index d250768..230d6d7 100644 --- a/src/Code_LayerLock.cpp +++ b/src/Code_LayerLock.cpp @@ -2,7 +2,7 @@ void Code_LayerLock::press() { - refStateLayers.lock(layer); + refLayerState.lock(layer); } void Code_LayerLock::release() diff --git a/src/Code_LayerLock.h b/src/Code_LayerLock.h index 2605328..c4df5fb 100644 --- a/src/Code_LayerLock.h +++ b/src/Code_LayerLock.h @@ -3,18 +3,18 @@ #include #include -#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(); }; diff --git a/src/Code_LayeredCodeSc.cpp b/src/Code_LayeredCodeSc.cpp index cb03a09..9c0d005 100644 --- a/src/Code_LayeredCodeSc.cpp +++ b/src/Code_LayeredCodeSc.cpp @@ -2,6 +2,6 @@ void Code_LayeredCodeSc::press() { - layer = refStateLayers.getActiveLayer(); + layer = refLayerState.getActiveLayer(); pressCode(); } diff --git a/src/Code_LayeredCodeSc.h b/src/Code_LayeredCodeSc.h index 1773a5c..0566078 100644 --- a/src/Code_LayeredCodeSc.h +++ b/src/Code_LayeredCodeSc.h @@ -3,18 +3,18 @@ #include #include #include -#include +#include /* 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) { } diff --git a/src/Code_LayeredCodeScBase.h b/src/Code_LayeredCodeScBase.h index 9faf6d8..c2eb62b 100644 --- a/src/Code_LayeredCodeScBase.h +++ b/src/Code_LayeredCodeScBase.h @@ -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 diff --git a/src/Code_LayeredScSc.cpp b/src/Code_LayeredScSc.cpp index 8ab1fcd..c6d20df 100644 --- a/src/Code_LayeredScSc.cpp +++ b/src/Code_LayeredScSc.cpp @@ -2,6 +2,6 @@ void Code_LayeredScSc::press() { - layer = refStateLayers.getActiveLayer(); + layer = refLayerState.getActiveLayer(); pressScancode(); } diff --git a/src/Code_LayeredScSc.h b/src/Code_LayeredScSc.h index f4ee53a..88e765d 100644 --- a/src/Code_LayeredScSc.h +++ b/src/Code_LayeredScSc.h @@ -2,18 +2,18 @@ #define CODE_LAYEREDSCSC_H #include #include -#include +#include #include /* 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) { } diff --git a/src/Key_LayeredKeysArray.cpp b/src/Key_LayeredKeysArray.cpp index 1670f93..1c3c735 100644 --- a/src/Key_LayeredKeysArray.cpp +++ b/src/Key_LayeredKeysArray.cpp @@ -2,7 +2,7 @@ void Key_LayeredKeysArray::press() { - layer = refStateLayers.getActiveLayer(); + layer = refLayerState.getActiveLayer(); ptrsKeys[layer]->press(); } diff --git a/src/Key_LayeredKeysArray.h b/src/Key_LayeredKeysArray.h index b2b26f4..72693bf 100644 --- a/src/Key_LayeredKeysArray.h +++ b/src/Key_LayeredKeysArray.h @@ -2,13 +2,13 @@ #define KEY_LAYEREDKEYSARRAY_H #include #include -#include +#include #include /* 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(); diff --git a/src/StateLayers.cpp b/src/LayerState.cpp similarity index 52% rename from src/StateLayers.cpp rename to src/LayerState.cpp index cc83f9e..005e688 100644 --- a/src/StateLayers.cpp +++ b/src/LayerState.cpp @@ -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; } diff --git a/src/StateLayers.h b/src/LayerState.h similarity index 62% rename from src/StateLayers.h rename to src/LayerState.h index 004b292..cf1e9aa 100644 --- a/src/StateLayers.h +++ b/src/LayerState.h @@ -2,20 +2,20 @@ #define LAYERSTATE_H #include -#include +#include -/* 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 diff --git a/src/LayerStateInterface.h b/src/LayerStateInterface.h new file mode 100644 index 0000000..5af5486 --- /dev/null +++ b/src/LayerStateInterface.h @@ -0,0 +1,11 @@ +#ifndef LAYERSTATEINTERFACE_H +#define LAYERSTATEINTERFACE_H + +/* LayerStateInterface in an interface class +*/ +class LayerStateInterface +{ + public: + virtual uint8_t getActiveLayer()=0; +}; +#endif diff --git a/src/StateLayersInterface.h b/src/StateLayersInterface.h deleted file mode 100644 index f2bc0e3..0000000 --- a/src/StateLayersInterface.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef STATELAYERSINTERFACE_H -#define STATELAYERSINTERFACE_H - -/* StateLayersInterface in an interface class -*/ -class StateLayersInterface -{ - public: - virtual uint8_t getActiveLayer()=0; -}; -#endif diff --git a/tutorials/keybrd_3a_multi-layer_annotated/keybrd_3a_multi-layer_annotated.ino b/tutorials/keybrd_3a_multi-layer_annotated/keybrd_3a_multi-layer_annotated.ino index c7d90e4..f8acde0 100644 --- a/tutorials/keybrd_3a_multi-layer_annotated/keybrd_3a_multi-layer_annotated.ino +++ b/tutorials/keybrd_3a_multi-layer_annotated/keybrd_3a_multi-layer_annotated.ino @@ -26,7 +26,7 @@ Holding the fn key down makes it the active layer. Releasing the fn key restore //Codes #include -#include +#include #include #include @@ -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 -------------------- diff --git a/tutorials/keybrd_3b_autoShift_annotated/keybrd_3b_autoShift_annotated.ino b/tutorials/keybrd_3b_autoShift_annotated/keybrd_3b_autoShift_annotated.ino index fd32cf3..57abb0b 100644 --- a/tutorials/keybrd_3b_autoShift_annotated/keybrd_3b_autoShift_annotated.ino +++ b/tutorials/keybrd_3b_autoShift_annotated/keybrd_3b_autoShift_annotated.ino @@ -26,7 +26,7 @@ Holding the fn key down makes it the active layer. Releasing the fn key restore #include #include #include -#include +#include #include #include @@ -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 }; diff --git a/tutorials/tutorial_3a_multi-layer_keyboard.md b/tutorials/tutorial_3a_multi-layer_keyboard.md index f4b98dd..21a1d7a 100644 --- a/tutorials/tutorial_3a_multi-layer_keyboard.md +++ b/tutorials/tutorial_3a_multi-layer_keyboard.md @@ -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