diff options
-rw-r--r-- | Model01-Firmware.ino | 191 | ||||
-rw-r--r-- | keymap-wrapper.h | 55 | ||||
-rw-r--r-- | keymaps.h | 88 |
3 files changed, 189 insertions, 145 deletions
diff --git a/Model01-Firmware.ino b/Model01-Firmware.ino index fff564c..ca11319 100644 --- a/Model01-Firmware.ino +++ b/Model01-Firmware.ino @@ -140,106 +140,20 @@ enum { PRIMARY, NUMPAD, FUNCTION, FVWM }; // layers #define PRIMARY_KEYMAP_QWERTY // #define PRIMARY_KEYMAP_DVORAK - - -/* This comment temporarily turns off astyle's indent enforcement - * so we can make the keymaps actually resemble the physical key layout better - */ -// *INDENT-OFF* - -KEYMAPS( - -#if defined (PRIMARY_KEYMAP_QWERTY) - [PRIMARY] = KEYMAP_STACKED - (___, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext, - Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, - Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, - Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape, - Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, - ShiftToLayer(FVWM), - - M(MACRO_ANY), Key_6, Key_7, Key_8, Key_9, Key_0, LockLayer(NUMPAD), - Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, - Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, - Key_RightAlt, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, - Key_RightShift, Key_LeftAlt, Key_Spacebar, Key_RightControl, - ShiftToLayer(FUNCTION)), - -#elif defined (PRIMARY_KEYMAP_DVORAK) - - [PRIMARY] = KEYMAP_STACKED - (___, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext, - Key_Backtick, Key_Quote, Key_Comma, Key_Period, Key_P, Key_Y, Key_Tab, - Key_PageUp, Key_A, Key_O, Key_E, Key_U, Key_I, - Key_PageDown, Key_Semicolon, Key_Q, Key_J, Key_K, Key_X, Key_Escape, - Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, - ShiftToLayer(FVWM), - - M(MACRO_ANY), Key_6, Key_7, Key_8, Key_9, Key_0, LockLayer(NUMPAD), - Key_Enter, Key_F, Key_G, Key_C, Key_R, Key_L, Key_Slash, - Key_D, Key_H, Key_T, Key_N, Key_S, Key_Minus, - Key_RightAlt, Key_B, Key_M, Key_W, Key_V, Key_Z, Key_Equals, - Key_RightShift, Key_LeftAlt, Key_Spacebar, Key_RightControl, - ShiftToLayer(FUNCTION)), - -#else - -#error "No default keymap defined. You should make sure that you have a line like '#define PRIMARY_KEYMAP_QWERTY' in your sketch" - -#endif - - - - [NUMPAD] = KEYMAP_STACKED - (___, ___, ___, ___, ___, ___, ___, - ___, ___, ___, ___, ___, ___, ___, - ___, ___, ___, ___, ___, ___, - ___, ___, ___, ___, ___, ___, ___, - ___, ___, ___, ___, - ___, - - M(MACRO_VERSION_INFO), ___, Key_Keypad7, Key_Keypad8, Key_Keypad9, Key_KeypadSubtract, ___, - ___, ___, Key_Keypad4, Key_Keypad5, Key_Keypad6, Key_KeypadAdd, ___, - ___, Key_Keypad1, Key_Keypad2, Key_Keypad3, Key_Equals, ___, - ___, ___, Key_Keypad0, Key_KeypadDot, Key_KeypadMultiply, Key_KeypadDivide, Key_Enter, - ___, ___, ___, ___, - ___), - - [FUNCTION] = KEYMAP_STACKED - (___, Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, Key_CapsLock, - Key_Tab, ___, Key_mouseUp, ___, Key_mouseBtnR, Key_mouseWarpEnd, Key_mouseWarpNE, - Key_Home, Key_mouseL, Key_mouseDn, Key_mouseR, Key_mouseBtnL, Key_mouseWarpNW, - Key_End, Key_PrintScreen, Key_Insert, ___, Key_mouseBtnM, Key_mouseWarpSW, Key_mouseWarpSE, - ___, Key_Delete, ___, ___, - ___, - - ___, Key_F6, Key_F7, Key_F8, Key_F9, Key_F10, Key_F11, - ___, ___, Key_LeftCurlyBracket, Key_RightCurlyBracket, Key_LeftBracket, Key_RightBracket, Key_F12, - Key_LeftArrow, Key_DownArrow, Key_UpArrow, Key_RightArrow, ___, ___, - Key_PcApplication, ___, ___, ___, ___, Key_Backslash, Key_Pipe, - ___, ___, Key_Enter, ___, - ___), - - [FVWM] = KEYMAP_STACKED - (___, Key_BacklightDown, Key_BacklightUp, LALT(Key_F1), LALT(Key_F2), ___, ___, - ___, ___, ___, ___, ___, ___, ___, - ___, ___, LALT(Key_Keypad4), LALT(Key_Keypad2), LALT(Key_Keypad8), LALT(Key_Keypad6), - ___, ___, ___, ___, ___, ___, LALT(Key_KeypadMultiply), - ___, LALT(Key_Backtick), LSHIFT(LALT(Key_Backtick)), ___, - ___, - - ___, Consumer_Mute, Consumer_VolumeDecrement, Consumer_VolumeIncrement, ___, Consumer_Eject, ___, - ___, ___, ___, ___, ___, ___, LSHIFT(LALT(Key_KeypadDivide)), - LALT(Key_LeftArrow), LALT(Key_DownArrow), LALT(Key_UpArrow), LALT(Key_RightArrow), ___, LSHIFT(LALT(Key_KeypadEnter)), - LALT(Key_Pause), ___, ___, ___, ___, LALT(Key_M), LSHIFT(LALT(Key_KeypadDot)), - ___, ___, ___, ___, - ___) -) // KEYMAPS( - -/* Re-enable astyle's indent enforcement */ -// *INDENT-ON* - class DakkarColor: public kaleidoscope::plugin::LEDMode { +public: + class color { + public: + enum { + OFF, + BASE, + LAUNCH, WINDOW, VIEWPORT, + MOUSE, MOUSE_BUTTON, MOUSE_WARP, + FUNCTION, + }; + }; + + DakkarColor(const cRGB _colors[], const uint8_t _map[][ROWS][COLS]) : colors(_colors), map(_map) { } private: static constexpr cRGB color_off = CRGB(0,0,0); @@ -252,9 +166,8 @@ private: static constexpr cRGB color_mouse_warp = CRGB(64,128,128); static constexpr cRGB color_function = CRGB(64,128,64); - cRGB color_layer; -public: - DakkarColor(cRGB layer) : color_layer(layer) { } + const cRGB *colors; + const uint8_t (*map)[ROWS][COLS]; protected: void update(void) final { for (uint8_t r = 0; r < ROWS; r++) { @@ -264,52 +177,40 @@ protected: } } void refreshAt(byte r, byte c) final { - Key k = Layer.lookupOnActiveLayer(r, c); - uint8_t current_layer = Layer.top(); - Key layer_key = Layer.getKey(current_layer, r, c); - bool is_on_layer = (k == layer_key && k != Key_NoKey); - - cRGB color = color_off; - if (current_layer == FVWM) { // FVWM keys - if (is_on_layer) { - color = color_window; - } - switch (k.keyCode) { - case Key_F1.keyCode ... Key_F12.keyCode: case Key_Backtick.keyCode: - color = color_lauch; break; - - case Key_LeftArrow.keyCode: case Key_RightArrow.keyCode: case Key_UpArrow.keyCode: case Key_DownArrow.keyCode: - color = color_viewport; break; - } - if (k.flags & SHIFT_HELD) { - color.r >>= 1; color.g >>= 1; color.b >>= 1; - } - } - else if (current_layer == FUNCTION) { - if (k.flags & IS_MOUSE_KEY) { - switch (k.keyCode) { - case Key_mouseUp.keyCode: case Key_mouseDn.keyCode: case Key_mouseL.keyCode: case Key_mouseR.keyCode: - color = color_mouse; break; - } - if (k.keyCode & KEY_MOUSE_WARP) { color = color_mouse_warp; } - else if (k.keyCode & KEY_MOUSE_BUTTON) { color = color_mouse_button; } - } - else if (is_on_layer) { - color = color_function; - } - } - else { // only light up keys that are specific to this layer - if (k == layer_key && k != Key_NoKey) { - color = color_layer; - } - } - - LEDControl.setCrgbAt(r, c, color); + LEDControl.setCrgbAt(r, c, colors[map[Layer.top()][r][c]]); } }; -static DakkarColor DakkarColorDark(CRGB(0,0,0)); -static DakkarColor DakkarColorBright(CRGB(0,0,150)); +#include "keymap-wrapper.h" + +static constexpr cRGB dark_colors[] = + { + [DakkarColor::color::OFF] = CRGB(0,0,0), + [DakkarColor::color::BASE] = CRGB(0,0,0), + [DakkarColor::color::LAUNCH] = CRGB(0,0,150), + [DakkarColor::color::WINDOW] = CRGB(150,0,0), + [DakkarColor::color::VIEWPORT] = CRGB(0,150,0), + [DakkarColor::color::MOUSE] = CRGB(100,100,0), + [DakkarColor::color::MOUSE_BUTTON] = CRGB(50,0,50), + [DakkarColor::color::MOUSE_WARP] = CRGB(0,50,50), + [DakkarColor::color::FUNCTION] = CRGB(100,100,100), + }; + +static constexpr cRGB bright_colors[] = + { + [DakkarColor::color::OFF] = CRGB(0,0,0), + [DakkarColor::color::BASE] = CRGB(50,50,50), + [DakkarColor::color::LAUNCH] = CRGB(0,0,100), + [DakkarColor::color::WINDOW] = CRGB(100,0,0), + [DakkarColor::color::VIEWPORT] = CRGB(0,100,0), + [DakkarColor::color::MOUSE] = CRGB(50,50,0), + [DakkarColor::color::MOUSE_BUTTON] = CRGB(30,0,30), + [DakkarColor::color::MOUSE_WARP] = CRGB(0,30,30), + [DakkarColor::color::FUNCTION] = CRGB(50,50,80), + }; + +static DakkarColor DakkarColorDark(dark_colors,color_keymaps); +static DakkarColor DakkarColorBright(bright_colors,color_keymaps); /** versionInfoMacro handles the 'firmware version info' macro * When a key bound to the macro is pressed, this macro diff --git a/keymap-wrapper.h b/keymap-wrapper.h new file mode 100644 index 0000000..08e709c --- /dev/null +++ b/keymap-wrapper.h @@ -0,0 +1,55 @@ +#pragma once + +#define cOff(x) x +#define cBase(x) x +#define cLnch(x) x +#define cWind(x) x +#define cView(x) x +#define cMs(x) x +#define cMsW(x) x +#define cMsB(x) x +#define cFunc(x) x + +#define ColorKeymaps(layers...) KEYMAPS(layers) + +#include "keymaps.h" + + +#undef cOff +#undef cBase +#undef cLnch +#undef cWind +#undef cView +#undef cMs +#undef cMsW +#undef cMsB +#undef cFunc + +#undef ColorKeymaps + +#define cOff(x) DakkarColor::color::OFF +#define cBase(x) DakkarColor::color::BASE +#define cLnch(x) DakkarColor::color::LAUNCH +#define cWind(x) DakkarColor::color::WINDOW +#define cView(x) DakkarColor::color::VIEWPORT +#define cMs(x) DakkarColor::color::MOUSE +#define cMsW(x) DakkarColor::color::MOUSE_WARP +#define cMsB(x) DakkarColor::color::MOUSE_BUTTON +#define cFunc(x) DakkarColor::color::FUNCTION + +#define ColorKeymaps(layers...) \ + static constexpr uint8_t color_keymaps[][ROWS][COLS] PROGMEM = { layers }; + +#include "keymaps.h" + +#undef cOff +#undef cBase +#undef cLnch +#undef cWind +#undef cView +#undef cMs +#undef cMsW +#undef cMsB +#undef cFunc + +#undef ColorKeymaps diff --git a/keymaps.h b/keymaps.h new file mode 100644 index 0000000..c6fe12d --- /dev/null +++ b/keymaps.h @@ -0,0 +1,88 @@ +ColorKeymaps( + +#if defined (PRIMARY_KEYMAP_QWERTY) + [PRIMARY] = KEYMAP_STACKED + (cBase(___), cBase(Key_1), cBase(Key_2), cBase(Key_3), cBase(Key_4), cBase(Key_5), cBase(Key_LEDEffectNext), + cBase(Key_Backtick), cBase(Key_Q), cBase(Key_W), cBase(Key_E), cBase(Key_R), cBase(Key_T), cBase(Key_Tab), + cBase(Key_PageUp), cBase(Key_A), cBase(Key_S), cBase(Key_D), cBase(Key_F), cBase(Key_G), + cBase(Key_PageDown), cBase(Key_Z), cBase(Key_X), cBase(Key_C), cBase(Key_V), cBase(Key_B), cBase(Key_Escape), + cBase(Key_LeftControl), cBase(Key_Backspace), cBase(Key_LeftGui), cBase(Key_LeftShift), + cBase(ShiftToLayer(FVWM)), + + cBase(M(MACRO_ANY)), cBase(Key_6), cBase(Key_7), cBase(Key_8), cBase(Key_9), cBase(Key_0), cBase(LockLayer(NUMPAD)), + cBase(Key_Enter), cBase(Key_Y), cBase(Key_U), cBase(Key_I), cBase(Key_O), cBase(Key_P), cBase(Key_Equals), + cBase(Key_H), cBase(Key_J), cBase(Key_K), cBase(Key_L), cBase(Key_Semicolon), cBase(Key_Quote), + cBase(Key_RightAlt), cBase(Key_N), cBase(Key_M), cBase(Key_Comma), cBase(Key_Period), cBase(Key_Slash), cBase(Key_Minus), + cBase(Key_RightShift), cBase(Key_LeftAlt), cBase(Key_Spacebar), cBase(Key_RightControl), + cBase(ShiftToLayer(FUNCTION))), + +#elif defined (PRIMARY_KEYMAP_DVORAK) + + [PRIMARY] = KEYMAP_STACKED + (cBase(___), cBase(Key_1), cBase(Key_2), cBase(Key_3), cBase(Key_4), cBase(Key_5), cBase(Key_LEDEffectNext), + cBase(Key_Backtick), cBase(Key_Quote), cBase(Key_Comma), cBase(Key_Period), cBase(Key_P), cBase(Key_Y), cBase(Key_Tab), + cBase(Key_PageUp), cBase(Key_A), cBase(Key_O), cBase(Key_E), cBase(Key_U), cBase(Key_I), + cBase(Key_PageDown), cBase(Key_Semicolon), cBase(Key_Q), cBase(Key_J), cBase(Key_K), cBase(Key_X), cBase(Key_Escape), + cBase(Key_LeftControl), cBase(Key_Backspace), cBase(Key_LeftGui), cBase(Key_LeftShift), + cBase(ShiftToLayer(FVWM)), + + cBase(M(MACRO_ANY)), cBase(Key_6), cBase(Key_7), cBase(Key_8), cBase(Key_9), cBase(Key_0), cBase(LockLayer(NUMPAD)), + cBase(Key_Enter), cBase(Key_F), cBase(Key_G), cBase(Key_C), cBase(Key_R), cBase(Key_L), cBase(Key_Slash), + cBase(Key_D), cBase(Key_H), cBase(Key_T), cBase(Key_N), cBase(Key_S), cBase(Key_Minus), + cBase(Key_RightAlt), cBase(Key_B), cBase(Key_M), cBase(Key_W), cBase(Key_V), cBase(Key_Z), cBase(Key_Equals), + cBase(Key_RightShift), cBase(Key_LeftAlt), cBase(Key_Spacebar), cBase(Key_RightControl), + cBase(ShiftToLayer(FUNCTION))), + +#else + +#error "No default keymap defined. You should make sure that you have a line like '#define PRIMARY_KEYMAP_QWERTY' in your sketch" + +#endif + + + + [NUMPAD] = KEYMAP_STACKED + (cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), + cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), + cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), + cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), + cOff(___), cOff(___), cOff(___), cOff(___), + cOff(___), + + cBase(M(MACRO_VERSION_INFO)), cOff(XXX), cBase(Key_Keypad7), cBase(Key_Keypad8), cBase(Key_Keypad9), cBase(Key_KeypadSubtract), cOff(XXX), + cOff(XXX), cOff(XXX), cBase(Key_Keypad4), cBase(Key_Keypad5), cBase(Key_Keypad6), cBase(Key_KeypadAdd), cOff(XXX), + cOff(XXX), cBase(Key_Keypad1), cBase(Key_Keypad2), cBase(Key_Keypad3), cBase(Key_Equals), cOff(XXX), + cOff(XXX), cOff(XXX), cBase(Key_Keypad0), cBase(Key_KeypadDot), cBase(Key_KeypadMultiply), cBase(Key_KeypadDivide), cBase(Key_Enter), + cOff(___), cOff(___), cOff(___), cOff(___), + cOff(___)), + + [FUNCTION] = KEYMAP_STACKED + (cOff(XXX), cFunc(Key_F1), cFunc(Key_F2), cFunc(Key_F3), cFunc(Key_F4), cFunc(Key_F5), cFunc(Key_CapsLock), + cFunc(Key_Tab), cOff(XXX), cMs(Key_mouseUp), cOff(XXX), cMsB(Key_mouseBtnR), cMsW(Key_mouseWarpEnd), cMsW(Key_mouseWarpNE), + cFunc(Key_Home), cMs(Key_mouseL), cMs(Key_mouseDn), cMs(Key_mouseR), cMsB(Key_mouseBtnL), cMsW(Key_mouseWarpNW), + cFunc(Key_End), cFunc(Key_PrintScreen), cFunc(Key_Insert), cOff(XXX), cMsB(Key_mouseBtnM), cMsW(Key_mouseWarpSW), cMsW(Key_mouseWarpSE), + cOff(___), cFunc(Key_Delete), cOff(___), cOff(___), + cOff(___), + + cOff(XXX), cFunc(Key_F6), cFunc(Key_F7), cFunc(Key_F8), cFunc(Key_F9), cFunc(Key_F10), cFunc(Key_F11), + cOff(XXX), cOff(XXX), cFunc(Key_LeftCurlyBracket), cFunc(Key_RightCurlyBracket), cFunc(Key_LeftBracket), cFunc(Key_RightBracket), cFunc(Key_F12), + cFunc(Key_LeftArrow), cFunc(Key_DownArrow), cFunc(Key_UpArrow), cFunc(Key_RightArrow), cOff(XXX), cOff(XXX), + cFunc(Key_PcApplication), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cFunc(Key_Backslash), cFunc(Key_Pipe), + cOff(___), cOff(___), cFunc(Key_Enter), cOff(___), + cOff(___)), + + [FVWM] = KEYMAP_STACKED + (cOff(XXX), cLnch(Key_BacklightDown), cLnch(Key_BacklightUp), cLnch(LALT(Key_F1)), cLnch(LALT(Key_F2)), cOff(XXX), cOff(XXX), + cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), + cOff(XXX), cOff(XXX), cWind(LALT(Key_Keypad4)), cWind(LALT(Key_Keypad2)), cWind(LALT(Key_Keypad8)), cWind(LALT(Key_Keypad6)), + cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cWind(LALT(Key_KeypadMultiply)), + cOff(___), cLnch(LALT(Key_Backtick)), cLnch(LSHIFT(LALT(Key_Backtick))), cOff(___), + cOff(___), + + cOff(XXX), cLnch(Consumer_Mute), cLnch(Consumer_VolumeDecrement), cLnch(Consumer_VolumeIncrement), cOff(XXX), cLnch(Consumer_Eject), cOff(XXX), + cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cWind(LSHIFT(LALT(Key_KeypadDivide))), + cView(LALT(Key_LeftArrow)), cView(LALT(Key_DownArrow)), cView(LALT(Key_UpArrow)), cView(LALT(Key_RightArrow)), cOff(XXX), cWind(LSHIFT(LALT(Key_KeypadEnter))), + cLnch(LALT(Key_Pause)), cOff(XXX), cOff(XXX), cOff(XXX), cOff(XXX), cWind(LALT(Key_M)), cWind(LSHIFT(LALT(Key_KeypadDot))), + cOff(___), cOff(___), cOff(___), cOff(___), + cOff(___)) +); |