diff options
| author | Fred Sundvik <fsundvik@gmail.com> | 2017-04-02 01:31:04 +0300 |
|---|---|---|
| committer | Fred Sundvik <fsundvik@gmail.com> | 2017-04-09 18:34:59 +0300 |
| commit | 39385144e7dc3337e623cdc8147b4a441f22fd62 (patch) | |
| tree | c553b85bbd7c0754296f999e83647ac7b779a22d /quantum/visualizer | |
| parent | 9a4ce28683b667ab67d48d92196bab7e277d4800 (diff) | |
| download | qmk_firmware-39385144e7dc3337e623cdc8147b4a441f22fd62.tar.gz qmk_firmware-39385144e7dc3337e623cdc8147b4a441f22fd62.zip | |
Emulate Ergodox EZ leds by LCD colors
Diffstat (limited to 'quantum/visualizer')
| -rw-r--r-- | quantum/visualizer/visualizer.c | 25 | ||||
| -rw-r--r-- | quantum/visualizer/visualizer.h | 8 |
2 files changed, 32 insertions, 1 deletions
diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index 62ebebcee..bff0df494 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c | |||
| @@ -64,6 +64,9 @@ static visualizer_keyboard_status_t current_status = { | |||
| 64 | .mods = 0xFF, | 64 | .mods = 0xFF, |
| 65 | .leds = 0xFFFFFFFF, | 65 | .leds = 0xFFFFFFFF, |
| 66 | .suspended = false, | 66 | .suspended = false, |
| 67 | #ifdef VISUALIZER_USER_DATA_SIZE | ||
| 68 | .user_data = {0} | ||
| 69 | #endif | ||
| 67 | }; | 70 | }; |
| 68 | 71 | ||
| 69 | static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboard_status_t* status2) { | 72 | static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboard_status_t* status2) { |
| @@ -71,11 +74,19 @@ static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboa | |||
| 71 | status1->default_layer == status2->default_layer && | 74 | status1->default_layer == status2->default_layer && |
| 72 | status1->mods == status2->mods && | 75 | status1->mods == status2->mods && |
| 73 | status1->leds == status2->leds && | 76 | status1->leds == status2->leds && |
| 74 | status1->suspended == status2->suspended; | 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 | ; | ||
| 75 | } | 82 | } |
| 76 | 83 | ||
| 77 | static bool visualizer_enabled = false; | 84 | static bool visualizer_enabled = false; |
| 78 | 85 | ||
| 86 | #ifdef VISUALIZER_USER_DATA_SIZE | ||
| 87 | static uint8_t user_data[VISUALIZER_USER_DATA_SIZE]; | ||
| 88 | #endif | ||
| 89 | |||
| 79 | #define MAX_SIMULTANEOUS_ANIMATIONS 4 | 90 | #define MAX_SIMULTANEOUS_ANIMATIONS 4 |
| 80 | static keyframe_animation_t* animations[MAX_SIMULTANEOUS_ANIMATIONS] = {}; | 91 | static keyframe_animation_t* animations[MAX_SIMULTANEOUS_ANIMATIONS] = {}; |
| 81 | 92 | ||
| @@ -431,6 +442,9 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { | |||
| 431 | .mods = 0xFF, | 442 | .mods = 0xFF, |
| 432 | .leds = 0xFFFFFFFF, | 443 | .leds = 0xFFFFFFFF, |
| 433 | .suspended = false, | 444 | .suspended = false, |
| 445 | #ifdef VISUALIZER_USER_DATA_SIZE | ||
| 446 | .user_data = {0}, | ||
| 447 | #endif | ||
| 434 | }; | 448 | }; |
| 435 | 449 | ||
| 436 | visualizer_state_t state = { | 450 | visualizer_state_t state = { |
| @@ -590,6 +604,12 @@ uint8_t visualizer_get_mods() { | |||
| 590 | return mods; | 604 | return mods; |
| 591 | } | 605 | } |
| 592 | 606 | ||
| 607 | #ifdef VISUALIZER_USER_DATA_SIZE | ||
| 608 | void visualizer_set_user_data(void* u) { | ||
| 609 | memcpy(user_data, u, VISUALIZER_USER_DATA_SIZE); | ||
| 610 | } | ||
| 611 | #endif | ||
| 612 | |||
| 593 | void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uint32_t leds) { | 613 | void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uint32_t leds) { |
| 594 | // Note that there's a small race condition here, the thread could read | 614 | // Note that there's a small race condition here, the thread could read |
| 595 | // a state where one of these are set but not the other. But this should | 615 | // a state where one of these are set but not the other. But this should |
| @@ -618,6 +638,9 @@ void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uin | |||
| 618 | .leds = leds, | 638 | .leds = leds, |
| 619 | .suspended = current_status.suspended, | 639 | .suspended = current_status.suspended, |
| 620 | }; | 640 | }; |
| 641 | #ifdef VISUALIZER_USER_DATA_SIZE | ||
| 642 | memcpy(new_status.user_data, user_data, VISUALIZER_USER_DATA_SIZE); | ||
| 643 | #endif | ||
| 621 | if (!same_status(¤t_status, &new_status)) { | 644 | if (!same_status(¤t_status, &new_status)) { |
| 622 | changed = true; | 645 | changed = true; |
| 623 | current_status = new_status; | 646 | current_status = new_status; |
diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h index 2c81cb9f7..beb8f2ab4 100644 --- a/quantum/visualizer/visualizer.h +++ b/quantum/visualizer/visualizer.h | |||
| @@ -68,6 +68,9 @@ typedef struct { | |||
| 68 | uint8_t mods; | 68 | uint8_t mods; |
| 69 | uint32_t leds; // See led.h for available statuses | 69 | uint32_t leds; // See led.h for available statuses |
| 70 | bool suspended; | 70 | bool suspended; |
| 71 | #ifdef VISUALIZER_USER_DATA_SIZE | ||
| 72 | uint8_t user_data[VISUALIZER_USER_DATA_SIZE]; | ||
| 73 | #endif | ||
| 71 | } visualizer_keyboard_status_t; | 74 | } visualizer_keyboard_status_t; |
| 72 | 75 | ||
| 73 | // The state struct is used by the various keyframe functions | 76 | // The state struct is used by the various keyframe functions |
| @@ -146,6 +149,11 @@ bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualiz | |||
| 146 | // directly from the initalize_user_visualizer function (the animation can be null) | 149 | // directly from the initalize_user_visualizer function (the animation can be null) |
| 147 | bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state); | 150 | bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state); |
| 148 | 151 | ||
| 152 | // The master can set userdata which will be transferred to the slave | ||
| 153 | #ifdef VISUALIZER_USER_DATA_SIZE | ||
| 154 | void visualizer_set_user_data(void* user_data); | ||
| 155 | #endif | ||
| 156 | |||
| 149 | // These functions have to be implemented by the user | 157 | // These functions have to be implemented by the user |
| 150 | void initialize_user_visualizer(visualizer_state_t* state); | 158 | void initialize_user_visualizer(visualizer_state_t* state); |
| 151 | void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t prev_status); | 159 | void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t prev_status); |
