diff options
author | skullY <skullydazed@gmail.com> | 2019-08-30 11:19:03 -0700 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-08-30 15:01:52 -0700 |
commit | b624f32f944acdc59dcb130674c09090c5c404cb (patch) | |
tree | bc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /quantum/visualizer/visualizer.c | |
parent | 61af76a10d00aba185b8338604171de490a13e3b (diff) | |
download | qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip |
clang-format changes
Diffstat (limited to 'quantum/visualizer/visualizer.c')
-rw-r--r-- | quantum/visualizer/visualizer.c | 256 |
1 files changed, 116 insertions, 140 deletions
diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index 516cf2a84..3f182e74d 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c | |||
@@ -26,26 +26,26 @@ SOFTWARE. | |||
26 | #include "visualizer.h" | 26 | #include "visualizer.h" |
27 | #include <string.h> | 27 | #include <string.h> |
28 | #ifdef PROTOCOL_CHIBIOS | 28 | #ifdef PROTOCOL_CHIBIOS |
29 | #include "ch.h" | 29 | # include "ch.h" |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | #include "gfx.h" | 32 | #include "gfx.h" |
33 | 33 | ||
34 | #ifdef LCD_BACKLIGHT_ENABLE | 34 | #ifdef LCD_BACKLIGHT_ENABLE |
35 | #include "lcd_backlight.h" | 35 | # include "lcd_backlight.h" |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | //#define DEBUG_VISUALIZER | 38 | //#define DEBUG_VISUALIZER |
39 | 39 | ||
40 | #ifdef DEBUG_VISUALIZER | 40 | #ifdef DEBUG_VISUALIZER |
41 | #include "debug.h" | 41 | # include "debug.h" |
42 | #else | 42 | #else |
43 | #include "nodebug.h" | 43 | # include "nodebug.h" |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | #ifdef SERIAL_LINK_ENABLE | 46 | #ifdef SERIAL_LINK_ENABLE |
47 | #include "serial_link/protocol/transport.h" | 47 | # include "serial_link/protocol/transport.h" |
48 | #include "serial_link/system/serial_link.h" | 48 | # include "serial_link/system/serial_link.h" |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | #include "action_util.h" | 51 | #include "action_util.h" |
@@ -53,36 +53,31 @@ SOFTWARE. | |||
53 | // Define this in config.h | 53 | // Define this in config.h |
54 | #ifndef VISUALIZER_THREAD_PRIORITY | 54 | #ifndef VISUALIZER_THREAD_PRIORITY |
55 | // The visualizer needs gfx thread priorities | 55 | // The visualizer needs gfx thread priorities |
56 | #define VISUALIZER_THREAD_PRIORITY (NORMAL_PRIORITY - 2) | 56 | # define VISUALIZER_THREAD_PRIORITY (NORMAL_PRIORITY - 2) |
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | static visualizer_keyboard_status_t current_status = { | 59 | static visualizer_keyboard_status_t current_status = {.layer = 0xFFFFFFFF, |
60 | .layer = 0xFFFFFFFF, | 60 | .default_layer = 0xFFFFFFFF, |
61 | .default_layer = 0xFFFFFFFF, | 61 | .leds = 0xFFFFFFFF, |
62 | .leds = 0xFFFFFFFF, | ||
63 | #ifdef BACKLIGHT_ENABLE | 62 | #ifdef BACKLIGHT_ENABLE |
64 | .backlight_level = 0, | 63 | .backlight_level = 0, |
65 | #endif | 64 | #endif |
66 | .mods = 0xFF, | 65 | .mods = 0xFF, |
67 | .suspended = false, | 66 | .suspended = false, |
68 | #ifdef VISUALIZER_USER_DATA_SIZE | 67 | #ifdef VISUALIZER_USER_DATA_SIZE |
69 | .user_data = {0} | 68 | .user_data = {0} |
70 | #endif | 69 | #endif |
71 | }; | 70 | }; |
72 | 71 | ||
73 | 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) { |
74 | return status1->layer == status2->layer && | 73 | return status1->layer == status2->layer && status1->default_layer == status2->default_layer && status1->mods == status2->mods && status1->leds == status2->leds && status1->suspended == status2->suspended |
75 | status1->default_layer == status2->default_layer && | ||
76 | status1->mods == status2->mods && | ||
77 | status1->leds == status2->leds && | ||
78 | status1->suspended == status2->suspended | ||
79 | #ifdef BACKLIGHT_ENABLE | 74 | #ifdef BACKLIGHT_ENABLE |
80 | && status1->backlight_level == status2->backlight_level | 75 | && status1->backlight_level == status2->backlight_level |
81 | #endif | 76 | #endif |
82 | #ifdef VISUALIZER_USER_DATA_SIZE | 77 | #ifdef VISUALIZER_USER_DATA_SIZE |
83 | && memcmp(status1->user_data, status2->user_data, VISUALIZER_USER_DATA_SIZE) == 0 | 78 | && memcmp(status1->user_data, status2->user_data, VISUALIZER_USER_DATA_SIZE) == 0 |
84 | #endif | 79 | #endif |
85 | ; | 80 | ; |
86 | } | 81 | } |
87 | 82 | ||
88 | static bool visualizer_enabled = false; | 83 | static bool visualizer_enabled = false; |
@@ -107,44 +102,38 @@ GDisplay* LCD_DISPLAY = 0; | |||
107 | GDisplay* LED_DISPLAY = 0; | 102 | GDisplay* LED_DISPLAY = 0; |
108 | 103 | ||
109 | #ifdef LCD_DISPLAY_NUMBER | 104 | #ifdef LCD_DISPLAY_NUMBER |
110 | __attribute__((weak)) | 105 | __attribute__((weak)) GDisplay* get_lcd_display(void) { return gdispGetDisplay(LCD_DISPLAY_NUMBER); } |
111 | GDisplay* get_lcd_display(void) { | ||
112 | return gdispGetDisplay(LCD_DISPLAY_NUMBER); | ||
113 | } | ||
114 | #endif | 106 | #endif |
115 | 107 | ||
116 | #ifdef LED_DISPLAY_NUMBER | 108 | #ifdef LED_DISPLAY_NUMBER |
117 | __attribute__((weak)) | 109 | __attribute__((weak)) GDisplay* get_led_display(void) { return gdispGetDisplay(LED_DISPLAY_NUMBER); } |
118 | GDisplay* get_led_display(void) { | ||
119 | return gdispGetDisplay(LED_DISPLAY_NUMBER); | ||
120 | } | ||
121 | #endif | 110 | #endif |
122 | 111 | ||
123 | void start_keyframe_animation(keyframe_animation_t* animation) { | 112 | void start_keyframe_animation(keyframe_animation_t* animation) { |
124 | animation->current_frame = -1; | 113 | animation->current_frame = -1; |
125 | animation->time_left_in_frame = 0; | 114 | animation->time_left_in_frame = 0; |
126 | animation->need_update = true; | 115 | animation->need_update = true; |
127 | int free_index = -1; | 116 | int free_index = -1; |
128 | for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) { | 117 | for (int i = 0; i < MAX_SIMULTANEOUS_ANIMATIONS; i++) { |
129 | if (animations[i] == animation) { | 118 | if (animations[i] == animation) { |
130 | return; | 119 | return; |
131 | } | 120 | } |
132 | if (free_index == -1 && animations[i] == NULL) { | 121 | if (free_index == -1 && animations[i] == NULL) { |
133 | free_index=i; | 122 | free_index = i; |
134 | } | 123 | } |
135 | } | 124 | } |
136 | if (free_index!=-1) { | 125 | if (free_index != -1) { |
137 | animations[free_index] = animation; | 126 | animations[free_index] = animation; |
138 | } | 127 | } |
139 | } | 128 | } |
140 | 129 | ||
141 | void stop_keyframe_animation(keyframe_animation_t* animation) { | 130 | void stop_keyframe_animation(keyframe_animation_t* animation) { |
142 | animation->current_frame = animation->num_frames; | 131 | animation->current_frame = animation->num_frames; |
143 | animation->time_left_in_frame = 0; | 132 | animation->time_left_in_frame = 0; |
144 | animation->need_update = true; | 133 | animation->need_update = true; |
145 | animation->first_update_of_frame = false; | 134 | animation->first_update_of_frame = false; |
146 | animation->last_update_of_frame = false; | 135 | animation->last_update_of_frame = false; |
147 | for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) { | 136 | for (int i = 0; i < MAX_SIMULTANEOUS_ANIMATIONS; i++) { |
148 | if (animations[i] == animation) { | 137 | if (animations[i] == animation) { |
149 | animations[i] = NULL; | 138 | animations[i] = NULL; |
150 | return; | 139 | return; |
@@ -153,21 +142,21 @@ void stop_keyframe_animation(keyframe_animation_t* animation) { | |||
153 | } | 142 | } |
154 | 143 | ||
155 | void stop_all_keyframe_animations(void) { | 144 | void stop_all_keyframe_animations(void) { |
156 | for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) { | 145 | for (int i = 0; i < MAX_SIMULTANEOUS_ANIMATIONS; i++) { |
157 | if (animations[i]) { | 146 | if (animations[i]) { |
158 | animations[i]->current_frame = animations[i]->num_frames; | 147 | animations[i]->current_frame = animations[i]->num_frames; |
159 | animations[i]->time_left_in_frame = 0; | 148 | animations[i]->time_left_in_frame = 0; |
160 | animations[i]->need_update = true; | 149 | animations[i]->need_update = true; |
161 | animations[i]->first_update_of_frame = false; | 150 | animations[i]->first_update_of_frame = false; |
162 | animations[i]->last_update_of_frame = false; | 151 | animations[i]->last_update_of_frame = false; |
163 | animations[i] = NULL; | 152 | animations[i] = NULL; |
164 | } | 153 | } |
165 | } | 154 | } |
166 | } | 155 | } |
167 | 156 | ||
168 | static uint8_t get_num_running_animations(void) { | 157 | static uint8_t get_num_running_animations(void) { |
169 | uint8_t count = 0; | 158 | uint8_t count = 0; |
170 | for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) { | 159 | for (int i = 0; i < MAX_SIMULTANEOUS_ANIMATIONS; i++) { |
171 | count += animations[i] ? 1 : 0; | 160 | count += animations[i] ? 1 : 0; |
172 | } | 161 | } |
173 | return count; | 162 | return count; |
@@ -175,46 +164,44 @@ static uint8_t get_num_running_animations(void) { | |||
175 | 164 | ||
176 | static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systemticks_t delta, systemticks_t* sleep_time) { | 165 | static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systemticks_t delta, systemticks_t* sleep_time) { |
177 | // TODO: Clean up this messy code | 166 | // TODO: Clean up this messy code |
178 | 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, animation->time_left_in_frame, delta); |
179 | animation->time_left_in_frame, delta); | ||
180 | if (animation->current_frame == animation->num_frames) { | 168 | if (animation->current_frame == animation->num_frames) { |
181 | animation->need_update = false; | 169 | animation->need_update = false; |
182 | return false; | 170 | return false; |
183 | } | 171 | } |
184 | if (animation->current_frame == -1) { | 172 | if (animation->current_frame == -1) { |
185 | animation->current_frame = 0; | 173 | animation->current_frame = 0; |
186 | animation->time_left_in_frame = animation->frame_lengths[0]; | 174 | animation->time_left_in_frame = animation->frame_lengths[0]; |
187 | animation->need_update = true; | 175 | animation->need_update = true; |
188 | animation->first_update_of_frame = true; | 176 | animation->first_update_of_frame = true; |
189 | } else { | 177 | } else { |
190 | animation->time_left_in_frame -= delta; | 178 | animation->time_left_in_frame -= delta; |
191 | while (animation->time_left_in_frame <= 0) { | 179 | while (animation->time_left_in_frame <= 0) { |
192 | int left = animation->time_left_in_frame; | 180 | int left = animation->time_left_in_frame; |
193 | if (animation->need_update) { | 181 | if (animation->need_update) { |
194 | animation->time_left_in_frame = 0; | 182 | animation->time_left_in_frame = 0; |
195 | animation->last_update_of_frame = true; | 183 | animation->last_update_of_frame = true; |
196 | (*animation->frame_functions[animation->current_frame])(animation, state); | 184 | (*animation->frame_functions[animation->current_frame])(animation, state); |
197 | animation->last_update_of_frame = false; | 185 | animation->last_update_of_frame = false; |
198 | } | 186 | } |
199 | animation->current_frame++; | 187 | animation->current_frame++; |
200 | animation->need_update = true; | 188 | animation->need_update = true; |
201 | animation->first_update_of_frame = true; | 189 | animation->first_update_of_frame = true; |
202 | if (animation->current_frame == animation->num_frames) { | 190 | if (animation->current_frame == animation->num_frames) { |
203 | if (animation->loop) { | 191 | if (animation->loop) { |
204 | animation->current_frame = 0; | 192 | animation->current_frame = 0; |
205 | } | 193 | } else { |
206 | else { | ||
207 | stop_keyframe_animation(animation); | 194 | stop_keyframe_animation(animation); |
208 | return false; | 195 | return false; |
209 | } | 196 | } |
210 | } | 197 | } |
211 | delta = -left; | 198 | delta = -left; |
212 | animation->time_left_in_frame = animation->frame_lengths[animation->current_frame]; | 199 | animation->time_left_in_frame = animation->frame_lengths[animation->current_frame]; |
213 | animation->time_left_in_frame -= delta; | 200 | animation->time_left_in_frame -= delta; |
214 | } | 201 | } |
215 | } | 202 | } |
216 | if (animation->need_update) { | 203 | if (animation->need_update) { |
217 | animation->need_update = (*animation->frame_functions[animation->current_frame])(animation, state); | 204 | animation->need_update = (*animation->frame_functions[animation->current_frame])(animation, state); |
218 | animation->first_update_of_frame = false; | 205 | animation->first_update_of_frame = false; |
219 | } | 206 | } |
220 | 207 | ||
@@ -231,13 +218,13 @@ void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* stat | |||
231 | if (next_frame == animation->num_frames) { | 218 | if (next_frame == animation->num_frames) { |
232 | next_frame = 0; | 219 | next_frame = 0; |
233 | } | 220 | } |
234 | keyframe_animation_t temp_animation = *animation; | 221 | keyframe_animation_t temp_animation = *animation; |
235 | temp_animation.current_frame = next_frame; | 222 | temp_animation.current_frame = next_frame; |
236 | temp_animation.time_left_in_frame = animation->frame_lengths[next_frame]; | 223 | temp_animation.time_left_in_frame = animation->frame_lengths[next_frame]; |
237 | temp_animation.first_update_of_frame = true; | 224 | temp_animation.first_update_of_frame = true; |
238 | temp_animation.last_update_of_frame = false; | 225 | temp_animation.last_update_of_frame = false; |
239 | temp_animation.need_update = false; | 226 | temp_animation.need_update = false; |
240 | visualizer_state_t temp_state = *state; | 227 | visualizer_state_t temp_state = *state; |
241 | (*temp_animation.frame_functions[next_frame])(&temp_animation, &temp_state); | 228 | (*temp_animation.frame_functions[next_frame])(&temp_animation, &temp_state); |
242 | } | 229 | } |
243 | 230 | ||
@@ -252,70 +239,64 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { | |||
252 | 239 | ||
253 | visualizer_keyboard_status_t initial_status = { | 240 | visualizer_keyboard_status_t initial_status = { |
254 | .default_layer = 0xFFFFFFFF, | 241 | .default_layer = 0xFFFFFFFF, |
255 | .layer = 0xFFFFFFFF, | 242 | .layer = 0xFFFFFFFF, |
256 | .mods = 0xFF, | 243 | .mods = 0xFF, |
257 | .leds = 0xFFFFFFFF, | 244 | .leds = 0xFFFFFFFF, |
258 | .suspended = false, | 245 | .suspended = false, |
259 | #ifdef BACKLIGHT_ENABLE | 246 | #ifdef BACKLIGHT_ENABLE |
260 | .backlight_level = 0, | 247 | .backlight_level = 0, |
261 | #endif | 248 | #endif |
262 | #ifdef VISUALIZER_USER_DATA_SIZE | 249 | #ifdef VISUALIZER_USER_DATA_SIZE |
263 | .user_data = {0}, | 250 | .user_data = {0}, |
264 | #endif | 251 | #endif |
265 | }; | 252 | }; |
266 | 253 | ||
267 | visualizer_state_t state = { | 254 | visualizer_state_t state = {.status = initial_status, |
268 | .status = initial_status, | 255 | .current_lcd_color = 0, |
269 | .current_lcd_color = 0, | ||
270 | #ifdef LCD_ENABLE | 256 | #ifdef LCD_ENABLE |
271 | .font_fixed5x8 = gdispOpenFont("fixed_5x8"), | 257 | .font_fixed5x8 = gdispOpenFont("fixed_5x8"), |
272 | .font_dejavusansbold12 = gdispOpenFont("DejaVuSansBold12") | 258 | .font_dejavusansbold12 = gdispOpenFont("DejaVuSansBold12") |
273 | #endif | 259 | #endif |
274 | }; | 260 | }; |
275 | initialize_user_visualizer(&state); | 261 | initialize_user_visualizer(&state); |
276 | state.prev_lcd_color = state.current_lcd_color; | 262 | state.prev_lcd_color = state.current_lcd_color; |
277 | 263 | ||
278 | #ifdef LCD_BACKLIGHT_ENABLE | 264 | #ifdef LCD_BACKLIGHT_ENABLE |
279 | lcd_backlight_color( | 265 | lcd_backlight_color(LCD_HUE(state.current_lcd_color), LCD_SAT(state.current_lcd_color), LCD_INT(state.current_lcd_color)); |
280 | LCD_HUE(state.current_lcd_color), | ||
281 | LCD_SAT(state.current_lcd_color), | ||
282 | LCD_INT(state.current_lcd_color)); | ||
283 | #endif | 266 | #endif |
284 | 267 | ||
285 | systemticks_t sleep_time = TIME_INFINITE; | 268 | systemticks_t sleep_time = TIME_INFINITE; |
286 | systemticks_t current_time = gfxSystemTicks(); | 269 | systemticks_t current_time = gfxSystemTicks(); |
287 | bool force_update = true; | 270 | bool force_update = true; |
288 | 271 | ||
289 | while(true) { | 272 | while (true) { |
290 | systemticks_t new_time = gfxSystemTicks(); | 273 | systemticks_t new_time = gfxSystemTicks(); |
291 | systemticks_t delta = new_time - current_time; | 274 | systemticks_t delta = new_time - current_time; |
292 | current_time = new_time; | 275 | current_time = new_time; |
293 | bool enabled = visualizer_enabled; | 276 | bool enabled = visualizer_enabled; |
294 | if (force_update || !same_status(&state.status, ¤t_status)) { | 277 | if (force_update || !same_status(&state.status, ¤t_status)) { |
295 | force_update = false; | 278 | force_update = false; |
296 | #if BACKLIGHT_ENABLE | 279 | #if BACKLIGHT_ENABLE |
297 | if(current_status.backlight_level != state.status.backlight_level) { | 280 | if (current_status.backlight_level != state.status.backlight_level) { |
298 | if (current_status.backlight_level != 0) { | 281 | if (current_status.backlight_level != 0) { |
299 | gdispGSetPowerMode(LED_DISPLAY, powerOn); | 282 | gdispGSetPowerMode(LED_DISPLAY, powerOn); |
300 | uint16_t percent = (uint16_t)current_status.backlight_level * 100 / BACKLIGHT_LEVELS; | 283 | uint16_t percent = (uint16_t)current_status.backlight_level * 100 / BACKLIGHT_LEVELS; |
301 | gdispGSetBacklight(LED_DISPLAY, percent); | 284 | gdispGSetBacklight(LED_DISPLAY, percent); |
302 | } | 285 | } else { |
303 | else { | ||
304 | gdispGSetPowerMode(LED_DISPLAY, powerOff); | 286 | gdispGSetPowerMode(LED_DISPLAY, powerOff); |
305 | } | 287 | } |
306 | state.status.backlight_level = current_status.backlight_level; | 288 | state.status.backlight_level = current_status.backlight_level; |
307 | } | 289 | } |
308 | #endif | 290 | #endif |
309 | if (visualizer_enabled) { | 291 | if (visualizer_enabled) { |
310 | if (current_status.suspended) { | 292 | if (current_status.suspended) { |
311 | stop_all_keyframe_animations(); | 293 | stop_all_keyframe_animations(); |
312 | visualizer_enabled = false; | 294 | visualizer_enabled = false; |
313 | state.status = current_status; | 295 | state.status = current_status; |
314 | user_visualizer_suspend(&state); | 296 | user_visualizer_suspend(&state); |
315 | } | 297 | } else { |
316 | else { | ||
317 | visualizer_keyboard_status_t prev_status = state.status; | 298 | visualizer_keyboard_status_t prev_status = state.status; |
318 | state.status = current_status; | 299 | state.status = current_status; |
319 | update_user_visualizer_state(&state, &prev_status); | 300 | update_user_visualizer_state(&state, &prev_status); |
320 | } | 301 | } |
321 | state.prev_lcd_color = state.current_lcd_color; | 302 | state.prev_lcd_color = state.current_lcd_color; |
@@ -324,14 +305,14 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { | |||
324 | if (!enabled && state.status.suspended && current_status.suspended == false) { | 305 | if (!enabled && state.status.suspended && current_status.suspended == false) { |
325 | // Setting the status to the initial status will force an update | 306 | // Setting the status to the initial status will force an update |
326 | // when the visualizer is enabled again | 307 | // when the visualizer is enabled again |
327 | state.status = initial_status; | 308 | state.status = initial_status; |
328 | state.status.suspended = false; | 309 | state.status.suspended = false; |
329 | stop_all_keyframe_animations(); | 310 | stop_all_keyframe_animations(); |
330 | user_visualizer_resume(&state); | 311 | user_visualizer_resume(&state); |
331 | state.prev_lcd_color = state.current_lcd_color; | 312 | state.prev_lcd_color = state.current_lcd_color; |
332 | } | 313 | } |
333 | sleep_time = TIME_INFINITE; | 314 | sleep_time = TIME_INFINITE; |
334 | for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) { | 315 | for (int i = 0; i < MAX_SIMULTANEOUS_ANIMATIONS; i++) { |
335 | if (animations[i]) { | 316 | if (animations[i]) { |
336 | update_keyframe_animation(animations[i], &state, delta, &sleep_time); | 317 | update_keyframe_animation(animations[i], &state, delta, &sleep_time); |
337 | } | 318 | } |
@@ -350,17 +331,16 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { | |||
350 | // Enable the visualizer when the startup or the suspend animation has finished | 331 | // Enable the visualizer when the startup or the suspend animation has finished |
351 | if (!visualizer_enabled && state.status.suspended == false && get_num_running_animations() == 0) { | 332 | if (!visualizer_enabled && state.status.suspended == false && get_num_running_animations() == 0) { |
352 | visualizer_enabled = true; | 333 | visualizer_enabled = true; |
353 | force_update = true; | 334 | force_update = true; |
354 | sleep_time = 0; | 335 | sleep_time = 0; |
355 | } | 336 | } |
356 | 337 | ||
357 | systemticks_t after_update = gfxSystemTicks(); | 338 | systemticks_t after_update = gfxSystemTicks(); |
358 | unsigned update_delta = after_update - current_time; | 339 | unsigned update_delta = after_update - current_time; |
359 | if (sleep_time != TIME_INFINITE) { | 340 | if (sleep_time != TIME_INFINITE) { |
360 | if (sleep_time > update_delta) { | 341 | if (sleep_time > update_delta) { |
361 | sleep_time -= update_delta; | 342 | sleep_time -= update_delta; |
362 | } | 343 | } else { |
363 | else { | ||
364 | sleep_time = 0; | 344 | sleep_time = 0; |
365 | } | 345 | } |
366 | } | 346 | } |
@@ -388,26 +368,25 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { | |||
388 | void visualizer_init(void) { | 368 | void visualizer_init(void) { |
389 | gfxInit(); | 369 | gfxInit(); |
390 | 370 | ||
391 | #ifdef LCD_BACKLIGHT_ENABLE | 371 | #ifdef LCD_BACKLIGHT_ENABLE |
392 | lcd_backlight_init(); | 372 | lcd_backlight_init(); |
393 | #endif | 373 | #endif |
394 | 374 | ||
395 | #ifdef SERIAL_LINK_ENABLE | 375 | #ifdef SERIAL_LINK_ENABLE |
396 | add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) ); | 376 | add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*)); |
397 | #endif | 377 | #endif |
398 | 378 | ||
399 | #ifdef LCD_ENABLE | 379 | #ifdef LCD_ENABLE |
400 | LCD_DISPLAY = get_lcd_display(); | 380 | LCD_DISPLAY = get_lcd_display(); |
401 | #endif | 381 | #endif |
402 | 382 | ||
403 | #ifdef BACKLIGHT_ENABLE | 383 | #ifdef BACKLIGHT_ENABLE |
404 | LED_DISPLAY = get_led_display(); | 384 | LED_DISPLAY = get_led_display(); |
405 | #endif | 385 | #endif |
406 | 386 | ||
407 | // We are using a low priority thread, the idea is to have it run only | 387 | // We are using a low priority thread, the idea is to have it run only |
408 | // when the main thread is sleeping during the matrix scanning | 388 | // when the main thread is sleeping during the matrix scanning |
409 | gfxThreadCreate(visualizerThreadStack, sizeof(visualizerThreadStack), | 389 | gfxThreadCreate(visualizerThreadStack, sizeof(visualizerThreadStack), VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL); |
410 | VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL); | ||
411 | } | 390 | } |
412 | 391 | ||
413 | void update_status(bool changed) { | 392 | void update_status(bool changed) { |
@@ -418,33 +397,31 @@ void update_status(bool changed) { | |||
418 | } | 397 | } |
419 | } | 398 | } |
420 | #ifdef SERIAL_LINK_ENABLE | 399 | #ifdef SERIAL_LINK_ENABLE |
421 | static systime_t last_update = 0; | 400 | static systime_t last_update = 0; |
422 | systime_t current_update = chVTGetSystemTimeX(); | 401 | systime_t current_update = chVTGetSystemTimeX(); |
423 | systime_t delta = current_update - last_update; | 402 | systime_t delta = current_update - last_update; |
424 | if (changed || delta > MS2ST(10)) { | 403 | if (changed || delta > MS2ST(10)) { |
425 | last_update = current_update; | 404 | last_update = current_update; |
426 | visualizer_keyboard_status_t* r = begin_write_current_status(); | 405 | visualizer_keyboard_status_t* r = begin_write_current_status(); |
427 | *r = current_status; | 406 | *r = current_status; |
428 | end_write_current_status(); | 407 | end_write_current_status(); |
429 | } | 408 | } |
430 | #endif | 409 | #endif |
431 | } | 410 | } |
432 | 411 | ||
433 | uint8_t visualizer_get_mods() { | 412 | uint8_t visualizer_get_mods() { |
434 | uint8_t mods = get_mods(); | 413 | uint8_t mods = get_mods(); |
435 | 414 | ||
436 | #ifndef NO_ACTION_ONESHOT | 415 | #ifndef NO_ACTION_ONESHOT |
437 | if (!has_oneshot_mods_timed_out()) { | 416 | if (!has_oneshot_mods_timed_out()) { |
438 | mods |= get_oneshot_mods(); | 417 | mods |= get_oneshot_mods(); |
439 | } | 418 | } |
440 | #endif | 419 | #endif |
441 | return mods; | 420 | return mods; |
442 | } | 421 | } |
443 | 422 | ||
444 | #ifdef VISUALIZER_USER_DATA_SIZE | 423 | #ifdef VISUALIZER_USER_DATA_SIZE |
445 | void visualizer_set_user_data(void* u) { | 424 | void visualizer_set_user_data(void* u) { memcpy(user_data, u, VISUALIZER_USER_DATA_SIZE); } |
446 | memcpy(user_data, u, VISUALIZER_USER_DATA_SIZE); | ||
447 | } | ||
448 | #endif | 425 | #endif |
449 | 426 | ||
450 | void visualizer_update(layer_state_t default_state, layer_state_t state, uint8_t mods, uint32_t leds) { | 427 | void visualizer_update(layer_state_t default_state, layer_state_t state, uint8_t mods, uint32_t leds) { |
@@ -455,34 +432,33 @@ void visualizer_update(layer_state_t default_state, layer_state_t state, uint8_t | |||
455 | 432 | ||
456 | bool changed = false; | 433 | bool changed = false; |
457 | #ifdef SERIAL_LINK_ENABLE | 434 | #ifdef SERIAL_LINK_ENABLE |
458 | if (is_serial_link_connected ()) { | 435 | if (is_serial_link_connected()) { |
459 | visualizer_keyboard_status_t* new_status = read_current_status(); | 436 | visualizer_keyboard_status_t* new_status = read_current_status(); |
460 | if (new_status) { | 437 | if (new_status) { |
461 | if (!same_status(¤t_status, new_status)) { | 438 | if (!same_status(¤t_status, new_status)) { |
462 | changed = true; | 439 | changed = true; |
463 | current_status = *new_status; | 440 | current_status = *new_status; |
464 | } | 441 | } |
465 | } | 442 | } |
466 | } | 443 | } else { |
467 | else { | ||
468 | #else | 444 | #else |
469 | { | 445 | { |
470 | #endif | 446 | #endif |
471 | visualizer_keyboard_status_t new_status = { | 447 | visualizer_keyboard_status_t new_status = { |
472 | .layer = state, | 448 | .layer = state, |
473 | .default_layer = default_state, | 449 | .default_layer = default_state, |
474 | .mods = mods, | 450 | .mods = mods, |
475 | .leds = leds, | 451 | .leds = leds, |
476 | #ifdef BACKLIGHT_ENABLE | 452 | #ifdef BACKLIGHT_ENABLE |
477 | .backlight_level = current_status.backlight_level, | 453 | .backlight_level = current_status.backlight_level, |
478 | #endif | 454 | #endif |
479 | .suspended = current_status.suspended, | 455 | .suspended = current_status.suspended, |
480 | }; | 456 | }; |
481 | #ifdef VISUALIZER_USER_DATA_SIZE | 457 | #ifdef VISUALIZER_USER_DATA_SIZE |
482 | memcpy(new_status.user_data, user_data, VISUALIZER_USER_DATA_SIZE); | 458 | memcpy(new_status.user_data, user_data, VISUALIZER_USER_DATA_SIZE); |
483 | #endif | 459 | #endif |
484 | if (!same_status(¤t_status, &new_status)) { | 460 | if (!same_status(¤t_status, &new_status)) { |
485 | changed = true; | 461 | changed = true; |
486 | current_status = new_status; | 462 | current_status = new_status; |
487 | } | 463 | } |
488 | } | 464 | } |