diff options
| author | Fred Sundvik <fsundvik@gmail.com> | 2017-04-05 10:08:25 +0300 |
|---|---|---|
| committer | Fred Sundvik <fsundvik@gmail.com> | 2017-04-09 18:34:59 +0300 |
| commit | 64d63ab42281318d891434fbc00277043298dd70 (patch) | |
| tree | 03747a21a2a5a30df3e120e117bdd51ce99346e6 | |
| parent | 1e7585e76771e1a2d8ca733fc09c19f9fa0e903c (diff) | |
| download | qmk_firmware-64d63ab42281318d891434fbc00277043298dd70.tar.gz qmk_firmware-64d63ab42281318d891434fbc00277043298dd70.zip | |
Remove the need to manually enable the visualizer
| -rw-r--r-- | keyboards/ergodox/infinity/visualizer.c | 6 | ||||
| -rw-r--r-- | keyboards/ergodox/keymaps/default/visualizer.c | 6 | ||||
| -rw-r--r-- | quantum/visualizer/visualizer.c | 28 | ||||
| -rw-r--r-- | quantum/visualizer/visualizer.h | 14 |
4 files changed, 27 insertions, 27 deletions
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) { | |||
| 136 | // Don't worry, if the startup animation is long, you can use the keyboard like normal | 136 | // Don't worry, if the startup animation is long, you can use the keyboard like normal |
| 137 | // during that time | 137 | // during that time |
| 138 | static keyframe_animation_t startup_animation = { | 138 | static keyframe_animation_t startup_animation = { |
| 139 | .num_frames = 3, | 139 | .num_frames = 2, |
| 140 | .loop = false, | 140 | .loop = false, |
| 141 | .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, | 141 | .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, |
| 142 | .frame_functions = { | 142 | .frame_functions = { |
| 143 | display_logo, | 143 | display_logo, |
| 144 | backlight_keyframe_animate_color, | 144 | backlight_keyframe_animate_color, |
| 145 | enable_visualization | ||
| 146 | }, | 145 | }, |
| 147 | }; | 146 | }; |
| 148 | 147 | ||
| @@ -198,7 +197,7 @@ static keyframe_animation_t suspend_animation = { | |||
| 198 | }; | 197 | }; |
| 199 | 198 | ||
| 200 | static keyframe_animation_t resume_animation = { | 199 | static keyframe_animation_t resume_animation = { |
| 201 | .num_frames = 5, | 200 | .num_frames = 4, |
| 202 | .loop = false, | 201 | .loop = false, |
| 203 | .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, | 202 | .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, |
| 204 | .frame_functions = { | 203 | .frame_functions = { |
| @@ -206,7 +205,6 @@ static keyframe_animation_t resume_animation = { | |||
| 206 | backlight_keyframe_enable, | 205 | backlight_keyframe_enable, |
| 207 | display_logo, | 206 | display_logo, |
| 208 | backlight_keyframe_animate_color, | 207 | backlight_keyframe_animate_color, |
| 209 | enable_visualization, | ||
| 210 | }, | 208 | }, |
| 211 | }; | 209 | }; |
| 212 | 210 | ||
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) { | |||
| 110 | // Don't worry, if the startup animation is long, you can use the keyboard like normal | 110 | // Don't worry, if the startup animation is long, you can use the keyboard like normal |
| 111 | // during that time | 111 | // during that time |
| 112 | static keyframe_animation_t startup_animation = { | 112 | static keyframe_animation_t startup_animation = { |
| 113 | .num_frames = 3, | 113 | .num_frames = 2, |
| 114 | .loop = false, | 114 | .loop = false, |
| 115 | .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, | 115 | .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, |
| 116 | .frame_functions = { | 116 | .frame_functions = { |
| 117 | display_logo, | 117 | display_logo, |
| 118 | backlight_keyframe_animate_color, | 118 | backlight_keyframe_animate_color, |
| 119 | enable_visualization | ||
| 120 | }, | 119 | }, |
| 121 | }; | 120 | }; |
| 122 | 121 | ||
| @@ -140,7 +139,7 @@ static keyframe_animation_t suspend_animation = { | |||
| 140 | }; | 139 | }; |
| 141 | 140 | ||
| 142 | static keyframe_animation_t resume_animation = { | 141 | static keyframe_animation_t resume_animation = { |
| 143 | .num_frames = 5, | 142 | .num_frames = 4, |
| 144 | .loop = false, | 143 | .loop = false, |
| 145 | .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, | 144 | .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, |
| 146 | .frame_functions = { | 145 | .frame_functions = { |
| @@ -148,7 +147,6 @@ static keyframe_animation_t resume_animation = { | |||
| 148 | backlight_keyframe_enable, | 147 | backlight_keyframe_enable, |
| 149 | display_logo, | 148 | display_logo, |
| 150 | backlight_keyframe_animate_color, | 149 | backlight_keyframe_animate_color, |
| 151 | enable_visualization, | ||
| 152 | }, | 150 | }, |
| 153 | }; | 151 | }; |
| 154 | 152 | ||
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) { | |||
| 154 | } | 154 | } |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | static uint8_t get_num_running_animations(void) { | ||
| 158 | uint8_t count = 0; | ||
| 159 | for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) { | ||
| 160 | count += animations[i] ? 1 : 0; | ||
| 161 | } | ||
| 162 | return count; | ||
| 163 | } | ||
| 164 | |||
| 157 | static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systemticks_t delta, systemticks_t* sleep_time) { | 165 | static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systemticks_t delta, systemticks_t* sleep_time) { |
| 158 | // TODO: Clean up this messy code | 166 | // TODO: Clean up this messy code |
| 159 | dprintf("Animation frame%d, left %d, delta %d\n", animation->current_frame, | 167 | dprintf("Animation frame%d, left %d, delta %d\n", animation->current_frame, |
| @@ -228,14 +236,6 @@ bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* | |||
| 228 | return false; | 236 | return false; |
| 229 | } | 237 | } |
| 230 | 238 | ||
| 231 | bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state) { | ||
| 232 | (void)animation; | ||
| 233 | (void)state; | ||
| 234 | dprint("User visualizer inited\n"); | ||
| 235 | visualizer_enabled = true; | ||
| 236 | return false; | ||
| 237 | } | ||
| 238 | |||
| 239 | // TODO: Optimize the stack size, this is probably way too big | 239 | // TODO: Optimize the stack size, this is probably way too big |
| 240 | static DECLARE_THREAD_STACK(visualizerThreadStack, 1024); | 240 | static DECLARE_THREAD_STACK(visualizerThreadStack, 1024); |
| 241 | static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { | 241 | static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { |
| @@ -276,13 +276,15 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { | |||
| 276 | 276 | ||
| 277 | systemticks_t sleep_time = TIME_INFINITE; | 277 | systemticks_t sleep_time = TIME_INFINITE; |
| 278 | systemticks_t current_time = gfxSystemTicks(); | 278 | systemticks_t current_time = gfxSystemTicks(); |
| 279 | bool force_update = true; | ||
| 279 | 280 | ||
| 280 | while(true) { | 281 | while(true) { |
| 281 | systemticks_t new_time = gfxSystemTicks(); | 282 | systemticks_t new_time = gfxSystemTicks(); |
| 282 | systemticks_t delta = new_time - current_time; | 283 | systemticks_t delta = new_time - current_time; |
| 283 | current_time = new_time; | 284 | current_time = new_time; |
| 284 | bool enabled = visualizer_enabled; | 285 | bool enabled = visualizer_enabled; |
| 285 | if (!same_status(&state.status, ¤t_status)) { | 286 | if (force_update || !same_status(&state.status, ¤t_status)) { |
| 287 | force_update = false; | ||
| 286 | if (visualizer_enabled) { | 288 | if (visualizer_enabled) { |
| 287 | if (current_status.suspended) { | 289 | if (current_status.suspended) { |
| 288 | stop_all_keyframe_animations(); | 290 | stop_all_keyframe_animations(); |
| @@ -320,10 +322,10 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { | |||
| 320 | #ifdef EMULATOR | 322 | #ifdef EMULATOR |
| 321 | draw_emulator(); | 323 | draw_emulator(); |
| 322 | #endif | 324 | #endif |
| 323 | // The animation can enable the visualizer | 325 | // Enable the visualizer when the startup or the suspend animation has finished |
| 324 | // And we might need to update the state when that happens | 326 | if (!visualizer_enabled && state.status.suspended == false && get_num_running_animations() == 0) { |
| 325 | // so don't sleep | 327 | visualizer_enabled = true; |
| 326 | if (enabled != visualizer_enabled) { | 328 | force_update = true; |
| 327 | sleep_time = 0; | 329 | sleep_time = 0; |
| 328 | } | 330 | } |
| 329 | 331 | ||
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 | |||
| 130 | // Does nothing, useful for adding delays | 130 | // Does nothing, useful for adding delays |
| 131 | bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state); | 131 | bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state); |
| 132 | 132 | ||
| 133 | // Call this once, when the initial animation has finished, alternatively you can call it | ||
| 134 | // directly from the initalize_user_visualizer function (the animation can be null) | ||
| 135 | bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state); | ||
| 136 | |||
| 137 | // The master can set userdata which will be transferred to the slave | 133 | // The master can set userdata which will be transferred to the slave |
| 138 | #ifdef VISUALIZER_USER_DATA_SIZE | 134 | #ifdef VISUALIZER_USER_DATA_SIZE |
| 139 | void visualizer_set_user_data(void* user_data); | 135 | void visualizer_set_user_data(void* user_data); |
| 140 | #endif | 136 | #endif |
| 141 | 137 | ||
| 142 | // These functions have to be implemented by the user | 138 | // These functions have to be implemented by the user |
| 143 | void initialize_user_visualizer(visualizer_state_t* state); | 139 | // Called regularly each time the state has changed (but not every scan loop) |
| 144 | void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status); | 140 | void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status); |
| 141 | // Called when the computer goes to suspend, will also stop calling update_user_visualizer_state | ||
| 145 | void user_visualizer_suspend(visualizer_state_t* state); | 142 | void user_visualizer_suspend(visualizer_state_t* state); |
| 143 | // You have to start at least one animation as a response to the following two functions | ||
| 144 | // When the animation has finished the visualizer will resume normal operation and start calling the | ||
| 145 | // update_user_visualizer_state again | ||
| 146 | // Called when the keyboard boots up | ||
| 147 | void initialize_user_visualizer(visualizer_state_t* state); | ||
| 148 | // Called when the computer resumes from a suspend | ||
| 146 | void user_visualizer_resume(visualizer_state_t* state); | 149 | void user_visualizer_resume(visualizer_state_t* state); |
| 147 | 150 | ||
| 148 | |||
| 149 | #endif /* VISUALIZER_H */ | 151 | #endif /* VISUALIZER_H */ |
