From 1c4fec2ceed29d764a5b4a2dbc43a195557c0ec1 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sun, 10 Feb 2019 11:38:58 +0000 Subject: mixed static / functional colors this probably replaces the Numpad plugin completely --- Model01-Firmware.ino | 101 +++++++++++++++++++++++++++++++++++++-------------- keymap-wrapper.h | 2 +- keymaps.h | 8 ++-- 3 files changed, 78 insertions(+), 33 deletions(-) diff --git a/Model01-Firmware.ino b/Model01-Firmware.ino index aac0431..b45f626 100644 --- a/Model01-Firmware.ino +++ b/Model01-Firmware.ino @@ -140,60 +140,105 @@ typedef enum { Lnch, Wind, View, Ms, MsB, MsW, Func, + Num, + NumBreathe, COLOR_COUNT, -} color_enum; +} color_index; class DakkarColor: public kaleidoscope::plugin::LEDMode { public: + typedef const cRGB (*color_function)(); + + struct colorSrc { + enum { VALUE, FUNCTION }; + uint8_t value_or_function; + union { + cRGB value; + color_function function; + } vf; + }; + + typedef const color_index (*color_index_map)[ROWS][COLS]; + typedef const colorSrc *color_src_array; - DakkarColor(const cRGB _colors[], const color_enum _map[][ROWS][COLS]) : colors(_colors), map(_map) { } + DakkarColor( + const color_index_map _map, + const color_src_array _colors + ) : map(_map), + color_sources(_colors) {} private: - const cRGB *colors; - const color_enum (*map)[ROWS][COLS]; + const color_index_map map; + const color_src_array color_sources; + + cRGB getColor(uint8_t l, uint8_t r, uint8_t c) { + color_index index = map[l][r][c]; + colorSrc color_src = color_sources[index]; + if (color_src.value_or_function == colorSrc::VALUE) { + return color_src.vf.value; + } + else { + return color_src.vf.function(); + } + } protected: void update(void) final { uint8_t layer = Layer.top(); for (uint8_t r = 0; r < ROWS; r++) { for (uint8_t c = 0; c < COLS; c++) { - LEDControl.setCrgbAt(r, c, colors[map[layer][r][c]]); + LEDControl.setCrgbAt(r, c, getColor(layer,r,c)); } } } void refreshAt(byte r, byte c) final { - LEDControl.setCrgbAt(r, c, colors[map[Layer.top()][r][c]]); + LEDControl.setCrgbAt(r, c, getColor(Layer.top(),r,c)); } }; #include "keymap-wrapper.h" -static constexpr cRGB dark_colors[COLOR_COUNT] = +const cRGB num_breathe() { return breath_compute(170); } + +#define D_C(r,g,b) ((DakkarColor::colorSrc){ \ + .value_or_function = DakkarColor::colorSrc::VALUE, \ + .vf = { .value = CRGB(r,g,b) } \ +}) +#define D_F(f) ((DakkarColor::colorSrc){ \ + .value_or_function = DakkarColor::colorSrc::FUNCTION, \ + .vf = { .function = f } \ +}) + +static constexpr DakkarColor::colorSrc dark_colors[COLOR_COUNT] = { - [Off] = CRGB(0,0,0), - [Base] = CRGB(0,0,0), - [Lnch] = CRGB(0,0,150), - [Wind] = CRGB(150,0,0), - [View] = CRGB(0,150,0), - [Ms] = CRGB(100,100,0), - [MsB] = CRGB(50,0,50), - [MsW] = CRGB(0,50,50), - [Func] = CRGB(100,100,100), + [Off] = D_C(0,0,0), + [Base] = D_C(0,0,0), + [Lnch] = D_C(0,0,150), + [Wind] = D_C(150,0,0), + [View] = D_C(0,150,0), + [Ms] = D_C(100,100,0), + [MsB] = D_C(50,0,50), + [MsW] = D_C(0,50,50), + [Func] = D_C(100,100,150), + [Num] = D_C(150,0,0), + [NumBreathe] = D_F(num_breathe), }; -static constexpr cRGB bright_colors[COLOR_COUNT] = +static constexpr DakkarColor::colorSrc bright_colors[COLOR_COUNT] = { - [Off] = CRGB(0,0,0), - [Base] = CRGB(50,50,50), - [Lnch] = CRGB(0,0,100), - [Wind] = CRGB(100,0,0), - [View] = CRGB(0,100,0), - [Ms] = CRGB(50,50,0), - [MsB] = CRGB(30,0,30), - [MsW] = CRGB(0,30,30), - [Func] = CRGB(50,50,80), + [Off] = D_C(0,0,0), + [Base] = D_C(50,50,50), + [Lnch] = D_C(0,0,100), + [Wind] = D_C(100,0,0), + [View] = D_C(0,100,0), + [Ms] = D_C(50,50,0), + [MsB] = D_C(30,0,30), + [MsW] = D_C(0,30,30), + [Func] = D_C(50,50,80), + [Num] = D_C(100,0,0), + [NumBreathe] = D_F(num_breathe), }; -static DakkarColor DakkarColorDark(dark_colors,color_keymaps); -static DakkarColor DakkarColorBright(bright_colors,color_keymaps); +static DakkarColor DakkarColorDark(color_keymaps,dark_colors); +static DakkarColor DakkarColorBright(color_keymaps,bright_colors); /** 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 index 71c7137..ce7a507 100644 --- a/keymap-wrapper.h +++ b/keymap-wrapper.h @@ -12,7 +12,7 @@ #define CK(k,c) c #define ColorKeymaps(layers...) \ - static constexpr color_enum color_keymaps[][ROWS][COLS] = { layers }; + static constexpr color_index color_keymaps[][ROWS][COLS] = { layers }; #include "keymaps.h" diff --git a/keymaps.h b/keymaps.h index defda8f..781b560 100644 --- a/keymaps.h +++ b/keymaps.h @@ -49,10 +49,10 @@ ColorKeymaps( CK(___,Off), CK(___,Off), CK(___,Off), CK(___,Off), CK(___,Off), - CK(M(MACRO_VERSION_INFO),Base), CK(XXX,Off), CK(Key_Keypad7,Base), CK(Key_Keypad8,Base), CK(Key_Keypad9,Base), CK(Key_KeypadSubtract,Base), CK(___,Off), - CK(XXX,Off), CK(XXX,Off), CK(Key_Keypad4,Base), CK(Key_Keypad5,Base), CK(Key_Keypad6,Base), CK(Key_KeypadAdd,Base), CK(XXX,Off), - CK(XXX,Off), CK(Key_Keypad1,Base), CK(Key_Keypad2,Base), CK(Key_Keypad3,Base), CK(Key_Equals,Base), CK(XXX,Off), - CK(XXX,Off), CK(XXX,Off), CK(Key_Keypad0,Base), CK(Key_KeypadDot,Base), CK(Key_KeypadMultiply,Base), CK(Key_KeypadDivide,Base), CK(Key_Enter,Base), + CK(M(MACRO_VERSION_INFO),Base), CK(XXX,Off), CK(Key_Keypad7,Num), CK(Key_Keypad8,Num), CK(Key_Keypad9,Num), CK(Key_KeypadSubtract,Num), CK(___,NumBreathe), + CK(XXX,Off), CK(XXX,Off), CK(Key_Keypad4,Num), CK(Key_Keypad5,Num), CK(Key_Keypad6,Num), CK(Key_KeypadAdd,Num), CK(XXX,Off), + CK(XXX,Off), CK(Key_Keypad1,Num), CK(Key_Keypad2,Num), CK(Key_Keypad3,Num), CK(Key_Equals,Num), CK(XXX,Off), + CK(XXX,Off), CK(XXX,Off), CK(Key_Keypad0,Num), CK(Key_KeypadDot,Num), CK(Key_KeypadMultiply,Num), CK(Key_KeypadDivide,Num), CK(Key_Enter,Num), CK(___,Off), CK(___,Off), CK(___,Off), CK(___,Off), CK(___,Off)), -- cgit v1.2.3