From d512dd4d3f4b1740ed4cd4a6a31ddec46c1316ab Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Mon, 23 Oct 2017 11:11:10 -0700 Subject: [PATCH] fix visualizer for ergodox_infinity layout --- .../keymaps/don/{Makefile => rules.mk} | 12 +- keyboards/ergodox_ez/keymaps/don/visualizer.c | 160 ++++++++++++------ 2 files changed, 116 insertions(+), 56 deletions(-) rename keyboards/ergodox_ez/keymaps/don/{Makefile => rules.mk} (91%) diff --git a/keyboards/ergodox_ez/keymaps/don/Makefile b/keyboards/ergodox_ez/keymaps/don/rules.mk similarity index 91% rename from keyboards/ergodox_ez/keymaps/don/Makefile rename to keyboards/ergodox_ez/keymaps/don/rules.mk index bb0dd5d8f..20ab1b344 100644 --- a/keyboards/ergodox_ez/keymaps/don/Makefile +++ b/keyboards/ergodox_ez/keymaps/don/rules.mk @@ -8,20 +8,23 @@ EXTRAKEY_ENABLE = yes # Audio control and System control(+450) CONSOLE_ENABLE = no # Console for debug(+400) COMMAND_ENABLE = yes # Commands for debug and configuration NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work -BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality MIDI_ENABLE = no # MIDI controls AUDIO_ENABLE = no # Audio output on port C6 UNICODE_ENABLE = yes # Unicode BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend -ifeq ($(SUBPROJECT_DIR),'infinity') +ifeq ($(strip $(KEYBOARD)),ergodox_infinity) VISUALIZER_ENABLE = yes LCD_BACKLIGHT_ENABLE = yes +BACKLIGHT_ENABLE = yes LCD_ENABLE = yes +# ifndef QUANTUM_DIR +# include ../../../../Makefile +# endif else OPT_DEFS+= -DLEFT_LEDS -RGBLIGHT_ENABLE = no +BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality endif dfu-util: $(BUILD_DIR)/$(TARGET).bin sizeafter @@ -35,6 +38,3 @@ dfu-util: $(BUILD_DIR)/$(TARGET).bin sizeafter sudo dfu-util --device DFU -D $(BUILD_DIR)/$(TARGET).bin -ifndef QUANTUM_DIR - include ../../../../Makefile -endif diff --git a/keyboards/ergodox_ez/keymaps/don/visualizer.c b/keyboards/ergodox_ez/keymaps/don/visualizer.c index 253325c56..78aaae531 100644 --- a/keyboards/ergodox_ez/keymaps/don/visualizer.c +++ b/keyboards/ergodox_ez/keymaps/don/visualizer.c @@ -27,8 +27,17 @@ along with this program. If not, see . #endif #include "visualizer.h" +#include "visualizer_keyframes.h" +#include "lcd_keyframes.h" +#include "lcd_backlight_keyframes.h" +#include "led_backlight_keyframes.h" +#include "system/serial_link.h" +// #include "default_animations.h" // #include "led_test.h" +static bool keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state); +static bool keyframe_fade_in(keyframe_animation_t* animation, visualizer_state_t* state); + static const char* welcome_text[] = {"QMK: Don Keymap", "Infinity Ergodox"}; // Just an example how to write custom keyframe functions, we could have moved @@ -46,70 +55,121 @@ bool display_welcome(keyframe_animation_t* animation, visualizer_state_t* state) gdispFlush(); // you could set the backlight color as well, but we won't do it here, since // it's part of the following animation - // lcd_backlight_color(hue, saturation, intensity); + // lcd_backlight_color(hue, 0xFF, intensity); // We don't need constant updates, just drawing the screen once is enough return false; } // Feel free to modify the animations below, or even add new ones if needed +static bool keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) { +#ifdef LCD_ENABLE + lcd_keyframe_enable(animation, state); +#endif +#ifdef LCD_BACKLIGHT_ENABLE + lcd_backlight_keyframe_enable(animation, state); +#endif +#ifdef BACKLIGHT_ENABLE + led_backlight_keyframe_enable(animation, state); +#endif + return false; +} + +static bool keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) { +#ifdef LCD_ENABLE + lcd_keyframe_disable(animation, state); +#endif +#ifdef LCD_BACKLIGHT_ENABLE + lcd_backlight_keyframe_disable(animation, state); +#endif +#ifdef BACKLIGHT_ENABLE + led_backlight_keyframe_disable(animation, state); +#endif + return false; +} + +static bool keyframe_fade_in(keyframe_animation_t* animation, visualizer_state_t* state) { + bool ret = false; +#ifdef LCD_BACKLIGHT_ENABLE + ret |= lcd_backlight_keyframe_animate_color(animation, state); +#endif +#ifdef BACKLIGHT_ENABLE + ret |= led_backlight_keyframe_fade_in_all(animation, state); +#endif + return ret; +} + +static bool keyframe_fade_out(keyframe_animation_t* animation, visualizer_state_t* state) { + bool ret = false; +#ifdef LCD_BACKLIGHT_ENABLE + ret |= lcd_backlight_keyframe_animate_color(animation, state); +#endif +#ifdef BACKLIGHT_ENABLE + ret |= led_backlight_keyframe_fade_out_all(animation, state); +#endif + return ret; +} + // Don't worry, if the startup animation is long, you can use the keyboard like normal // during that time static keyframe_animation_t startup_animation = { - .num_frames = 4, +#if LCD_ENABLE + .num_frames = 3, +#else + .num_frames = 2, +#endif .loop = false, - .frame_lengths = {0, gfxMillisecondsToTicks(1000), gfxMillisecondsToTicks(5000), 0}, + .frame_lengths = { + 0, +#if LCD_ENABLE + 0, +#endif + gfxMillisecondsToTicks(5000)}, .frame_functions = { + keyframe_enable, +#if LCD_ENABLE display_welcome, - keyframe_animate_backlight_color, - keyframe_no_operation, - enable_visualization +#endif + keyframe_fade_in, }, }; -// The color animation animates the LCD color when you change layers -static keyframe_animation_t color_animation = { - .num_frames = 2, - .loop = false, - // Note that there's a 200 ms no-operation frame, - // this prevents the color from changing when activating the layer - // momentarily - .frame_lengths = {gfxMillisecondsToTicks(200), gfxMillisecondsToTicks(500)}, - .frame_functions = {keyframe_no_operation, keyframe_animate_backlight_color}, -}; - -// The LCD animation alternates between the layer name display and a -// bitmap that displays all active layers -static keyframe_animation_t lcd_animation = { - .num_frames = 2, - .loop = true, - .frame_lengths = {gfxMillisecondsToTicks(2000), gfxMillisecondsToTicks(2000)}, - .frame_functions = {keyframe_display_layer_text, keyframe_display_layer_bitmap}, -}; - -static keyframe_animation_t suspend_animation = { +keyframe_animation_t suspend_animation = { +#if LCD_ENABLE .num_frames = 3, +#else + .num_frames = 2, +#endif .loop = false, - .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, + .frame_lengths = { +#if LCD_ENABLE + 0, +#endif + gfxMillisecondsToTicks(1000), + 0}, .frame_functions = { - keyframe_display_layer_text, - keyframe_animate_backlight_color, - keyframe_disable_lcd_and_backlight, +#if LCD_ENABLE + lcd_keyframe_display_layer_text, +#endif + keyframe_fade_out, + keyframe_disable, }, }; -static keyframe_animation_t resume_animation = { - .num_frames = 5, - .loop = false, - .frame_lengths = {0, 0, gfxMillisecondsToTicks(1000), gfxMillisecondsToTicks(5000), 0}, - .frame_functions = { - keyframe_enable_lcd_and_backlight, - display_welcome, - keyframe_animate_backlight_color, - keyframe_no_operation, - enable_visualization, - }, -}; +void user_visualizer_suspend(visualizer_state_t* state) { + state->layer_text = "Suspending..."; + uint8_t hue = LCD_HUE(state->current_lcd_color); + uint8_t sat = LCD_SAT(state->current_lcd_color); + state->target_lcd_color = LCD_COLOR(hue, sat, 0); + start_keyframe_animation(&suspend_animation); +} + +void user_visualizer_resume(visualizer_state_t* state) { + state->current_lcd_color = LCD_COLOR(0,0,0); + state->target_lcd_color = LCD_COLOR(0,0,0xFF); + // initial_update = true; + start_keyframe_animation(&startup_animation); +} void initialize_user_visualizer(visualizer_state_t* state) { // The brightness will be dynamically adjustable in the future @@ -121,7 +181,7 @@ void initialize_user_visualizer(visualizer_state_t* state) { // start_keyframe_animation(&led_test_animation); } -void update_user_visualizer_state(visualizer_state_t* state) { +void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) { // Add more tests, change the colors and layer texts here // Usually you want to check the high bits (higher layers first) // because that's the order layers are processed for keypresses @@ -130,27 +190,27 @@ void update_user_visualizer_state(visualizer_state_t* state) { // state->status.default_layer // state->status.leds (see led.h for available statuses) if (state->status.layer & 0x20) { - state->target_lcd_color = LCD_COLOR(0xB0, saturation, 0xFF); + state->target_lcd_color = LCD_COLOR(0xB0, 0xFF, 0xFF); state->layer_text = "Plover"; } else if (state->status.layer & 0x10) { - state->target_lcd_color = LCD_COLOR(0x90, saturation, 0xFF); + state->target_lcd_color = LCD_COLOR(0x90, 0xFF, 0xFF); state->layer_text = "Numpad"; } else if (state->status.layer & 0x8) { - state->target_lcd_color = LCD_COLOR(0x60, saturation, 0xFF); + state->target_lcd_color = LCD_COLOR(0x60, 0xFF, 0xFF); state->layer_text = "KBD FXNs"; } else if (state->status.layer & 0x4) { - state->target_lcd_color = LCD_COLOR(0x30, saturation, 0xFF); + state->target_lcd_color = LCD_COLOR(0x30, 0xFF, 0xFF); state->layer_text = "Mouse"; } else if (state->status.layer & 0x2) { - state->target_lcd_color = LCD_COLOR(0x00, saturation, 0xFF); + state->target_lcd_color = LCD_COLOR(0x00, 0xFF, 0xFF); state->layer_text = "FXN/Symbols"; } else { - state->target_lcd_color = LCD_COLOR(0x00, saturation, 0x80); + state->target_lcd_color = LCD_COLOR(0x00, 0xFF, 0x80); state->layer_text = "Default"; } } -- 2.39.5