From aee9b10e92a597984ba9693b2dfcf597ca380a70 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 10 Jul 2016 23:45:39 +0300 Subject: Add a keyboard specific visualizer --- keyboards/ergodox/infinity/visualizer.c | 168 ++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 keyboards/ergodox/infinity/visualizer.c (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c new file mode 100644 index 000000000..c0d335ce6 --- /dev/null +++ b/keyboards/ergodox/infinity/visualizer.c @@ -0,0 +1,168 @@ +/* +Copyright 2016 Fred Sundvik + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +// Currently we are assuming that both the backlight and LCD are enabled +// But it's entirely possible to write a custom visualizer that use only +// one of them +#ifndef LCD_BACKLIGHT_ENABLE +#error This visualizer needs that LCD backlight is enabled +#endif + +#ifndef LCD_ENABLE +#error This visualizer needs that LCD is enabled +#endif + +#include "visualizer.h" +#include "led_test.h" + +static const char* welcome_text[] = {"TMK", "Infinity Ergodox"}; + +// Just an example how to write custom keyframe functions, we could have moved +// all this into the init function +bool display_welcome(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)animation; + // Read the uGFX documentation for information how to use the displays + // http://wiki.ugfx.org/index.php/Main_Page + gdispClear(White); + // You can use static variables for things that can't be found in the animation + // or state structs + gdispDrawString(0, 3, welcome_text[0], state->font_dejavusansbold12, Black); + gdispDrawString(0, 15, welcome_text[1], state->font_dejavusansbold12, Black); + // Always remember to flush the display + 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); + // 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 + +// 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, + .loop = false, + .frame_lengths = {0, gfxMillisecondsToTicks(1000), gfxMillisecondsToTicks(5000), 0}, + .frame_functions = { + display_welcome, + keyframe_animate_backlight_color, + keyframe_no_operation, + enable_visualization + }, +}; + +// 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 = { + .num_frames = 3, + .loop = false, + .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, + .frame_functions = { + keyframe_display_layer_text, + keyframe_animate_backlight_color, + keyframe_disable_lcd_and_backlight, + }, +}; + +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 initialize_user_visualizer(visualizer_state_t* state) { + // The brightness will be dynamically adjustable in the future + // But for now, change it here. + lcd_backlight_brightness(0x50); + state->current_lcd_color = LCD_COLOR(0x00, 0x00, 0xFF); + state->target_lcd_color = LCD_COLOR(0x10, 0xFF, 0xFF); + start_keyframe_animation(&startup_animation); + start_keyframe_animation(&led_test_animation); +} + +void update_user_visualizer_state(visualizer_state_t* state) { + // 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 + // You can for check for example: + // state->status.layer + // state->status.default_layer + // state->status.leds (see led.h for available statuses) + if (state->status.layer & 0x8) { + state->target_lcd_color = LCD_COLOR(0xC0, 0xB0, 0xFF); + state->layer_text = "Numpad"; + } + else if (state->status.layer & 0x4) { + state->target_lcd_color = LCD_COLOR(0, 0xB0, 0xFF); + state->layer_text = "KBD functions"; + } + else if (state->status.layer & 0x2) { + state->target_lcd_color = LCD_COLOR(0x80, 0xB0, 0xFF); + state->layer_text = "Function keys"; + } + else { + state->target_lcd_color = LCD_COLOR(0x40, 0xB0, 0xFF); + state->layer_text = "Default"; + } + // You can also stop existing animations, and start your custom ones here + // remember that you should normally have only one animation for the LCD + // and one for the background. But you can also combine them if you want. + start_keyframe_animation(&lcd_animation); + start_keyframe_animation(&color_animation); +} + +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(0x00, 0x00, 0x00); + state->target_lcd_color = LCD_COLOR(0x10, 0xFF, 0xFF); + start_keyframe_animation(&resume_animation); + start_keyframe_animation(&led_test_animation); +} -- cgit v1.2.3 From e6f7a8a47a82258725683980b83e215c8323aef2 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 1 Apr 2017 16:37:31 +0300 Subject: Display QMK logo at startup of Infinity Ergodox --- keyboards/ergodox/infinity/lcd_logo.png | Bin 0 -> 490 bytes keyboards/ergodox/infinity/visualizer.c | 89 +++++++++++++++++++++++--------- 2 files changed, 65 insertions(+), 24 deletions(-) create mode 100644 keyboards/ergodox/infinity/lcd_logo.png (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/lcd_logo.png b/keyboards/ergodox/infinity/lcd_logo.png new file mode 100644 index 000000000..6cf26fc67 Binary files /dev/null and b/keyboards/ergodox/infinity/lcd_logo.png differ diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index c0d335ce6..0ce1d4ae4 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -29,25 +29,68 @@ along with this program. If not, see . #include "visualizer.h" #include "led_test.h" -static const char* welcome_text[] = {"TMK", "Infinity Ergodox"}; +// To generate an image array like this +// Ensure the image is 128 x 32 or smaller +// Convert the bitmap to a C array using a program like http://www.riuson.com/lcd-image-converter/ +// Ensure the the conversion process produces a monochrome format array - 1 bit/pixel, left to right, top to bottom +// Update array in the source code with the C array produced by the conversion program + +// The image below is generated from lcd_logo.png +static const uint8_t image_data_lcd_logo[512] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xf8, 0xfe, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x06, 0x29, 0x41, 0x24, 0x52, 0x24, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x42, 0xaa, 0xaa, 0xaa, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x82, 0x28, 0xaa, 0xae, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x43, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x0a, 0x55, 0x42, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x05, 0x45, 0x42, 0x28, 0x89, 0x4a, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x18, 0x38, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1c, 0x38, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0e, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0xff, 0x80, 0x04, 0x45, 0x14, 0xa4, 0x92, 0x83, 0x52, 0x22, 0x22, 0x36, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0xba, 0x84, 0x55, 0x55, 0x57, 0x45, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0xb2, 0x55, 0x55, 0x42, 0x65, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x56, 0x65, 0x42, 0x45, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x54, 0x45, 0x42, 0x45, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x04, 0x48, 0xa2, 0x4a, 0x89, 0x06, 0x24, 0x42, 0x41, 0x36, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0x80); +static const uint32_t initial_color = LCD_COLOR(0, 0, 0xFF); -// Just an example how to write custom keyframe functions, we could have moved -// all this into the init function -bool display_welcome(keyframe_animation_t* animation, visualizer_state_t* state) { +bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)state; (void)animation; + (void)state; // Read the uGFX documentation for information how to use the displays // http://wiki.ugfx.org/index.php/Main_Page gdispClear(White); + // You can use static variables for things that can't be found in the animation - // or state structs - gdispDrawString(0, 3, welcome_text[0], state->font_dejavusansbold12, Black); - gdispDrawString(0, 15, welcome_text[1], state->font_dejavusansbold12, Black); + // or state structs, here we use the image + + //gdispGBlitArea is a tricky function to use since it supports blitting part of the image + // if you have full screen image, then just use 128 and 32 for both source and target dimensions + gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)image_data_lcd_logo); + // Always remember to flush the display 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); - // We don't need constant updates, just drawing the screen once is enough return false; } @@ -56,13 +99,12 @@ bool display_welcome(keyframe_animation_t* animation, visualizer_state_t* state) // 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, + .num_frames = 3, .loop = false, - .frame_lengths = {0, gfxMillisecondsToTicks(1000), gfxMillisecondsToTicks(5000), 0}, + .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { - display_welcome, + display_logo, keyframe_animate_backlight_color, - keyframe_no_operation, enable_visualization }, }; @@ -78,6 +120,7 @@ static keyframe_animation_t color_animation = { .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 = { @@ -99,14 +142,13 @@ static keyframe_animation_t suspend_animation = { }; static keyframe_animation_t resume_animation = { - .num_frames = 5, + .num_frames = 4, .loop = false, - .frame_lengths = {0, 0, gfxMillisecondsToTicks(1000), gfxMillisecondsToTicks(5000), 0}, + .frame_lengths = {0, 0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { keyframe_enable_lcd_and_backlight, - display_welcome, + display_logo, keyframe_animate_backlight_color, - keyframe_no_operation, enable_visualization, }, }; @@ -115,10 +157,9 @@ void initialize_user_visualizer(visualizer_state_t* state) { // The brightness will be dynamically adjustable in the future // But for now, change it here. lcd_backlight_brightness(0x50); - state->current_lcd_color = LCD_COLOR(0x00, 0x00, 0xFF); - state->target_lcd_color = LCD_COLOR(0x10, 0xFF, 0xFF); + state->current_lcd_color = initial_color; + state->target_lcd_color = logo_background_color; start_keyframe_animation(&startup_animation); - start_keyframe_animation(&led_test_animation); } void update_user_visualizer_state(visualizer_state_t* state) { @@ -161,8 +202,8 @@ void user_visualizer_suspend(visualizer_state_t* state) { } void user_visualizer_resume(visualizer_state_t* state) { - state->current_lcd_color = LCD_COLOR(0x00, 0x00, 0x00); - state->target_lcd_color = LCD_COLOR(0x10, 0xFF, 0xFF); + state->current_lcd_color = initial_color; + state->target_lcd_color = logo_background_color; start_keyframe_animation(&resume_animation); start_keyframe_animation(&led_test_animation); } -- cgit v1.2.3 From bc97413bf70b1906b387dea35bb22575ec57eff8 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 1 Apr 2017 16:38:12 +0300 Subject: Disable LEDs on Infinity Ergodox --- keyboards/ergodox/infinity/rules.mk | 2 +- keyboards/ergodox/infinity/visualizer.c | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/rules.mk b/keyboards/ergodox/infinity/rules.mk index d51574aca..aaadfe34b 100644 --- a/keyboards/ergodox/infinity/rules.mk +++ b/keyboards/ergodox/infinity/rules.mk @@ -61,7 +61,7 @@ CUSTOM_MATRIX ?= yes # Custom matrix file SERIAL_LINK_ENABLE = yes VISUALIZER_ENABLE ?= yes LCD_ENABLE ?= yes -LED_ENABLE ?= yes +LED_ENABLE ?= no LCD_BACKLIGHT_ENABLE ?= yes MIDI_ENABLE = no RGBLIGHT_ENABLE = no diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 0ce1d4ae4..c8fc3d78e 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -27,7 +27,6 @@ along with this program. If not, see . #endif #include "visualizer.h" -#include "led_test.h" // To generate an image array like this // Ensure the image is 128 x 32 or smaller @@ -205,5 +204,4 @@ void user_visualizer_resume(visualizer_state_t* state) { state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; start_keyframe_animation(&resume_animation); - start_keyframe_animation(&led_test_animation); } -- cgit v1.2.3 From 951b6f33a0dc479d29831aaa5c73fc526faf0471 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 1 Apr 2017 21:28:27 +0300 Subject: CIE 1931 for the LCD backlight --- keyboards/ergodox/infinity/infinity.c | 29 ++++++++++++++++++++++++++--- keyboards/ergodox/infinity/visualizer.c | 6 +++--- 2 files changed, 29 insertions(+), 6 deletions(-) (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/infinity.c b/keyboards/ergodox/infinity/infinity.c index 02db67eaf..ecc072abb 100644 --- a/keyboards/ergodox/infinity/infinity.c +++ b/keyboards/ergodox/infinity/infinity.c @@ -70,10 +70,33 @@ void lcd_backlight_hal_init(void) { RGB_PORT->PCR[BLUE_PIN] = RGB_MODE; } +static uint16_t cie_lightness(uint16_t v) { + // The CIE 1931 formula for lightness + // Y = luminance (output) 0-1 + // L = lightness input 0 - 100 + + // Y = (L* / 902.3) if L* <= 8 + // Y = ((L* + 16) / 116)^3 if L* > 8 + + float l = 100.0f * (v / 65535.0f); + float y = 0.0f; + if (l <= 8.0f) { + y = l / 902.3; + } + else { + y = ((l + 16.0f) / 116.0f); + y = y * y * y; + if (y > 1.0f) { + y = 1.0f; + } + } + return y * 65535.0f; +} + void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b) { - CHANNEL_RED.CnV = r; - CHANNEL_GREEN.CnV = g; - CHANNEL_BLUE.CnV = b; + CHANNEL_RED.CnV = cie_lightness(r); + CHANNEL_GREEN.CnV = cie_lightness(g); + CHANNEL_BLUE.CnV = cie_lightness(b); } __attribute__ ((weak)) diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index c8fc3d78e..12336fdc5 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -70,8 +70,8 @@ static const uint8_t image_data_lcd_logo[512] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0x80); -static const uint32_t initial_color = LCD_COLOR(0, 0, 0xFF); +static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); +static const uint32_t initial_color = LCD_COLOR(0, 0, 0); bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { (void)state; @@ -155,7 +155,7 @@ static keyframe_animation_t resume_animation = { void initialize_user_visualizer(visualizer_state_t* state) { // The brightness will be dynamically adjustable in the future // But for now, change it here. - lcd_backlight_brightness(0x50); + lcd_backlight_brightness(130); state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; start_keyframe_animation(&startup_animation); -- cgit v1.2.3 From 9a4ce28683b667ab67d48d92196bab7e277d4800 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 1 Apr 2017 22:52:58 +0300 Subject: Display layer bitmap and keyboard led states on the LCD --- keyboards/ergodox/infinity/visualizer.c | 86 ++++++++++++++++++++++----------- quantum/visualizer/visualizer.c | 38 ++++++++++++++- quantum/visualizer/visualizer.h | 4 +- 3 files changed, 97 insertions(+), 31 deletions(-) (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 12336fdc5..6af3a72ee 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -73,6 +73,14 @@ static const uint8_t image_data_lcd_logo[512] = { static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); static const uint32_t initial_color = LCD_COLOR(0, 0, 0); +typedef enum { + LCD_STATE_INITIAL, + LCD_STATE_LAYER_BITMAP, + LCD_STATE_BITMAP_AND_LEDS, +} lcd_state_t; + +static lcd_state_t lcd_state = LCD_STATE_INITIAL; + bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { (void)state; (void)animation; @@ -122,11 +130,18 @@ static keyframe_animation_t color_animation = { // The LCD animation alternates between the layer name display and a // bitmap that displays all active layers -static keyframe_animation_t lcd_animation = { +static keyframe_animation_t lcd_bitmap_animation = { + .num_frames = 1, + .loop = false, + .frame_lengths = {gfxMillisecondsToTicks(0)}, + .frame_functions = {keyframe_display_layer_bitmap}, +}; + +static keyframe_animation_t lcd_bitmap_leds_animation = { .num_frames = 2, .loop = true, .frame_lengths = {gfxMillisecondsToTicks(2000), gfxMillisecondsToTicks(2000)}, - .frame_functions = {keyframe_display_layer_text, keyframe_display_layer_bitmap}, + .frame_functions = {keyframe_display_layer_bitmap, keyframe_display_led_states}, }; static keyframe_animation_t suspend_animation = { @@ -158,38 +173,50 @@ void initialize_user_visualizer(visualizer_state_t* state) { lcd_backlight_brightness(130); state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; + lcd_state = LCD_STATE_INITIAL; start_keyframe_animation(&startup_animation); } -void update_user_visualizer_state(visualizer_state_t* state) { - // 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 - // You can for check for example: - // state->status.layer - // state->status.default_layer - // state->status.leds (see led.h for available statuses) - if (state->status.layer & 0x8) { - state->target_lcd_color = LCD_COLOR(0xC0, 0xB0, 0xFF); - state->layer_text = "Numpad"; - } - else if (state->status.layer & 0x4) { - state->target_lcd_color = LCD_COLOR(0, 0xB0, 0xFF); - state->layer_text = "KBD functions"; - } - else if (state->status.layer & 0x2) { - state->target_lcd_color = LCD_COLOR(0x80, 0xB0, 0xFF); - state->layer_text = "Function keys"; - } - else { +void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t prev_status) { + // Check the status here to start and stop animations + // You might have to save some state, like the current animation here so that you can start the right + // This function is called every time the status changes + + // NOTE that this is called from the visualizer thread, so don't access anything else outside the status + // This is also important because the slave won't have access to the active layer for example outside the + // status. + + if (lcd_state == LCD_STATE_INITIAL) { state->target_lcd_color = LCD_COLOR(0x40, 0xB0, 0xFF); - state->layer_text = "Default"; + start_keyframe_animation(&color_animation); + } + + if (state->status.leds) { + if (lcd_state != LCD_STATE_BITMAP_AND_LEDS || + state->status.leds != prev_status.leds || + state->status.layer != prev_status.layer || + state->status.default_layer != prev_status.default_layer) { + + // NOTE: that it doesn't matter if the animation isn't playing, stop will do nothing in that case + stop_keyframe_animation(&lcd_bitmap_animation); + + lcd_state = LCD_STATE_BITMAP_AND_LEDS; + // For information: + // The logic in this function makes sure that this doesn't happen, but if you call start on an + // animation that is already playing it will be restarted. + start_keyframe_animation(&lcd_bitmap_leds_animation); + } + } else { + if (lcd_state != LCD_STATE_LAYER_BITMAP || + state->status.layer != prev_status.layer || + state->status.default_layer != prev_status.default_layer) { + + stop_keyframe_animation(&lcd_bitmap_leds_animation); + + lcd_state = LCD_STATE_LAYER_BITMAP; + start_keyframe_animation(&lcd_bitmap_animation); + } } - // You can also stop existing animations, and start your custom ones here - // remember that you should normally have only one animation for the LCD - // and one for the background. But you can also combine them if you want. - start_keyframe_animation(&lcd_animation); - start_keyframe_animation(&color_animation); } void user_visualizer_suspend(visualizer_state_t* state) { @@ -203,5 +230,6 @@ void user_visualizer_suspend(visualizer_state_t* state) { void user_visualizer_resume(visualizer_state_t* state) { state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; + lcd_state = LCD_STATE_INITIAL; start_keyframe_animation(&resume_animation); } diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index 5826d909e..62ebebcee 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c @@ -56,6 +56,8 @@ SOFTWARE. // mods status #include "action_util.h" +#include "led.h" + static visualizer_keyboard_status_t current_status = { .layer = 0xFFFFFFFF, .default_layer = 0xFFFFFFFF, @@ -350,6 +352,39 @@ bool keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_st gdispFlush(); return false; } + +bool keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state) +{ + char output[sizeof("NUM CAPS SCRL COMP KANA")]; + uint8_t pos = 0; + + if (state->status.leds & (1u << USB_LED_NUM_LOCK)) { + memcpy(output + pos, "NUM ", 4); + pos += 4; + } + if (state->status.leds & (1u << USB_LED_CAPS_LOCK)) { + memcpy(output + pos, "CAPS ", 5); + pos += 5; + } + if (state->status.leds & (1u << USB_LED_SCROLL_LOCK)) { + memcpy(output + pos, "SCRL ", 5); + pos += 5; + } + if (state->status.leds & (1u << USB_LED_COMPOSE)) { + memcpy(output + pos, "COMP ", 5); + pos += 5; + } + if (state->status.leds & (1u << USB_LED_KANA)) { + memcpy(output + pos, "KANA ", 5); + pos += 5; + } + output[pos] = 0; + gdispClear(White); + gdispDrawString(0, 10, output, state->font_dejavusansbold12, Black); + gdispFlush(); + return false; +} + #endif // LCD_ENABLE bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) { @@ -433,8 +468,9 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { user_visualizer_suspend(&state); } else { + visualizer_keyboard_status_t prev_status = state.status; state.status = current_status; - update_user_visualizer_state(&state); + update_user_visualizer_state(&state, prev_status); } state.prev_lcd_color = state.current_lcd_color; } diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h index 315af5022..2c81cb9f7 100644 --- a/quantum/visualizer/visualizer.h +++ b/quantum/visualizer/visualizer.h @@ -136,6 +136,8 @@ bool keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_sta bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state); // Displays a bitmap (0/1) of all the currently active mods bool keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state); +// Displays the keyboard led states (CAPS (Caps lock), NUM (Num lock), SCRL (Scroll lock), COMP (Compose), KANA) +bool keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state); bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); @@ -146,7 +148,7 @@ bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* s // These functions have to be implemented by the user void initialize_user_visualizer(visualizer_state_t* state); -void update_user_visualizer_state(visualizer_state_t* state); +void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t prev_status); void user_visualizer_suspend(visualizer_state_t* state); void user_visualizer_resume(visualizer_state_t* state); -- cgit v1.2.3 From 39385144e7dc3337e623cdc8147b4a441f22fd62 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 2 Apr 2017 01:31:04 +0300 Subject: Emulate Ergodox EZ leds by LCD colors --- keyboards/ergodox/infinity/config.h | 2 + keyboards/ergodox/infinity/infinity.c | 22 +++- keyboards/ergodox/infinity/infinity.h | 71 +++++++------ keyboards/ergodox/infinity/visualizer.c | 175 ++++++++++++++++++++++++++++++-- quantum/visualizer/visualizer.c | 25 ++++- quantum/visualizer/visualizer.h | 8 ++ 6 files changed, 258 insertions(+), 45 deletions(-) (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/config.h b/keyboards/ergodox/infinity/config.h index 9e264083b..6cde193e1 100644 --- a/keyboards/ergodox/infinity/config.h +++ b/keyboards/ergodox/infinity/config.h @@ -54,6 +54,8 @@ along with this program. If not, see . // The visualizer needs gfx thread priorities #define VISUALIZER_THREAD_PRIORITY (NORMAL_PRIORITY - 2) +#define VISUALIZER_USER_DATA_SIZE 16 + /* * Feature disable options * These options are also useful to firmware size reduction. diff --git a/keyboards/ergodox/infinity/infinity.c b/keyboards/ergodox/infinity/infinity.c index ecc072abb..62259ed3f 100644 --- a/keyboards/ergodox/infinity/infinity.c +++ b/keyboards/ergodox/infinity/infinity.c @@ -126,34 +126,48 @@ void matrix_scan_kb(void) { matrix_scan_user(); } +__attribute__ ((weak)) void ergodox_board_led_on(void){ } +__attribute__ ((weak)) void ergodox_right_led_1_on(void){ } +__attribute__ ((weak)) void ergodox_right_led_2_on(void){ } +__attribute__ ((weak)) void ergodox_right_led_3_on(void){ } -void ergodox_right_led_on(uint8_t led){ -} - +__attribute__ ((weak)) void ergodox_board_led_off(void){ } +__attribute__ ((weak)) void ergodox_right_led_1_off(void){ } +__attribute__ ((weak)) void ergodox_right_led_2_off(void){ } +__attribute__ ((weak)) void ergodox_right_led_3_off(void){ } -void ergodox_right_led_off(uint8_t led){ +__attribute__ ((weak)) +void ergodox_right_led_1_set(uint8_t n) { +} + +__attribute__ ((weak)) +void ergodox_right_led_2_set(uint8_t n) { +} + +__attribute__ ((weak)) +void ergodox_right_led_3_set(uint8_t n) { } #ifdef ONEHAND_ENABLE diff --git a/keyboards/ergodox/infinity/infinity.h b/keyboards/ergodox/infinity/infinity.h index fec9e565c..73a0f4bf7 100644 --- a/keyboards/ergodox/infinity/infinity.h +++ b/keyboards/ergodox/infinity/infinity.h @@ -7,13 +7,38 @@ void ergodox_board_led_on(void); void ergodox_right_led_1_on(void); void ergodox_right_led_2_on(void); void ergodox_right_led_3_on(void); -void ergodox_right_led_on(uint8_t led); + +inline void ergodox_right_led_on(uint8_t led) { + switch (led) { + case 0: + ergodox_right_led_1_on(); + break; + case 1: + ergodox_right_led_2_on(); + break; + case 2: + ergodox_right_led_3_on(); + break; + } +} void ergodox_board_led_off(void); void ergodox_right_led_1_off(void); void ergodox_right_led_2_off(void); void ergodox_right_led_3_off(void); -void ergodox_right_led_off(uint8_t led); +inline void ergodox_right_led_off(uint8_t led) { + switch (led) { + case 0: + ergodox_right_led_1_off(); + break; + case 1: + ergodox_right_led_2_off(); + break; + case 2: + ergodox_right_led_3_off(); + break; + } +} inline void ergodox_led_all_on(void) { @@ -31,36 +56,22 @@ inline void ergodox_led_all_off(void) ergodox_right_led_3_off(); } -inline void ergodox_right_led_1_set(uint8_t n){ - if (n) { - ergodox_right_led_1_on(); - } else { - ergodox_right_led_1_off(); - } -} - -inline void ergodox_right_led_2_set(uint8_t n){ - if (n) { - ergodox_right_led_2_on(); - } else { - ergodox_right_led_2_off(); - } -} - -inline void ergodox_right_led_3_set(uint8_t n){ - if (n) { - ergodox_right_led_3_on(); - } else { - ergodox_right_led_3_off(); - } -} +void ergodox_right_led_1_set(uint8_t n); +void ergodox_right_led_2_set(uint8_t n); +void ergodox_right_led_3_set(uint8_t n); inline void ergodox_right_led_set(uint8_t led, uint8_t n){ - if (n) { - ergodox_right_led_on(led); - } else { - ergodox_right_led_off(led); - } + switch (led) { + case 0: + ergodox_right_led_1_set(n); + break; + case 1: + ergodox_right_led_2_set(n); + break; + case 2: + ergodox_right_led_3_set(n); + break; + } } inline void ergodox_led_all_set(uint8_t n) { diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 6af3a72ee..7bc42fbc7 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -27,6 +27,7 @@ along with this program. If not, see . #endif #include "visualizer.h" +#include "system/serial_link.h" // To generate an image array like this // Ensure the image is 128 x 32 or smaller @@ -73,6 +74,15 @@ static const uint8_t image_data_lcd_logo[512] = { static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); static const uint32_t initial_color = LCD_COLOR(0, 0, 0); +static const uint32_t led_emulation_colors[4] = { + LCD_COLOR(0, 0, 0), + LCD_COLOR(255, 255, 255), + LCD_COLOR(84, 255, 255), + LCD_COLOR(168, 255, 255), +}; + +static uint32_t next_led_target_color = 0; + typedef enum { LCD_STATE_INITIAL, LCD_STATE_LAYER_BITMAP, @@ -81,6 +91,19 @@ typedef enum { static lcd_state_t lcd_state = LCD_STATE_INITIAL; +typedef struct { + uint8_t led_on; + uint8_t led1; + uint8_t led2; + uint8_t led3; +} visualizer_user_data_t; + +// Don't access from visualization function, use the visualizer state instead +static visualizer_user_data_t user_data_keyboard = {}; + +_Static_assert(sizeof(visualizer_user_data_t) <= VISUALIZER_USER_DATA_SIZE, + "Please increase the VISUALIZER_USER_DATA_SIZE"); + bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { (void)state; (void)animation; @@ -117,16 +140,27 @@ static keyframe_animation_t startup_animation = { }; // The color animation animates the LCD color when you change layers -static keyframe_animation_t color_animation = { - .num_frames = 2, +static keyframe_animation_t one_led_color = { + .num_frames = 1, .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}, + .frame_lengths = {gfxMillisecondsToTicks(0)}, + .frame_functions = {keyframe_set_backlight_color}, }; +bool swap_led_target_color(keyframe_animation_t* animation, visualizer_state_t* state) { + uint32_t temp = next_led_target_color; + next_led_target_color = state->target_lcd_color; + state->target_lcd_color = temp; + return false; +} + +// The color animation animates the LCD color when you change layers +static keyframe_animation_t two_led_colors = { + .num_frames = 2, + .loop = true, + .frame_lengths = {gfxMillisecondsToTicks(1000), gfxMillisecondsToTicks(0)}, + .frame_functions = {keyframe_set_backlight_color, swap_led_target_color}, +}; // The LCD animation alternates between the layer name display and a // bitmap that displays all active layers @@ -177,6 +211,45 @@ void initialize_user_visualizer(visualizer_state_t* state) { start_keyframe_animation(&startup_animation); } +static const uint32_t red; +static const uint32_t green; +static const uint32_t blue; + +inline bool is_led_on(visualizer_user_data_t* user_data, uint8_t num) { + return user_data->led_on & (1u << num); +} + +static uint8_t get_led_index_master(visualizer_user_data_t* user_data) { + for (int i=0; i < 3; i++) { + if (is_led_on(user_data, i)) { + return i + 1; + } + } + return 0; +} + +static uint8_t get_led_index_slave(visualizer_user_data_t* user_data) { + uint8_t master_index = get_led_index_master(user_data); + if (master_index!=0) { + for (int i=master_index; i < 3; i++) { + if (is_led_on(user_data, i)) { + return i + 1; + } + } + } + + return 0; +} + +static uint8_t get_secondary_led_index(visualizer_user_data_t* user_data) { + if (is_led_on(user_data, 0) && + is_led_on(user_data, 1) && + is_led_on(user_data, 2)) { + return 3; + } + return 0; +} + void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t prev_status) { // Check the status here to start and stop animations // You might have to save some state, like the current animation here so that you can start the right @@ -186,9 +259,38 @@ void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard // This is also important because the slave won't have access to the active layer for example outside the // status. - if (lcd_state == LCD_STATE_INITIAL) { - state->target_lcd_color = LCD_COLOR(0x40, 0xB0, 0xFF); - start_keyframe_animation(&color_animation); + + visualizer_user_data_t* user_data_new = (visualizer_user_data_t*)state->status.user_data; + visualizer_user_data_t* user_data_old = (visualizer_user_data_t*)prev_status.user_data; + + uint8_t new_index; + uint8_t old_index; + + if (is_serial_link_master()) { + new_index = get_led_index_master(user_data_new); + old_index = get_led_index_master(user_data_old); + } + else { + new_index = get_led_index_slave(user_data_new); + old_index = get_led_index_slave(user_data_old); + } + uint8_t new_secondary_index = get_secondary_led_index(user_data_new); + uint8_t old_secondary_index = get_secondary_led_index(user_data_old); + + if (lcd_state == LCD_STATE_INITIAL || + new_index != old_index || + new_secondary_index != old_secondary_index) { + + if (new_secondary_index != 0) { + state->target_lcd_color = led_emulation_colors[new_index]; + next_led_target_color = led_emulation_colors[new_secondary_index]; + stop_keyframe_animation(&one_led_color); + start_keyframe_animation(&two_led_colors); + } else { + state->target_lcd_color = led_emulation_colors[new_index]; + stop_keyframe_animation(&two_led_colors); + start_keyframe_animation(&one_led_color); + } } if (state->status.leds) { @@ -233,3 +335,56 @@ void user_visualizer_resume(visualizer_state_t* state) { lcd_state = LCD_STATE_INITIAL; start_keyframe_animation(&resume_animation); } + +void ergodox_board_led_on(void){ + // No board led support +} + +void ergodox_right_led_1_on(void){ + user_data_keyboard.led_on |= (1u << 0); + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_right_led_2_on(void){ + user_data_keyboard.led_on |= (1u << 1); + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_right_led_3_on(void){ + user_data_keyboard.led_on |= (1u << 2); + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_board_led_off(void){ + // No board led support +} + +void ergodox_right_led_1_off(void){ + user_data_keyboard.led_on &= ~(1u << 0); + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_right_led_2_off(void){ + user_data_keyboard.led_on &= ~(1u << 1); + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_right_led_3_off(void){ + user_data_keyboard.led_on &= ~(1u << 2); + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_right_led_1_set(uint8_t n) { + user_data_keyboard.led1 = n; + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_right_led_2_set(uint8_t n) { + user_data_keyboard.led2 = n; + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_right_led_3_set(uint8_t n) { + user_data_keyboard.led3 = n; + visualizer_set_user_data(&user_data_keyboard); +} diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index 62ebebcee..bff0df494 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c @@ -64,6 +64,9 @@ static visualizer_keyboard_status_t current_status = { .mods = 0xFF, .leds = 0xFFFFFFFF, .suspended = false, +#ifdef VISUALIZER_USER_DATA_SIZE + .user_data = {0} +#endif }; static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboard_status_t* status2) { @@ -71,11 +74,19 @@ static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboa status1->default_layer == status2->default_layer && status1->mods == status2->mods && status1->leds == status2->leds && - status1->suspended == status2->suspended; + status1->suspended == status2->suspended +#ifdef VISUALIZER_USER_DATA_SIZE + && memcmp(status1->user_data, status2->user_data, VISUALIZER_USER_DATA_SIZE) == 0 +#endif + ; } static bool visualizer_enabled = false; +#ifdef VISUALIZER_USER_DATA_SIZE +static uint8_t user_data[VISUALIZER_USER_DATA_SIZE]; +#endif + #define MAX_SIMULTANEOUS_ANIMATIONS 4 static keyframe_animation_t* animations[MAX_SIMULTANEOUS_ANIMATIONS] = {}; @@ -431,6 +442,9 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { .mods = 0xFF, .leds = 0xFFFFFFFF, .suspended = false, +#ifdef VISUALIZER_USER_DATA_SIZE + .user_data = {0}, +#endif }; visualizer_state_t state = { @@ -590,6 +604,12 @@ uint8_t visualizer_get_mods() { return mods; } +#ifdef VISUALIZER_USER_DATA_SIZE +void visualizer_set_user_data(void* u) { + memcpy(user_data, u, VISUALIZER_USER_DATA_SIZE); +} +#endif + void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uint32_t leds) { // Note that there's a small race condition here, the thread could read // a state where one of these are set but not the other. But this should @@ -618,6 +638,9 @@ void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uin .leds = leds, .suspended = current_status.suspended, }; +#ifdef VISUALIZER_USER_DATA_SIZE + memcpy(new_status.user_data, user_data, VISUALIZER_USER_DATA_SIZE); +#endif if (!same_status(¤t_status, &new_status)) { changed = true; current_status = new_status; diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h index 2c81cb9f7..beb8f2ab4 100644 --- a/quantum/visualizer/visualizer.h +++ b/quantum/visualizer/visualizer.h @@ -68,6 +68,9 @@ typedef struct { uint8_t mods; uint32_t leds; // See led.h for available statuses bool suspended; +#ifdef VISUALIZER_USER_DATA_SIZE + uint8_t user_data[VISUALIZER_USER_DATA_SIZE]; +#endif } visualizer_keyboard_status_t; // The state struct is used by the various keyframe functions @@ -146,6 +149,11 @@ bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualiz // directly from the initalize_user_visualizer function (the animation can be null) bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state); +// The master can set userdata which will be transferred to the slave +#ifdef VISUALIZER_USER_DATA_SIZE +void visualizer_set_user_data(void* user_data); +#endif + // These functions have to be implemented by the user void initialize_user_visualizer(visualizer_state_t* state); void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t prev_status); -- cgit v1.2.3 From 5fbaf31dc26a7bb27eb276ec419255e92b293d60 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 2 Apr 2017 02:29:50 +0300 Subject: Brightness for Ergodox Infinity emulated LEDs --- keyboards/ergodox/infinity/config.h | 2 +- keyboards/ergodox/infinity/visualizer.c | 76 ++++++++++++++++++++++++--------- quantum/visualizer/lcd_backlight.h | 4 ++ quantum/visualizer/visualizer.c | 2 +- quantum/visualizer/visualizer.h | 2 +- 5 files changed, 63 insertions(+), 23 deletions(-) (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/config.h b/keyboards/ergodox/infinity/config.h index 6cde193e1..95f713819 100644 --- a/keyboards/ergodox/infinity/config.h +++ b/keyboards/ergodox/infinity/config.h @@ -40,7 +40,7 @@ along with this program. If not, see . /* number of backlight levels */ #define BACKLIGHT_LEVELS 3 -#define LED_BRIGHTNESS_LO 15 +#define LED_BRIGHTNESS_LO 100 #define LED_BRIGHTNESS_HI 255 /* define if matrix has ghost */ diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 7bc42fbc7..c7afd9384 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -99,7 +99,12 @@ typedef struct { } visualizer_user_data_t; // Don't access from visualization function, use the visualizer state instead -static visualizer_user_data_t user_data_keyboard = {}; +static visualizer_user_data_t user_data_keyboard = { + .led_on = 0, + .led1 = LED_BRIGHTNESS_HI, + .led2 = LED_BRIGHTNESS_HI, + .led3 = LED_BRIGHTNESS_HI, +}; _Static_assert(sizeof(visualizer_user_data_t) <= VISUALIZER_USER_DATA_SIZE, "Please increase the VISUALIZER_USER_DATA_SIZE"); @@ -250,18 +255,21 @@ static uint8_t get_secondary_led_index(visualizer_user_data_t* user_data) { return 0; } -void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t prev_status) { - // Check the status here to start and stop animations - // You might have to save some state, like the current animation here so that you can start the right - // This function is called every time the status changes - - // NOTE that this is called from the visualizer thread, so don't access anything else outside the status - // This is also important because the slave won't have access to the active layer for example outside the - // status. - +static uint8_t get_brightness(visualizer_user_data_t* user_data, uint8_t index) { + switch (index) { + case 1: + return user_data->led1; + case 2: + return user_data->led2; + case 3: + return user_data->led3; + } + return 0; +} +static void update_emulated_leds(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) { visualizer_user_data_t* user_data_new = (visualizer_user_data_t*)state->status.user_data; - visualizer_user_data_t* user_data_old = (visualizer_user_data_t*)prev_status.user_data; + visualizer_user_data_t* user_data_old = (visualizer_user_data_t*)prev_status->user_data; uint8_t new_index; uint8_t old_index; @@ -277,27 +285,41 @@ void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard uint8_t new_secondary_index = get_secondary_led_index(user_data_new); uint8_t old_secondary_index = get_secondary_led_index(user_data_old); + uint8_t old_brightness = get_brightness(user_data_old, old_index); + uint8_t new_brightness = get_brightness(user_data_new, new_index); + + uint8_t old_secondary_brightness = get_brightness(user_data_old, old_secondary_index); + uint8_t new_secondary_brightness = get_brightness(user_data_new, new_secondary_index); + if (lcd_state == LCD_STATE_INITIAL || new_index != old_index || - new_secondary_index != old_secondary_index) { + new_secondary_index != old_secondary_index || + new_brightness != old_brightness || + new_secondary_brightness != old_secondary_brightness) { if (new_secondary_index != 0) { - state->target_lcd_color = led_emulation_colors[new_index]; - next_led_target_color = led_emulation_colors[new_secondary_index]; + state->target_lcd_color = change_lcd_color_intensity( + led_emulation_colors[new_index], new_brightness); + next_led_target_color = change_lcd_color_intensity( + led_emulation_colors[new_secondary_index], new_secondary_brightness); + stop_keyframe_animation(&one_led_color); start_keyframe_animation(&two_led_colors); } else { - state->target_lcd_color = led_emulation_colors[new_index]; + state->target_lcd_color = change_lcd_color_intensity( + led_emulation_colors[new_index], new_brightness); stop_keyframe_animation(&two_led_colors); start_keyframe_animation(&one_led_color); } } +} +static void update_lcd_text(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) { if (state->status.leds) { if (lcd_state != LCD_STATE_BITMAP_AND_LEDS || - state->status.leds != prev_status.leds || - state->status.layer != prev_status.layer || - state->status.default_layer != prev_status.default_layer) { + state->status.leds != prev_status->leds || + state->status.layer != prev_status->layer || + state->status.default_layer != prev_status->default_layer) { // NOTE: that it doesn't matter if the animation isn't playing, stop will do nothing in that case stop_keyframe_animation(&lcd_bitmap_animation); @@ -310,8 +332,8 @@ void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard } } else { if (lcd_state != LCD_STATE_LAYER_BITMAP || - state->status.layer != prev_status.layer || - state->status.default_layer != prev_status.default_layer) { + state->status.layer != prev_status->layer || + state->status.default_layer != prev_status->default_layer) { stop_keyframe_animation(&lcd_bitmap_leds_animation); @@ -321,6 +343,20 @@ void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard } } +void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) { + // Check the status here to start and stop animations + // You might have to save some state, like the current animation here so that you can start the right + // This function is called every time the status changes + + // NOTE that this is called from the visualizer thread, so don't access anything else outside the status + // This is also important because the slave won't have access to the active layer for example outside the + // status. + + update_emulated_leds(state, prev_status); + update_lcd_text(state, prev_status); + +} + void user_visualizer_suspend(visualizer_state_t* state) { state->layer_text = "Suspending..."; uint8_t hue = LCD_HUE(state->current_lcd_color); diff --git a/quantum/visualizer/lcd_backlight.h b/quantum/visualizer/lcd_backlight.h index dd3e37a06..14dde64a1 100644 --- a/quantum/visualizer/lcd_backlight.h +++ b/quantum/visualizer/lcd_backlight.h @@ -32,6 +32,10 @@ SOFTWARE. #define LCD_SAT(color) ((color >> 8) & 0xFF) #define LCD_INT(color) (color & 0xFF) +inline uint32_t change_lcd_color_intensity(uint32_t color, uint8_t new_intensity) { + return (color & 0xFFFFFF00) | new_intensity; +} + void lcd_backlight_init(void); void lcd_backlight_color(uint8_t hue, uint8_t saturation, uint8_t intensity); void lcd_backlight_brightness(uint8_t b); diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index bff0df494..3b3f51b1f 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c @@ -484,7 +484,7 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { else { visualizer_keyboard_status_t prev_status = state.status; state.status = current_status; - update_user_visualizer_state(&state, prev_status); + update_user_visualizer_state(&state, &prev_status); } state.prev_lcd_color = state.current_lcd_color; } diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h index beb8f2ab4..e8ace5b37 100644 --- a/quantum/visualizer/visualizer.h +++ b/quantum/visualizer/visualizer.h @@ -156,7 +156,7 @@ void visualizer_set_user_data(void* user_data); // These functions have to be implemented by the user void initialize_user_visualizer(visualizer_state_t* state); -void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t prev_status); +void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status); void user_visualizer_suspend(visualizer_state_t* state); void user_visualizer_resume(visualizer_state_t* state); -- cgit v1.2.3 From 5815c5d317b02d688990980fdf01848e81247c21 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Wed, 5 Apr 2017 08:40:39 +0300 Subject: Move LCD keyframes to its own file --- keyboards/ergodox/infinity/visualizer.c | 7 +- keyboards/ergodox/keymaps/default/visualizer.c | 5 +- quantum/visualizer/lcd_keyframes.c | 160 +++++++++++++++++++++++++ quantum/visualizer/lcd_keyframes.h | 33 +++++ quantum/visualizer/visualizer.c | 150 +---------------------- quantum/visualizer/visualizer.h | 9 -- quantum/visualizer/visualizer.mk | 1 + 7 files changed, 203 insertions(+), 162 deletions(-) create mode 100644 quantum/visualizer/lcd_keyframes.c create mode 100644 quantum/visualizer/lcd_keyframes.h (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index c7afd9384..3abed08db 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -27,6 +27,7 @@ along with this program. If not, see . #endif #include "visualizer.h" +#include "lcd_keyframes.h" #include "system/serial_link.h" // To generate an image array like this @@ -173,14 +174,14 @@ static keyframe_animation_t lcd_bitmap_animation = { .num_frames = 1, .loop = false, .frame_lengths = {gfxMillisecondsToTicks(0)}, - .frame_functions = {keyframe_display_layer_bitmap}, + .frame_functions = {lcd_keyframe_display_layer_bitmap}, }; static keyframe_animation_t lcd_bitmap_leds_animation = { .num_frames = 2, .loop = true, .frame_lengths = {gfxMillisecondsToTicks(2000), gfxMillisecondsToTicks(2000)}, - .frame_functions = {keyframe_display_layer_bitmap, keyframe_display_led_states}, + .frame_functions = {lcd_keyframe_display_layer_bitmap, lcd_keyframe_display_led_states}, }; static keyframe_animation_t suspend_animation = { @@ -188,7 +189,7 @@ static keyframe_animation_t suspend_animation = { .loop = false, .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, .frame_functions = { - keyframe_display_layer_text, + lcd_keyframe_display_layer_text, keyframe_animate_backlight_color, keyframe_disable_lcd_and_backlight, }, diff --git a/keyboards/ergodox/keymaps/default/visualizer.c b/keyboards/ergodox/keymaps/default/visualizer.c index 305aaae15..ef87ac419 100644 --- a/keyboards/ergodox/keymaps/default/visualizer.c +++ b/keyboards/ergodox/keymaps/default/visualizer.c @@ -27,6 +27,7 @@ along with this program. If not, see . #endif #include "visualizer.h" +#include "lcd_keyframes.h" #include "system/serial_link.h" #include "led.h" @@ -122,7 +123,7 @@ static keyframe_animation_t lcd_layer_display = { .num_frames = 1, .loop = false, .frame_lengths = {gfxMillisecondsToTicks(0)}, - .frame_functions = {keyframe_display_layer_and_led_states} + .frame_functions = {lcd_keyframe_display_layer_and_led_states} }; static keyframe_animation_t suspend_animation = { @@ -130,7 +131,7 @@ static keyframe_animation_t suspend_animation = { .loop = false, .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, .frame_functions = { - keyframe_display_layer_text, + lcd_keyframe_display_layer_text, keyframe_animate_backlight_color, keyframe_disable_lcd_and_backlight, }, diff --git a/quantum/visualizer/lcd_keyframes.c b/quantum/visualizer/lcd_keyframes.c new file mode 100644 index 000000000..00d9734e6 --- /dev/null +++ b/quantum/visualizer/lcd_keyframes.c @@ -0,0 +1,160 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "lcd_keyframes.h" +#include +#include "action_util.h" +#include "led.h" + +bool lcd_keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)animation; + gdispClear(White); + gdispDrawString(0, 10, state->layer_text, state->font_dejavusansbold12, Black); + gdispFlush(); + return false; +} + +static void format_layer_bitmap_string(uint16_t default_layer, uint16_t layer, char* buffer) { + for (int i=0; i<16;i++) + { + uint32_t mask = (1u << i); + if (default_layer & mask) { + if (layer & mask) { + *buffer = 'B'; + } else { + *buffer = 'D'; + } + } else if (layer & mask) { + *buffer = '1'; + } else { + *buffer = '0'; + } + ++buffer; + + if (i==3 || i==7 || i==11) { + *buffer = ' '; + ++buffer; + } + } + *buffer = 0; +} + +bool lcd_keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)animation; + const char* layer_help = "1=On D=Default B=Both"; + char layer_buffer[16 + 4]; // 3 spaces and one null terminator + gdispClear(White); + gdispDrawString(0, 0, layer_help, state->font_fixed5x8, Black); + format_layer_bitmap_string(state->status.default_layer, state->status.layer, layer_buffer); + gdispDrawString(0, 10, layer_buffer, state->font_fixed5x8, Black); + format_layer_bitmap_string(state->status.default_layer >> 16, state->status.layer >> 16, layer_buffer); + gdispDrawString(0, 20, layer_buffer, state->font_fixed5x8, Black); + gdispFlush(); + return false; +} + +static void format_mods_bitmap_string(uint8_t mods, char* buffer) { + *buffer = ' '; + ++buffer; + + for (int i = 0; i<8; i++) + { + uint32_t mask = (1u << i); + if (mods & mask) { + *buffer = '1'; + } else { + *buffer = '0'; + } + ++buffer; + + if (i==3) { + *buffer = ' '; + ++buffer; + } + } + *buffer = 0; +} + +bool lcd_keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)animation; + + const char* title = "Modifier states"; + const char* mods_header = " CSAG CSAG "; + char status_buffer[12]; + + gdispClear(White); + gdispDrawString(0, 0, title, state->font_fixed5x8, Black); + gdispDrawString(0, 10, mods_header, state->font_fixed5x8, Black); + format_mods_bitmap_string(state->status.mods, status_buffer); + gdispDrawString(0, 20, status_buffer, state->font_fixed5x8, Black); + + gdispFlush(); + return false; +} + +#define LED_STATE_STRING_SIZE sizeof("NUM CAPS SCRL COMP KANA") + +static void get_led_state_string(char* output, visualizer_state_t* state) { + uint8_t pos = 0; + + if (state->status.leds & (1u << USB_LED_NUM_LOCK)) { + memcpy(output + pos, "NUM ", 4); + pos += 4; + } + if (state->status.leds & (1u << USB_LED_CAPS_LOCK)) { + memcpy(output + pos, "CAPS ", 5); + pos += 5; + } + if (state->status.leds & (1u << USB_LED_SCROLL_LOCK)) { + memcpy(output + pos, "SCRL ", 5); + pos += 5; + } + if (state->status.leds & (1u << USB_LED_COMPOSE)) { + memcpy(output + pos, "COMP ", 5); + pos += 5; + } + if (state->status.leds & (1u << USB_LED_KANA)) { + memcpy(output + pos, "KANA ", 5); + pos += 5; + } + output[pos] = 0; +} + +bool lcd_keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state) +{ + (void)animation; + char output[LED_STATE_STRING_SIZE]; + get_led_state_string(output, state); + gdispClear(White); + gdispDrawString(0, 10, output, state->font_dejavusansbold12, Black); + gdispFlush(); + return false; +} + +bool lcd_keyframe_display_layer_and_led_states(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)animation; + gdispClear(White); + uint8_t y = 10; + if (state->status.leds) { + char output[LED_STATE_STRING_SIZE]; + get_led_state_string(output, state); + gdispDrawString(0, 1, output, state->font_dejavusansbold12, Black); + y = 17; + } + gdispDrawString(0, y, state->layer_text, state->font_dejavusansbold12, Black); + gdispFlush(); + return false; +} diff --git a/quantum/visualizer/lcd_keyframes.h b/quantum/visualizer/lcd_keyframes.h new file mode 100644 index 000000000..0c9f39ab8 --- /dev/null +++ b/quantum/visualizer/lcd_keyframes.h @@ -0,0 +1,33 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef QUANTUM_VISUALIZER_LCD_KEYFRAMES_H_ +#define QUANTUM_VISUALIZER_LCD_KEYFRAMES_H_ + +#include "visualizer.h" + +// Displays the layer text centered vertically on the screen +bool lcd_keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state); +// Displays a bitmap (0/1) of all the currently active layers +bool lcd_keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state); +// Displays a bitmap (0/1) of all the currently active mods +bool lcd_keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state); +// Displays the keyboard led states (CAPS (Caps lock), NUM (Num lock), SCRL (Scroll lock), COMP (Compose), KANA) +bool lcd_keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state); +// Displays both the layer text and the led states +bool lcd_keyframe_display_layer_and_led_states(keyframe_animation_t* animation, visualizer_state_t* state); + +#endif /* QUANTUM_VISUALIZER_LCD_KEYFRAMES_H_ */ diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index 2533eb709..514d7c44e 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c @@ -48,16 +48,13 @@ SOFTWARE. #include "serial_link/system/serial_link.h" #endif +#include "action_util.h" + // Define this in config.h #ifndef VISUALIZER_THREAD_PRIORITY #define "Visualizer thread priority not defined" #endif -// mods status -#include "action_util.h" - -#include "led.h" - static visualizer_keyboard_status_t current_status = { .layer = 0xFFFFFFFF, .default_layer = 0xFFFFFFFF, @@ -277,149 +274,6 @@ bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_st } #endif // LCD_BACKLIGHT_ENABLE -#ifdef LCD_ENABLE -bool keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state) { - (void)animation; - gdispClear(White); - gdispDrawString(0, 10, state->layer_text, state->font_dejavusansbold12, Black); - gdispFlush(); - return false; -} - -static void format_layer_bitmap_string(uint16_t default_layer, uint16_t layer, char* buffer) { - for (int i=0; i<16;i++) - { - uint32_t mask = (1u << i); - if (default_layer & mask) { - if (layer & mask) { - *buffer = 'B'; - } else { - *buffer = 'D'; - } - } else if (layer & mask) { - *buffer = '1'; - } else { - *buffer = '0'; - } - ++buffer; - - if (i==3 || i==7 || i==11) { - *buffer = ' '; - ++buffer; - } - } - *buffer = 0; -} - -bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) { - (void)animation; - const char* layer_help = "1=On D=Default B=Both"; - char layer_buffer[16 + 4]; // 3 spaces and one null terminator - gdispClear(White); - gdispDrawString(0, 0, layer_help, state->font_fixed5x8, Black); - format_layer_bitmap_string(state->status.default_layer, state->status.layer, layer_buffer); - gdispDrawString(0, 10, layer_buffer, state->font_fixed5x8, Black); - format_layer_bitmap_string(state->status.default_layer >> 16, state->status.layer >> 16, layer_buffer); - gdispDrawString(0, 20, layer_buffer, state->font_fixed5x8, Black); - gdispFlush(); - return false; -} - -static void format_mods_bitmap_string(uint8_t mods, char* buffer) { - *buffer = ' '; - ++buffer; - - for (int i = 0; i<8; i++) - { - uint32_t mask = (1u << i); - if (mods & mask) { - *buffer = '1'; - } else { - *buffer = '0'; - } - ++buffer; - - if (i==3) { - *buffer = ' '; - ++buffer; - } - } - *buffer = 0; -} - -bool keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) { - (void)animation; - - const char* title = "Modifier states"; - const char* mods_header = " CSAG CSAG "; - char status_buffer[12]; - - gdispClear(White); - gdispDrawString(0, 0, title, state->font_fixed5x8, Black); - gdispDrawString(0, 10, mods_header, state->font_fixed5x8, Black); - format_mods_bitmap_string(state->status.mods, status_buffer); - gdispDrawString(0, 20, status_buffer, state->font_fixed5x8, Black); - - gdispFlush(); - return false; -} - -#define LED_STATE_STRING_SIZE sizeof("NUM CAPS SCRL COMP KANA") - -static void get_led_state_string(char* output, visualizer_state_t* state) { - uint8_t pos = 0; - - if (state->status.leds & (1u << USB_LED_NUM_LOCK)) { - memcpy(output + pos, "NUM ", 4); - pos += 4; - } - if (state->status.leds & (1u << USB_LED_CAPS_LOCK)) { - memcpy(output + pos, "CAPS ", 5); - pos += 5; - } - if (state->status.leds & (1u << USB_LED_SCROLL_LOCK)) { - memcpy(output + pos, "SCRL ", 5); - pos += 5; - } - if (state->status.leds & (1u << USB_LED_COMPOSE)) { - memcpy(output + pos, "COMP ", 5); - pos += 5; - } - if (state->status.leds & (1u << USB_LED_KANA)) { - memcpy(output + pos, "KANA ", 5); - pos += 5; - } - output[pos] = 0; -} - -bool keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state) -{ - (void)animation; - char output[LED_STATE_STRING_SIZE]; - get_led_state_string(output, state); - gdispClear(White); - gdispDrawString(0, 10, output, state->font_dejavusansbold12, Black); - gdispFlush(); - return false; -} - -bool keyframe_display_layer_and_led_states(keyframe_animation_t* animation, visualizer_state_t* state) { - (void)animation; - gdispClear(White); - uint8_t y = 10; - if (state->status.leds) { - char output[LED_STATE_STRING_SIZE]; - get_led_state_string(output, state); - gdispDrawString(0, 1, output, state->font_dejavusansbold12, Black); - y = 17; - } - gdispDrawString(0, y, state->layer_text, state->font_dejavusansbold12, Black); - gdispFlush(); - return false; -} - -#endif // LCD_ENABLE - bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) { (void)animation; (void)state; diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h index 3b05c305e..440044fd3 100644 --- a/quantum/visualizer/visualizer.h +++ b/quantum/visualizer/visualizer.h @@ -133,15 +133,6 @@ bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* bool keyframe_animate_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state); // Sets the backlight color to the target color bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state); -// Displays the layer text centered vertically on the screen -bool keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state); -// Displays a bitmap (0/1) of all the currently active layers -bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state); -// Displays a bitmap (0/1) of all the currently active mods -bool keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state); -// Displays the keyboard led states (CAPS (Caps lock), NUM (Num lock), SCRL (Scroll lock), COMP (Compose), KANA) -bool keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state); -bool keyframe_display_layer_and_led_states(keyframe_animation_t* animation, visualizer_state_t* state); bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); diff --git a/quantum/visualizer/visualizer.mk b/quantum/visualizer/visualizer.mk index 3861cb1f0..325cefd6f 100644 --- a/quantum/visualizer/visualizer.mk +++ b/quantum/visualizer/visualizer.mk @@ -34,6 +34,7 @@ endif ifeq ($(strip $(LCD_ENABLE)), yes) SRC += $(VISUALIZER_DIR)/lcd_backlight.c +SRC += $(VISUALIZER_DIR)/lcd_keyframes.c OPT_DEFS += -DLCD_BACKLIGHT_ENABLE endif -- cgit v1.2.3 From 5ba228b684a32c1099efc6207842a56ff102961a Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Wed, 5 Apr 2017 08:48:30 +0300 Subject: Move LCD backlight keyframes to its own file --- keyboards/ergodox/infinity/visualizer.c | 11 ++--- keyboards/ergodox/keymaps/default/visualizer.c | 9 ++-- quantum/visualizer/lcd_backlight_keyframes.c | 61 ++++++++++++++++++++++++++ quantum/visualizer/lcd_backlight_keyframes.h | 27 ++++++++++++ quantum/visualizer/visualizer.c | 46 ------------------- quantum/visualizer/visualizer.h | 4 -- quantum/visualizer/visualizer.mk | 1 + 7 files changed, 100 insertions(+), 59 deletions(-) create mode 100644 quantum/visualizer/lcd_backlight_keyframes.c create mode 100644 quantum/visualizer/lcd_backlight_keyframes.h (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 3abed08db..bbed4e989 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -28,6 +28,7 @@ along with this program. If not, see . #include "visualizer.h" #include "lcd_keyframes.h" +#include "lcd_backlight_keyframes.h" #include "system/serial_link.h" // To generate an image array like this @@ -140,7 +141,7 @@ static keyframe_animation_t startup_animation = { .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { display_logo, - keyframe_animate_backlight_color, + backlight_keyframe_animate_color, enable_visualization }, }; @@ -150,7 +151,7 @@ static keyframe_animation_t one_led_color = { .num_frames = 1, .loop = false, .frame_lengths = {gfxMillisecondsToTicks(0)}, - .frame_functions = {keyframe_set_backlight_color}, + .frame_functions = {backlight_keyframe_set_color}, }; bool swap_led_target_color(keyframe_animation_t* animation, visualizer_state_t* state) { @@ -165,7 +166,7 @@ static keyframe_animation_t two_led_colors = { .num_frames = 2, .loop = true, .frame_lengths = {gfxMillisecondsToTicks(1000), gfxMillisecondsToTicks(0)}, - .frame_functions = {keyframe_set_backlight_color, swap_led_target_color}, + .frame_functions = {backlight_keyframe_set_color, swap_led_target_color}, }; // The LCD animation alternates between the layer name display and a @@ -190,7 +191,7 @@ static keyframe_animation_t suspend_animation = { .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, .frame_functions = { lcd_keyframe_display_layer_text, - keyframe_animate_backlight_color, + backlight_keyframe_animate_color, keyframe_disable_lcd_and_backlight, }, }; @@ -202,7 +203,7 @@ static keyframe_animation_t resume_animation = { .frame_functions = { keyframe_enable_lcd_and_backlight, display_logo, - keyframe_animate_backlight_color, + backlight_keyframe_animate_color, enable_visualization, }, }; diff --git a/keyboards/ergodox/keymaps/default/visualizer.c b/keyboards/ergodox/keymaps/default/visualizer.c index ef87ac419..07f5a44ab 100644 --- a/keyboards/ergodox/keymaps/default/visualizer.c +++ b/keyboards/ergodox/keymaps/default/visualizer.c @@ -28,6 +28,7 @@ along with this program. If not, see . #include "visualizer.h" #include "lcd_keyframes.h" +#include "lcd_backlight_keyframes.h" #include "system/serial_link.h" #include "led.h" @@ -114,7 +115,7 @@ static keyframe_animation_t startup_animation = { .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { display_logo, - keyframe_animate_backlight_color, + backlight_keyframe_animate_color, enable_visualization }, }; @@ -132,7 +133,7 @@ static keyframe_animation_t suspend_animation = { .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, .frame_functions = { lcd_keyframe_display_layer_text, - keyframe_animate_backlight_color, + backlight_keyframe_animate_color, keyframe_disable_lcd_and_backlight, }, }; @@ -144,7 +145,7 @@ static keyframe_animation_t resume_animation = { .frame_functions = { keyframe_enable_lcd_and_backlight, display_logo, - keyframe_animate_backlight_color, + backlight_keyframe_animate_color, enable_visualization, }, }; @@ -157,7 +158,7 @@ static keyframe_animation_t color_animation = { // 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}, + .frame_functions = {keyframe_no_operation, backlight_keyframe_animate_color}, }; void initialize_user_visualizer(visualizer_state_t* state) { diff --git a/quantum/visualizer/lcd_backlight_keyframes.c b/quantum/visualizer/lcd_backlight_keyframes.c new file mode 100644 index 000000000..096473708 --- /dev/null +++ b/quantum/visualizer/lcd_backlight_keyframes.c @@ -0,0 +1,61 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "lcd_backlight_keyframes.h" + +bool backlight_keyframe_animate_color(keyframe_animation_t* animation, visualizer_state_t* state) { + int frame_length = animation->frame_lengths[animation->current_frame]; + int current_pos = frame_length - animation->time_left_in_frame; + uint8_t t_h = LCD_HUE(state->target_lcd_color); + uint8_t t_s = LCD_SAT(state->target_lcd_color); + uint8_t t_i = LCD_INT(state->target_lcd_color); + uint8_t p_h = LCD_HUE(state->prev_lcd_color); + uint8_t p_s = LCD_SAT(state->prev_lcd_color); + uint8_t p_i = LCD_INT(state->prev_lcd_color); + + uint8_t d_h1 = t_h - p_h; //Modulo arithmetic since we want to wrap around + int d_h2 = t_h - p_h; + // Chose the shortest way around + int d_h = abs(d_h2) < d_h1 ? d_h2 : d_h1; + int d_s = t_s - p_s; + int d_i = t_i - p_i; + + int hue = (d_h * current_pos) / frame_length; + int sat = (d_s * current_pos) / frame_length; + int intensity = (d_i * current_pos) / frame_length; + //dprintf("%X -> %X = %X\n", p_h, t_h, hue); + hue += p_h; + sat += p_s; + intensity += p_i; + state->current_lcd_color = LCD_COLOR(hue, sat, intensity); + lcd_backlight_color( + LCD_HUE(state->current_lcd_color), + LCD_SAT(state->current_lcd_color), + LCD_INT(state->current_lcd_color)); + + return true; +} + +bool backlight_keyframe_set_color(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)animation; + state->prev_lcd_color = state->target_lcd_color; + state->current_lcd_color = state->target_lcd_color; + lcd_backlight_color( + LCD_HUE(state->current_lcd_color), + LCD_SAT(state->current_lcd_color), + LCD_INT(state->current_lcd_color)); + return false; +} diff --git a/quantum/visualizer/lcd_backlight_keyframes.h b/quantum/visualizer/lcd_backlight_keyframes.h new file mode 100644 index 000000000..8cd5a46c6 --- /dev/null +++ b/quantum/visualizer/lcd_backlight_keyframes.h @@ -0,0 +1,27 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef QUANTUM_VISUALIZER_LCD_BACKLIGHT_KEYFRAMES_H_ +#define QUANTUM_VISUALIZER_LCD_BACKLIGHT_KEYFRAMES_H_ + +#include "visualizer.h" + +// Animates the LCD backlight color between the current color and the target color (of the state) +bool backlight_keyframe_animate_color(keyframe_animation_t* animation, visualizer_state_t* state); +// Sets the backlight color to the target color +bool backlight_keyframe_set_color(keyframe_animation_t* animation, visualizer_state_t* state); + +#endif /* QUANTUM_VISUALIZER_LCD_BACKLIGHT_KEYFRAMES_H_ */ diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index 514d7c44e..6ebd806e4 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c @@ -228,52 +228,6 @@ bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* return false; } -#ifdef LCD_BACKLIGHT_ENABLE -bool keyframe_animate_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state) { - int frame_length = animation->frame_lengths[animation->current_frame]; - int current_pos = frame_length - animation->time_left_in_frame; - uint8_t t_h = LCD_HUE(state->target_lcd_color); - uint8_t t_s = LCD_SAT(state->target_lcd_color); - uint8_t t_i = LCD_INT(state->target_lcd_color); - uint8_t p_h = LCD_HUE(state->prev_lcd_color); - uint8_t p_s = LCD_SAT(state->prev_lcd_color); - uint8_t p_i = LCD_INT(state->prev_lcd_color); - - uint8_t d_h1 = t_h - p_h; //Modulo arithmetic since we want to wrap around - int d_h2 = t_h - p_h; - // Chose the shortest way around - int d_h = abs(d_h2) < d_h1 ? d_h2 : d_h1; - int d_s = t_s - p_s; - int d_i = t_i - p_i; - - int hue = (d_h * current_pos) / frame_length; - int sat = (d_s * current_pos) / frame_length; - int intensity = (d_i * current_pos) / frame_length; - //dprintf("%X -> %X = %X\n", p_h, t_h, hue); - hue += p_h; - sat += p_s; - intensity += p_i; - state->current_lcd_color = LCD_COLOR(hue, sat, intensity); - lcd_backlight_color( - LCD_HUE(state->current_lcd_color), - LCD_SAT(state->current_lcd_color), - LCD_INT(state->current_lcd_color)); - - return true; -} - -bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state) { - (void)animation; - state->prev_lcd_color = state->target_lcd_color; - state->current_lcd_color = state->target_lcd_color; - lcd_backlight_color( - LCD_HUE(state->current_lcd_color), - LCD_SAT(state->current_lcd_color), - LCD_INT(state->current_lcd_color)); - return false; -} -#endif // LCD_BACKLIGHT_ENABLE - bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) { (void)animation; (void)state; diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h index 440044fd3..5c870dbfe 100644 --- a/quantum/visualizer/visualizer.h +++ b/quantum/visualizer/visualizer.h @@ -129,10 +129,6 @@ void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* stat // Some predefined keyframe functions that can be used by the user code // Does nothing, useful for adding delays bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state); -// Animates the LCD backlight color between the current color and the target color (of the state) -bool keyframe_animate_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state); -// Sets the backlight color to the target color -bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state); bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); diff --git a/quantum/visualizer/visualizer.mk b/quantum/visualizer/visualizer.mk index 325cefd6f..c9eb8c5bb 100644 --- a/quantum/visualizer/visualizer.mk +++ b/quantum/visualizer/visualizer.mk @@ -35,6 +35,7 @@ endif ifeq ($(strip $(LCD_ENABLE)), yes) SRC += $(VISUALIZER_DIR)/lcd_backlight.c SRC += $(VISUALIZER_DIR)/lcd_keyframes.c +SRC += $(VISUALIZER_DIR)/lcd_backlight_keyframes.c OPT_DEFS += -DLCD_BACKLIGHT_ENABLE endif -- cgit v1.2.3 From 1e7585e76771e1a2d8ca733fc09c19f9fa0e903c Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Wed, 5 Apr 2017 09:21:18 +0300 Subject: Separated backlight and LCD disable/enable Also moved them to correct places --- keyboards/ergodox/infinity/visualizer.c | 14 ++++++++------ keyboards/ergodox/keymaps/default/visualizer.c | 14 ++++++++------ quantum/visualizer/lcd_backlight_keyframes.c | 16 ++++++++++++++++ quantum/visualizer/lcd_backlight_keyframes.h | 3 +++ quantum/visualizer/lcd_keyframes.c | 14 ++++++++++++++ quantum/visualizer/lcd_keyframes.h | 4 ++++ quantum/visualizer/visualizer.c | 21 --------------------- quantum/visualizer/visualizer.h | 3 --- 8 files changed, 53 insertions(+), 36 deletions(-) (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index bbed4e989..8e684d991 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -186,22 +186,24 @@ static keyframe_animation_t lcd_bitmap_leds_animation = { }; static keyframe_animation_t suspend_animation = { - .num_frames = 3, + .num_frames = 4, .loop = false, - .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, + .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0, 0}, .frame_functions = { lcd_keyframe_display_layer_text, backlight_keyframe_animate_color, - keyframe_disable_lcd_and_backlight, + lcd_keyframe_disable, + lcd_keyframe_disable, }, }; static keyframe_animation_t resume_animation = { - .num_frames = 4, + .num_frames = 5, .loop = false, - .frame_lengths = {0, 0, gfxMillisecondsToTicks(10000), 0}, + .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { - keyframe_enable_lcd_and_backlight, + lcd_keyframe_enable, + backlight_keyframe_enable, display_logo, backlight_keyframe_animate_color, enable_visualization, diff --git a/keyboards/ergodox/keymaps/default/visualizer.c b/keyboards/ergodox/keymaps/default/visualizer.c index 07f5a44ab..5ee49c9bc 100644 --- a/keyboards/ergodox/keymaps/default/visualizer.c +++ b/keyboards/ergodox/keymaps/default/visualizer.c @@ -128,22 +128,24 @@ static keyframe_animation_t lcd_layer_display = { }; static keyframe_animation_t suspend_animation = { - .num_frames = 3, + .num_frames = 4, .loop = false, - .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, + .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0, 0}, .frame_functions = { lcd_keyframe_display_layer_text, backlight_keyframe_animate_color, - keyframe_disable_lcd_and_backlight, + lcd_keyframe_disable, + lcd_keyframe_disable, }, }; static keyframe_animation_t resume_animation = { - .num_frames = 4, + .num_frames = 5, .loop = false, - .frame_lengths = {0, 0, gfxMillisecondsToTicks(10000), 0}, + .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { - keyframe_enable_lcd_and_backlight, + lcd_keyframe_enable, + backlight_keyframe_enable, display_logo, backlight_keyframe_animate_color, enable_visualization, diff --git a/quantum/visualizer/lcd_backlight_keyframes.c b/quantum/visualizer/lcd_backlight_keyframes.c index 096473708..8436d4e3d 100644 --- a/quantum/visualizer/lcd_backlight_keyframes.c +++ b/quantum/visualizer/lcd_backlight_keyframes.c @@ -59,3 +59,19 @@ bool backlight_keyframe_set_color(keyframe_animation_t* animation, visualizer_st LCD_INT(state->current_lcd_color)); return false; } + +bool backlight_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)animation; + (void)state; + lcd_backlight_hal_color(0, 0, 0); + return false; +} + +bool backlight_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)animation; + (void)state; + lcd_backlight_color(LCD_HUE(state->current_lcd_color), + LCD_SAT(state->current_lcd_color), + LCD_INT(state->current_lcd_color)); + return false; +} diff --git a/quantum/visualizer/lcd_backlight_keyframes.h b/quantum/visualizer/lcd_backlight_keyframes.h index 8cd5a46c6..e1c125cf9 100644 --- a/quantum/visualizer/lcd_backlight_keyframes.h +++ b/quantum/visualizer/lcd_backlight_keyframes.h @@ -24,4 +24,7 @@ bool backlight_keyframe_animate_color(keyframe_animation_t* animation, visualize // Sets the backlight color to the target color bool backlight_keyframe_set_color(keyframe_animation_t* animation, visualizer_state_t* state); +bool backlight_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state); +bool backlight_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state); + #endif /* QUANTUM_VISUALIZER_LCD_BACKLIGHT_KEYFRAMES_H_ */ diff --git a/quantum/visualizer/lcd_keyframes.c b/quantum/visualizer/lcd_keyframes.c index 00d9734e6..74f6e3b47 100644 --- a/quantum/visualizer/lcd_keyframes.c +++ b/quantum/visualizer/lcd_keyframes.c @@ -158,3 +158,17 @@ bool lcd_keyframe_display_layer_and_led_states(keyframe_animation_t* animation, gdispFlush(); return false; } + +bool lcd_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)animation; + (void)state; + gdispSetPowerMode(powerOff); + return false; +} + +bool lcd_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)animation; + (void)state; + gdispSetPowerMode(powerOn); + return false; +} diff --git a/quantum/visualizer/lcd_keyframes.h b/quantum/visualizer/lcd_keyframes.h index 0c9f39ab8..8f79a541c 100644 --- a/quantum/visualizer/lcd_keyframes.h +++ b/quantum/visualizer/lcd_keyframes.h @@ -30,4 +30,8 @@ bool lcd_keyframe_display_led_states(keyframe_animation_t* animation, visualizer // Displays both the layer text and the led states bool lcd_keyframe_display_layer_and_led_states(keyframe_animation_t* animation, visualizer_state_t* state); +bool lcd_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state); +bool lcd_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state); + + #endif /* QUANTUM_VISUALIZER_LCD_KEYFRAMES_H_ */ diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index 6ebd806e4..98cd7ba55 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c @@ -228,27 +228,6 @@ bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* return false; } -bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) { - (void)animation; - (void)state; -#ifdef LCD_ENABLE - gdispSetPowerMode(powerOff); -#endif -#ifdef LCD_BACKLIGHT_ENABLE - lcd_backlight_hal_color(0, 0, 0); -#endif - return false; -} - -bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) { - (void)animation; - (void)state; -#ifdef LCD_ENABLE - gdispSetPowerMode(powerOn); -#endif - return false; -} - bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state) { (void)animation; (void)state; diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h index 5c870dbfe..f37ce8416 100644 --- a/quantum/visualizer/visualizer.h +++ b/quantum/visualizer/visualizer.h @@ -130,9 +130,6 @@ void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* stat // Does nothing, useful for adding delays bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state); -bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); -bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); - // Call this once, when the initial animation has finished, alternatively you can call it // directly from the initalize_user_visualizer function (the animation can be null) bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state); -- cgit v1.2.3 From 64d63ab42281318d891434fbc00277043298dd70 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Wed, 5 Apr 2017 10:08:25 +0300 Subject: Remove the need to manually enable the visualizer --- keyboards/ergodox/infinity/visualizer.c | 6 ++---- keyboards/ergodox/keymaps/default/visualizer.c | 6 ++---- quantum/visualizer/visualizer.c | 28 ++++++++++++++------------ quantum/visualizer/visualizer.h | 14 +++++++------ 4 files changed, 27 insertions(+), 27 deletions(-) (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 8e684d991..0897ea348 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -136,13 +136,12 @@ bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { // 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 = 3, + .num_frames = 2, .loop = false, .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { display_logo, backlight_keyframe_animate_color, - enable_visualization }, }; @@ -198,7 +197,7 @@ static keyframe_animation_t suspend_animation = { }; static keyframe_animation_t resume_animation = { - .num_frames = 5, + .num_frames = 4, .loop = false, .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { @@ -206,7 +205,6 @@ static keyframe_animation_t resume_animation = { backlight_keyframe_enable, display_logo, backlight_keyframe_animate_color, - enable_visualization, }, }; diff --git a/keyboards/ergodox/keymaps/default/visualizer.c b/keyboards/ergodox/keymaps/default/visualizer.c index 5ee49c9bc..73d864c64 100644 --- a/keyboards/ergodox/keymaps/default/visualizer.c +++ b/keyboards/ergodox/keymaps/default/visualizer.c @@ -110,13 +110,12 @@ bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { // 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 = 3, + .num_frames = 2, .loop = false, .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { display_logo, backlight_keyframe_animate_color, - enable_visualization }, }; @@ -140,7 +139,7 @@ static keyframe_animation_t suspend_animation = { }; static keyframe_animation_t resume_animation = { - .num_frames = 5, + .num_frames = 4, .loop = false, .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { @@ -148,7 +147,6 @@ static keyframe_animation_t resume_animation = { backlight_keyframe_enable, display_logo, backlight_keyframe_animate_color, - enable_visualization, }, }; diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index 98cd7ba55..5fbd12031 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c @@ -154,6 +154,14 @@ void stop_all_keyframe_animations(void) { } } +static uint8_t get_num_running_animations(void) { + uint8_t count = 0; + for (int i=0;icurrent_frame, @@ -228,14 +236,6 @@ bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* return false; } -bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state) { - (void)animation; - (void)state; - dprint("User visualizer inited\n"); - visualizer_enabled = true; - return false; -} - // TODO: Optimize the stack size, this is probably way too big static DECLARE_THREAD_STACK(visualizerThreadStack, 1024); static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { @@ -276,13 +276,15 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { systemticks_t sleep_time = TIME_INFINITE; systemticks_t current_time = gfxSystemTicks(); + bool force_update = true; while(true) { systemticks_t new_time = gfxSystemTicks(); systemticks_t delta = new_time - current_time; current_time = new_time; bool enabled = visualizer_enabled; - if (!same_status(&state.status, ¤t_status)) { + if (force_update || !same_status(&state.status, ¤t_status)) { + force_update = false; if (visualizer_enabled) { if (current_status.suspended) { stop_all_keyframe_animations(); @@ -320,10 +322,10 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { #ifdef EMULATOR draw_emulator(); #endif - // The animation can enable the visualizer - // And we might need to update the state when that happens - // so don't sleep - if (enabled != visualizer_enabled) { + // Enable the visualizer when the startup or the suspend animation has finished + if (!visualizer_enabled && state.status.suspended == false && get_num_running_animations() == 0) { + visualizer_enabled = true; + force_update = true; sleep_time = 0; } diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h index f37ce8416..463934849 100644 --- a/quantum/visualizer/visualizer.h +++ b/quantum/visualizer/visualizer.h @@ -130,20 +130,22 @@ void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* stat // Does nothing, useful for adding delays bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state); -// Call this once, when the initial animation has finished, alternatively you can call it -// directly from the initalize_user_visualizer function (the animation can be null) -bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state); - // The master can set userdata which will be transferred to the slave #ifdef VISUALIZER_USER_DATA_SIZE void visualizer_set_user_data(void* user_data); #endif // These functions have to be implemented by the user -void initialize_user_visualizer(visualizer_state_t* state); +// Called regularly each time the state has changed (but not every scan loop) void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status); +// Called when the computer goes to suspend, will also stop calling update_user_visualizer_state void user_visualizer_suspend(visualizer_state_t* state); +// You have to start at least one animation as a response to the following two functions +// When the animation has finished the visualizer will resume normal operation and start calling the +// update_user_visualizer_state again +// Called when the keyboard boots up +void initialize_user_visualizer(visualizer_state_t* state); +// Called when the computer resumes from a suspend void user_visualizer_resume(visualizer_state_t* state); - #endif /* VISUALIZER_H */ -- cgit v1.2.3 From b7041d06aef4dcf2f2a47504a699e538cfb1d9ac Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Wed, 5 Apr 2017 10:14:24 +0300 Subject: Move common visualizer keyframes into visualizer_keyframes.h --- keyboards/ergodox/infinity/visualizer.c | 1 + keyboards/ergodox/keymaps/default/visualizer.c | 1 + quantum/visualizer/visualizer.c | 6 ------ quantum/visualizer/visualizer.h | 6 +----- quantum/visualizer/visualizer.mk | 3 ++- quantum/visualizer/visualizer_keyframes.c | 23 +++++++++++++++++++++++ quantum/visualizer/visualizer_keyframes.h | 26 ++++++++++++++++++++++++++ 7 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 quantum/visualizer/visualizer_keyframes.c create mode 100644 quantum/visualizer/visualizer_keyframes.h (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 0897ea348..2e10fdd70 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -27,6 +27,7 @@ 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 "system/serial_link.h" diff --git a/keyboards/ergodox/keymaps/default/visualizer.c b/keyboards/ergodox/keymaps/default/visualizer.c index 73d864c64..f6159e1ef 100644 --- a/keyboards/ergodox/keymaps/default/visualizer.c +++ b/keyboards/ergodox/keymaps/default/visualizer.c @@ -27,6 +27,7 @@ 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 "system/serial_link.h" diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index 5fbd12031..2479a64c7 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c @@ -230,12 +230,6 @@ void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* stat (*temp_animation.frame_functions[next_frame])(&temp_animation, &temp_state); } -bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state) { - (void)animation; - (void)state; - return false; -} - // TODO: Optimize the stack size, this is probably way too big static DECLARE_THREAD_STACK(visualizerThreadStack, 1024); static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h index 463934849..d6f279e10 100644 --- a/quantum/visualizer/visualizer.h +++ b/quantum/visualizer/visualizer.h @@ -34,7 +34,7 @@ SOFTWARE. #include "lcd_backlight.h" #endif -// use this function to merget both real_mods and oneshot_mods in a uint16_t +// use this function to merge both real_mods and oneshot_mods in a uint16_t uint8_t visualizer_get_mods(void); // This need to be called once at the start @@ -126,10 +126,6 @@ void stop_keyframe_animation(keyframe_animation_t* animation); // Useful for crossfades for example void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* state); -// Some predefined keyframe functions that can be used by the user code -// Does nothing, useful for adding delays -bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state); - // The master can set userdata which will be transferred to the slave #ifdef VISUALIZER_USER_DATA_SIZE void visualizer_set_user_data(void* user_data); diff --git a/quantum/visualizer/visualizer.mk b/quantum/visualizer/visualizer.mk index c9eb8c5bb..799379e3d 100644 --- a/quantum/visualizer/visualizer.mk +++ b/quantum/visualizer/visualizer.mk @@ -20,7 +20,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -SRC += $(VISUALIZER_DIR)/visualizer.c +SRC += $(VISUALIZER_DIR)/visualizer.c \ + $(VISUALIZER_DIR)/visualizer_keyframes.c EXTRAINCDIRS += $(GFXINC) $(VISUALIZER_DIR) GFXLIB = $(LIB_PATH)/ugfx VPATH += $(VISUALIZER_PATH) diff --git a/quantum/visualizer/visualizer_keyframes.c b/quantum/visualizer/visualizer_keyframes.c new file mode 100644 index 000000000..8f6a7e15a --- /dev/null +++ b/quantum/visualizer/visualizer_keyframes.c @@ -0,0 +1,23 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "visualizer_keyframes.h" + +bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)animation; + (void)state; + return false; +} diff --git a/quantum/visualizer/visualizer_keyframes.h b/quantum/visualizer/visualizer_keyframes.h new file mode 100644 index 000000000..9ef7653c5 --- /dev/null +++ b/quantum/visualizer/visualizer_keyframes.h @@ -0,0 +1,26 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef QUANTUM_VISUALIZER_VISUALIZER_KEYFRAMES_H_ +#define QUANTUM_VISUALIZER_VISUALIZER_KEYFRAMES_H_ + +#include "visualizer.h" + +// Some predefined keyframe functions that can be used by the user code +// Does nothing, useful for adding delays +bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state); + +#endif /* QUANTUM_VISUALIZER_VISUALIZER_KEYFRAMES_H_ */ -- cgit v1.2.3 From 3eb8785e8770c07e6a4280c50240d5d951461911 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Apr 2017 20:10:20 +0300 Subject: Add automatic flush for the LCD screen --- .../ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c | 1 + keyboards/ergodox/infinity/visualizer.c | 2 -- keyboards/ergodox/keymaps/default/visualizer.c | 2 -- quantum/visualizer/lcd_keyframes.c | 5 ----- quantum/visualizer/visualizer.c | 4 ++++ 5 files changed, 5 insertions(+), 9 deletions(-) (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c index 0de457a7a..5b7b6d44c 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c +++ b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c @@ -262,6 +262,7 @@ LLDSPEC void gdisp_lld_blit_area(GDisplay *g) { srcbit++; } } + g->flags |= GDISP_FLG_NEEDFLUSH; } #if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 2e10fdd70..6f9b0210a 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -127,8 +127,6 @@ bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { // if you have full screen image, then just use 128 and 32 for both source and target dimensions gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)image_data_lcd_logo); - // Always remember to flush the display - gdispFlush(); return false; } diff --git a/keyboards/ergodox/keymaps/default/visualizer.c b/keyboards/ergodox/keymaps/default/visualizer.c index f6159e1ef..1b0f12f25 100644 --- a/keyboards/ergodox/keymaps/default/visualizer.c +++ b/keyboards/ergodox/keymaps/default/visualizer.c @@ -101,8 +101,6 @@ bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { // if you have full screen image, then just use 128 and 32 for both source and target dimensions gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)image_data_lcd_logo); - // Always remember to flush the display - gdispFlush(); return false; } diff --git a/quantum/visualizer/lcd_keyframes.c b/quantum/visualizer/lcd_keyframes.c index 74f6e3b47..c6e04d0ca 100644 --- a/quantum/visualizer/lcd_keyframes.c +++ b/quantum/visualizer/lcd_keyframes.c @@ -23,7 +23,6 @@ bool lcd_keyframe_display_layer_text(keyframe_animation_t* animation, visualizer (void)animation; gdispClear(White); gdispDrawString(0, 10, state->layer_text, state->font_dejavusansbold12, Black); - gdispFlush(); return false; } @@ -62,7 +61,6 @@ bool lcd_keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualiz gdispDrawString(0, 10, layer_buffer, state->font_fixed5x8, Black); format_layer_bitmap_string(state->status.default_layer >> 16, state->status.layer >> 16, layer_buffer); gdispDrawString(0, 20, layer_buffer, state->font_fixed5x8, Black); - gdispFlush(); return false; } @@ -101,7 +99,6 @@ bool lcd_keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualize format_mods_bitmap_string(state->status.mods, status_buffer); gdispDrawString(0, 20, status_buffer, state->font_fixed5x8, Black); - gdispFlush(); return false; } @@ -140,7 +137,6 @@ bool lcd_keyframe_display_led_states(keyframe_animation_t* animation, visualizer get_led_state_string(output, state); gdispClear(White); gdispDrawString(0, 10, output, state->font_dejavusansbold12, Black); - gdispFlush(); return false; } @@ -155,7 +151,6 @@ bool lcd_keyframe_display_layer_and_led_states(keyframe_animation_t* animation, y = 17; } gdispDrawString(0, y, state->layer_text, state->font_dejavusansbold12, Black); - gdispFlush(); return false; } diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index 2479a64c7..6f134097f 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c @@ -313,6 +313,10 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { gdispGFlush(LED_DISPLAY); #endif +#ifdef LCD_ENABLE + gdispGFlush(LCD_DISPLAY); +#endif + #ifdef EMULATOR draw_emulator(); #endif -- cgit v1.2.3 From df67169d4260881443d88b142855d4aa2def6dc3 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Apr 2017 21:19:44 +0300 Subject: Move LCD logo to visualizer resources --- keyboards/ergodox/infinity/lcd_logo.png | Bin 490 -> 0 bytes keyboards/ergodox/infinity/visualizer.c | 44 +----------------- keyboards/ergodox/keymaps/default/visualizer.c | 44 +----------------- quantum/visualizer/resources/lcd_logo.c | 61 +++++++++++++++++++++++++ quantum/visualizer/resources/lcd_logo.png | Bin 0 -> 490 bytes quantum/visualizer/resources/resources.h | 27 +++++++++++ quantum/visualizer/visualizer.mk | 2 + 7 files changed, 94 insertions(+), 84 deletions(-) delete mode 100644 keyboards/ergodox/infinity/lcd_logo.png create mode 100644 quantum/visualizer/resources/lcd_logo.c create mode 100644 quantum/visualizer/resources/lcd_logo.png create mode 100644 quantum/visualizer/resources/resources.h (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/lcd_logo.png b/keyboards/ergodox/infinity/lcd_logo.png deleted file mode 100644 index 6cf26fc67..000000000 Binary files a/keyboards/ergodox/infinity/lcd_logo.png and /dev/null differ diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 6f9b0210a..90933b00a 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -32,47 +32,7 @@ along with this program. If not, see . #include "lcd_backlight_keyframes.h" #include "system/serial_link.h" -// To generate an image array like this -// Ensure the image is 128 x 32 or smaller -// Convert the bitmap to a C array using a program like http://www.riuson.com/lcd-image-converter/ -// Ensure the the conversion process produces a monochrome format array - 1 bit/pixel, left to right, top to bottom -// Update array in the source code with the C array produced by the conversion program - -// The image below is generated from lcd_logo.png -static const uint8_t image_data_lcd_logo[512] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0xf8, 0xfe, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x06, 0x29, 0x41, 0x24, 0x52, 0x24, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x42, 0xaa, 0xaa, 0xaa, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x82, 0x28, 0xaa, 0xae, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x43, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x0a, 0x55, 0x42, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x05, 0x45, 0x42, 0x28, 0x89, 0x4a, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x18, 0x38, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x1c, 0x38, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x0e, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x03, 0xff, 0x80, 0x04, 0x45, 0x14, 0xa4, 0x92, 0x83, 0x52, 0x22, 0x22, 0x36, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0xba, 0x84, 0x55, 0x55, 0x57, 0x45, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0xb2, 0x55, 0x55, 0x42, 0x65, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x56, 0x65, 0x42, 0x45, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x54, 0x45, 0x42, 0x45, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x04, 0x48, 0xa2, 0x4a, 0x89, 0x06, 0x24, 0x42, 0x41, 0x36, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; +#include "resources/resources.h" static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); static const uint32_t initial_color = LCD_COLOR(0, 0, 0); @@ -125,7 +85,7 @@ bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { //gdispGBlitArea is a tricky function to use since it supports blitting part of the image // if you have full screen image, then just use 128 and 32 for both source and target dimensions - gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)image_data_lcd_logo); + gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)resource_lcd_logo); return false; } diff --git a/keyboards/ergodox/keymaps/default/visualizer.c b/keyboards/ergodox/keymaps/default/visualizer.c index 1b0f12f25..f03702f60 100644 --- a/keyboards/ergodox/keymaps/default/visualizer.c +++ b/keyboards/ergodox/keymaps/default/visualizer.c @@ -33,47 +33,7 @@ along with this program. If not, see . #include "system/serial_link.h" #include "led.h" -// To generate an image array like this -// Ensure the image is 128 x 32 or smaller -// Convert the bitmap to a C array using a program like http://www.riuson.com/lcd-image-converter/ -// Ensure the the conversion process produces a monochrome format array - 1 bit/pixel, left to right, top to bottom -// Update array in the source code with the C array produced by the conversion program - -// The image below is generated from lcd_logo.png -static const uint8_t image_data_lcd_logo[512] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0xf8, 0xfe, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x06, 0x29, 0x41, 0x24, 0x52, 0x24, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x42, 0xaa, 0xaa, 0xaa, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x82, 0x28, 0xaa, 0xae, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x43, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x0a, 0x55, 0x42, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x05, 0x45, 0x42, 0x28, 0x89, 0x4a, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x18, 0x38, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x1c, 0x38, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x0e, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x03, 0xff, 0x80, 0x04, 0x45, 0x14, 0xa4, 0x92, 0x83, 0x52, 0x22, 0x22, 0x36, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0xba, 0x84, 0x55, 0x55, 0x57, 0x45, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0xb2, 0x55, 0x55, 0x42, 0x65, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x56, 0x65, 0x42, 0x45, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x54, 0x45, 0x42, 0x45, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x04, 0x48, 0xa2, 0x4a, 0x89, 0x06, 0x24, 0x42, 0x41, 0x36, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; +#include "resources/resources.h" static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); static const uint32_t initial_color = LCD_COLOR(0, 0, 0); @@ -99,7 +59,7 @@ bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { //gdispGBlitArea is a tricky function to use since it supports blitting part of the image // if you have full screen image, then just use 128 and 32 for both source and target dimensions - gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)image_data_lcd_logo); + gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)resource_lcd_logo); return false; } diff --git a/quantum/visualizer/resources/lcd_logo.c b/quantum/visualizer/resources/lcd_logo.c new file mode 100644 index 000000000..d1a0ffa7f --- /dev/null +++ b/quantum/visualizer/resources/lcd_logo.c @@ -0,0 +1,61 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "resources.h" + + +// To generate an image array like this +// Ensure the image is 128 x 32 or smaller +// Convert the bitmap to a C array using a program like http://www.riuson.com/lcd-image-converter/ +// Ensure the the conversion process produces a monochrome format array - 1 bit/pixel, left to right, top to bottom +// Update array in the source code with the C array produced by the conversion program + +// The image below is generated from lcd_logo.png +const uint8_t resource_lcd_logo[512] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xf8, 0xfe, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x06, 0x29, 0x41, 0x24, 0x52, 0x24, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x42, 0xaa, 0xaa, 0xaa, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x82, 0x28, 0xaa, 0xae, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x43, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x0a, 0x55, 0x42, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x05, 0x45, 0x42, 0x28, 0x89, 0x4a, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x18, 0x38, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1c, 0x38, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0e, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0xff, 0x80, 0x04, 0x45, 0x14, 0xa4, 0x92, 0x83, 0x52, 0x22, 0x22, 0x36, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0xba, 0x84, 0x55, 0x55, 0x57, 0x45, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0xb2, 0x55, 0x55, 0x42, 0x65, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x56, 0x65, 0x42, 0x45, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x54, 0x45, 0x42, 0x45, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x04, 0x48, 0xa2, 0x4a, 0x89, 0x06, 0x24, 0x42, 0x41, 0x36, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + diff --git a/quantum/visualizer/resources/lcd_logo.png b/quantum/visualizer/resources/lcd_logo.png new file mode 100644 index 000000000..6cf26fc67 Binary files /dev/null and b/quantum/visualizer/resources/lcd_logo.png differ diff --git a/quantum/visualizer/resources/resources.h b/quantum/visualizer/resources/resources.h new file mode 100644 index 000000000..1ea27a536 --- /dev/null +++ b/quantum/visualizer/resources/resources.h @@ -0,0 +1,27 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef QUANTUM_VISUALIZER_RESOURCES_RESOURCES_H_ +#define QUANTUM_VISUALIZER_RESOURCES_RESOURCES_H_ + +#include + +#ifdef LCD_ENABLE +extern const uint8_t resource_lcd_logo[]; +#endif + + +#endif /* QUANTUM_VISUALIZER_RESOURCES_RESOURCES_H_ */ diff --git a/quantum/visualizer/visualizer.mk b/quantum/visualizer/visualizer.mk index 799379e3d..7c8e98d67 100644 --- a/quantum/visualizer/visualizer.mk +++ b/quantum/visualizer/visualizer.mk @@ -37,6 +37,8 @@ ifeq ($(strip $(LCD_ENABLE)), yes) SRC += $(VISUALIZER_DIR)/lcd_backlight.c SRC += $(VISUALIZER_DIR)/lcd_keyframes.c SRC += $(VISUALIZER_DIR)/lcd_backlight_keyframes.c +# Note, that the linker will strip out any resources that are not actually in use +SRC += $(VISUALIZER_DIR)/resources/lcd_logo.c OPT_DEFS += -DLCD_BACKLIGHT_ENABLE endif -- cgit v1.2.3 From 3074269c4a07ff7f1ab2a76ebdb8904cd642e283 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Apr 2017 21:30:11 +0300 Subject: Move the logo drawing keyframe to lcd_keyframes --- keyboards/ergodox/infinity/visualizer.c | 22 ++-------------------- keyboards/ergodox/keymaps/default/visualizer.c | 22 ++-------------------- quantum/visualizer/lcd_keyframes.c | 19 +++++++++++++++++++ quantum/visualizer/lcd_keyframes.h | 2 ++ 4 files changed, 25 insertions(+), 40 deletions(-) (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 90933b00a..bac85c593 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -72,24 +72,6 @@ static visualizer_user_data_t user_data_keyboard = { _Static_assert(sizeof(visualizer_user_data_t) <= VISUALIZER_USER_DATA_SIZE, "Please increase the VISUALIZER_USER_DATA_SIZE"); -bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { - (void)state; - (void)animation; - (void)state; - // Read the uGFX documentation for information how to use the displays - // http://wiki.ugfx.org/index.php/Main_Page - gdispClear(White); - - // You can use static variables for things that can't be found in the animation - // or state structs, here we use the image - - //gdispGBlitArea is a tricky function to use since it supports blitting part of the image - // if you have full screen image, then just use 128 and 32 for both source and target dimensions - gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)resource_lcd_logo); - - return false; -} - // Feel free to modify the animations below, or even add new ones if needed // Don't worry, if the startup animation is long, you can use the keyboard like normal @@ -99,7 +81,7 @@ static keyframe_animation_t startup_animation = { .loop = false, .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { - display_logo, + lcd_keyframe_draw_logo, backlight_keyframe_animate_color, }, }; @@ -162,7 +144,7 @@ static keyframe_animation_t resume_animation = { .frame_functions = { lcd_keyframe_enable, backlight_keyframe_enable, - display_logo, + lcd_keyframe_draw_logo, backlight_keyframe_animate_color, }, }; diff --git a/keyboards/ergodox/keymaps/default/visualizer.c b/keyboards/ergodox/keymaps/default/visualizer.c index f03702f60..afa6f1bdd 100644 --- a/keyboards/ergodox/keymaps/default/visualizer.c +++ b/keyboards/ergodox/keymaps/default/visualizer.c @@ -46,24 +46,6 @@ typedef enum { static lcd_state_t lcd_state = LCD_STATE_INITIAL; -bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { - (void)state; - (void)animation; - (void)state; - // Read the uGFX documentation for information how to use the displays - // http://wiki.ugfx.org/index.php/Main_Page - gdispClear(White); - - // You can use static variables for things that can't be found in the animation - // or state structs, here we use the image - - //gdispGBlitArea is a tricky function to use since it supports blitting part of the image - // if you have full screen image, then just use 128 and 32 for both source and target dimensions - gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)resource_lcd_logo); - - return false; -} - // Feel free to modify the animations below, or even add new ones if needed // Don't worry, if the startup animation is long, you can use the keyboard like normal @@ -73,7 +55,7 @@ static keyframe_animation_t startup_animation = { .loop = false, .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { - display_logo, + lcd_keyframe_draw_logo, backlight_keyframe_animate_color, }, }; @@ -104,7 +86,7 @@ static keyframe_animation_t resume_animation = { .frame_functions = { lcd_keyframe_enable, backlight_keyframe_enable, - display_logo, + lcd_keyframe_draw_logo, backlight_keyframe_animate_color, }, }; diff --git a/quantum/visualizer/lcd_keyframes.c b/quantum/visualizer/lcd_keyframes.c index c6e04d0ca..df11861dd 100644 --- a/quantum/visualizer/lcd_keyframes.c +++ b/quantum/visualizer/lcd_keyframes.c @@ -18,6 +18,7 @@ #include #include "action_util.h" #include "led.h" +#include "resources/resources.h" bool lcd_keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state) { (void)animation; @@ -154,6 +155,24 @@ bool lcd_keyframe_display_layer_and_led_states(keyframe_animation_t* animation, return false; } +bool lcd_keyframe_draw_logo(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)state; + (void)animation; + // Read the uGFX documentation for information how to use the displays + // http://wiki.ugfx.org/index.php/Main_Page + gdispClear(White); + + // You can use static variables for things that can't be found in the animation + // or state structs, here we use the image + + //gdispGBlitArea is a tricky function to use since it supports blitting part of the image + // if you have full screen image, then just use 128 and 32 for both source and target dimensions + gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)resource_lcd_logo); + + return false; +} + + bool lcd_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) { (void)animation; (void)state; diff --git a/quantum/visualizer/lcd_keyframes.h b/quantum/visualizer/lcd_keyframes.h index 8f79a541c..2e912b4c7 100644 --- a/quantum/visualizer/lcd_keyframes.h +++ b/quantum/visualizer/lcd_keyframes.h @@ -29,6 +29,8 @@ bool lcd_keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualize bool lcd_keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state); // Displays both the layer text and the led states bool lcd_keyframe_display_layer_and_led_states(keyframe_animation_t* animation, visualizer_state_t* state); +// Displays the QMK logo on the LCD screen +bool lcd_keyframe_draw_logo(keyframe_animation_t* animation, visualizer_state_t* state); bool lcd_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state); bool lcd_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state); -- cgit v1.2.3 From ed1710589f2f63e485c8780c7c8c03e0f65136a0 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Apr 2017 21:34:30 +0300 Subject: Fix suspend not disabling backlight --- keyboards/ergodox/infinity/visualizer.c | 2 +- keyboards/ergodox/keymaps/default/visualizer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index bac85c593..8c3f3f29f 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -133,7 +133,7 @@ static keyframe_animation_t suspend_animation = { lcd_keyframe_display_layer_text, backlight_keyframe_animate_color, lcd_keyframe_disable, - lcd_keyframe_disable, + backlight_keyframe_disable, }, }; diff --git a/keyboards/ergodox/keymaps/default/visualizer.c b/keyboards/ergodox/keymaps/default/visualizer.c index afa6f1bdd..6a7178968 100644 --- a/keyboards/ergodox/keymaps/default/visualizer.c +++ b/keyboards/ergodox/keymaps/default/visualizer.c @@ -75,7 +75,7 @@ static keyframe_animation_t suspend_animation = { lcd_keyframe_display_layer_text, backlight_keyframe_animate_color, lcd_keyframe_disable, - lcd_keyframe_disable, + backlight_keyframe_disable, }, }; -- cgit v1.2.3 From c6ca996f4eaa4cce90e02c123230e1e655c9465a Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Apr 2017 22:30:37 +0300 Subject: Combine startup and resume animations --- .../drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c | 3 +-- keyboards/ergodox/infinity/visualizer.c | 20 +++++--------------- quantum/visualizer/lcd_backlight.c | 8 ++++---- 3 files changed, 10 insertions(+), 21 deletions(-) (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c index 5b7b6d44c..b04ad0293 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c +++ b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c @@ -127,7 +127,6 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { write_cmd(g, ST7565_INVERT_DISPLAY); write_cmd(g, ST7565_ALLON_NORMAL); - write_cmd(g, ST7565_DISPLAY_ON); write_cmd(g, ST7565_START_LINE | 0); write_cmd(g, ST7565_RMW); @@ -143,7 +142,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { g->g.Width = GDISP_SCREEN_WIDTH; g->g.Height = GDISP_SCREEN_HEIGHT; g->g.Orientation = GDISP_ROTATE_0; - g->g.Powermode = powerOn; + g->g.Powermode = powerOff; g->g.Backlight = GDISP_INITIAL_BACKLIGHT; g->g.Contrast = GDISP_INITIAL_CONTRAST; return TRUE; diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 8c3f3f29f..7ae371c5f 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -77,10 +77,12 @@ _Static_assert(sizeof(visualizer_user_data_t) <= VISUALIZER_USER_DATA_SIZE, // 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 = 2, + .num_frames = 4, .loop = false, - .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, + .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { + lcd_keyframe_enable, + backlight_keyframe_enable, lcd_keyframe_draw_logo, backlight_keyframe_animate_color, }, @@ -137,18 +139,6 @@ static keyframe_animation_t suspend_animation = { }, }; -static keyframe_animation_t resume_animation = { - .num_frames = 4, - .loop = false, - .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, - .frame_functions = { - lcd_keyframe_enable, - backlight_keyframe_enable, - lcd_keyframe_draw_logo, - backlight_keyframe_animate_color, - }, -}; - void initialize_user_visualizer(visualizer_state_t* state) { // The brightness will be dynamically adjustable in the future // But for now, change it here. @@ -312,7 +302,7 @@ void user_visualizer_resume(visualizer_state_t* state) { state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; lcd_state = LCD_STATE_INITIAL; - start_keyframe_animation(&resume_animation); + start_keyframe_animation(&startup_animation); } void ergodox_board_led_on(void){ diff --git a/quantum/visualizer/lcd_backlight.c b/quantum/visualizer/lcd_backlight.c index 70187d1e0..00de3fab5 100644 --- a/quantum/visualizer/lcd_backlight.c +++ b/quantum/visualizer/lcd_backlight.c @@ -25,10 +25,10 @@ SOFTWARE. #include "lcd_backlight.h" #include -static uint8_t current_hue = 0x00; -static uint8_t current_saturation = 0x00; -static uint8_t current_intensity = 0xFF; -static uint8_t current_brightness = 0x7F; +static uint8_t current_hue = 0; +static uint8_t current_saturation = 0; +static uint8_t current_intensity = 0; +static uint8_t current_brightness = 0; void lcd_backlight_init(void) { lcd_backlight_hal_init(); -- cgit v1.2.3 From 306353bf06e5e5a76890ffb0c48a4dcca76c4399 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Apr 2017 22:48:18 +0300 Subject: Create a file for shared Ergodox Infinity animations --- keyboards/ergodox/infinity/animations.c | 54 ++++++++++++++++++++++++++ keyboards/ergodox/infinity/animations.h | 25 ++++++++++++ keyboards/ergodox/infinity/rules.mk | 5 ++- keyboards/ergodox/infinity/visualizer.c | 38 ++---------------- keyboards/ergodox/keymaps/default/visualizer.c | 45 ++------------------- 5 files changed, 90 insertions(+), 77 deletions(-) create mode 100644 keyboards/ergodox/infinity/animations.c create mode 100644 keyboards/ergodox/infinity/animations.h (limited to 'keyboards/ergodox/infinity/visualizer.c') diff --git a/keyboards/ergodox/infinity/animations.c b/keyboards/ergodox/infinity/animations.c new file mode 100644 index 000000000..54ab99460 --- /dev/null +++ b/keyboards/ergodox/infinity/animations.c @@ -0,0 +1,54 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "animations.h" +#include "visualizer.h" +#ifdef LCD_ENABLE +#include "lcd_keyframes.h" +#endif +#ifdef LCD_BACKLIGHT_ENABLE +#include "lcd_backlight_keyframes.h" +#endif + +#if defined(VISUALIZER_ENABLE) && defined(LCD_ENABLE) && defined(LCD_BACKLIGHT_ENABLE) + +// Don't worry, if the startup animation is long, you can use the keyboard like normal +// during that time +keyframe_animation_t default_startup_animation = { + .num_frames = 4, + .loop = false, + .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(5000), 0}, + .frame_functions = { + lcd_keyframe_enable, + backlight_keyframe_enable, + lcd_keyframe_draw_logo, + backlight_keyframe_animate_color, + }, +}; + +keyframe_animation_t default_suspend_animation = { + .num_frames = 4, + .loop = false, + .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0, 0}, + .frame_functions = { + lcd_keyframe_display_layer_text, + backlight_keyframe_animate_color, + lcd_keyframe_disable, + backlight_keyframe_disable, + }, +}; + +#endif diff --git a/keyboards/ergodox/infinity/animations.h b/keyboards/ergodox/infinity/animations.h new file mode 100644 index 000000000..0c441ff7e --- /dev/null +++ b/keyboards/ergodox/infinity/animations.h @@ -0,0 +1,25 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef KEYBOARDS_ERGODOX_INFINITY_ANIMATIONS_H_ +#define KEYBOARDS_ERGODOX_INFINITY_ANIMATIONS_H_ + +#include "visualizer.h" + +extern keyframe_animation_t default_startup_animation; +extern keyframe_animation_t default_suspend_animation; + +#endif /* KEYBOARDS_ERGODOX_INFINITY_ANIMATIONS_H_ */ diff --git a/keyboards/ergodox/infinity/rules.mk b/keyboards/ergodox/infinity/rules.mk index aaadfe34b..9e6170d89 100644 --- a/keyboards/ergodox/infinity/rules.mk +++ b/keyboards/ergodox/infinity/rules.mk @@ -1,6 +1,7 @@ # project specific files SRC = matrix.c \ - led.c + led.c \ + animations.c ## chip/board settings # - the next two should match the directories in @@ -72,4 +73,4 @@ endif ifdef LED_ENABLE include $(SUBPROJECT_PATH)/drivers/gdisp/IS31FL3731C/driver.mk -endif +endif \ No newline at end of file diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 7ae371c5f..a4b09a34d 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -31,8 +31,7 @@ along with this program. If not, see . #include "lcd_keyframes.h" #include "lcd_backlight_keyframes.h" #include "system/serial_link.h" - -#include "resources/resources.h" +#include "animations.h" static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); static const uint32_t initial_color = LCD_COLOR(0, 0, 0); @@ -74,19 +73,6 @@ _Static_assert(sizeof(visualizer_user_data_t) <= VISUALIZER_USER_DATA_SIZE, // Feel free to modify the animations below, or even add new ones if needed -// 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, - .loop = false, - .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, - .frame_functions = { - lcd_keyframe_enable, - backlight_keyframe_enable, - lcd_keyframe_draw_logo, - backlight_keyframe_animate_color, - }, -}; // The color animation animates the LCD color when you change layers static keyframe_animation_t one_led_color = { @@ -127,18 +113,6 @@ static keyframe_animation_t lcd_bitmap_leds_animation = { .frame_functions = {lcd_keyframe_display_layer_bitmap, lcd_keyframe_display_led_states}, }; -static keyframe_animation_t suspend_animation = { - .num_frames = 4, - .loop = false, - .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0, 0}, - .frame_functions = { - lcd_keyframe_display_layer_text, - backlight_keyframe_animate_color, - lcd_keyframe_disable, - backlight_keyframe_disable, - }, -}; - void initialize_user_visualizer(visualizer_state_t* state) { // The brightness will be dynamically adjustable in the future // But for now, change it here. @@ -146,13 +120,9 @@ void initialize_user_visualizer(visualizer_state_t* state) { state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; lcd_state = LCD_STATE_INITIAL; - start_keyframe_animation(&startup_animation); + start_keyframe_animation(&default_startup_animation); } -static const uint32_t red; -static const uint32_t green; -static const uint32_t blue; - inline bool is_led_on(visualizer_user_data_t* user_data, uint8_t num) { return user_data->led_on & (1u << num); } @@ -295,14 +265,14 @@ void user_visualizer_suspend(visualizer_state_t* state) { 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); + start_keyframe_animation(&default_suspend_animation); } void user_visualizer_resume(visualizer_state_t* state) { state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; lcd_state = LCD_STATE_INITIAL; - start_keyframe_animation(&startup_animation); + start_keyframe_animation(&default_startup_animation); } void ergodox_board_led_on(void){ diff --git a/keyboards/ergodox/keymaps/default/visualizer.c b/keyboards/ergodox/keymaps/default/visualizer.c index 6a7178968..779de0050 100644 --- a/keyboards/ergodox/keymaps/default/visualizer.c +++ b/keyboards/ergodox/keymaps/default/visualizer.c @@ -32,8 +32,7 @@ along with this program. If not, see . #include "lcd_backlight_keyframes.h" #include "system/serial_link.h" #include "led.h" - -#include "resources/resources.h" +#include "animations.h" static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); static const uint32_t initial_color = LCD_COLOR(0, 0, 0); @@ -48,18 +47,6 @@ static lcd_state_t lcd_state = LCD_STATE_INITIAL; // Feel free to modify the animations below, or even add new ones if needed -// 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 = 2, - .loop = false, - .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, - .frame_functions = { - lcd_keyframe_draw_logo, - backlight_keyframe_animate_color, - }, -}; - static keyframe_animation_t lcd_layer_display = { .num_frames = 1, .loop = false, @@ -67,30 +54,6 @@ static keyframe_animation_t lcd_layer_display = { .frame_functions = {lcd_keyframe_display_layer_and_led_states} }; -static keyframe_animation_t suspend_animation = { - .num_frames = 4, - .loop = false, - .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0, 0}, - .frame_functions = { - lcd_keyframe_display_layer_text, - backlight_keyframe_animate_color, - lcd_keyframe_disable, - backlight_keyframe_disable, - }, -}; - -static keyframe_animation_t resume_animation = { - .num_frames = 4, - .loop = false, - .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, - .frame_functions = { - lcd_keyframe_enable, - backlight_keyframe_enable, - lcd_keyframe_draw_logo, - backlight_keyframe_animate_color, - }, -}; - // The color animation animates the LCD color when you change layers static keyframe_animation_t color_animation = { .num_frames = 2, @@ -109,7 +72,7 @@ void initialize_user_visualizer(visualizer_state_t* state) { state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; lcd_state = LCD_STATE_INITIAL; - start_keyframe_animation(&startup_animation); + start_keyframe_animation(&default_startup_animation); } void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) { @@ -156,12 +119,12 @@ void user_visualizer_suspend(visualizer_state_t* state) { 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); + start_keyframe_animation(&default_suspend_animation); } void user_visualizer_resume(visualizer_state_t* state) { state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; lcd_state = LCD_STATE_INITIAL; - start_keyframe_animation(&resume_animation); + start_keyframe_animation(&default_startup_animation); } -- cgit v1.2.3