Use 30-second elapsed button hold and bounded reboot UART wait

This commit is contained in:
raduet committed 2026-10-15 10:39:39 +02:00
1 parent 4f33a19387
commit 1c0811d343
6 files changed
+8876 -8854

No files matched your search

+12 -6
View File
@@ -110,7 +110,9 @@ void ED_Delay(uint32_t Delay)
static void StopButtonControl(void){ static void StopButtonControl(void){
static uint32_t tick; static uint32_t tick;
static uint32_t hold_time; static uint32_t pressed_at;
static uint8_t holding;
static uint8_t unlocked;
static uint8_t stop_btn_fault = 1; static uint8_t stop_btn_fault = 1;
uint32_t now = HAL_GetTick(); uint32_t now = HAL_GetTick();
@@ -130,14 +132,17 @@ static void StopButtonControl(void){
} }
if(pressed){ if(pressed){
if(hold_time == 0){ if(!holding){
pressed_at = now;
holding = 1;
CONN.connControl = CMD_STOP; CONN.connControl = CMD_STOP;
} }
hold_time += 10; uint32_t hold_time = now - pressed_at;
if(hold_time == 5000){ if(!unlocked && hold_time >= 5000u){
unlocked = 1;
CONN.connControl = CMD_FORCE_UNLOCK; CONN.connControl = CMD_FORCE_UNLOCK;
} }
if(hold_time > 40000){ if(hold_time >= 30000u){
SC_SendPacket(NULL, 0, EVENT_HOST_REBOOT); SC_SendPacket(NULL, 0, EVENT_HOST_REBOOT);
{ {
uint32_t t0 = HAL_GetTick(); uint32_t t0 = HAL_GetTick();
@@ -153,7 +158,8 @@ static void StopButtonControl(void){
} }
} }
else{ else{
hold_time = 0; holding = 0;
unlocked = 0;
} }
} }
+9 -1
View File
@@ -116,7 +116,15 @@ void SC_CommandHandler(ReceivedCommand_t* cmd) {
// 2. Отправляем SUCCESS (хост может успеть получить его перед ребутом) // 2. Отправляем SUCCESS (хост может успеть получить его перед ребутом)
SC_SendPacket(NULL, 0, RESP_SUCCESS); SC_SendPacket(NULL, 0, RESP_SUCCESS);
while(huart2.gState == HAL_UART_STATE_BUSY_TX); // Ожидание завершения передачи {
uint32_t t0 = HAL_GetTick();
while (huart2.gState == HAL_UART_STATE_BUSY_TX) {
if ((HAL_GetTick() - t0) > 50u) {
(void)HAL_UART_AbortTransmit(&huart2);
break;
}
}
} // Ожидание завершения передачи
HAL_Delay(10); HAL_Delay(10);
// 3. Выполняем программный сброс // 3. Выполняем программный сброс
Binary file not shown.
Binary file not shown.
+4428 -4424
View File
File diff suppressed because it is too large. Load diff
+4427 -4423
View File
File diff suppressed because it is too large. Load diff