aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-06-01 09:22:47 +0300
committerFred Sundvik <fsundvik@gmail.com>2016-06-01 09:22:47 +0300
commit73d890a2c9c34b905cd5e74e7146fdd4578dcb96 (patch)
tree06c7268ec5d72782666e438557ae8562bf3f5b05
parent489288f67462e0c6fae8e54644af2fa4593e4406 (diff)
downloadqmk_firmware-73d890a2c9c34b905cd5e74e7146fdd4578dcb96.tar.gz
qmk_firmware-73d890a2c9c34b905cd5e74e7146fdd4578dcb96.zip
Fix visualizer sleeping too long
The documentation for ugfx gEventWait wait is wrong and the function takes the time in milliseconds, instead of system ticks. This caused the the thread to sleep way too long. It also caused somewhat random sleeping behaviour as the MS2ST function overflows at around 43 seconds sleep. The event source is also now initialized correctly, so that the thread actually can be woken up by events.
-rw-r--r--visualizer.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/visualizer.c b/visualizer.c
index 0e587221f..c24073405 100644
--- a/visualizer.c
+++ b/visualizer.c
@@ -25,6 +25,9 @@ SOFTWARE.
25#include "visualizer.h" 25#include "visualizer.h"
26#include "config.h" 26#include "config.h"
27#include <string.h> 27#include <string.h>
28#ifdef PROTOCOL_CHIBIOS
29#include "ch.h"
30#endif
28 31
29#ifdef LCD_ENABLE 32#ifdef LCD_ENABLE
30#include "gfx.h" 33#include "gfx.h"
@@ -67,7 +70,6 @@ static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboa
67 status1->suspended == status2->suspended; 70 status1->suspended == status2->suspended;
68} 71}
69 72
70static GSourceHandle layer_changed_event;
71static bool visualizer_enabled = false; 73static bool visualizer_enabled = false;
72 74
73#define MAX_SIMULTANEOUS_ANIMATIONS 4 75#define MAX_SIMULTANEOUS_ANIMATIONS 4
@@ -185,8 +187,8 @@ static bool update_keyframe_animation(keyframe_animation_t* animation, visualize
185 animation->first_update_of_frame = false; 187 animation->first_update_of_frame = false;
186 } 188 }
187 189
188 int wanted_sleep = animation->need_update ? 10 : animation->time_left_in_frame; 190 systemticks_t wanted_sleep = animation->need_update ? gfxMillisecondsToTicks(10) : (unsigned)animation->time_left_in_frame;
189 if ((unsigned)wanted_sleep < *sleep_time) { 191 if (wanted_sleep < *sleep_time) {
190 *sleep_time = wanted_sleep; 192 *sleep_time = wanted_sleep;
191 } 193 }
192 194
@@ -345,7 +347,7 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
345 347
346 GListener event_listener; 348 GListener event_listener;
347 geventListenerInit(&event_listener); 349 geventListenerInit(&event_listener);
348 geventAttachSource(&event_listener, layer_changed_event, 0); 350 geventAttachSource(&event_listener, (GSourceHandle)&current_status, 0);
349 351
350 visualizer_keyboard_status_t initial_status = { 352 visualizer_keyboard_status_t initial_status = {
351 .default_layer = 0xFFFFFFFF, 353 .default_layer = 0xFFFFFFFF,
@@ -435,6 +437,16 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
435 } 437 }
436 } 438 }
437 dprintf("Update took %d, last delta %d, sleep_time %d\n", update_delta, delta, sleep_time); 439 dprintf("Update took %d, last delta %d, sleep_time %d\n", update_delta, delta, sleep_time);
440#ifdef PROTOCOL_CHIBIOS
441 // The gEventWait function really takes milliseconds, even if the documentation says ticks.
442 // Unfortunately there's no generic ugfx conversion from system time to milliseconds,
443 // so let's do it in a platform dependent way.
444
445 // On windows the system ticks is the same as milliseconds anyway
446 if (sleep_time != TIME_INFINITE) {
447 sleep_time = ST2MS(sleep_time);
448 }
449#endif
438 geventEventWait(&event_listener, sleep_time); 450 geventEventWait(&event_listener, sleep_time);
439 } 451 }
440#ifdef LCD_ENABLE 452#ifdef LCD_ENABLE
@@ -473,7 +485,7 @@ void visualizer_init(void) {
473 485
474void update_status(bool changed) { 486void update_status(bool changed) {
475 if (changed) { 487 if (changed) {
476 GSourceListener* listener = geventGetSourceListener(layer_changed_event, NULL); 488 GSourceListener* listener = geventGetSourceListener((GSourceHandle)&current_status, NULL);
477 if (listener) { 489 if (listener) {
478 geventSendEvent(listener); 490 geventSendEvent(listener);
479 } 491 }