diff options
| -rw-r--r-- | keyboards/ergodox/infinity/config.h | 2 | ||||
| -rw-r--r-- | keyboards/ergodox/infinity/visualizer.c | 76 | ||||
| -rw-r--r-- | quantum/visualizer/lcd_backlight.h | 4 | ||||
| -rw-r--r-- | quantum/visualizer/visualizer.c | 2 | ||||
| -rw-r--r-- | quantum/visualizer/visualizer.h | 2 |
5 files changed, 63 insertions, 23 deletions
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 <http://www.gnu.org/licenses/>. | |||
| 40 | /* number of backlight levels */ | 40 | /* number of backlight levels */ |
| 41 | #define BACKLIGHT_LEVELS 3 | 41 | #define BACKLIGHT_LEVELS 3 |
| 42 | 42 | ||
| 43 | #define LED_BRIGHTNESS_LO 15 | 43 | #define LED_BRIGHTNESS_LO 100 |
| 44 | #define LED_BRIGHTNESS_HI 255 | 44 | #define LED_BRIGHTNESS_HI 255 |
| 45 | 45 | ||
| 46 | /* define if matrix has ghost */ | 46 | /* 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 { | |||
| 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 |
| 102 | static visualizer_user_data_t user_data_keyboard = {}; | 102 | static 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 | ||
| 253 | void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t prev_status) { | 258 | static 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 | ||
| 270 | static 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 | ||
| 317 | static 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 | ||
| 346 | void 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 | |||
| 324 | void user_visualizer_suspend(visualizer_state_t* state) { | 360 | void 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); |
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. | |||
| 32 | #define LCD_SAT(color) ((color >> 8) & 0xFF) | 32 | #define LCD_SAT(color) ((color >> 8) & 0xFF) |
| 33 | #define LCD_INT(color) (color & 0xFF) | 33 | #define LCD_INT(color) (color & 0xFF) |
| 34 | 34 | ||
| 35 | inline uint32_t change_lcd_color_intensity(uint32_t color, uint8_t new_intensity) { | ||
| 36 | return (color & 0xFFFFFF00) | new_intensity; | ||
| 37 | } | ||
| 38 | |||
| 35 | void lcd_backlight_init(void); | 39 | void lcd_backlight_init(void); |
| 36 | void lcd_backlight_color(uint8_t hue, uint8_t saturation, uint8_t intensity); | 40 | void lcd_backlight_color(uint8_t hue, uint8_t saturation, uint8_t intensity); |
| 37 | void lcd_backlight_brightness(uint8_t b); | 41 | 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) { | |||
| 484 | else { | 484 | else { |
| 485 | visualizer_keyboard_status_t prev_status = state.status; | 485 | visualizer_keyboard_status_t prev_status = state.status; |
| 486 | state.status = current_status; | 486 | state.status = current_status; |
| 487 | update_user_visualizer_state(&state, prev_status); | 487 | update_user_visualizer_state(&state, &prev_status); |
| 488 | } | 488 | } |
| 489 | state.prev_lcd_color = state.current_lcd_color; | 489 | state.prev_lcd_color = state.current_lcd_color; |
| 490 | } | 490 | } |
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); | |||
| 156 | 156 | ||
| 157 | // These functions have to be implemented by the user | 157 | // These functions have to be implemented by the user |
| 158 | void initialize_user_visualizer(visualizer_state_t* state); | 158 | void initialize_user_visualizer(visualizer_state_t* state); |
| 159 | void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t prev_status); | 159 | void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status); |
| 160 | void user_visualizer_suspend(visualizer_state_t* state); | 160 | void user_visualizer_suspend(visualizer_state_t* state); |
| 161 | void user_visualizer_resume(visualizer_state_t* state); | 161 | void user_visualizer_resume(visualizer_state_t* state); |
| 162 | 162 | ||
