From 172b589397e9fd2d3c5469b0e893737e07447035 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Mon, 17 Jun 2024 12:34:10 +0800 Subject: [PATCH] try PIR --- LoRaWAN/App/lora_app.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 6dc2f40..178c62d 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -53,6 +53,7 @@ volatile uint8_t sts_ac_code[YUNHORN_STS_AC_CODE_SIZE]={0x0}; extern hmac_result_t hmac_result; extern volatile uint8_t sts_reed_hall_ext_int; extern volatile uint8_t sts_hall1_read, sts_hall2_read; +volatile uint8_t last_sts_hall1_read=0; extern volatile uint8_t sts_reed_hall_1_changed, sts_reed_hall_2_changed; volatile uint8_t sts_reed_hall_result =0, sts_emergency_button_pushed=0; // inital 0 = close extern volatile uint8_t sts_work_mode, sts_cloud_netcolor, sts_lamp_bar_color, sts_status_color; @@ -689,18 +690,22 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) case HALL1_Pin: if (sts_reed_hall_1_changed) { - HAL_Delay(250); //de-bouncing - sts_hall1_read = HALL1_STATE; - APP_LOG(TS_OFF, VLEVEL_M, "\n\n Door Contact Read = %02x --%20s\r\n", HALL1_STATE, (HALL1_STATE==STS_Status_Door_Close)?"Door Closed":"Door Opened"); - OnSensor1StateChanged(); - /* Note: when "EventType == TX_ON_TIMER" this GPIO is not initialized */ - // if (EventType == TX_ON_EVENT) - { - //sensor_data_ready =1; - UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP1), CFG_SEQ_Prio_0); - UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); - } - //sts_reed_hall_1_changed =0; + HAL_Delay(250); //de-bouncing + sts_hall1_read = HALL1_STATE; + //if (last_sts_hall1_read !=sts_hall1_read) + { + APP_LOG(TS_OFF, VLEVEL_M, "\n\n Door Contact Read = %02x --%20s\r\n", HALL1_STATE, (HALL1_STATE==STS_Status_Door_Close)?"Door Closed":"Door Opened"); + OnSensor1StateChanged(); + /* Note: when "EventType == TX_ON_TIMER" this GPIO is not initialized */ + // if (EventType == TX_ON_EVENT) + { + //sensor_data_ready =1; + UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP1), CFG_SEQ_Prio_0); + UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); + } + //sts_reed_hall_1_changed =0; + last_sts_hall1_read = sts_hall1_read; + } } break;