visualizer.c 20 KB

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