This guide if for maintaining and writing new classes for the keybrd library and its extension libraries. The most common reason for new classes are:
This guide is for the maintainers and developers of the keybrd library and it’s extensions. It is assumed the reader is familiar with C++ language including pointers, objects, classes, static class variables, composition, inheritance, polymorphism, and enum. Some classes use bit manipulation.
Keybrd library class inheritance diagram
Matrix
RowBase
|
Row
IOExpanderPort
_______ RowPort _______
/ | \
RowPort_AVR RowPort_MCP23018 RowPort_PCA9655E (one RowPort class for each type of IC)
_______ ColPort _______
/ | \
ColPort_AVR ColPort_MCP23018 ColPort_PCA9655E (one ColPort class for each type of IC)
_____ LED ______
/ | \
LED_AVR LED_MCP23018 LED_PCA9655E (one LED class for each type of IC)
LayerStateInterface
|
LayerState
Key __
| \
| Key_LayeredKeysArray
|
Code
|_____________________
| \ \
| Code_LayerLock Code_LayerHold
|
|___________________________
| \ \
| Code_LayeredScScBase Code_LayeredCodeScBase
| | |
| Code_LayeredScSc Code_LayeredCodeSc
|
|__________________________________________
\ \ \ \
Code_Sc Code_Shift Code_AutoShift Code_LockLED
/ | \
Code_ScS Code_ScNS Code_ScNS_00
single-layer dependency diagram with LEDs
matrix[1..*]
|
row[1..*]_____________________________
| \ \ \
rowPort[1] rowPin[1] colPort[1] keys[1]
| |
colPins[1..*] code[1..*]
|
LED[1]
multi-layer dependency diagram with LEDs and I/O Expander
matrix[1..*]
| layerStates[1..*]
row[1..*]_________________________________________/__ | \
| \ \ \ / \ | \
rowPort[1] rowPin[1] colPort[1] keys[1] / code_layer[1..*] LED[0..*]
\ / \ | / /
\ / colPins[1..*] key[1..*] /
\ / | /
\ / code[1..*] /
\ / ______________________________________/
IOExpanderPort[0..*]
Class names start with upper case letter. Most derived-class names start with the base class name followed by “_” and a name e.g.
Code
|
Code_LayerLock
This convention leads to class names that convey information about the classes inheritance. Underscore delineates base class name and sub-class name. Capital letters delineate words.
Code_Layer class names are concatenations of “Code_“, “Layer” or layer name, and persistence. Example persistences are:
Example Code_Layer class names:
LayerState class names start with “LayerState” and end with a descriptive name. Example LayerState class names:
Code_Layered class names start with “Code_Layered” and end with a descriptive name. Example Code_Layered class names:
Following the style guide makes it easier for the next programmer to understand your code.
void printArray(char[] array);
not
void printArray( char* array);
Arduino does not have a debugger; so here is a list of functions in the order that they are called. Refer to it like a table of contents while reading the keybrd library.
Matrix::scan() for each row
Row::process()
Row::scan()
RowPort_*::setActivePin*() strobe row on
for each col port
ColPort_*::read() read col port
RowPort_*::setActivePin*() strobe row off
Row::getRowState() for each col port
for each connected col pin
if key is pressed
set rowState bit
Row::debounce() debounce
Row::detectEdge() detect edge
Row::pressRelease() for each key in row
if rising edge
Key_*::press() scanCode->press()
Code_*::press() Keyboard.press(scancode)
The keybrd libraries compile on the Arduino IDE and make extensive use of the following Arduino libraries:
#include <Arduino.h>
#include <Wire.h>
#include <Keyboard.h>
#include <Mouse.h>
keybrd guide by Wolfram Volpi is licensed under a Creative Commons Attribution 4.0 International License.
Permissions beyond the scope of this license may be available at https://github.com/wolfv6/keybrd/issues/new.