xuxinyi 2 сар өмнө
parent
commit
7722741a90
2 өөрчлөгдсөн 43 нэмэгдсэн , 41 устгасан
  1. 21 19
      Core/Src/main.c
  2. 22 22
      Core/Src/stm32f1xx_it.c

+ 21 - 19
Core/Src/main.c

@@ -311,25 +311,27 @@ int main(void)
       }
       HAL_Delay(3000);
     }
-
-    if (SOS_key_struct.sosCheckActive) {
-      RTC_DateTimeTypeDef now;
-      RTC_GetDateTime(&hrtc, &now);
-
-      uint32_t diffSec = RTC_CalcDiffSeconds(&firstPressTime, &now);
-      if (diffSec > 60) {
-        // 超过5秒,停止检测
-        if (SOS_key_struct.SOS_key_Count >= 5) {
-          printf("SOS TRIGGERED!!!\r\n");
-          // TODO: 触发SOS逻辑
-        }
-        // 重置状态
-        SOS_key_struct.sosCheckActive = FALSE;
-        SOS_key_struct.SOS_key_Count = 0;
-      }else {
-
-      }
-    }
+    GPIO_PinState state;
+    state = HAL_GPIO_ReadPin(SOS_KEY_GPIO_Port, SOS_KEY_Pin);
+    printf("SOS_KEY_Pin pin state = %d\r\n", state);
+    // if (SOS_key_struct.sosCheckActive) {
+    //   RTC_DateTimeTypeDef now;
+    //   RTC_GetDateTime(&hrtc, &now);
+    //
+    //   uint32_t diffSec = RTC_CalcDiffSeconds(&firstPressTime, &now);
+    //   if (diffSec > 60) {
+    //     // 超过5秒,停止检测
+    //     if (SOS_key_struct.SOS_key_Count >= 5) {
+    //       printf("SOS TRIGGERED!!!\r\n");
+    //       // TODO: 触发SOS逻辑
+    //     }
+    //     // 重置状态
+    //     SOS_key_struct.sosCheckActive = FALSE;
+    //     SOS_key_struct.SOS_key_Count = 0;
+    //   }else {
+    //
+    //   }
+    // }
 
     // 03:请求蓝牙数据
     if (GET_CMD( deviceInfo.commandFromCloud)  == REQUEST_BLUETOOTH_DATA && deviceInfo.isOnline) {

+ 22 - 22
Core/Src/stm32f1xx_it.c

@@ -378,28 +378,28 @@ void EXTI15_10_IRQHandler(void) {
 
   /* USER CODE END EXTI15_10_IRQn 0 */
   HAL_GPIO_EXTI_IRQHandler(SOS_KEY_Pin);
-  printf("I AM SOS KEY\r\n");
-  RTC_DateTimeTypeDef currentDT;
-  // 读取当前时间日期
-  RTC_GetDateTime(&hrtc, &currentDT);
-
-  if (SOS_key_struct.sosCheckActive == 0) {
-    // 第一次触发,记录时间
-    firstPressTime = currentDT;
-    SOS_key_struct.SOS_key_Count = 1;
-    SOS_key_struct.sosCheckActive = TRUE;
-  } else {
-    // 后续触发,只计数
-    SOS_key_struct.SOS_key_Count++;
-  }
-
-  printf("当前时间: %02X:%02X:%02X\n",
-     currentDT.hours, currentDT.minutes, currentDT.seconds);
-  // printf("当前日期: 20%02X年%02X月%02X日 星期%d\n",
-  //        currentDT.year, currentDT.month, currentDT.date, currentDT.weekday);
-
-  printf("第一次按下时间: %02X:%02X:%02X\n",
-       firstPressTime.hours, firstPressTime.minutes, firstPressTime.seconds);
+  // printf("I AM SOS KEY\r\n");
+  // RTC_DateTimeTypeDef currentDT;
+  // // 读取当前时间日期
+  // RTC_GetDateTime(&hrtc, &currentDT);
+  //
+  // if (SOS_key_struct.sosCheckActive == 0) {
+  //   // 第一次触发,记录时间
+  //   firstPressTime = currentDT;
+  //   SOS_key_struct.SOS_key_Count = 1;
+  //   SOS_key_struct.sosCheckActive = TRUE;
+  // } else {
+  //   // 后续触发,只计数
+  //   SOS_key_struct.SOS_key_Count++;
+  // }
+  //
+  // printf("当前时间: %02X:%02X:%02X\n",
+  //    currentDT.hours, currentDT.minutes, currentDT.seconds);
+  // // printf("当前日期: 20%02X年%02X月%02X日 星期%d\n",
+  // //        currentDT.year, currentDT.month, currentDT.date, currentDT.weekday);
+  //
+  // printf("第一次按下时间: %02X:%02X:%02X\n",
+  //      firstPressTime.hours, firstPressTime.minutes, firstPressTime.seconds);
   // printf("第一次按下日期: 20%02X年%02X月%02X日 星期%d\n",
   //        firstPressTime.year, firstPressTime.month, firstPressTime.date, firstPressTime.weekday);