From 0403b50e52a6574096bc053dcb1ba471f54eb662 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 8 Feb 2019 21:07:52 +0000 Subject: my color scheme! --- Model01-Firmware.ino | 119 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 75 insertions(+), 44 deletions(-) diff --git a/Model01-Firmware.ino b/Model01-Firmware.ino index 85a2178..8687ad1 100644 --- a/Model01-Firmware.ino +++ b/Model01-Firmware.ino @@ -239,6 +239,79 @@ KEYMAPS( /* Re-enable astyle's indent enforcement */ // *INDENT-ON* +class DakkarColor: public kaleidoscope::plugin::LEDMode { +private: + static constexpr cRGB color_off = CRGB(0,0,0); + + static constexpr cRGB color_window = CRGB(255,0,0); + static constexpr cRGB color_viewport = CRGB(0,255,0); + static constexpr cRGB color_lauch = CRGB(0,0,255); + + static constexpr cRGB color_mouse = CRGB(0,0,255); + static constexpr cRGB color_mouse_button = CRGB(0,128,128); + 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) { } +protected: + void update(void) final { + for (uint8_t r = 0; r < ROWS; r++) { + for (uint8_t c = 0; c < COLS; c++) { + this->refreshAt(r, c); + } + } + } + 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); + + cRGB color = color_off; + if (current_layer == FVWM) { // FVWM keys + if (k.flags & LALT_HELD) { + switch (k.keyCode) { + case Key_F1.keyCode ... Key_F12.keyCode: case Key_Backtick.keyCode: + color = color_lauch; break; + + case Key_Keypad1.keyCode ... Key_Keypad0.keyCode: case Key_KeypadDivide.keyCode ... Key_KeypadEnter.keyCode: case Key_M.keyCode: + color = color_window; 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 (k == layer_key && k != Key_NoKey) { + 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); + } +}; + +static DakkarColor DakkarColorDark(CRGB(0,0,0)); +static DakkarColor DakkarColorBright(CRGB(0,0,150)); + /** versionInfoMacro handles the 'firmware version info' macro * When a key bound to the macro is pressed, this macro * prints out the firmware build information as virtual keystrokes @@ -300,19 +373,6 @@ const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { -// These 'solid' color effect definitions define a rainbow of -// LED color modes calibrated to draw 500mA or less on the -// Keyboardio Model 01. - - -static kaleidoscope::plugin::LEDSolidColor solidRed(160, 0, 0); -static kaleidoscope::plugin::LEDSolidColor solidOrange(140, 70, 0); -static kaleidoscope::plugin::LEDSolidColor solidYellow(130, 100, 0); -static kaleidoscope::plugin::LEDSolidColor solidGreen(0, 160, 0); -static kaleidoscope::plugin::LEDSolidColor solidBlue(0, 70, 130); -static kaleidoscope::plugin::LEDSolidColor solidIndigo(0, 0, 170); -static kaleidoscope::plugin::LEDSolidColor solidViolet(130, 0, 120); - /** toggleLedsOnSuspendResume toggles the LEDs off when the host goes to sleep, * and turns them back on when it wakes up. */ @@ -402,33 +462,7 @@ KALEIDOSCOPE_INIT_PLUGINS( // LEDControl provides support for other LED modes LEDControl, - // We start with the LED effect that turns off all the LEDs. - LEDOff, - - // The rainbow effect changes the color of all of the keyboard's keys at the same time - // running through all the colors of the rainbow. - //LEDRainbowEffect, - - // The rainbow wave effect lights up your keyboard with all the colors of a rainbow - // and slowly moves the rainbow across your keyboard - //LEDRainbowWaveEffect, - - // The chase effect follows the adventure of a blue pixel which chases a red pixel across - // your keyboard. Spoiler: the blue pixel never catches the red pixel - //LEDChaseEffect, - - // These static effects turn your keyboard's LEDs a variety of colors - solidRed, solidOrange, solidYellow, solidGreen, solidBlue, solidIndigo, solidViolet, - - // The breathe effect slowly pulses all of the LEDs on your keyboard - //LEDBreatheEffect, - - // The AlphaSquare effect prints each character you type, using your - // keyboard's LEDs as a display - //AlphaSquareEffect, - - // The stalker effect lights up the keys you've pressed recently - //StalkerEffect, + DakkarColorDark, DakkarColorBright, // The numpad plugin is responsible for lighting up the 'numpad' mode // with a custom LED effect @@ -468,10 +502,7 @@ void setup() { // needs to be explicitly told which keymap layer is your numpad layer NumPad.numPadLayer = NUMPAD; - // We want to make sure that the firmware starts with LED effects off - // This avoids over-taxing devices that don't have a lot of power to share - // with USB devices - LEDOff.activate(); + DakkarColorDark.activate(); // To make the keymap editable without flashing new firmware, we store // additional layers in EEPROM. For now, we reserve space for five layers. If -- cgit v1.2.3