Skip to content

Commit e1d0567

Browse files
committed
pbio/sys/hmi: Use standard mechanism for shutdown animation.
Now that this is integrated in the HMI and already implemented for the light matrix, we can also use it for the single LED hubs. This way we don't need a hardcoded number in sys/core just to keep an animation going.
1 parent 1cdfa97 commit e1d0567

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

lib/pbio/sys/core.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,8 @@ void pbsys_deinit(void) {
8989
pbsys_storage_deinit();
9090
pbsys_hmi_deinit();
9191

92-
uint32_t start = pbdrv_clock_get_ms();
93-
94-
// Wait for all relevant pbsys processes to end, but at least 500 ms so we
95-
// see a shutdown animation even if the button is released sooner.
96-
while (pbio_busy_count_busy() || pbdrv_clock_get_ms() - start < 500) {
92+
// Wait for all relevant pbsys processes to end.
93+
while (pbio_busy_count_busy()) {
9794
pbio_os_run_processes_and_wait_for_event();
9895
}
9996
}

lib/pbio/sys/hmi_pup.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ static pbio_error_t boot_animation_process_boot_thread(pbio_os_state_t *state, v
8282
PBIO_OS_ASYNC_END(PBIO_SUCCESS);
8383
}
8484

85+
// Boot and shutdown animation are the same.
86+
static pbio_os_process_func_t boot_animation_process_shutdown_thread = boot_animation_process_boot_thread;
87+
8588
/**
8689
* Animation frame for program running animation.
8790
*/
@@ -115,10 +118,24 @@ static void light_matrix_start_run_animation(void) {
115118
pbio_light_animation_start(&pbsys_hub_light_matrix->animation);
116119
}
117120

118-
static pbio_os_process_t boot_animation_process;
121+
#else
122+
123+
/**
124+
* This shutdown "animation" just pauses for half a second. The actual animation
125+
* is handled by the system light based on the shutdown status.
126+
*/
127+
static pbio_error_t boot_animation_process_shutdown_thread(pbio_os_state_t *state, void *context) {
128+
static pbio_os_timer_t timer;
129+
PBIO_OS_ASYNC_BEGIN(state);
130+
PBIO_OS_AWAIT_MS(state, &timer, 500);
131+
pbio_busy_count_down();
132+
PBIO_OS_ASYNC_END(PBIO_SUCCESS);
133+
}
119134

120135
#endif
121136

137+
static pbio_os_process_t boot_animation_process;
138+
122139
void pbsys_hmi_init(void) {
123140
#if PBIO_CONFIG_LIGHT_MATRIX
124141
pbio_busy_count_up();
@@ -136,10 +153,8 @@ void pbsys_hmi_deinit(void) {
136153
pbsys_status_clear(PBIO_PYBRICKS_STATUS_BLE_HOST_CONNECTED);
137154
pbsys_status_clear(PBIO_PYBRICKS_STATUS_USB_HOST_CONNECTED);
138155

139-
#if PBIO_CONFIG_LIGHT_MATRIX
140156
pbio_busy_count_up();
141-
pbio_os_process_start(&boot_animation_process, boot_animation_process_boot_thread, (void *)false);
142-
#endif
157+
pbio_os_process_start(&boot_animation_process, boot_animation_process_shutdown_thread, (void *)false);
143158
}
144159

145160
/**

0 commit comments

Comments
 (0)