Resample shutdown before disabling gates in ALWAYS_OFF mode

This commit is contained in:
dcode 2024-01-02 15:28:37 +01:00
parent a9a1faf317
commit c87d2032ea
1 changed files with 17 additions and 7 deletions

View File

@ -72,7 +72,7 @@ void shutdown_hold(bool hold) {
m_shutdown_hold = hold; m_shutdown_hold = hold;
} }
static bool do_shutdown(void) { static bool do_shutdown(bool resample) {
conf_general_store_backup_data(); conf_general_store_backup_data();
#ifdef USE_LISPBM #ifdef USE_LISPBM
lispif_process_shutdown(); lispif_process_shutdown();
@ -83,9 +83,19 @@ static bool do_shutdown(void) {
chThdSleepMilliseconds(5); chThdSleepMilliseconds(5);
} }
DISABLE_GATE(); bool disable_gates = true;
HW_SHUTDOWN_HOLD_OFF(); if (resample) {
return true; chMtxLock(&m_sample_mutex);
if (!m_sampling_disabled) {
disable_gates = HW_SAMPLE_SHUTDOWN();
}
chMtxUnlock(&m_sample_mutex);
}
if (disable_gates) {
DISABLE_GATE();
HW_SHUTDOWN_HOLD_OFF();
}
return disable_gates;
} }
static THD_FUNCTION(shutdown_thread, arg) { static THD_FUNCTION(shutdown_thread, arg) {
@ -124,7 +134,7 @@ static THD_FUNCTION(shutdown_thread, arg) {
switch (conf->shutdown_mode) { switch (conf->shutdown_mode) {
case SHUTDOWN_MODE_ALWAYS_OFF: case SHUTDOWN_MODE_ALWAYS_OFF:
if (m_button_pressed) { if (m_button_pressed) {
gates_disabled_here = do_shutdown(); gates_disabled_here = do_shutdown(true);
} }
break; break;
@ -146,7 +156,7 @@ static THD_FUNCTION(shutdown_thread, arg) {
default: default:
if (clicked) { if (clicked) {
gates_disabled_here = do_shutdown(); gates_disabled_here = do_shutdown(false);
} }
break; break;
} }
@ -179,7 +189,7 @@ static THD_FUNCTION(shutdown_thread, arg) {
} }
if (m_inactivity_time >= shutdown_timeout && m_button_pressed) { if (m_inactivity_time >= shutdown_timeout && m_button_pressed) {
gates_disabled_here = do_shutdown(); gates_disabled_here = do_shutdown(false);
} }
} }