Skip to content

Commit dc2f38c

Browse files
committed
!squash: Handle events before expecting light animation frame.
1 parent 920c812 commit dc2f38c

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

lib/pbio/test/src/test_animation.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include <test-pbio.h>
1111

12+
#include <pbio/main.h>
13+
1214
#include "../src/light/animation.h"
1315
#include "../drv/clock/clock_test.h"
1416

@@ -33,10 +35,13 @@ static PT_THREAD(test_light_animation(struct pt *pt)) {
3335
tt_want(!process_is_running(&pbio_light_animation_process));
3436
tt_want(!pbio_light_animation_is_started(&test_animation));
3537

36-
// starting animation should start process and call next() once synchonously
38+
// starting animation should start process and set a timer at 0ms to call next() soon
3739
pbio_light_animation_start(&test_animation);
3840
tt_want(pbio_light_animation_is_started(&test_animation));
3941
tt_want(process_is_running(&pbio_light_animation_process));
42+
// Wait for events to be handled, so first animation frame is active.
43+
while (pbio_do_one_event()) {
44+
}
4045
tt_want_uint_op(test_animation_set_hsv_call_count, ==, 1);
4146

4247
// next() should not be called again until after a delay

lib/pbio/test/src/test_color_light.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <pbio/color.h>
1212
#include <pbio/error.h>
1313
#include <pbio/light.h>
14+
#include <pbio/main.h>
1415
#include <test-pbio.h>
1516

1617
#include "../src/light/color_light.h"
@@ -45,6 +46,15 @@ static const pbio_color_light_funcs_t test_light_funcs = {
4546
.set_hsv = test_light_set_hsv,
4647
};
4748

49+
/**
50+
* Handles pending events to ensure animation has started and first frame
51+
* has been activated.
52+
*/
53+
static void wait_for_first_animation_frame(void) {
54+
while (pbio_do_one_event()) {
55+
}
56+
}
57+
4858
static PT_THREAD(test_color_light(struct pt *pt)) {
4959
PT_BEGIN(pt);
5060

@@ -66,6 +76,7 @@ static PT_THREAD(test_color_light(struct pt *pt)) {
6676
// starting animation should call set_hsv() synchonously
6777
static const pbio_color_hsv_t hsv = { .h = PBIO_COLOR_HUE_BLUE, .s = 100, .v = 100 };
6878
pbio_color_light_start_blink_animation(&test_light, &hsv, test_blink);
79+
wait_for_first_animation_frame();
6980
tt_want_uint_op(test_light_set_hsv_call_count, ==, 1);
7081
// even blink cells turns the light on
7182
tt_want_uint_op(test_light_set_hsv_last_hue, ==, PBIO_COLOR_HUE_BLUE);
@@ -94,6 +105,7 @@ static PT_THREAD(test_color_light(struct pt *pt)) {
94105

95106
// starting animation should call set_hsv() synchonously
96107
pbio_color_light_start_animation(&test_light, TEST_ANIMATION_TIME, test_animation);
108+
wait_for_first_animation_frame();
97109
tt_want_uint_op(test_light_set_hsv_call_count, ==, 1);
98110
tt_want_uint_op(test_light_set_hsv_last_hue, ==, PBIO_COLOR_HUE_CYAN);
99111

lib/pbio/test/src/test_light_matrix.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <test-pbio.h>
1212

1313
#include <pbio/error.h>
14+
#include <pbio/main.h>
1415
#include <pbio/light_matrix.h>
1516

1617
#include "../src/light/light_matrix.h"
@@ -82,9 +83,12 @@ static PT_THREAD(test_light_matrix(struct pt *pt)) {
8283
IMAGE_DATA(1, 2, 3, 4, 5, 6, 7, 8, 9)), ==, PBIO_SUCCESS);
8384
tt_want_light_matrix_data(1, 2, 3, 4, 5, 6, 7, 8, 9);
8485

85-
// starting animation should call set_pixel() synchonously with the first cell data
86+
// starting animation should schedule timer event at 0 ms to call set_pixel() soon
8687
test_light_matrix_reset();
8788
pbio_light_matrix_start_animation(&test_light_matrix, test_animation, 2, INTERVAL);
89+
// Wait for events to be handled, so first animation frame is active.
90+
while (pbio_do_one_event()) {
91+
}
8892
tt_want_light_matrix_data(1, 2, 3, 4, 5, 6, 7, 8, 9);
8993

9094
// set_pixel() should not be called again until after a delay and it should

0 commit comments

Comments
 (0)