Skip to content

Commit c43465c

Browse files
committed
bricks/main: handle pending events before user program
Changes in how the HMI works requires that we handle events before starting the user program, otherwise the user program start event handlers will not run until after the user program has started which leads to race conditions with control of the hub lights. Fixes: pybricks/pybricks-micropython#13
1 parent f367be6 commit c43465c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

bricks/nxt/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ int main(int argc, char **argv) {
8585

8686
// Get system hardware ready
8787
pbsys_prepare_user_program(&user_program_callbacks);
88+
// make sure any pending events are handled before starting MicroPython
89+
while (pbio_do_one_event()) {
90+
}
8891

8992
// Initialize MicroPython and run default imports
9093
mp_init();

bricks/stm32/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ int main(int argc, char **argv) {
286286

287287
// Get system hardware ready
288288
pbsys_prepare_user_program(&user_program_callbacks);
289+
// make sure any pending events are handled before starting MicroPython
290+
while (pbio_do_one_event()) {
291+
}
292+
289293
mp_init();
290294

291295
// Execute the user script

0 commit comments

Comments
 (0)