aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-03-12 19:42:57 +0200
committerFred Sundvik <fsundvik@gmail.com>2016-03-12 19:42:57 +0200
commit315edb48265e6baedd07f34c9e6e323d28814b4e (patch)
tree9c80ba72b48cb029a5a7891b23aab5fecfb6bc52
parent725929ec8bb5d57b6c4f53fa7d15e04df15f2535 (diff)
downloadqmk_firmware-315edb48265e6baedd07f34c9e6e323d28814b4e.tar.gz
qmk_firmware-315edb48265e6baedd07f34c9e6e323d28814b4e.zip
Add serial link support for visualizer
-rw-r--r--visualizer.c63
1 files changed, 55 insertions, 8 deletions
diff --git a/visualizer.c b/visualizer.c
index 402bbd151..ca7bcb776 100644
--- a/visualizer.c
+++ b/visualizer.c
@@ -42,6 +42,11 @@ SOFTWARE.
42#include "nodebug.h" 42#include "nodebug.h"
43#endif 43#endif
44 44
45#ifdef USE_SERIAL_LINK
46#include "serial_link/protocol/transport.h"
47#include "serial_link/system/driver.h"
48#endif
49
45 50
46static visualizer_keyboard_status_t current_status = { 51static visualizer_keyboard_status_t current_status = {
47 .layer = 0xFFFFFFFF, 52 .layer = 0xFFFFFFFF,
@@ -59,6 +64,16 @@ static bool visualizer_enabled = false;
59#define MAX_SIMULTANEOUS_ANIMATIONS 4 64#define MAX_SIMULTANEOUS_ANIMATIONS 4
60static keyframe_animation_t* animations[MAX_SIMULTANEOUS_ANIMATIONS] = {}; 65static keyframe_animation_t* animations[MAX_SIMULTANEOUS_ANIMATIONS] = {};
61 66
67#ifdef USE_SERIAL_LINK
68MASTER_TO_ALL_SLAVES_OBJECT(current_status, visualizer_keyboard_status_t);
69
70static remote_object_t* remote_objects[] = {
71 REMOTE_OBJECT(current_status),
72};
73
74#endif
75
76
62void start_keyframe_animation(keyframe_animation_t* animation) { 77void start_keyframe_animation(keyframe_animation_t* animation) {
63 animation->current_frame = -1; 78 animation->current_frame = -1;
64 animation->time_left_in_frame = 0; 79 animation->time_left_in_frame = 0;
@@ -328,6 +343,10 @@ void visualizer_init(void) {
328#ifdef LCD_BACKLIGHT_ENABLE 343#ifdef LCD_BACKLIGHT_ENABLE
329 lcd_backlight_init(); 344 lcd_backlight_init();
330#endif 345#endif
346
347#ifdef USE_SERIAL_LINK
348 add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) );
349#endif
331 // We are using a low priority thread, the idea is to have it run only 350 // We are using a low priority thread, the idea is to have it run only
332 // when the main thread is sleeping during the matrix scanning 351 // when the main thread is sleeping during the matrix scanning
333 chEvtObjectInit(&layer_changed_event); 352 chEvtObjectInit(&layer_changed_event);
@@ -340,17 +359,45 @@ void visualizer_set_state(uint32_t default_state, uint32_t state, uint32_t leds)
340 // a state where one of these are set but not the other. But this should 359 // a state where one of these are set but not the other. But this should
341 // not really matter as it will be fixed during the next loop step. 360 // not really matter as it will be fixed during the next loop step.
342 // Alternatively a mutex could be used instead of the volatile variables 361 // Alternatively a mutex could be used instead of the volatile variables
362
343 bool changed = false; 363 bool changed = false;
344 visualizer_keyboard_status_t new_status = { 364#ifdef USE_SERIAL_LINK
345 .layer = state, 365 if (is_serial_link_connected ()) {
346 .default_layer = default_state, 366 visualizer_keyboard_status_t* new_status = read_current_status();
347 .leds = leds, 367 if (new_status) {
348 }; 368 if (!same_status(&current_status, new_status)) {
349 if (!same_status(&current_status, &new_status)) { 369 changed = true;
350 changed = true; 370 current_status = *new_status;
371 }
372 }
373 }
374 else {
375#else
376 {
377#endif
378 visualizer_keyboard_status_t new_status = {
379 .layer = state,
380 .default_layer = default_state,
381 .leds = leds,
382 };
383 if (!same_status(&current_status, &new_status)) {
384 changed = true;
385 current_status = new_status;
386 }
351 } 387 }
352 current_status = new_status;
353 if (changed) { 388 if (changed) {
354 chEvtBroadcast(&layer_changed_event); 389 chEvtBroadcast(&layer_changed_event);
390
355 } 391 }
392#ifdef USE_SERIAL_LINK
393 static systime_t last_update = 0;
394 systime_t current_update = chVTGetSystemTimeX();
395 systime_t delta = current_update - last_update;
396 if (changed || delta > MS2ST(10)) {
397 last_update = current_update;
398 visualizer_keyboard_status_t* r = begin_write_current_status();
399 *r = current_status;
400 end_write_current_status();
401 }
402#endif
356} 403}