aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboards/ergodox/keymaps/default/visualizer.c76
-rw-r--r--quantum/visualizer/visualizer.c28
-rw-r--r--quantum/visualizer/visualizer.h1
3 files changed, 44 insertions, 61 deletions
diff --git a/keyboards/ergodox/keymaps/default/visualizer.c b/keyboards/ergodox/keymaps/default/visualizer.c
index d99d5f702..305aaae15 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 <http://www.gnu.org/licenses/>.
28 28
29#include "visualizer.h" 29#include "visualizer.h"
30#include "system/serial_link.h" 30#include "system/serial_link.h"
31#include "led.h"
31 32
32// To generate an image array like this 33// To generate an image array like this
33// Ensure the image is 128 x 32 or smaller 34// Ensure the image is 128 x 32 or smaller
@@ -117,34 +118,11 @@ static keyframe_animation_t startup_animation = {
117 }, 118 },
118}; 119};
119 120
120// The LCD animation alternates between the layer name display and a 121static keyframe_animation_t lcd_layer_display = {
121// bitmap that displays all active layers 122 .num_frames = 1,
122static keyframe_animation_t lcd_layer_bitmap_animation = { 123 .loop = false,
123 .num_frames = 2, 124 .frame_lengths = {gfxMillisecondsToTicks(0)},
124 .loop = true, 125 .frame_functions = {keyframe_display_layer_and_led_states}
125 .frame_lengths = {
126 gfxMillisecondsToTicks(2000),
127 gfxMillisecondsToTicks(2000)
128 },
129 .frame_functions = {
130 keyframe_display_layer_text,
131 keyframe_display_layer_bitmap
132 },
133};
134
135static keyframe_animation_t lcd_layer_bitmap_leds_animation = {
136 .num_frames = 3,
137 .loop = true,
138 .frame_lengths = {
139 gfxMillisecondsToTicks(2000),
140 gfxMillisecondsToTicks(2000),
141 gfxMillisecondsToTicks(2000)
142 },
143 .frame_functions = {
144 keyframe_display_layer_text,
145 keyframe_display_led_states,
146 keyframe_display_layer_bitmap,
147 },
148}; 126};
149 127
150static keyframe_animation_t suspend_animation = { 128static keyframe_animation_t suspend_animation = {
@@ -200,49 +178,31 @@ void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard
200 // state->status.default_layer 178 // state->status.default_layer
201 // state->status.leds (see led.h for available statuses) 179 // state->status.leds (see led.h for available statuses)
202 180
181 uint8_t saturation = 60;
182 if (state->status.leds & (1u << USB_LED_CAPS_LOCK)) {
183 saturation = 255;
184 }
203 if (state->status.layer & 0x4) { 185 if (state->status.layer & 0x4) {
204 state->target_lcd_color = LCD_COLOR(0, 0xB0, 0xFF); 186 state->target_lcd_color = LCD_COLOR(0, saturation, 0xFF);
205 state->layer_text = "Media & Mouse"; 187 state->layer_text = "Media & Mouse";
206 } 188 }
207 else if (state->status.layer & 0x2) { 189 else if (state->status.layer & 0x2) {
208 state->target_lcd_color = LCD_COLOR(0x80, 0xB0, 0xFF); 190 state->target_lcd_color = LCD_COLOR(168, saturation, 0xFF);
209 state->layer_text = "Symbol"; 191 state->layer_text = "Symbol";
210 } 192 }
211 else { 193 else {
212 state->target_lcd_color = LCD_COLOR(0x40, 0xB0, 0xFF); 194 state->target_lcd_color = LCD_COLOR(84, saturation, 0xFF);
213 state->layer_text = "Default"; 195 state->layer_text = "Default";
214 } 196 }
215 197
216 if (lcd_state == LCD_STATE_INITIAL || state->status.layer != prev_status->layer) { 198 if (lcd_state == LCD_STATE_INITIAL ||
199 state->status.layer != prev_status->layer ||
200 state->status.default_layer != prev_status->default_layer ||
201 state->status.leds != prev_status->leds) {
217 start_keyframe_animation(&color_animation); 202 start_keyframe_animation(&color_animation);
203 start_keyframe_animation(&lcd_layer_display);
218 } 204 }
219 205
220 if (state->status.leds) {
221 if (lcd_state != LCD_STATE_BITMAP_AND_LEDS ||
222 state->status.leds != prev_status->leds ||
223 state->status.layer != prev_status->layer ||
224 state->status.default_layer != prev_status->default_layer) {
225
226 // NOTE: that it doesn't matter if the animation isn't playing, stop will do nothing in that case
227 stop_keyframe_animation(&lcd_layer_bitmap_animation);
228
229 lcd_state = LCD_STATE_BITMAP_AND_LEDS;
230 // For information:
231 // The logic in this function makes sure that this doesn't happen, but if you call start on an
232 // animation that is already playing it will be restarted.
233 start_keyframe_animation(&lcd_layer_bitmap_leds_animation);
234 }
235 } else {
236 if (lcd_state != LCD_STATE_LAYER_BITMAP ||
237 state->status.layer != prev_status->layer ||
238 state->status.default_layer != prev_status->default_layer) {
239
240 stop_keyframe_animation(&lcd_layer_bitmap_leds_animation);
241
242 lcd_state = LCD_STATE_LAYER_BITMAP;
243 start_keyframe_animation(&lcd_layer_bitmap_animation);
244 }
245 }
246 // You can also stop existing animations, and start your custom ones here 206 // You can also stop existing animations, and start your custom ones here
247 // remember that you should normally have only one animation for the LCD 207 // remember that you should normally have only one animation for the LCD
248 // and one for the background. But you can also combine them if you want. 208 // and one for the background. But you can also combine them if you want.
diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c
index 3b3f51b1f..2533eb709 100644
--- a/quantum/visualizer/visualizer.c
+++ b/quantum/visualizer/visualizer.c
@@ -364,9 +364,9 @@ bool keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_st
364 return false; 364 return false;
365} 365}
366 366
367bool keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state) 367#define LED_STATE_STRING_SIZE sizeof("NUM CAPS SCRL COMP KANA")
368{ 368
369 char output[sizeof("NUM CAPS SCRL COMP KANA")]; 369static void get_led_state_string(char* output, visualizer_state_t* state) {
370 uint8_t pos = 0; 370 uint8_t pos = 0;
371 371
372 if (state->status.leds & (1u << USB_LED_NUM_LOCK)) { 372 if (state->status.leds & (1u << USB_LED_NUM_LOCK)) {
@@ -390,12 +390,34 @@ bool keyframe_display_led_states(keyframe_animation_t* animation, visualizer_sta
390 pos += 5; 390 pos += 5;
391 } 391 }
392 output[pos] = 0; 392 output[pos] = 0;
393}
394
395bool keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state)
396{
397 (void)animation;
398 char output[LED_STATE_STRING_SIZE];
399 get_led_state_string(output, state);
393 gdispClear(White); 400 gdispClear(White);
394 gdispDrawString(0, 10, output, state->font_dejavusansbold12, Black); 401 gdispDrawString(0, 10, output, state->font_dejavusansbold12, Black);
395 gdispFlush(); 402 gdispFlush();
396 return false; 403 return false;
397} 404}
398 405
406bool keyframe_display_layer_and_led_states(keyframe_animation_t* animation, visualizer_state_t* state) {
407 (void)animation;
408 gdispClear(White);
409 uint8_t y = 10;
410 if (state->status.leds) {
411 char output[LED_STATE_STRING_SIZE];
412 get_led_state_string(output, state);
413 gdispDrawString(0, 1, output, state->font_dejavusansbold12, Black);
414 y = 17;
415 }
416 gdispDrawString(0, y, state->layer_text, state->font_dejavusansbold12, Black);
417 gdispFlush();
418 return false;
419}
420
399#endif // LCD_ENABLE 421#endif // LCD_ENABLE
400 422
401bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) { 423bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) {
diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h
index e8ace5b37..3b05c305e 100644
--- a/quantum/visualizer/visualizer.h
+++ b/quantum/visualizer/visualizer.h
@@ -141,6 +141,7 @@ bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_s
141bool keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state); 141bool keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state);
142// Displays the keyboard led states (CAPS (Caps lock), NUM (Num lock), SCRL (Scroll lock), COMP (Compose), KANA) 142// Displays the keyboard led states (CAPS (Caps lock), NUM (Num lock), SCRL (Scroll lock), COMP (Compose), KANA)
143bool keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state); 143bool keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state);
144bool keyframe_display_layer_and_led_states(keyframe_animation_t* animation, visualizer_state_t* state);
144 145
145bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); 146bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state);
146bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); 147bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state);