2016-09-20 03:59:05 +00:00
|
|
|
/* keybrd_3f_autoShift.ino
|
2016-05-09 14:05:08 +00:00
|
|
|
|
|
|
|
This sketch:
|
|
|
|
is a simple 2-layer keyboard with AutoShift
|
|
|
|
runs on the first two rows and columns of a breadboard keyboard
|
|
|
|
|
|
|
|
| Layout | **0** | **1** |
|
|
|
|
|:------:|-------|-------|
|
2016-09-22 02:29:40 +00:00
|
|
|
| **0** | a ! | b @ |
|
|
|
|
| **1** | fn | shift |
|
2016-05-09 14:05:08 +00:00
|
|
|
|
|
|
|
The layered keys in row 0 have two layers; one character for each layer.
|
|
|
|
Letters 'a' and 'b' are on the normal layer. Symbols '!' and '@' are one the fn layer.
|
|
|
|
Holding the fn key down makes it the active layer. Releasing the fn key restores the normal layer.
|
|
|
|
*/
|
|
|
|
// ################## GLOBAL ###################
|
|
|
|
// ================= INCLUDES ==================
|
|
|
|
|
2016-07-18 02:03:03 +00:00
|
|
|
//Keys
|
2016-05-09 14:05:08 +00:00
|
|
|
#include <Code_Sc.h>
|
|
|
|
#include <Code_ScS.h>
|
|
|
|
#include <Code_Shift.h>
|
2016-05-28 21:16:32 +00:00
|
|
|
#include <LayerState.h>
|
2016-05-09 14:05:08 +00:00
|
|
|
#include <Code_LayerHold.h>
|
2016-09-18 06:42:21 +00:00
|
|
|
#include <Key_LayeredKeys.h>
|
2016-05-09 14:05:08 +00:00
|
|
|
|
|
|
|
//Matrix
|
2016-09-20 01:46:03 +00:00
|
|
|
#include <Row.h>
|
|
|
|
#include <Scanner_uC.h>
|
2016-07-18 02:03:03 +00:00
|
|
|
#include <ScanDelay.h>
|
2016-05-09 14:05:08 +00:00
|
|
|
|
2016-07-18 02:03:03 +00:00
|
|
|
// ============ SPEED CONFIGURATION ============
|
|
|
|
ScanDelay scanDelay(9000);
|
2016-05-09 14:05:08 +00:00
|
|
|
|
2016-09-20 01:46:03 +00:00
|
|
|
// ================== SCANNER ==================
|
2016-07-18 02:03:03 +00:00
|
|
|
uint8_t readPins[] = {14, 15};
|
2016-09-20 01:46:03 +00:00
|
|
|
uint8_t readPinCount = sizeof(readPins)/sizeof(*readPins);
|
|
|
|
|
|
|
|
Scanner_uC scanner(LOW, readPins, readPinCount);
|
2016-05-09 14:05:08 +00:00
|
|
|
|
|
|
|
// =================== CODES ===================
|
|
|
|
// ---------------- LAYER CODE -----------------
|
2016-09-22 13:46:50 +00:00
|
|
|
enum layerIds { NORMAL, FN };
|
2016-05-09 14:05:08 +00:00
|
|
|
|
2016-05-28 21:16:32 +00:00
|
|
|
LayerState layerState;
|
|
|
|
Code_LayerHold l_fn(FN, layerState);
|
2016-05-09 14:05:08 +00:00
|
|
|
|
2016-07-18 02:03:03 +00:00
|
|
|
/* ---------------- SCAN CODES -----------------
|
|
|
|
The "Sc" in Code_Sc means "scancode".
|
|
|
|
When a Code_Sc is pressed, it sends its scancode.
|
2016-05-09 14:05:08 +00:00
|
|
|
*/
|
|
|
|
Code_Sc s_a(KEY_A);
|
|
|
|
Code_Sc s_b(KEY_B);
|
2016-07-18 02:03:03 +00:00
|
|
|
|
|
|
|
/* The "ScS" in Code_ScS means "scancode shifted".
|
2016-05-09 14:05:08 +00:00
|
|
|
When Code_ScS is pressed, it calls Code_AutoShift before sending its scancode.
|
|
|
|
*/
|
|
|
|
Code_ScS s_exclamation(KEY_1);
|
|
|
|
Code_ScS s_at(KEY_2);
|
|
|
|
|
|
|
|
// ----------------- SHIFT CODE ----------------
|
|
|
|
/*
|
2016-07-18 02:03:03 +00:00
|
|
|
The Code_Shift constructor takes one shift scancode.
|
2016-05-09 14:05:08 +00:00
|
|
|
*/
|
|
|
|
Code_Shift s_shift(MODIFIERKEY_LEFT_SHIFT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Code_Shift pointers are placed in an array because most keyboards have a left and right shift.
|
|
|
|
This sketch only has one shift code.
|
|
|
|
*/
|
|
|
|
Code_Shift* const ptrsS[] = { &s_shift };
|
|
|
|
Code_Shift* const* const Code_AutoShift::ptrsShifts = ptrsS;
|
2016-07-18 02:03:03 +00:00
|
|
|
const uint8_t Code_AutoShift::shiftCount = sizeof(ptrsS)/sizeof(*ptrsS);
|
2016-05-09 14:05:08 +00:00
|
|
|
|
|
|
|
/*
|
2016-07-18 02:03:03 +00:00
|
|
|
HOW SHIFT WORKS
|
2016-09-22 02:29:40 +00:00
|
|
|
When a shift key is pressed, a standard keyboard driver will temporarily modify the action of other scancodes.
|
2016-05-09 14:05:08 +00:00
|
|
|
KEY_1 writes '1'
|
|
|
|
MODIFIERKEY_LEFT_SHIFT + KEY_1 writes '!'
|
|
|
|
|
|
|
|
KEY_2 writes '2'
|
|
|
|
MODIFIERKEY_LEFT_SHIFT + KEY_2 writes '@'
|
|
|
|
|
2016-07-18 02:03:03 +00:00
|
|
|
HOW AUTOSHIFT WORKS
|
2016-05-09 14:05:08 +00:00
|
|
|
Code_ScS takes care of the MODIFIERKEY_LEFT_SHIFT automatically
|
|
|
|
When the user presses '!' or '@' on the fn layer:
|
|
|
|
Code_AutoShift checks the position of each shift key
|
|
|
|
Code_ScS sends MODIFIERKEY_LEFT_SHIFT scancode if needed
|
|
|
|
Code_ScS sends its scancode
|
|
|
|
*/
|
|
|
|
|
2016-07-18 02:03:03 +00:00
|
|
|
// =================== KEYS ====================
|
2016-09-22 02:29:40 +00:00
|
|
|
Key* const ptrsKeys_00[] = { &s_a, &s_exclamation };
|
|
|
|
Key_LayeredKeys k_00(ptrsKeys_00);
|
2016-05-09 14:05:08 +00:00
|
|
|
|
2016-09-22 02:29:40 +00:00
|
|
|
Key* const ptrsKeys_01[] = { &s_b, &s_at };
|
|
|
|
Key_LayeredKeys k_01(ptrsKeys_01);
|
2016-05-09 14:05:08 +00:00
|
|
|
|
2016-09-18 06:42:21 +00:00
|
|
|
LayerStateInterface& Key_LayeredKeys::refLayerState = layerState;
|
2016-05-09 14:05:08 +00:00
|
|
|
|
2016-07-18 02:03:03 +00:00
|
|
|
// =================== ROWS ====================
|
2016-09-22 02:29:40 +00:00
|
|
|
Key* const ptrsKeys_0[] = { &k_00, &k_01 };
|
2016-09-20 01:46:03 +00:00
|
|
|
uint8_t keyCount_0 = sizeof(ptrsKeys_0)/sizeof(*ptrsKeys_0);
|
|
|
|
Row row_0(scanner, 0, ptrsKeys_0, keyCount_0);
|
2016-05-09 14:05:08 +00:00
|
|
|
|
2016-09-22 02:29:40 +00:00
|
|
|
Key* const ptrsKeys_1[] = { &l_fn, &s_shift };
|
2016-09-20 01:46:03 +00:00
|
|
|
uint8_t keyCount_1 = sizeof(ptrsKeys_1)/sizeof(*ptrsKeys_1);
|
|
|
|
Row row_1(scanner, 1, ptrsKeys_1, keyCount_1);
|
2016-05-09 14:05:08 +00:00
|
|
|
|
|
|
|
// ################### MAIN ####################
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
2016-07-18 02:03:03 +00:00
|
|
|
row_0.process();
|
|
|
|
row_1.process();
|
|
|
|
scanDelay.delay();
|
2016-05-09 14:05:08 +00:00
|
|
|
}
|