Archived
1
0

Code_LayerHoldShift and tutorials/keybrd_3g_shift_pairings/keybrd_3g_shift_pairings.ino

This commit is contained in:
wolfv6 2016-11-16 23:28:37 -07:00
parent 09b3e8ceb7
commit a2d1e30f2e
7 changed files with 172 additions and 25 deletions

View File

@ -6,6 +6,11 @@ This project adheres to [Semantic Versioning 2.0.0](http://semver.org/).
keybrd version 0.x.x is for initial development.
keybrd version 1.0.0 will be released when the public API is stable.
0.6.5 (2016-11-16)
------------------
* Enhancements
* add Code_LayerHoldShift and tutorials/keybrd_3g_shift_pairings/keybrd_3g_shift_pairings.ino
0.6.4 (2016-11-16)
------------------
* Enhancements

View File

@ -3,7 +3,7 @@
#include <inttypes.h>
#include <Code.h>
#include "LayerState.h"
#include <LayerState.h>
/* Code_LayerHold calls LayerState when pressed to change activeLayer.
*/

View File

@ -0,0 +1,13 @@
#include "Code_LayerHoldShift.h"
void Code_LayerHoldShift::press()
{
refLayerState.hold(layerId);
refCodeShift.press();
}
void Code_LayerHoldShift::release()
{
refLayerState.unhold(layerId);
refCodeShift.release();
}

31
src/Code_LayerHoldShift.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef CODE_LAYERHOLDSHIFT_H
#define CODE_LAYERHOLDSHIFT_H
#include <inttypes.h>
#include <Code.h>
#include <LayerState.h>
#include <Code_Shift.h>
/* Code_LayerHoldShift calls LayerState when pressed to change activeLayer.
When a Code_LayerHoldShift object is pressed or released, it:
* sends scancode in refCodeShift
* calls LayerState to change activeLayer
Codes defined in sketch would be Code_Sc and Code_ScNS
(Code_ScS is not need because refCodeShift sends the shift scancode).
*/
class Code_LayerHoldShift : public Code
{
private:
const uint8_t layerId;
LayerState& refLayerState;
Code_Shift& refCodeShift;
public:
Code_LayerHoldShift(const uint8_t layerId, LayerState& refLayerState,
Code_Shift& refCodeShift)
: layerId(layerId), refLayerState(refLayerState),
refCodeShift(refCodeShift) {}
virtual void press();
virtual void release();
};
#endif

View File

@ -16,27 +16,27 @@ This has been tested on teensy2.0.
#include <Code_ScNS_00.h>
// ********** SCANCODES NOT SHIFTED *********
Code_ScNS_00 sns_00; //double zero
Code_ScNS_00 ns_00; //double zero
Code_ScNS sns_1(KEY_1); //could get similar effect with s_pad1
Code_ScNS sns_2(KEY_2);
Code_ScNS sns_3(KEY_3);
Code_ScNS sns_4(KEY_4);
Code_ScNS sns_5(KEY_5);
Code_ScNS sns_6(KEY_6);
Code_ScNS sns_7(KEY_7);
Code_ScNS sns_8(KEY_8);
Code_ScNS sns_9(KEY_9);
Code_ScNS sns_0(KEY_0);
Code_ScNS ns_1(KEY_1); //could get similar effect with s_pad1
Code_ScNS ns_2(KEY_2);
Code_ScNS ns_3(KEY_3);
Code_ScNS ns_4(KEY_4);
Code_ScNS ns_5(KEY_5);
Code_ScNS ns_6(KEY_6);
Code_ScNS ns_7(KEY_7);
Code_ScNS ns_8(KEY_8);
Code_ScNS ns_9(KEY_9);
Code_ScNS ns_0(KEY_0);
Code_ScNS sns_minus(KEY_MINUS); //could get similar effect with s_padMinus
Code_ScNS sns_equal(KEY_EQUAL);
Code_ScNS sns_leftBracket(KEY_LEFT_BRACE); //[ ("brace" means curly bracket {})
Code_ScNS sns_rightBracket(KEY_RIGHT_BRACE); //]
Code_ScNS sns_backslash(KEY_BACKSLASH);
Code_ScNS sns_semicolon(KEY_SEMICOLON);
Code_ScNS sns_quote(KEY_QUOTE);
Code_ScNS sns_tilde(KEY_TILDE);
Code_ScNS sns_comma(KEY_COMMA);
Code_ScNS sns_period(KEY_PERIOD);
Code_ScNS sns_slash(KEY_SLASH);
Code_ScNS ns_minus(KEY_MINUS); //could get similar effect with s_padMinus
Code_ScNS ns_equal(KEY_EQUAL);
Code_ScNS ns_leftBracket(KEY_LEFT_BRACE); //[ ("brace" means curly bracket {})
Code_ScNS ns_rightBracket(KEY_RIGHT_BRACE); //]
Code_ScNS ns_backslash(KEY_BACKSLASH);
Code_ScNS ns_semicolon(KEY_SEMICOLON);
Code_ScNS ns_quote(KEY_QUOTE);
Code_ScNS ns_tilde(KEY_TILDE);
Code_ScNS ns_comma(KEY_COMMA);
Code_ScNS ns_period(KEY_PERIOD);
Code_ScNS ns_slash(KEY_SLASH);

View File

@ -102,12 +102,10 @@ LayerStateInterface& Key_LayeredKeys::refLayerState = layerState;
Key* const ptrsKeys_0[] = { &k_00, &k_01 };
uint8_t keyCount_0 = sizeof(ptrsKeys_0)/sizeof(*ptrsKeys_0);
Row row_0(scanner, 0, ptrsKeys_0, keyCount_0);
//Row row_0(0, readPins, READ_PIN_COUNT, ptrsKeys_0);
Key* const ptrsKeys_1[] = { &l_fn, &s_shift };
uint8_t keyCount_1 = sizeof(ptrsKeys_1)/sizeof(*ptrsKeys_1);
Row row_1(scanner, 1, ptrsKeys_1, keyCount_1);
//Row row_1(1, readPins, READ_PIN_COUNT, ptrsKeys_1);
// ################### MAIN ####################
void setup()

View File

@ -0,0 +1,100 @@
/* keybrd_3g_shift_pairings.ino
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** |
|:------:|-------|-------|
| **0** | 8 ( | = - |
| **1** | shift | 5 % |
The layout has one shift key in the lower right. The top-row keys are custom pairings.
Characters '8' and '=' are on the normal layer. Characters '(' and '-' are on the shift layer.
Holding the shift key down makes it the active layer.
Releasing the shift key restores the normal layer.
*/
// ################## GLOBAL ###################
// ================= INCLUDES ==================
//Keys
#include <Code_Sc.h>
#include <Code_ScNS.h>
#include <Code_Shift.h>
#include <LayerState.h>
#include <Code_LayerHoldShift.h>
#include <Key_LayeredKeys.h>
//Matrix
#include <Row.h>
#include <Scanner_uC.h>
#include <ScanDelay.h>
// ============ SPEED CONFIGURATION ============
ScanDelay scanDelay(9000);
// ================== SCANNER ==================
uint8_t readPins[] = {14, 15};
uint8_t readPinCount = sizeof(readPins)/sizeof(*readPins);
Scanner_uC scanner(LOW, readPins, readPinCount);
// =================== CODES ===================
// ---------------- LAYER CODE -----------------
enum layerIds { NORMAL, SHIFT };
LayerState layerState;
Code_Shift s_shift(MODIFIERKEY_LEFT_SHIFT);
Code_LayerHoldShift l_shift(SHIFT, layerState, s_shift);
/* ---------------- SCAN CODES -----------------
The "Sc" in Code_Sc means "scancode".
When a Code_Sc is pressed, it sends its scancode.
*/
Code_Sc s_a(KEY_A);
Code_Sc s_5(KEY_5);
Code_Sc s_8(KEY_8);
Code_Sc s_equal(KEY_EQUAL);
Code_Sc s_leftParen(KEY_9);
/* The "ScNS" in Code_ScNS means "scancode not shifted".
When Code_ScNS is pressed, it calls Code_AutoShift before sending its scancode.
*/
Code_ScNS ns_minus(KEY_MINUS);
/*
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;
const uint8_t Code_AutoShift::shiftCount = sizeof(ptrsS)/sizeof(*ptrsS);
// =============== LAYERED KEYS ================
Key* const ptrsKeys_00[] = { &s_8, &s_leftParen }; //custom key pairing
Key_LayeredKeys k_00(ptrsKeys_00);
Key* const ptrsKeys_01[] = { &s_equal, &ns_minus }; //custom key pairing
Key_LayeredKeys k_01(ptrsKeys_01);
LayerStateInterface& Key_LayeredKeys::refLayerState = layerState;
// =================== ROWS ====================
Key* const ptrsKeys_0[] = { &k_00, &k_01 };
uint8_t keyCount_0 = sizeof(ptrsKeys_0)/sizeof(*ptrsKeys_0);
Row row_0(scanner, 0, ptrsKeys_0, keyCount_0);
Key* const ptrsKeys_1[] = { &l_shift, &s_5 };
uint8_t keyCount_1 = sizeof(ptrsKeys_1)/sizeof(*ptrsKeys_1);
Row row_1(scanner, 1, ptrsKeys_1, keyCount_1);
// ################### MAIN ####################
void setup()
{
}
void loop()
{
row_0.process();
row_1.process();
scanDelay.delay();
}