Skip to content

Commit

Permalink
!squash: Handle events before expecting light animation frame.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensvalk committed Oct 3, 2024
1 parent 920c812 commit dc2f38c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/pbio/test/src/test_animation.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <test-pbio.h>

#include <pbio/main.h>

#include "../src/light/animation.h"
#include "../drv/clock/clock_test.h"

Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions lib/pbio/test/src/test_color_light.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <pbio/color.h>
#include <pbio/error.h>
#include <pbio/light.h>
#include <pbio/main.h>
#include <test-pbio.h>

#include "../src/light/color_light.h"
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion lib/pbio/test/src/test_light_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <test-pbio.h>

#include <pbio/error.h>
#include <pbio/main.h>
#include <pbio/light_matrix.h>

#include "../src/light/light_matrix.h"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dc2f38c

Please sign in to comment.