diff --git a/CHANGELOG.md b/CHANGELOG.md index aec3055d8..2edca6af6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,12 +22,15 @@ argument as already active ([support#1858]). - Fixed lockup and reboot with f-strings and slice allocations in tight loops ([support#1668]). +- Fixed program restarting if the stop button was held to end the program + without an exception ([support#1863]). [support#1623]: https://github.com/pybricks/support/issues/1623 [support#1661]: https://github.com/pybricks/support/issues/1661 [support#1668]: https://github.com/pybricks/support/issues/1668 [support#1846]: https://github.com/pybricks/support/issues/1846 [support#1858]: https://github.com/pybricks/support/issues/1858 +[support#1863]: https://github.com/pybricks/support/issues/1863 ## [3.6.0b1] - 2024-09-24 diff --git a/lib/pbio/sys/hmi.c b/lib/pbio/sys/hmi.c index 41b5db23a..fb32a52da 100644 --- a/lib/pbio/sys/hmi.c +++ b/lib/pbio/sys/hmi.c @@ -40,16 +40,15 @@ static uint8_t selected_slot = 0; */ static PT_THREAD(update_program_run_button_wait_state(bool button_pressed)) { struct pt *pt = &update_program_run_button_wait_state_pt; - // Creative use of protothread to reduce code size. This is the same - // as checking if the user program is running after each PT_WAIT. + + // This should not be active while a program is running. if (pbsys_status_test(PBIO_PYBRICKS_STATUS_USER_PROGRAM_RUNNING)) { - goto start; + PT_EXIT(pt); } PT_BEGIN(pt); for (;;) { - start: // button may still be pressed from power on or user program stop PT_WAIT_UNTIL(pt, !button_pressed); PT_WAIT_UNTIL(pt, button_pressed); @@ -73,16 +72,15 @@ static struct pt update_bluetooth_button_wait_state_pt; */ static PT_THREAD(update_bluetooth_button_wait_state(bool button_pressed)) { struct pt *pt = &update_bluetooth_button_wait_state_pt; - // Creative use of protothread to reduce code size. This is the same - // as checking if the user program is running after each PT_WAIT. + + // This should not be active while a program is running. if (pbsys_status_test(PBIO_PYBRICKS_STATUS_USER_PROGRAM_RUNNING)) { - goto start; + PT_EXIT(pt); } PT_BEGIN(pt); for (;;) { - start: // button may still be pressed during user program PT_WAIT_UNTIL(pt, !button_pressed); PT_WAIT_UNTIL(pt, button_pressed); @@ -115,10 +113,10 @@ uint8_t pbsys_hmi_get_selected_program_slot(void) { */ static PT_THREAD(update_left_right_button_wait_state(bool left_button_pressed, bool right_button_pressed)) { struct pt *pt = &update_left_right_button_wait_state_pt; - // Creative use of protothread to reduce code size. This is the same - // as checking if the user program is running after each PT_WAIT. + + // This should not be active while a program is running. if (pbsys_status_test(PBIO_PYBRICKS_STATUS_USER_PROGRAM_RUNNING)) { - goto start; + PT_EXIT(pt); } static uint8_t previous_slot; @@ -127,7 +125,6 @@ static PT_THREAD(update_left_right_button_wait_state(bool left_button_pressed, b PT_BEGIN(pt); for (;;) { - start: // Buttons may still be pressed during user program PT_WAIT_UNTIL(pt, !left_button_pressed && !right_button_pressed);