aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboards/ergodox/infinity/visualizer.c6
-rw-r--r--keyboards/ergodox/keymaps/default/visualizer.c6
-rw-r--r--quantum/visualizer/visualizer.c28
-rw-r--r--quantum/visualizer/visualizer.h14
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
138static keyframe_animation_t startup_animation = { 138static 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
200static keyframe_animation_t resume_animation = { 199static 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
112static keyframe_animation_t startup_animation = { 112static 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
142static keyframe_animation_t resume_animation = { 141static 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
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 */