From cf3a92f937ac4cd0623d902bf275664851c51442 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Mon, 25 Mar 2024 20:04:27 +0800 Subject: [PATCH] revised with lower power --- Core/Src/stm32_lpm_if.c | 5 ++--- LoRaWAN/App/lora_app.c | 29 +++++++++++++++++------------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Core/Src/stm32_lpm_if.c b/Core/Src/stm32_lpm_if.c index 011fc57..4ee647a 100644 --- a/Core/Src/stm32_lpm_if.c +++ b/Core/Src/stm32_lpm_if.c @@ -25,7 +25,7 @@ #include "usart_if.h" /* USER CODE BEGIN Includes */ - +#include "gpio.h" /* USER CODE END Includes */ /* External variables ---------------------------------------------------------*/ @@ -94,11 +94,10 @@ void PWR_EnterStopMode(void) /* USER CODE BEGIN EnterStopMode_1 */ /* USER CODE END EnterStopMode_1 */ - HAL_GPIO_DeInit(GPIOA,GPIO_PIN_0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_All, GPIO_PIN_RESET); //HAL_GPIO_WritePin(GPIOC, GPIO_PIN_All, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_All, GPIO_PIN_RESET); - + HAL_GPIO_DeInit(GPIOA,GPIO_PIN_0); HAL_SuspendTick(); /* Clear Status Flag before entering STOP/STANDBY Mode */ LL_PWR_ClearFlag_C1STOP_C1STB(); diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 41608db..3bcfabc 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -446,9 +446,19 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { case BUT1_Pin: /* Note: when "EventType == TX_ON_TIMER" this GPIO is not initialized */ + + HAL_Delay(10); //eliminate bouncing back 5ms + door_status = HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0); + + if (door_status != door_previous_status) + { + door_changed_flag = 1; + door_previous_status = door_status; + } + //if (EventType == TX_ON_EVENT) { - door_changed_flag =1; + // door_changed_flag =1; UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); } break; @@ -558,13 +568,7 @@ static void SendTxData(void) sensor_t sensor_data; UTIL_TIMER_Time_t nextTxIn = 0; - HAL_Delay(10); //eliminate bouncing back 5ms - door_status = HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0); - door_changed_flag = 0; - if (door_status != door_previous_status) - { - door_previous_status = door_status; - } + #if 0 if (door_changed_flag ==1 ) @@ -702,11 +706,12 @@ static void OnTxTimerEvent(void *context) } #endif MX_GPIO_Init(); - //door_status = HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0); - //door_changed_flag = 0; - //if (door_status != door_previous_status) + door_status = HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0); + + if (door_status != door_previous_status) { - //door_previous_status = door_status; + door_changed_flag = 1; + door_previous_status = door_status; UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);