diff --git a/lib/pbio/test/src/test_animation.c b/lib/pbio/test/src/test_animation.c index 05ff2fc55..ed5bb1d57 100644 --- a/lib/pbio/test/src/test_animation.c +++ b/lib/pbio/test/src/test_animation.c @@ -9,6 +9,8 @@ #include +#include + #include "../src/light/animation.h" #include "../drv/clock/clock_test.h" @@ -33,10 +35,13 @@ static PT_THREAD(test_light_animation(struct pt *pt)) { tt_want(!process_is_running(&pbio_light_animation_process)); tt_want(!pbio_light_animation_is_started(&test_animation)); - // starting animation should start process and call next() once synchonously + // starting animation should start process and set a timer at 0ms to call next() soon pbio_light_animation_start(&test_animation); tt_want(pbio_light_animation_is_started(&test_animation)); tt_want(process_is_running(&pbio_light_animation_process)); + // Wait for events to be handled, so first animation frame is active. + while (pbio_do_one_event()) { + } tt_want_uint_op(test_animation_set_hsv_call_count, ==, 1); // next() should not be called again until after a delay diff --git a/lib/pbio/test/src/test_color_light.c b/lib/pbio/test/src/test_color_light.c index 346599b68..0e4ed9a67 100644 --- a/lib/pbio/test/src/test_color_light.c +++ b/lib/pbio/test/src/test_color_light.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "../src/light/color_light.h" @@ -45,6 +46,15 @@ static const pbio_color_light_funcs_t test_light_funcs = { .set_hsv = test_light_set_hsv, }; +/** + * Handles pending events to ensure animation has started and first frame + * has been activated. + */ +static void wait_for_first_animation_frame(void) { + while (pbio_do_one_event()) { + } +} + static PT_THREAD(test_color_light(struct pt *pt)) { PT_BEGIN(pt); @@ -66,6 +76,7 @@ static PT_THREAD(test_color_light(struct pt *pt)) { // starting animation should call set_hsv() synchonously static const pbio_color_hsv_t hsv = { .h = PBIO_COLOR_HUE_BLUE, .s = 100, .v = 100 }; pbio_color_light_start_blink_animation(&test_light, &hsv, test_blink); + wait_for_first_animation_frame(); tt_want_uint_op(test_light_set_hsv_call_count, ==, 1); // even blink cells turns the light on 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)) { // starting animation should call set_hsv() synchonously pbio_color_light_start_animation(&test_light, TEST_ANIMATION_TIME, test_animation); + wait_for_first_animation_frame(); tt_want_uint_op(test_light_set_hsv_call_count, ==, 1); tt_want_uint_op(test_light_set_hsv_last_hue, ==, PBIO_COLOR_HUE_CYAN); diff --git a/lib/pbio/test/src/test_light_matrix.c b/lib/pbio/test/src/test_light_matrix.c index 0db48c23d..a5b196cc5 100644 --- a/lib/pbio/test/src/test_light_matrix.c +++ b/lib/pbio/test/src/test_light_matrix.c @@ -11,6 +11,7 @@ #include #include +#include #include #include "../src/light/light_matrix.h" @@ -82,9 +83,12 @@ static PT_THREAD(test_light_matrix(struct pt *pt)) { IMAGE_DATA(1, 2, 3, 4, 5, 6, 7, 8, 9)), ==, PBIO_SUCCESS); tt_want_light_matrix_data(1, 2, 3, 4, 5, 6, 7, 8, 9); - // starting animation should call set_pixel() synchonously with the first cell data + // starting animation should schedule timer event at 0 ms to call set_pixel() soon test_light_matrix_reset(); pbio_light_matrix_start_animation(&test_light_matrix, test_animation, 2, INTERVAL); + // Wait for events to be handled, so first animation frame is active. + while (pbio_do_one_event()) { + } tt_want_light_matrix_data(1, 2, 3, 4, 5, 6, 7, 8, 9); // set_pixel() should not be called again until after a delay and it should