summaryrefslogtreecommitdiff
path: root/visualizer.c
diff options
context:
space:
mode:
Diffstat (limited to 'visualizer.c')
-rw-r--r--visualizer.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/visualizer.c b/visualizer.c
index 605be30594..579837edcd 100644
--- a/visualizer.c
+++ b/visualizer.c
@@ -83,6 +83,9 @@ static remote_object_t* remote_objects[] = {
#endif
+GDisplay* LCD_DISPLAY = 0;
+GDisplay* LED_DISPLAY = 0;
+
void start_keyframe_animation(keyframe_animation_t* animation) {
animation->current_frame = -1;
@@ -106,6 +109,8 @@ void stop_keyframe_animation(keyframe_animation_t* animation) {
animation->current_frame = animation->num_frames;
animation->time_left_in_frame = 0;
animation->need_update = true;
+ animation->first_update_of_frame = false;
+ animation->last_update_of_frame = false;
for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) {
if (animations[i] == animation) {
animations[i] = NULL;
@@ -120,12 +125,15 @@ void stop_all_keyframe_animations(void) {
animations[i]->current_frame = animations[i]->num_frames;
animations[i]->time_left_in_frame = 0;
animations[i]->need_update = true;
+ animations[i]->first_update_of_frame = false;
+ animations[i]->last_update_of_frame = false;
animations[i] = NULL;
}
}
}
static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systime_t delta, systime_t* sleep_time) {
+ // TODO: Clean up this messy code
dprintf("Animation frame%d, left %d, delta %d\n", animation->current_frame,
animation->time_left_in_frame, delta);
if (animation->current_frame == animation->num_frames) {
@@ -136,16 +144,20 @@ static bool update_keyframe_animation(keyframe_animation_t* animation, visualize
animation->current_frame = 0;
animation->time_left_in_frame = animation->frame_lengths[0];
animation->need_update = true;
+ animation->first_update_of_frame = true;
} else {
animation->time_left_in_frame -= delta;
while (animation->time_left_in_frame <= 0) {
int left = animation->time_left_in_frame;
if (animation->need_update) {
animation->time_left_in_frame = 0;
+ animation->last_update_of_frame = true;
(*animation->frame_functions[animation->current_frame])(animation, state);
+ animation->last_update_of_frame = false;
}
animation->current_frame++;
animation->need_update = true;
+ animation->first_update_of_frame = true;
if (animation->current_frame == animation->num_frames) {
if (animation->loop) {
animation->current_frame = 0;
@@ -162,6 +174,7 @@ static bool update_keyframe_animation(keyframe_animation_t* animation, visualize
}
if (animation->need_update) {
animation->need_update = (*animation->frame_functions[animation->current_frame])(animation, state);
+ animation->first_update_of_frame = false;
}
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
return true;
}
+void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* state) {
+ int next_frame = animation->current_frame + 1;
+ if (next_frame == animation->num_frames) {
+ next_frame = 0;
+ }
+ keyframe_animation_t temp_animation = *animation;
+ temp_animation.current_frame = next_frame;
+ temp_animation.time_left_in_frame = animation->frame_lengths[next_frame];
+ temp_animation.first_update_of_frame = true;
+ temp_animation.last_update_of_frame = false;
+ temp_animation.need_update = false;
+ visualizer_state_t temp_state = *state;
+ (*temp_animation.frame_functions[next_frame])(&temp_animation, &temp_state);
+}
+
bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state) {
(void)animation;
(void)state;
@@ -373,6 +401,9 @@ static THD_FUNCTION(visualizerThread, arg) {
update_keyframe_animation(animations[i], &state, delta, &sleep_time);
}
}
+#ifdef LED_ENABLE
+ gdispGFlush(LED_DISPLAY);
+#endif
// The animation can enable the visualizer
// And we might need to update the state when that happens
// so don't sleep
@@ -411,6 +442,11 @@ void visualizer_init(void) {
#ifdef USE_SERIAL_LINK
add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) );
#endif
+ // TODO: Make sure these works when either of these are disabled
+ LCD_DISPLAY = gdispGetDisplay(0);
+ LED_DISPLAY = gdispGetDisplay(1);
+
+
// We are using a low priority thread, the idea is to have it run only
// when the main thread is sleeping during the matrix scanning
chEvtObjectInit(&layer_changed_event);