Quellcode durchsuchen

添加SOS按键损坏,导致一直发SOS

xuxinyi vor 2 Monaten
Ursprung
Commit
c3828ff41c
1 geänderte Dateien mit 13 neuen und 12 gelöschten Zeilen
  1. 13 12
      Core/Src/main.c

+ 13 - 12
Core/Src/main.c

@@ -363,18 +363,19 @@ int main(void)
       }
     }
 
-    // if (deviceInfo.isSOS) {
-    //   RTC_TimeTypeDef now = {0};
-    //   HAL_RTC_GetTime(&hrtc, &now, RTC_FORMAT_BIN);
-    //
-    //   int pressedSeconds = (now.Hours * 3600 + now.Minutes * 60 + now.Seconds)
-    //                      - (SOS_struct.Hours * 3600 + SOS_struct.Minutes * 60 + SOS_struct.Seconds);
-    //   if (pressedSeconds < 0) pressedSeconds += 24 * 3600;
-    //
-    //   if (pressedSeconds >= 120) { //如果出现异常情况,导致SOS一直处于被按下情况,关闭SOS。
-    //     deviceInfo.isSOS = FALSE;
-    //   }
-    // }
+    if (deviceInfo.isSOS) {
+      RTC_TimeTypeDef now = {0};
+      HAL_RTC_GetTime(&hrtc, &now, RTC_FORMAT_BIN);
+
+      int pressedSeconds = (now.Hours * 3600 + now.Minutes * 60 + now.Seconds)
+                         - (SOS_struct.Hours * 3600 + SOS_struct.Minutes * 60 + SOS_struct.Seconds);
+      if (pressedSeconds < 0) pressedSeconds += 24 * 3600;
+      printf("SOS按下时间为:%d\r\n",pressedSeconds);
+
+      if (pressedSeconds >= 20) { //如果出现异常情况,导致SOS一直处于被按下情况,关闭SOS。
+        deviceInfo.isSOS = FALSE;
+      }
+    }
 
 
     // 解析后台命令