Skip to content

Commit 9acd3ec

Browse files
committed
only play shutdown pattern after button is released
1 parent cddad07 commit 9acd3ec

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

src/system/system.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -422,27 +422,24 @@ int sys_user_shutdown(void)
422422
{
423423
int64_t start_time = k_uptime_get();
424424
bool use_shutdown = CONFIG_0_SETTINGS_READ(CONFIG_0_USER_SHUTDOWN);
425+
set_led(SYS_LED_PATTERN_LONG, SYS_LED_PRIORITY_HIGHEST);
426+
while (button_read()) // If alternate button is available and still pressed, wait for the user to stop pressing the button
427+
{
428+
if (k_uptime_get() - start_time > 4000) // held for over 5 seconds, cancel shutdown
429+
{
430+
set_led(SYS_LED_PATTERN_OFF, SYS_LED_PRIORITY_HIGHEST);
431+
return 1;
432+
}
433+
k_msleep(1);
434+
}
425435
if (use_shutdown)
426436
{
427437
LOG_INF("User shutdown requested");
428-
reboot_counter_write(0);
429438
set_led(SYS_LED_PATTERN_ONESHOT_POWEROFF, SYS_LED_PRIORITY_HIGHEST);
439+
k_msleep(1500);
440+
reboot_counter_write(0);
430441
}
431-
k_msleep(1500);
432-
if (button_read()) // If alternate button is available and still pressed, wait for the user to stop pressing the button
433-
{
434-
set_led(SYS_LED_PATTERN_LONG, SYS_LED_PRIORITY_HIGHEST);
435-
while (button_read())
436-
{
437-
if (k_uptime_get() - start_time > 4000) // held for over 5 seconds, cancel shutdown
438-
{
439-
set_led(SYS_LED_PATTERN_OFF, SYS_LED_PRIORITY_HIGHEST);
440-
return 1;
441-
}
442-
k_msleep(1);
443-
}
444-
set_led(SYS_LED_PATTERN_OFF_FORCE, SYS_LED_PRIORITY_HIGHEST);
445-
}
442+
set_led(SYS_LED_PATTERN_OFF_FORCE, SYS_LED_PRIORITY_HIGHEST);
446443
if (use_shutdown)
447444
sys_request_system_off(false);
448445
else

0 commit comments

Comments
 (0)