]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/visualizer/visualizer.c
2533eb7090ed457a7eeb618ee8f1f871ab4799e4
[qmk_firmware.git] / quantum / visualizer / visualizer.c
1 /*
2 The MIT License (MIT)
3
4 Copyright (c) 2016 Fred Sundvik
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24
25 #include "visualizer.h"
26 #include "config.h"
27 #include <string.h>
28 #ifdef PROTOCOL_CHIBIOS
29 #include "ch.h"
30 #endif
31
32 #include "gfx.h"
33
34 #ifdef LCD_BACKLIGHT_ENABLE
35 #include "lcd_backlight.h"
36 #endif
37
38 //#define DEBUG_VISUALIZER
39
40 #ifdef DEBUG_VISUALIZER
41 #include "debug.h"
42 #else
43 #include "nodebug.h"
44 #endif
45
46 #ifdef SERIAL_LINK_ENABLE
47 #include "serial_link/protocol/transport.h"
48 #include "serial_link/system/serial_link.h"
49 #endif
50
51 // Define this in config.h
52 #ifndef VISUALIZER_THREAD_PRIORITY
53 #define "Visualizer thread priority not defined"
54 #endif
55
56 // mods status
57 #include "action_util.h"
58
59 #include "led.h"
60
61 static visualizer_keyboard_status_t current_status = {
62     .layer = 0xFFFFFFFF,
63     .default_layer = 0xFFFFFFFF,
64     .mods = 0xFF,
65     .leds = 0xFFFFFFFF,
66     .suspended = false,
67 #ifdef VISUALIZER_USER_DATA_SIZE
68     .user_data = {0}
69 #endif
70 };
71
72 static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboard_status_t* status2) {
73     return status1->layer == status2->layer &&
74         status1->default_layer == status2->default_layer &&
75         status1->mods == status2->mods &&
76         status1->leds == status2->leds &&
77         status1->suspended == status2->suspended
78 #ifdef VISUALIZER_USER_DATA_SIZE
79         && memcmp(status1->user_data, status2->user_data, VISUALIZER_USER_DATA_SIZE) == 0
80 #endif
81     ;
82 }
83
84 static bool visualizer_enabled = false;
85
86 #ifdef VISUALIZER_USER_DATA_SIZE
87 static uint8_t user_data[VISUALIZER_USER_DATA_SIZE];
88 #endif
89
90 #define MAX_SIMULTANEOUS_ANIMATIONS 4
91 static keyframe_animation_t* animations[MAX_SIMULTANEOUS_ANIMATIONS] = {};
92
93 #ifdef SERIAL_LINK_ENABLE
94 MASTER_TO_ALL_SLAVES_OBJECT(current_status, visualizer_keyboard_status_t);
95
96 static remote_object_t* remote_objects[] = {
97     REMOTE_OBJECT(current_status),
98 };
99
100 #endif
101
102 GDisplay* LCD_DISPLAY = 0;
103 GDisplay* LED_DISPLAY = 0;
104
105 __attribute__((weak))
106 GDisplay* get_lcd_display(void) {
107     return gdispGetDisplay(0);
108 }
109
110 __attribute__((weak))
111 GDisplay* get_led_display(void) {
112     return gdispGetDisplay(1);
113 }
114
115 void start_keyframe_animation(keyframe_animation_t* animation) {
116     animation->current_frame = -1;
117     animation->time_left_in_frame = 0;
118     animation->need_update = true;
119     int free_index = -1;
120     for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) {
121         if (animations[i] == animation) {
122             return;
123         }
124         if (free_index == -1 && animations[i] == NULL) {
125            free_index=i;
126         }
127     }
128     if (free_index!=-1) {
129         animations[free_index] = animation;
130     }
131 }
132
133 void stop_keyframe_animation(keyframe_animation_t* animation) {
134     animation->current_frame = animation->num_frames;
135     animation->time_left_in_frame = 0;
136     animation->need_update = true;
137     animation->first_update_of_frame = false;
138     animation->last_update_of_frame = false;
139     for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) {
140         if (animations[i] == animation) {
141             animations[i] = NULL;
142             return;
143         }
144     }
145 }
146
147 void stop_all_keyframe_animations(void) {
148     for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) {
149         if (animations[i]) {
150             animations[i]->current_frame = animations[i]->num_frames;
151             animations[i]->time_left_in_frame = 0;
152             animations[i]->need_update = true;
153             animations[i]->first_update_of_frame = false;
154             animations[i]->last_update_of_frame = false;
155             animations[i] = NULL;
156         }
157     }
158 }
159
160 static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systemticks_t delta, systemticks_t* sleep_time) {
161     // TODO: Clean up this messy code
162     dprintf("Animation frame%d, left %d, delta %d\n", animation->current_frame,
163             animation->time_left_in_frame, delta);
164     if (animation->current_frame == animation->num_frames) {
165         animation->need_update = false;
166         return false;
167     }
168     if (animation->current_frame == -1) {
169        animation->current_frame = 0;
170        animation->time_left_in_frame = animation->frame_lengths[0];
171        animation->need_update = true;
172        animation->first_update_of_frame = true;
173     } else {
174         animation->time_left_in_frame -= delta;
175         while (animation->time_left_in_frame <= 0) {
176             int left = animation->time_left_in_frame;
177             if (animation->need_update) {
178                 animation->time_left_in_frame = 0;
179                 animation->last_update_of_frame = true;
180                 (*animation->frame_functions[animation->current_frame])(animation, state);
181                 animation->last_update_of_frame = false;
182             }
183             animation->current_frame++;
184             animation->need_update = true;
185             animation->first_update_of_frame = true;
186             if (animation->current_frame == animation->num_frames) {
187                 if (animation->loop) {
188                     animation->current_frame = 0;
189                 }
190                 else {
191                     stop_keyframe_animation(animation);
192                     return false;
193                 }
194             }
195             delta = -left;
196             animation->time_left_in_frame = animation->frame_lengths[animation->current_frame];
197             animation->time_left_in_frame -= delta;
198         }
199     }
200     if (animation->need_update) {
201         animation->need_update = (*animation->frame_functions[animation->current_frame])(animation, state);
202         animation->first_update_of_frame = false;
203     }
204
205     systemticks_t wanted_sleep = animation->need_update ? gfxMillisecondsToTicks(10) : (unsigned)animation->time_left_in_frame;
206     if (wanted_sleep < *sleep_time) {
207         *sleep_time = wanted_sleep;
208     }
209
210     return true;
211 }
212
213 void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* state) {
214     int next_frame = animation->current_frame + 1;
215     if (next_frame == animation->num_frames) {
216         next_frame = 0;
217     }
218     keyframe_animation_t temp_animation = *animation;
219     temp_animation.current_frame = next_frame;
220     temp_animation.time_left_in_frame = animation->frame_lengths[next_frame];
221     temp_animation.first_update_of_frame = true;
222     temp_animation.last_update_of_frame = false;
223     temp_animation.need_update  = false;
224     visualizer_state_t temp_state = *state;
225     (*temp_animation.frame_functions[next_frame])(&temp_animation, &temp_state);
226 }
227
228 bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state) {
229     (void)animation;
230     (void)state;
231     return false;
232 }
233
234 #ifdef LCD_BACKLIGHT_ENABLE
235 bool keyframe_animate_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state) {
236     int frame_length = animation->frame_lengths[animation->current_frame];
237     int current_pos = frame_length - animation->time_left_in_frame;
238     uint8_t t_h = LCD_HUE(state->target_lcd_color);
239     uint8_t t_s = LCD_SAT(state->target_lcd_color);
240     uint8_t t_i = LCD_INT(state->target_lcd_color);
241     uint8_t p_h = LCD_HUE(state->prev_lcd_color);
242     uint8_t p_s = LCD_SAT(state->prev_lcd_color);
243     uint8_t p_i = LCD_INT(state->prev_lcd_color);
244
245     uint8_t d_h1 = t_h - p_h; //Modulo arithmetic since we want to wrap around
246     int d_h2 = t_h - p_h;
247     // Chose the shortest way around
248     int d_h = abs(d_h2) < d_h1 ? d_h2 : d_h1;
249     int d_s = t_s - p_s;
250     int d_i = t_i - p_i;
251
252     int hue = (d_h * current_pos) / frame_length;
253     int sat = (d_s * current_pos) / frame_length;
254     int intensity = (d_i * current_pos) / frame_length;
255     //dprintf("%X -> %X = %X\n", p_h, t_h, hue);
256     hue += p_h;
257     sat += p_s;
258     intensity += p_i;
259     state->current_lcd_color = LCD_COLOR(hue, sat, intensity);
260     lcd_backlight_color(
261             LCD_HUE(state->current_lcd_color),
262             LCD_SAT(state->current_lcd_color),
263             LCD_INT(state->current_lcd_color));
264
265     return true;
266 }
267
268 bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state) {
269     (void)animation;
270     state->prev_lcd_color = state->target_lcd_color;
271     state->current_lcd_color = state->target_lcd_color;
272     lcd_backlight_color(
273             LCD_HUE(state->current_lcd_color),
274             LCD_SAT(state->current_lcd_color),
275             LCD_INT(state->current_lcd_color));
276     return false;
277 }
278 #endif // LCD_BACKLIGHT_ENABLE
279
280 #ifdef LCD_ENABLE
281 bool keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state) {
282     (void)animation;
283     gdispClear(White);
284     gdispDrawString(0, 10, state->layer_text, state->font_dejavusansbold12, Black);
285     gdispFlush();
286     return false;
287 }
288
289 static void format_layer_bitmap_string(uint16_t default_layer, uint16_t layer, char* buffer) {
290     for (int i=0; i<16;i++)
291     {
292         uint32_t mask = (1u << i);
293         if (default_layer & mask) {
294             if (layer & mask) {
295                 *buffer = 'B';
296             } else {
297                 *buffer = 'D';
298             }
299         } else if (layer & mask) {
300             *buffer = '1';
301         } else {
302             *buffer = '0';
303         }
304         ++buffer;
305
306         if (i==3 || i==7 || i==11) {
307             *buffer = ' ';
308             ++buffer;
309         }
310     }
311     *buffer = 0;
312 }
313
314 bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) {
315     (void)animation;
316     const char* layer_help = "1=On D=Default B=Both";
317     char layer_buffer[16 + 4]; // 3 spaces and one null terminator
318     gdispClear(White);
319     gdispDrawString(0, 0, layer_help, state->font_fixed5x8, Black);
320     format_layer_bitmap_string(state->status.default_layer, state->status.layer, layer_buffer);
321     gdispDrawString(0, 10, layer_buffer, state->font_fixed5x8, Black);
322     format_layer_bitmap_string(state->status.default_layer >> 16, state->status.layer >> 16, layer_buffer);
323     gdispDrawString(0, 20, layer_buffer, state->font_fixed5x8, Black);
324     gdispFlush();
325     return false;
326 }
327
328 static void format_mods_bitmap_string(uint8_t mods, char* buffer) {
329     *buffer = ' ';
330     ++buffer;
331
332     for (int i = 0; i<8; i++)
333     {
334         uint32_t mask = (1u << i);
335         if (mods & mask) {
336             *buffer = '1';
337         } else {
338             *buffer = '0';
339         }
340         ++buffer;
341
342         if (i==3) {
343             *buffer = ' ';
344             ++buffer;
345         }
346     }
347     *buffer = 0;
348 }
349
350 bool keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) {
351     (void)animation;
352
353     const char* title = "Modifier states";
354     const char* mods_header = " CSAG CSAG ";
355     char status_buffer[12]; 
356     
357     gdispClear(White);
358     gdispDrawString(0, 0, title, state->font_fixed5x8, Black);
359     gdispDrawString(0, 10, mods_header, state->font_fixed5x8, Black);
360     format_mods_bitmap_string(state->status.mods, status_buffer);
361     gdispDrawString(0, 20, status_buffer, state->font_fixed5x8, Black);
362
363     gdispFlush();
364     return false;
365 }
366
367 #define LED_STATE_STRING_SIZE sizeof("NUM CAPS SCRL COMP KANA")
368
369 static void get_led_state_string(char* output, visualizer_state_t* state) {
370     uint8_t pos = 0;
371
372     if (state->status.leds & (1u << USB_LED_NUM_LOCK)) {
373        memcpy(output + pos, "NUM ", 4);
374        pos += 4;
375     }
376     if (state->status.leds & (1u << USB_LED_CAPS_LOCK)) {
377        memcpy(output + pos, "CAPS ", 5);
378        pos += 5;
379     }
380     if (state->status.leds & (1u << USB_LED_SCROLL_LOCK)) {
381        memcpy(output + pos, "SCRL ", 5);
382        pos += 5;
383     }
384     if (state->status.leds & (1u << USB_LED_COMPOSE)) {
385        memcpy(output + pos, "COMP ", 5);
386        pos += 5;
387     }
388     if (state->status.leds & (1u << USB_LED_KANA)) {
389        memcpy(output + pos, "KANA ", 5);
390        pos += 5;
391     }
392     output[pos] = 0;
393 }
394
395 bool keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state)
396 {
397     (void)animation;
398     char output[LED_STATE_STRING_SIZE];
399     get_led_state_string(output, state);
400     gdispClear(White);
401     gdispDrawString(0, 10, output, state->font_dejavusansbold12, Black);
402     gdispFlush();
403     return false;
404 }
405
406 bool keyframe_display_layer_and_led_states(keyframe_animation_t* animation, visualizer_state_t* state) {
407     (void)animation;
408     gdispClear(White);
409     uint8_t y = 10;
410     if (state->status.leds) {
411         char output[LED_STATE_STRING_SIZE];
412         get_led_state_string(output, state);
413         gdispDrawString(0, 1, output, state->font_dejavusansbold12, Black);
414         y = 17;
415     }
416     gdispDrawString(0, y, state->layer_text, state->font_dejavusansbold12, Black);
417     gdispFlush();
418     return false;
419 }
420
421 #endif // LCD_ENABLE
422
423 bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) {
424     (void)animation;
425     (void)state;
426 #ifdef LCD_ENABLE
427     gdispSetPowerMode(powerOff);
428 #endif
429 #ifdef LCD_BACKLIGHT_ENABLE
430     lcd_backlight_hal_color(0, 0, 0);
431 #endif
432     return false;
433 }
434
435 bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) {
436     (void)animation;
437     (void)state;
438 #ifdef LCD_ENABLE
439     gdispSetPowerMode(powerOn);
440 #endif
441     return false;
442 }
443
444 bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state) {
445     (void)animation;
446     (void)state;
447     dprint("User visualizer inited\n");
448     visualizer_enabled = true;
449     return false;
450 }
451
452 // TODO: Optimize the stack size, this is probably way too big
453 static DECLARE_THREAD_STACK(visualizerThreadStack, 1024);
454 static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
455     (void)arg;
456
457     GListener event_listener;
458     geventListenerInit(&event_listener);
459     geventAttachSource(&event_listener, (GSourceHandle)&current_status, 0);
460
461     visualizer_keyboard_status_t initial_status = {
462         .default_layer = 0xFFFFFFFF,
463         .layer = 0xFFFFFFFF,
464         .mods = 0xFF,
465         .leds = 0xFFFFFFFF,
466         .suspended = false,
467 #ifdef VISUALIZER_USER_DATA_SIZE
468         .user_data = {0},
469 #endif
470     };
471
472     visualizer_state_t state = {
473         .status = initial_status,
474         .current_lcd_color = 0,
475 #ifdef LCD_ENABLE
476         .font_fixed5x8 = gdispOpenFont("fixed_5x8"),
477         .font_dejavusansbold12 = gdispOpenFont("DejaVuSansBold12")
478 #endif
479     };
480     initialize_user_visualizer(&state);
481     state.prev_lcd_color = state.current_lcd_color;
482
483 #ifdef LCD_BACKLIGHT_ENABLE
484     lcd_backlight_color(
485             LCD_HUE(state.current_lcd_color),
486             LCD_SAT(state.current_lcd_color),
487             LCD_INT(state.current_lcd_color));
488 #endif
489
490     systemticks_t sleep_time = TIME_INFINITE;
491     systemticks_t current_time = gfxSystemTicks();
492
493     while(true) {
494         systemticks_t new_time = gfxSystemTicks();
495         systemticks_t delta = new_time - current_time;
496         current_time = new_time;
497         bool enabled = visualizer_enabled;
498         if (!same_status(&state.status, &current_status)) {
499             if (visualizer_enabled) {
500                 if (current_status.suspended) {
501                     stop_all_keyframe_animations();
502                     visualizer_enabled = false;
503                     state.status = current_status;
504                     user_visualizer_suspend(&state);
505                 }
506                 else {
507                     visualizer_keyboard_status_t prev_status = state.status;
508                     state.status = current_status;
509                     update_user_visualizer_state(&state, &prev_status);
510                 }
511                 state.prev_lcd_color = state.current_lcd_color;
512             }
513         }
514         if (!enabled && state.status.suspended && current_status.suspended == false) {
515             // Setting the status to the initial status will force an update
516             // when the visualizer is enabled again
517             state.status = initial_status;
518             state.status.suspended = false;
519             stop_all_keyframe_animations();
520             user_visualizer_resume(&state);
521             state.prev_lcd_color = state.current_lcd_color;
522         }
523         sleep_time = TIME_INFINITE;
524         for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) {
525             if (animations[i]) {
526                 update_keyframe_animation(animations[i], &state, delta, &sleep_time);
527             }
528         }
529 #ifdef LED_ENABLE
530         gdispGFlush(LED_DISPLAY);
531 #endif
532
533 #ifdef EMULATOR
534         draw_emulator();
535 #endif
536         // The animation can enable the visualizer
537         // And we might need to update the state when that happens
538         // so don't sleep
539         if (enabled != visualizer_enabled) {
540             sleep_time = 0;
541         }
542
543         systemticks_t after_update = gfxSystemTicks();
544         unsigned update_delta = after_update - current_time;
545         if (sleep_time != TIME_INFINITE) {
546             if (sleep_time > update_delta) {
547                 sleep_time -= update_delta;
548             }
549             else {
550                 sleep_time = 0;
551             }
552         }
553         dprintf("Update took %d, last delta %d, sleep_time %d\n", update_delta, delta, sleep_time);
554 #ifdef PROTOCOL_CHIBIOS
555         // The gEventWait function really takes milliseconds, even if the documentation says ticks.
556         // Unfortunately there's no generic ugfx conversion from system time to milliseconds,
557         // so let's do it in a platform dependent way.
558
559         // On windows the system ticks is the same as milliseconds anyway
560         if (sleep_time != TIME_INFINITE) {
561             sleep_time = ST2MS(sleep_time);
562         }
563 #endif
564         geventEventWait(&event_listener, sleep_time);
565     }
566 #ifdef LCD_ENABLE
567     gdispCloseFont(state.font_fixed5x8);
568     gdispCloseFont(state.font_dejavusansbold12);
569 #endif
570
571     return 0;
572 }
573
574 void visualizer_init(void) {
575     gfxInit();
576
577 #ifdef LCD_BACKLIGHT_ENABLE
578     lcd_backlight_init();
579 #endif
580
581 #ifdef SERIAL_LINK_ENABLE
582     add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) );
583 #endif
584
585 #ifdef LCD_ENABLE
586     LCD_DISPLAY = get_lcd_display();
587 #endif
588 #ifdef LED_ENABLE
589     LED_DISPLAY = get_led_display();
590 #endif
591
592     // We are using a low priority thread, the idea is to have it run only
593     // when the main thread is sleeping during the matrix scanning
594     gfxThreadCreate(visualizerThreadStack, sizeof(visualizerThreadStack),
595                               VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL);
596 }
597
598 void update_status(bool changed) {
599     if (changed) {
600         GSourceListener* listener = geventGetSourceListener((GSourceHandle)&current_status, NULL);
601         if (listener) {
602             geventSendEvent(listener);
603         }
604     }
605 #ifdef SERIAL_LINK_ENABLE
606     static systime_t last_update = 0;
607     systime_t current_update = chVTGetSystemTimeX();
608     systime_t delta = current_update - last_update;
609     if (changed || delta > MS2ST(10)) {
610         last_update = current_update;
611         visualizer_keyboard_status_t* r = begin_write_current_status();
612         *r = current_status;
613         end_write_current_status();
614     }
615 #endif
616 }
617
618 uint8_t visualizer_get_mods() {
619   uint8_t mods = get_mods();
620
621 #ifndef NO_ACTION_ONESHOT
622   if (!has_oneshot_mods_timed_out()) {
623     mods |= get_oneshot_mods();
624   }
625 #endif  
626   return mods;
627 }
628
629 #ifdef VISUALIZER_USER_DATA_SIZE
630 void visualizer_set_user_data(void* u) {
631     memcpy(user_data, u, VISUALIZER_USER_DATA_SIZE);
632 }
633 #endif
634
635 void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uint32_t leds) {
636     // Note that there's a small race condition here, the thread could read
637     // a state where one of these are set but not the other. But this should
638     // not really matter as it will be fixed during the next loop step.
639     // Alternatively a mutex could be used instead of the volatile variables
640
641     bool changed = false;
642 #ifdef SERIAL_LINK_ENABLE
643     if (is_serial_link_connected ()) {
644         visualizer_keyboard_status_t* new_status = read_current_status();
645         if (new_status) {
646             if (!same_status(&current_status, new_status)) {
647                 changed = true;
648                 current_status = *new_status;
649             }
650         }
651     }
652     else {
653 #else
654    {
655 #endif
656         visualizer_keyboard_status_t new_status = {
657             .layer = state,
658             .default_layer = default_state,
659             .mods = mods,
660             .leds = leds,
661             .suspended = current_status.suspended,
662         };
663 #ifdef VISUALIZER_USER_DATA_SIZE
664        memcpy(new_status.user_data, user_data, VISUALIZER_USER_DATA_SIZE);
665 #endif
666         if (!same_status(&current_status, &new_status)) {
667             changed = true;
668             current_status = new_status;
669         }
670     }
671     update_status(changed);
672 }
673
674 void visualizer_suspend(void) {
675     current_status.suspended = true;
676     update_status(true);
677 }
678
679 void visualizer_resume(void) {
680     current_status.suspended = false;
681     update_status(true);
682 }