forked from achamaikin/CCSModuleSW30Web
Use 30-second elapsed button hold and bounded reboot UART wait
This commit is contained in:
1 parent
4f33a19387
commit
1c0811d343
6 files changed
+8876
-8854
No files matched your search
+12
-6
@@ -110,7 +110,9 @@ void ED_Delay(uint32_t Delay)
|
||||
|
||||
static void StopButtonControl(void){
|
||||
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;
|
||||
uint32_t now = HAL_GetTick();
|
||||
|
||||
@@ -130,14 +132,17 @@ static void StopButtonControl(void){
|
||||
}
|
||||
|
||||
if(pressed){
|
||||
if(hold_time == 0){
|
||||
if(!holding){
|
||||
pressed_at = now;
|
||||
holding = 1;
|
||||
CONN.connControl = CMD_STOP;
|
||||
}
|
||||
hold_time += 10;
|
||||
if(hold_time == 5000){
|
||||
uint32_t hold_time = now - pressed_at;
|
||||
if(!unlocked && hold_time >= 5000u){
|
||||
unlocked = 1;
|
||||
CONN.connControl = CMD_FORCE_UNLOCK;
|
||||
}
|
||||
if(hold_time > 40000){
|
||||
if(hold_time >= 30000u){
|
||||
SC_SendPacket(NULL, 0, EVENT_HOST_REBOOT);
|
||||
{
|
||||
uint32_t t0 = HAL_GetTick();
|
||||
@@ -153,7 +158,8 @@ static void StopButtonControl(void){
|
||||
}
|
||||
}
|
||||
else{
|
||||
hold_time = 0;
|
||||
holding = 0;
|
||||
unlocked = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,15 @@ void SC_CommandHandler(ReceivedCommand_t* cmd) {
|
||||
// 2. Отправляем 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);
|
||||
// 3. Выполняем программный сброс
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+4428
-4424
File diff suppressed because it is too large.
Load diff
+4427
-4423
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user