diff options
Diffstat (limited to 'quantum/visualizer/visualizer.c')
| -rw-r--r-- | quantum/visualizer/visualizer.c | 28 |
1 files changed, 15 insertions, 13 deletions
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 | ||
