aboutsummaryrefslogtreecommitdiff
path: root/quantum/visualizer
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/visualizer')
-rw-r--r--quantum/visualizer/visualizer.c28
-rw-r--r--quantum/visualizer/visualizer.h14
2 files changed, 23 insertions, 19 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
157static 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
157static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systemticks_t delta, systemticks_t* sleep_time) { 165static 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
231bool 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
240static DECLARE_THREAD_STACK(visualizerThreadStack, 1024); 240static DECLARE_THREAD_STACK(visualizerThreadStack, 1024);
241static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { 241static 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, &current_status)) { 286 if (force_update || !same_status(&state.status, &current_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
131bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state); 131bool 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)
135bool 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
139void visualizer_set_user_data(void* user_data); 135void 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
143void initialize_user_visualizer(visualizer_state_t* state); 139// Called regularly each time the state has changed (but not every scan loop)
144void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status); 140void 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
145void user_visualizer_suspend(visualizer_state_t* state); 142void 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
147void initialize_user_visualizer(visualizer_state_t* state);
148// Called when the computer resumes from a suspend
146void user_visualizer_resume(visualizer_state_t* state); 149void user_visualizer_resume(visualizer_state_t* state);
147 150
148
149#endif /* VISUALIZER_H */ 151#endif /* VISUALIZER_H */