diff options
Diffstat (limited to 'visualizer.c')
| -rw-r--r-- | visualizer.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/visualizer.c b/visualizer.c index 605be3059..579837edc 100644 --- a/visualizer.c +++ b/visualizer.c | |||
| @@ -83,6 +83,9 @@ static remote_object_t* remote_objects[] = { | |||
| 83 | 83 | ||
| 84 | #endif | 84 | #endif |
| 85 | 85 | ||
| 86 | GDisplay* LCD_DISPLAY = 0; | ||
| 87 | GDisplay* LED_DISPLAY = 0; | ||
| 88 | |||
| 86 | 89 | ||
| 87 | void start_keyframe_animation(keyframe_animation_t* animation) { | 90 | void start_keyframe_animation(keyframe_animation_t* animation) { |
| 88 | animation->current_frame = -1; | 91 | animation->current_frame = -1; |
| @@ -106,6 +109,8 @@ void stop_keyframe_animation(keyframe_animation_t* animation) { | |||
| 106 | animation->current_frame = animation->num_frames; | 109 | animation->current_frame = animation->num_frames; |
| 107 | animation->time_left_in_frame = 0; | 110 | animation->time_left_in_frame = 0; |
| 108 | animation->need_update = true; | 111 | animation->need_update = true; |
| 112 | animation->first_update_of_frame = false; | ||
| 113 | animation->last_update_of_frame = false; | ||
| 109 | for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) { | 114 | for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) { |
| 110 | if (animations[i] == animation) { | 115 | if (animations[i] == animation) { |
| 111 | animations[i] = NULL; | 116 | animations[i] = NULL; |
| @@ -120,12 +125,15 @@ void stop_all_keyframe_animations(void) { | |||
| 120 | animations[i]->current_frame = animations[i]->num_frames; | 125 | animations[i]->current_frame = animations[i]->num_frames; |
| 121 | animations[i]->time_left_in_frame = 0; | 126 | animations[i]->time_left_in_frame = 0; |
| 122 | animations[i]->need_update = true; | 127 | animations[i]->need_update = true; |
| 128 | animations[i]->first_update_of_frame = false; | ||
| 129 | animations[i]->last_update_of_frame = false; | ||
| 123 | animations[i] = NULL; | 130 | animations[i] = NULL; |
| 124 | } | 131 | } |
| 125 | } | 132 | } |
| 126 | } | 133 | } |
| 127 | 134 | ||
| 128 | static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systime_t delta, systime_t* sleep_time) { | 135 | static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systime_t delta, systime_t* sleep_time) { |
| 136 | // TODO: Clean up this messy code | ||
| 129 | dprintf("Animation frame%d, left %d, delta %d\n", animation->current_frame, | 137 | dprintf("Animation frame%d, left %d, delta %d\n", animation->current_frame, |
| 130 | animation->time_left_in_frame, delta); | 138 | animation->time_left_in_frame, delta); |
| 131 | if (animation->current_frame == animation->num_frames) { | 139 | if (animation->current_frame == animation->num_frames) { |
| @@ -136,16 +144,20 @@ static bool update_keyframe_animation(keyframe_animation_t* animation, visualize | |||
| 136 | animation->current_frame = 0; | 144 | animation->current_frame = 0; |
| 137 | animation->time_left_in_frame = animation->frame_lengths[0]; | 145 | animation->time_left_in_frame = animation->frame_lengths[0]; |
| 138 | animation->need_update = true; | 146 | animation->need_update = true; |
| 147 | animation->first_update_of_frame = true; | ||
| 139 | } else { | 148 | } else { |
| 140 | animation->time_left_in_frame -= delta; | 149 | animation->time_left_in_frame -= delta; |
| 141 | while (animation->time_left_in_frame <= 0) { | 150 | while (animation->time_left_in_frame <= 0) { |
| 142 | int left = animation->time_left_in_frame; | 151 | int left = animation->time_left_in_frame; |
| 143 | if (animation->need_update) { | 152 | if (animation->need_update) { |
| 144 | animation->time_left_in_frame = 0; | 153 | animation->time_left_in_frame = 0; |
| 154 | animation->last_update_of_frame = true; | ||
| 145 | (*animation->frame_functions[animation->current_frame])(animation, state); | 155 | (*animation->frame_functions[animation->current_frame])(animation, state); |
| 156 | animation->last_update_of_frame = false; | ||
| 146 | } | 157 | } |
| 147 | animation->current_frame++; | 158 | animation->current_frame++; |
| 148 | animation->need_update = true; | 159 | animation->need_update = true; |
| 160 | animation->first_update_of_frame = true; | ||
| 149 | if (animation->current_frame == animation->num_frames) { | 161 | if (animation->current_frame == animation->num_frames) { |
| 150 | if (animation->loop) { | 162 | if (animation->loop) { |
| 151 | animation->current_frame = 0; | 163 | animation->current_frame = 0; |
| @@ -162,6 +174,7 @@ static bool update_keyframe_animation(keyframe_animation_t* animation, visualize | |||
| 162 | } | 174 | } |
| 163 | if (animation->need_update) { | 175 | if (animation->need_update) { |
| 164 | animation->need_update = (*animation->frame_functions[animation->current_frame])(animation, state); | 176 | animation->need_update = (*animation->frame_functions[animation->current_frame])(animation, state); |
| 177 | animation->first_update_of_frame = false; | ||
| 165 | } | 178 | } |
| 166 | 179 | ||
| 167 | int wanted_sleep = animation->need_update ? 10 : animation->time_left_in_frame; | 180 | int wanted_sleep = animation->need_update ? 10 : animation->time_left_in_frame; |
| @@ -172,6 +185,21 @@ static bool update_keyframe_animation(keyframe_animation_t* animation, visualize | |||
| 172 | return true; | 185 | return true; |
| 173 | } | 186 | } |
| 174 | 187 | ||
| 188 | void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* state) { | ||
| 189 | int next_frame = animation->current_frame + 1; | ||
| 190 | if (next_frame == animation->num_frames) { | ||
| 191 | next_frame = 0; | ||
| 192 | } | ||
| 193 | keyframe_animation_t temp_animation = *animation; | ||
| 194 | temp_animation.current_frame = next_frame; | ||
| 195 | temp_animation.time_left_in_frame = animation->frame_lengths[next_frame]; | ||
| 196 | temp_animation.first_update_of_frame = true; | ||
| 197 | temp_animation.last_update_of_frame = false; | ||
| 198 | temp_animation.need_update = false; | ||
| 199 | visualizer_state_t temp_state = *state; | ||
| 200 | (*temp_animation.frame_functions[next_frame])(&temp_animation, &temp_state); | ||
| 201 | } | ||
| 202 | |||
| 175 | bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state) { | 203 | bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state) { |
| 176 | (void)animation; | 204 | (void)animation; |
| 177 | (void)state; | 205 | (void)state; |
| @@ -373,6 +401,9 @@ static THD_FUNCTION(visualizerThread, arg) { | |||
| 373 | update_keyframe_animation(animations[i], &state, delta, &sleep_time); | 401 | update_keyframe_animation(animations[i], &state, delta, &sleep_time); |
| 374 | } | 402 | } |
| 375 | } | 403 | } |
| 404 | #ifdef LED_ENABLE | ||
| 405 | gdispGFlush(LED_DISPLAY); | ||
| 406 | #endif | ||
| 376 | // The animation can enable the visualizer | 407 | // The animation can enable the visualizer |
| 377 | // And we might need to update the state when that happens | 408 | // And we might need to update the state when that happens |
| 378 | // so don't sleep | 409 | // so don't sleep |
| @@ -411,6 +442,11 @@ void visualizer_init(void) { | |||
| 411 | #ifdef USE_SERIAL_LINK | 442 | #ifdef USE_SERIAL_LINK |
| 412 | add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) ); | 443 | add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) ); |
| 413 | #endif | 444 | #endif |
| 445 | // TODO: Make sure these works when either of these are disabled | ||
| 446 | LCD_DISPLAY = gdispGetDisplay(0); | ||
| 447 | LED_DISPLAY = gdispGetDisplay(1); | ||
| 448 | |||
| 449 | |||
| 414 | // We are using a low priority thread, the idea is to have it run only | 450 | // We are using a low priority thread, the idea is to have it run only |
| 415 | // when the main thread is sleeping during the matrix scanning | 451 | // when the main thread is sleeping during the matrix scanning |
| 416 | chEvtObjectInit(&layer_changed_event); | 452 | chEvtObjectInit(&layer_changed_event); |
