|
|
@@ -415,24 +415,28 @@ void RTC_Alarm_IRQHandler(void)
|
|
|
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
|
|
|
RTC_TimeTypeDef currentTime = {0};
|
|
|
HAL_RTC_GetTime(&hrtc, ¤tTime, RTC_FORMAT_BIN);
|
|
|
+
|
|
|
// ===== SOS_KEY =====
|
|
|
if (GPIO_Pin == SOS_KEY_Pin) {
|
|
|
if (HAL_GPIO_ReadPin(SOS_KEY_GPIO_Port, SOS_KEY_Pin) == GPIO_PIN_SET) {
|
|
|
// 松开(上升沿)
|
|
|
printf("SOS_KEY 松开\r\n");
|
|
|
|
|
|
- printf("Current time: %02d:%02d:%02d\n",
|
|
|
- currentTime.Hours,
|
|
|
- currentTime.Minutes,
|
|
|
- currentTime.Seconds);
|
|
|
+ // 计算按下时间
|
|
|
+ int pressedSeconds = (currentTime.Hours * 3600 + currentTime.Minutes * 60 + currentTime.Seconds)
|
|
|
+ - (SOS_key_struct.Hours * 3600 + SOS_key_struct.Minutes * 60 + SOS_key_struct.Seconds);
|
|
|
+
|
|
|
+ // 防止跨天导致负值
|
|
|
+ if (pressedSeconds < 0) {
|
|
|
+ pressedSeconds += 24 * 3600;
|
|
|
+ }
|
|
|
+
|
|
|
+ printf("SOS_KEY 按下持续时间: %d 秒\r\n", pressedSeconds);
|
|
|
+
|
|
|
} else {
|
|
|
// 按下(下降沿)
|
|
|
printf("SOS_KEY 按下\r\n");
|
|
|
- // SOS_key_struct = currentTime;
|
|
|
- printf("Current time: %02d:%02d:%02d\n",
|
|
|
- currentTime.Hours,
|
|
|
- currentTime.Minutes,
|
|
|
- currentTime.Seconds);
|
|
|
+ SOS_key_struct = currentTime;
|
|
|
}
|
|
|
}
|
|
|
// ===== JUGE_KEY =====
|
|
|
@@ -440,17 +444,19 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
|
|
|
if (HAL_GPIO_ReadPin(JUGE_PIN_GPIO_Port, JUGE_PIN_Pin) == GPIO_PIN_SET) {
|
|
|
// 松开(上升沿)
|
|
|
printf("JUGE_KEY 松开\r\n");
|
|
|
- printf("Current time: %02d:%02d:%02d\n",
|
|
|
- currentTime.Hours,
|
|
|
- currentTime.Minutes,
|
|
|
- currentTime.Seconds);
|
|
|
+
|
|
|
+ int pressedSeconds = (currentTime.Hours * 3600 + currentTime.Minutes * 60 + currentTime.Seconds)
|
|
|
+ - (JUGE_key_struct.Hours * 3600 + JUGE_key_struct.Minutes * 60 + JUGE_key_struct.Seconds);
|
|
|
+ if (pressedSeconds < 0) {
|
|
|
+ pressedSeconds += 24 * 3600;
|
|
|
+ }
|
|
|
+
|
|
|
+ printf("JUGE_KEY 按下持续时间: %d 秒\r\n", pressedSeconds);
|
|
|
+
|
|
|
} else {
|
|
|
// 按下(下降沿)
|
|
|
printf("JUGE_KEY 按下\r\n");
|
|
|
- printf("Current time: %02d:%02d:%02d\n",
|
|
|
- currentTime.Hours,
|
|
|
- currentTime.Minutes,
|
|
|
- currentTime.Seconds);
|
|
|
+ JUGE_key_struct = currentTime;
|
|
|
}
|
|
|
}
|
|
|
}
|