2 Copyright 2017 Fred Sundvik
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 // Currently we are assuming that both the backlight and LCD are enabled
19 // But it's entirely possible to write a custom visualizer that use only
21 #ifndef LCD_BACKLIGHT_ENABLE
22 #error This visualizer needs that LCD backlight is enabled
26 #error This visualizer needs that LCD is enabled
29 #include "visualizer.h"
30 #include "visualizer_keyframes.h"
31 #include "lcd_keyframes.h"
32 #include "lcd_backlight_keyframes.h"
33 #include "system/serial_link.h"
36 #include "resources/resources.h"
38 static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF);
39 static const uint32_t initial_color = LCD_COLOR(0, 0, 0);
43 LCD_STATE_LAYER_BITMAP,
44 LCD_STATE_BITMAP_AND_LEDS,
47 static lcd_state_t lcd_state = LCD_STATE_INITIAL;
49 bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) {
53 // Read the uGFX documentation for information how to use the displays
54 // http://wiki.ugfx.org/index.php/Main_Page
57 // You can use static variables for things that can't be found in the animation
58 // or state structs, here we use the image
60 //gdispGBlitArea is a tricky function to use since it supports blitting part of the image
61 // if you have full screen image, then just use 128 and 32 for both source and target dimensions
62 gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)resource_lcd_logo);
67 // Feel free to modify the animations below, or even add new ones if needed
69 // Don't worry, if the startup animation is long, you can use the keyboard like normal
71 static keyframe_animation_t startup_animation = {
74 .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0},
77 backlight_keyframe_animate_color,
81 static keyframe_animation_t lcd_layer_display = {
84 .frame_lengths = {gfxMillisecondsToTicks(0)},
85 .frame_functions = {lcd_keyframe_display_layer_and_led_states}
88 static keyframe_animation_t suspend_animation = {
91 .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0, 0},
93 lcd_keyframe_display_layer_text,
94 backlight_keyframe_animate_color,
100 static keyframe_animation_t resume_animation = {
103 .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0},
106 backlight_keyframe_enable,
108 backlight_keyframe_animate_color,
112 // The color animation animates the LCD color when you change layers
113 static keyframe_animation_t color_animation = {
116 // Note that there's a 200 ms no-operation frame,
117 // this prevents the color from changing when activating the layer
119 .frame_lengths = {gfxMillisecondsToTicks(200), gfxMillisecondsToTicks(500)},
120 .frame_functions = {keyframe_no_operation, backlight_keyframe_animate_color},
123 void initialize_user_visualizer(visualizer_state_t* state) {
124 // The brightness will be dynamically adjustable in the future
125 // But for now, change it here.
126 lcd_backlight_brightness(130);
127 state->current_lcd_color = initial_color;
128 state->target_lcd_color = logo_background_color;
129 lcd_state = LCD_STATE_INITIAL;
130 start_keyframe_animation(&startup_animation);
133 void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) {
134 // Add more tests, change the colors and layer texts here
135 // Usually you want to check the high bits (higher layers first)
136 // because that's the order layers are processed for keypresses
137 // You can for check for example:
138 // state->status.layer
139 // state->status.default_layer
140 // state->status.leds (see led.h for available statuses)
142 uint8_t saturation = 60;
143 if (state->status.leds & (1u << USB_LED_CAPS_LOCK)) {
146 if (state->status.layer & 0x4) {
147 state->target_lcd_color = LCD_COLOR(0, saturation, 0xFF);
148 state->layer_text = "Media & Mouse";
150 else if (state->status.layer & 0x2) {
151 state->target_lcd_color = LCD_COLOR(168, saturation, 0xFF);
152 state->layer_text = "Symbol";
155 state->target_lcd_color = LCD_COLOR(84, saturation, 0xFF);
156 state->layer_text = "Default";
159 if (lcd_state == LCD_STATE_INITIAL ||
160 state->status.layer != prev_status->layer ||
161 state->status.default_layer != prev_status->default_layer ||
162 state->status.leds != prev_status->leds) {
163 start_keyframe_animation(&color_animation);
164 start_keyframe_animation(&lcd_layer_display);
167 // You can also stop existing animations, and start your custom ones here
168 // remember that you should normally have only one animation for the LCD
169 // and one for the background. But you can also combine them if you want.
172 void user_visualizer_suspend(visualizer_state_t* state) {
173 state->layer_text = "Suspending...";
174 uint8_t hue = LCD_HUE(state->current_lcd_color);
175 uint8_t sat = LCD_SAT(state->current_lcd_color);
176 state->target_lcd_color = LCD_COLOR(hue, sat, 0);
177 start_keyframe_animation(&suspend_animation);
180 void user_visualizer_resume(visualizer_state_t* state) {
181 state->current_lcd_color = initial_color;
182 state->target_lcd_color = logo_background_color;
183 lcd_state = LCD_STATE_INITIAL;
184 start_keyframe_animation(&resume_animation);