diff --git a/Core/Inc/sys_conf.h b/Core/Inc/sys_conf.h index 871fadc..bcb45b4 100644 --- a/Core/Inc/sys_conf.h +++ b/Core/Inc/sys_conf.h @@ -47,7 +47,7 @@ extern "C" { /** * @brief Verbose level for all trace logs */ -#define VERBOSE_LEVEL VLEVEL_M +#define VERBOSE_LEVEL VLEVEL_L /** * @brief Enable trace logs diff --git a/Core/Inc/yunhorn_sts_sensors.h b/Core/Inc/yunhorn_sts_sensors.h index 1e92e82..291ca7e 100644 --- a/Core/Inc/yunhorn_sts_sensors.h +++ b/Core/Inc/yunhorn_sts_sensors.h @@ -186,14 +186,19 @@ typedef struct STS_OO_SensorStatusDataTypeDef uint8_t dutycycletimelevel; /* level=0,255 */ uint8_t sts_service_mask; /* sts service mask */ uint32_t event_sensor1_start_time; + uint32_t event_sensor1_stop_time; uint32_t event_sensor1_duration; uint32_t event_sensor2_start_time; + uint32_t event_sensor2_stop_time; uint32_t event_sensor2_duration; uint32_t event_sensor3_motion_start_time; + uint32_t event_sensor3_motion_stop_time; uint32_t event_sensor3_motion_duration; uint32_t event_sensor3_fall_start_time; + uint32_t event_sensor3_fall_stop_time; uint32_t event_sensor3_fall_duration; uint32_t event_sensor4_start_time; + uint32_t event_sensor4_stop_time; uint32_t event_sensor4_duration; uint8_t alarm_indictor_mute_state; uint8_t alarm_indictor_reset_state; diff --git a/Core/Src/yunhorn_sts_process.c b/Core/Src/yunhorn_sts_process.c index fd0f106..3ef3210 100644 --- a/Core/Src/yunhorn_sts_process.c +++ b/Core/Src/yunhorn_sts_process.c @@ -585,14 +585,19 @@ void STS_PRESENCE_SENSOR_Init(void) sts_o7_sensorData.battery_Pct = 99; sts_o7_sensorData.dutycycletimelevel = 1; sts_o7_sensorData.event_sensor1_start_time = 0; + sts_o7_sensorData.event_sensor1_stop_time = 0; sts_o7_sensorData.event_sensor1_duration = 0; sts_o7_sensorData.event_sensor2_start_time = 0; + sts_o7_sensorData.event_sensor2_stop_time = 0; sts_o7_sensorData.event_sensor2_duration = 0; sts_o7_sensorData.event_sensor3_motion_start_time = 0; + sts_o7_sensorData.event_sensor3_motion_stop_time = 0; sts_o7_sensorData.event_sensor3_motion_duration = 0; sts_o7_sensorData.event_sensor3_fall_start_time = 0; + sts_o7_sensorData.event_sensor3_fall_stop_time = 0; sts_o7_sensorData.event_sensor3_fall_duration = 0; sts_o7_sensorData.event_sensor4_start_time = 0; + sts_o7_sensorData.event_sensor4_stop_time = 0; sts_o7_sensorData.event_sensor4_duration = 0; sts_o7_sensorData.over_stay_state = 0; @@ -838,7 +843,12 @@ void OnSensor1StateChanged(void) { sts_o7_sensorData.event_sensor1_start_time = sensor_event_time.Seconds; sts_o7_sensorData.event_sensor1_duration = 0; + } else if (sts_hall1_read==STS_Status_Door_Open) + { + sts_o7_sensorData.event_sensor1_stop_time = sensor_event_time.Seconds; + //sts_o7_sensorData.event_sensor1_duration = 0; } + } /* SOS emergency button on off */ @@ -849,6 +859,10 @@ void OnSensor2StateChanged(void) { sts_o7_sensorData.event_sensor2_start_time = sensor_event_time.Seconds; sts_o7_sensorData.event_sensor2_duration = 0; + }else if (sts_hall2_read==STS_Status_SOS_Release) + { + sts_o7_sensorData.event_sensor2_stop_time = sensor_event_time.Seconds; + //sts_o7_sensorData.event_sensor2_duration = 0; } } @@ -866,7 +880,13 @@ void OnSensor3StateChanged(void) { sts_o7_sensorData.event_sensor3_motion_start_time = sensor_event_time.Seconds; sts_o7_sensorData.event_sensor3_motion_duration = 0; + } else if (sts_rss_result == STS_RESULT_NO_MOTION) + { + sts_o7_sensorData.event_sensor3_motion_stop_time = sensor_event_time.Seconds; + //sts_o7_sensorData.event_sensor3_motion_duration = 0; } + + last_sts_rss_time_stamp = sensor_event_time.Seconds; if (sts_fall_rising_detected_result == STS_PRESENCE_FALL) { diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 2a40ef0..77fe392 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -53,7 +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; +volatile uint8_t last_sts_hall1_read=STS_Status_Door_Open, last_sts_hall2_read=STS_Status_SOS_Release; 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; @@ -690,23 +690,26 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) case HALL1_Pin: if (sts_reed_hall_1_changed) { - HAL_Delay(250); //de-bouncing + HAL_Delay(50); //de-bouncing sts_hall1_read = HALL1_STATE; SysTime_t current_event_time = SysTimeGetMcuTime(); - if (((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_start_time) > 5) && (last_sts_hall1_read !=sts_hall1_read)) -// if (last_sts_hall1_read !=sts_hall1_read) + if ((last_sts_hall1_read !=sts_hall1_read) && ((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_start_time)>5)&&((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_stop_time)>5)) { - 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) + if (((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_start_time) > 5) || ((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_stop_time) > 5)) + // if (last_sts_hall1_read !=sts_hall1_read) { - //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); + APP_LOG(TS_OFF, VLEVEL_L, "\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; } - //sts_reed_hall_1_changed =0; - last_sts_hall1_read = sts_hall1_read; } } break; @@ -714,14 +717,22 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) case HALL2_Pin: if (sts_reed_hall_2_changed) { - HAL_Delay(50); //de-bouncing - sts_hall2_read = HALL2_STATE; - APP_LOG(TS_OFF, VLEVEL_M, "\n\n SOS Button Read = %02x --%20s\r\n", HALL2_STATE, (HALL2_STATE==STS_Status_SOS_Pushdown)?"SOS Pushdown":"SOS Released"); - OnSensor2StateChanged(); - //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_2_changed =0; + HAL_Delay(50); //de-bouncing + sts_hall2_read = HALL2_STATE; + SysTime_t current_event_time = SysTimeGetMcuTime(); + if (last_sts_hall2_read != sts_hall2_read) + { + if (((current_event_time.Seconds - sts_o7_sensorData.event_sensor2_start_time) > 2) || ((current_event_time.Seconds - sts_o7_sensorData.event_sensor2_stop_time) > 2)) + { + APP_LOG(TS_OFF, VLEVEL_L, "\n\n SOS Button Read = %02x --%20s\r\n", HALL2_STATE, (HALL2_STATE==STS_Status_SOS_Pushdown)?"SOS Pushdown":"SOS Released"); + OnSensor2StateChanged(); + //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_2_changed =0; + } + last_sts_hall2_read = sts_hall2_read; + } } break; @@ -936,7 +947,7 @@ static void SendTxData(void) "\r\n######| Color = %s%s | Mode = %5s |\r\n",(char *)colorshow, sts_lamp_color_code[icl], (char*)sts_work_mode_code[sensorData.workmode]); if (sts_work_mode == STS_UNI_MODE) { - APP_LOG(TS_OFF, VLEVEL_H, + APP_LOG(TS_OFF, VLEVEL_L, "\r\n######| S1-DoorOpen | S2-Motion | S3-SOS | S4 |Distance(mm) | MotionScore| Unconscious | Over_Stay | Fall Detected|" "\r\n######| %1d | %1d | %1d | %1d | %04d | %04d | %1d | %1d | %1d |\r\n", sensorData.state_sensor1_on_off, sensorData.state_sensor2_on_off,sensorData.state_sensor3_on_off, sensorData.state_sensor4_on_off,