The problem of layout definition being a little too obtuse can be solved by adding a layer of indirection

pull/18/head
jesse 11 years ago
parent db6408c795
commit 71059ad363

@ -8,3 +8,6 @@ include build/arduino-mk/Arduino.mk
astyle:
astyle --style=linux ArduinoKeyboard.ino *.h
generate-keymaps:
find layout -type f -name \*.conf |xargs perl generate-keymaps.pl <

@ -27,29 +27,30 @@
#define LAYER_7 7
#define NoKey (Key){ KEY_FLAGS,0 }
#define Key_NoKey (Key){ KEY_FLAGS,0 }
#define Key_skip (Key){ KEY_FLAGS,0 }
#define macroKey1 (Key){ KEY_FLAGS|SYNTHETIC_KEY|IS_MACRO, 1}
#define Key_macroKey1 (Key){ KEY_FLAGS|SYNTHETIC_KEY|IS_MACRO, 1}
#define mouseUpL (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_UP | MOUSE_L }
#define mouseUp (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_UP }
#define mouseUpR (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_UP | MOUSE_R }
#define mouseL (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_L }
#define mouseR (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_R }
#define mouseDnL (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_DN | MOUSE_L }
#define mouseDn (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_DN }
#define mouseDnR (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_DN | MOUSE_R }
#define mouseScrollUp
#define mouseScrollDn
#define mouseScrollL
#define mouseScrollR
#define Key_mouseUpL (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_UP | MOUSE_L }
#define Key_mouseUp (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_UP }
#define Key_mouseUpR (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_UP | MOUSE_R }
#define Key_mouseL (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_L }
#define Key_mouseR (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_R }
#define Key_mouseDnL (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_DN | MOUSE_L }
#define Key_mouseDn (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_DN }
#define Key_mouseDnR (Key){ KEY_FLAGS|MOUSE_KEY, MOUSE_DN | MOUSE_R }
#define Key_mouseScrollUp
#define Key_mouseScrollDn
#define Key_mouseScrollL
#define Key_mouseScrollR
#define KEY_MOUSE_BTN_L 0x01 // Synthetic key
#define KEY_MOUSE_BTN_M 0x04 // Synthetic key
#define KEY_MOUSE_BTN_R 0x02 // Synthetic key
#define mouseBtnL (Key){ KEY_FLAGS | SYNTHETIC_KEY, KEY_MOUSE_BTN_L }
#define mouseBtnM (Key){ KEY_FLAGS | SYNTHETIC_KEY , KEY_MOUSE_BTN_M }
#define mouseBtnR (Key){ KEY_FLAGS | SYNTHETIC_KEY, KEY_MOUSE_BTN_R }
#define Key_mouseBtnL (Key){ KEY_FLAGS | SYNTHETIC_KEY, KEY_MOUSE_BTN_L }
#define Key_mouseBtnM (Key){ KEY_FLAGS | SYNTHETIC_KEY , KEY_MOUSE_BTN_M }
#define Key_mouseBtnR (Key){ KEY_FLAGS | SYNTHETIC_KEY, KEY_MOUSE_BTN_R }
@ -346,5 +347,5 @@
#define META_NEXT_KEYMAP_MOMENTARY 0xFF
#define NextKeymap (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_1 }
#define Key_NextKeymap (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_1 }

@ -1,49 +1,53 @@
#include "layouts-generated/qwerty.h"
#include "layouts-generated/qwerty_fn2.h"
static const Key keymaps[LAYERS][ROWS][COLS] = {
{
{ NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, NoKey, NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, NoKey },
{ Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, NoKey, NoKey, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals},
KEYMAP_QWERTY
/* {
{ Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, Key_NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, Key_NoKey },
{ Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_NoKey, Key_NoKey, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals},
{ Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_Tab, Key_Return, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote },
{ Key_PageDn, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Esc, Key_Return, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus},
{ Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, NextKeymap, NoKey, NoKey, NoKey, NoKey, NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt }
{ Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NextKeymap, Key_NoKey, Key_NoKey, Key_NoKey, Key_NoKey, Key_NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt }
},
{
{ NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, NoKey, NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, NoKey },
{ Key_Backtick, macroKey1, mouseBtnL, mouseBtnM, mouseBtnR, Key_T, NoKey, NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_P, Key_Equals},
{ Key_PageUp, mouseL, mouseUp, mouseDn, mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote},
{ Key_PageDn, Key_Z, mouseBtnL, mouseBtnM, mouseBtnR, Key_B, Key_Esc, Key_Return, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_Minus},
{ Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, NextKeymap, NoKey, NoKey, NoKey, NoKey, NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt }
*/
KEYMAP_QWERTY_FN2
/*{
{ Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, Key_NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, Key_NoKey },
{ Key_Backtick, Key_macroKey1, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_T, Key_NoKey, Key_NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_P, Key_Equals},
{ Key_PageUp, Key_mouseL, Key_mouseUp, Key_mouseDn, Key_mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote},
{ Key_PageDn, Key_Z, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_B, Key_Esc, Key_Return, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_Minus},
{ Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NextKeymap, Key_NoKey, Key_NoKey, Key_NoKey, Key_NoKey, Key_NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt }
},
*/
{
{ NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, NoKey, NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, NoKey },
{ Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, NoKey, NoKey, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals},
{ Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, Key_NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, Key_NoKey },
{ Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_NoKey, Key_NoKey, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals},
{ Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_Tab, Key_Return, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote },
{ Key_PageDn, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Esc, Key_Return, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus},
{ Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, NextKeymap, NoKey, NoKey, NoKey, NoKey, NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt }
{ Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NextKeymap, Key_NoKey, Key_NoKey, Key_NoKey, Key_NoKey, Key_NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt }
},
{
{ NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, NoKey, NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, NoKey },
{ Key_Backtick, Key_Q, mouseBtnL, mouseBtnM, mouseBtnR, Key_T, NoKey, NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_P, Key_Equals},
{ Key_PageUp, mouseL, mouseUp, mouseDn, mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote},
{ Key_PageDn, Key_Z, mouseBtnL, mouseBtnM, mouseBtnR, Key_B, Key_Esc, Key_Return, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_Minus},
{ Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, NextKeymap, NoKey, NoKey, NoKey, NoKey, NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt }
{ Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, Key_NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, Key_NoKey },
{ Key_Backtick, Key_Q, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_T, Key_NoKey, Key_NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_P, Key_Equals},
{ Key_PageUp, Key_mouseL, Key_mouseUp, Key_mouseDn, Key_mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote},
{ Key_PageDn, Key_Z, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_B, Key_Esc, Key_Return, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_Minus},
{ Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NextKeymap, Key_NoKey, Key_NoKey, Key_NoKey, Key_NoKey, Key_NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt }
},
{
{ NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, NoKey, NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, NoKey },
{ Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, NoKey, NoKey, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals},
{ Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, Key_NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, Key_NoKey },
{ Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_NoKey, Key_NoKey, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals},
{ Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_Tab, Key_Return, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote },
{ Key_PageDn, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Esc, Key_Return, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus},
{ Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, NextKeymap, NoKey, NoKey, NoKey, NoKey, NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt }
{ Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NextKeymap, Key_NoKey, Key_NoKey, Key_NoKey, Key_NoKey, Key_NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt }
},
{
{ NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, NoKey, NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, NoKey },
{ Key_Backtick, Key_Q, mouseBtnL, mouseBtnM, mouseBtnR, Key_T, NoKey, NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_P, Key_Equals},
{ Key_PageUp, mouseL, mouseUp, mouseDn, mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote},
{ Key_PageDn, Key_Z, mouseBtnL, mouseBtnM, mouseBtnR, Key_B, Key_Esc, Key_Return, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_Minus},
{ Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, NextKeymap, NoKey, NoKey, NoKey, NoKey, NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt }
{ Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, Key_NoKey, Key_6, Key_7, Key_8, Key_9, Key_0, Key_NoKey },
{ Key_Backtick, Key_Q, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_T, Key_NoKey, Key_NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_P, Key_Equals},
{ Key_PageUp, Key_mouseL, Key_mouseUp, Key_mouseDn, Key_mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote},
{ Key_PageDn, Key_Z, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_B, Key_Esc, Key_Return, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_Minus},
{ Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NextKeymap, Key_NoKey, Key_NoKey, Key_NoKey, Key_NoKey, Key_NextKeymap, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt }
},

@ -0,0 +1,6 @@
#NAME: QWERTY
skip 1 2 3 4 5 skip skip 6 7 8 9 0 skip
` Q W E R T skip skip Y U I O P =
PageUp A S D F G Tab Return H J K L ; '
PageDn Z X C V B Esc Enter N M , . / -
LGUI Backspace LShift LCtrl NextKeymap skip skip skip skip NextKeymap RCtrl RShift Space RAlt

@ -0,0 +1,6 @@
#NAME: QWERTY_FN2
skip 1 2 3 4 5 skip skip 6 7 8 9 0 skip
` macroKey1 mouseBtnL mouseBtnM mouseBtnR T NoKey NoKey { } [ ] P =
PageUp mouseL mouseUp mouseDn mouseR G Tab Return LArrow DnArrow UpArrow RArrow ; '
PageDn Z mouseBtnL mouseBtnM mouseBtnR B Esc Enter | M , . \ -
LGUI Backspace LShift LCtrl NextKeymap skip skip skip skip NextKeymap RCtrl RShift Space RAlt

@ -0,0 +1,49 @@
use warnings;
use strict;
my @data = <STDIN>;
use Data::Dumper;
my $name = 'Unnamed';
my @map;
for my $line (@data) {
chomp($line);
if ($line =~ /^#NAME: (.*)/i) {
$name = $1;
next
}
my @keys = split(/\s+/, $line);
push @map, join(', ', map{ 'Key_'.lookup($_).'' } @keys);
}
print "#define KEYMAP_$name { /* Generated keymap for $name */ ";
for my $line (@map) {
print "\t{". $line ."},\\\n";
}
print "},\n";
sub lookup {
my %table = (
'{' => 'LCurlyBracket',
'}' => 'RCurlyBracket',
'['=> 'LSquareBracket',
']'=> 'RSquareBracket',
'|'=> 'Pipe',
'\\' => 'Backslash',
';' => 'Semicolon',
',' => 'Comma',
'.' => 'Period',
'/' => 'Slash',
"'" => 'Quote',
'`' => 'Backtick',
'-' => 'Minus',
'=' => 'Equals');
my $x = shift;
return $x unless defined $table{$x};
return $table{$x};
}
Loading…
Cancel
Save