aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ergodox/infinity/visualizer.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/ergodox/infinity/visualizer.c')
-rw-r--r--keyboards/ergodox/infinity/visualizer.c76
1 files changed, 56 insertions, 20 deletions
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 {
99} visualizer_user_data_t; 99} visualizer_user_data_t;
100 100
101// Don't access from visualization function, use the visualizer state instead 101// Don't access from visualization function, use the visualizer state instead
102static visualizer_user_data_t user_data_keyboard = {}; 102static visualizer_user_data_t user_data_keyboard = {
103 .led_on = 0,
104 .led1 = LED_BRIGHTNESS_HI,
105 .led2 = LED_BRIGHTNESS_HI,
106 .led3 = LED_BRIGHTNESS_HI,
107};
103 108
104_Static_assert(sizeof(visualizer_user_data_t) <= VISUALIZER_USER_DATA_SIZE, 109_Static_assert(sizeof(visualizer_user_data_t) <= VISUALIZER_USER_DATA_SIZE,
105 "Please increase the VISUALIZER_USER_DATA_SIZE"); 110 "Please increase the VISUALIZER_USER_DATA_SIZE");
@@ -250,18 +255,21 @@ static uint8_t get_secondary_led_index(visualizer_user_data_t* user_data) {
250 return 0; 255 return 0;
251} 256}
252 257
253void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t prev_status) { 258static uint8_t get_brightness(visualizer_user_data_t* user_data, uint8_t index) {
254 // Check the status here to start and stop animations 259 switch (index) {
255 // You might have to save some state, like the current animation here so that you can start the right 260 case 1:
256 // This function is called every time the status changes 261 return user_data->led1;
257 262 case 2:
258 // NOTE that this is called from the visualizer thread, so don't access anything else outside the status 263 return user_data->led2;
259 // This is also important because the slave won't have access to the active layer for example outside the 264 case 3:
260 // status. 265 return user_data->led3;
261 266 }
267 return 0;
268}
262 269
270static void update_emulated_leds(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) {
263 visualizer_user_data_t* user_data_new = (visualizer_user_data_t*)state->status.user_data; 271 visualizer_user_data_t* user_data_new = (visualizer_user_data_t*)state->status.user_data;
264 visualizer_user_data_t* user_data_old = (visualizer_user_data_t*)prev_status.user_data; 272 visualizer_user_data_t* user_data_old = (visualizer_user_data_t*)prev_status->user_data;
265 273
266 uint8_t new_index; 274 uint8_t new_index;
267 uint8_t old_index; 275 uint8_t old_index;
@@ -277,27 +285,41 @@ void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard
277 uint8_t new_secondary_index = get_secondary_led_index(user_data_new); 285 uint8_t new_secondary_index = get_secondary_led_index(user_data_new);
278 uint8_t old_secondary_index = get_secondary_led_index(user_data_old); 286 uint8_t old_secondary_index = get_secondary_led_index(user_data_old);
279 287
288 uint8_t old_brightness = get_brightness(user_data_old, old_index);
289 uint8_t new_brightness = get_brightness(user_data_new, new_index);
290
291 uint8_t old_secondary_brightness = get_brightness(user_data_old, old_secondary_index);
292 uint8_t new_secondary_brightness = get_brightness(user_data_new, new_secondary_index);
293
280 if (lcd_state == LCD_STATE_INITIAL || 294 if (lcd_state == LCD_STATE_INITIAL ||
281 new_index != old_index || 295 new_index != old_index ||
282 new_secondary_index != old_secondary_index) { 296 new_secondary_index != old_secondary_index ||
297 new_brightness != old_brightness ||
298 new_secondary_brightness != old_secondary_brightness) {
283 299
284 if (new_secondary_index != 0) { 300 if (new_secondary_index != 0) {
285 state->target_lcd_color = led_emulation_colors[new_index]; 301 state->target_lcd_color = change_lcd_color_intensity(
286 next_led_target_color = led_emulation_colors[new_secondary_index]; 302 led_emulation_colors[new_index], new_brightness);
303 next_led_target_color = change_lcd_color_intensity(
304 led_emulation_colors[new_secondary_index], new_secondary_brightness);
305
287 stop_keyframe_animation(&one_led_color); 306 stop_keyframe_animation(&one_led_color);
288 start_keyframe_animation(&two_led_colors); 307 start_keyframe_animation(&two_led_colors);
289 } else { 308 } else {
290 state->target_lcd_color = led_emulation_colors[new_index]; 309 state->target_lcd_color = change_lcd_color_intensity(
310 led_emulation_colors[new_index], new_brightness);
291 stop_keyframe_animation(&two_led_colors); 311 stop_keyframe_animation(&two_led_colors);
292 start_keyframe_animation(&one_led_color); 312 start_keyframe_animation(&one_led_color);
293 } 313 }
294 } 314 }
315}
295 316
317static void update_lcd_text(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) {
296 if (state->status.leds) { 318 if (state->status.leds) {
297 if (lcd_state != LCD_STATE_BITMAP_AND_LEDS || 319 if (lcd_state != LCD_STATE_BITMAP_AND_LEDS ||
298 state->status.leds != prev_status.leds || 320 state->status.leds != prev_status->leds ||
299 state->status.layer != prev_status.layer || 321 state->status.layer != prev_status->layer ||
300 state->status.default_layer != prev_status.default_layer) { 322 state->status.default_layer != prev_status->default_layer) {
301 323
302 // NOTE: that it doesn't matter if the animation isn't playing, stop will do nothing in that case 324 // NOTE: that it doesn't matter if the animation isn't playing, stop will do nothing in that case
303 stop_keyframe_animation(&lcd_bitmap_animation); 325 stop_keyframe_animation(&lcd_bitmap_animation);
@@ -310,8 +332,8 @@ void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard
310 } 332 }
311 } else { 333 } else {
312 if (lcd_state != LCD_STATE_LAYER_BITMAP || 334 if (lcd_state != LCD_STATE_LAYER_BITMAP ||
313 state->status.layer != prev_status.layer || 335 state->status.layer != prev_status->layer ||
314 state->status.default_layer != prev_status.default_layer) { 336 state->status.default_layer != prev_status->default_layer) {
315 337
316 stop_keyframe_animation(&lcd_bitmap_leds_animation); 338 stop_keyframe_animation(&lcd_bitmap_leds_animation);
317 339
@@ -321,6 +343,20 @@ void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard
321 } 343 }
322} 344}
323 345
346void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) {
347 // Check the status here to start and stop animations
348 // You might have to save some state, like the current animation here so that you can start the right
349 // This function is called every time the status changes
350
351 // NOTE that this is called from the visualizer thread, so don't access anything else outside the status
352 // This is also important because the slave won't have access to the active layer for example outside the
353 // status.
354
355 update_emulated_leds(state, prev_status);
356 update_lcd_text(state, prev_status);
357
358}
359
324void user_visualizer_suspend(visualizer_state_t* state) { 360void user_visualizer_suspend(visualizer_state_t* state) {
325 state->layer_text = "Suspending..."; 361 state->layer_text = "Suspending...";
326 uint8_t hue = LCD_HUE(state->current_lcd_color); 362 uint8_t hue = LCD_HUE(state->current_lcd_color);