From c5d43191e943c6fc1ba34d51482b5dba056a77f6 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Tue, 11 Jun 2024 19:43:55 +0800 Subject: [PATCH] minor improve --- Core/Inc/yunhorn_sts_sensors.h | 7 +++++-- Core/Src/yunhorn_sts_presence_rss.c | 14 ++++++++++---- Core/Src/yunhorn_sts_process.c | 25 ++++++++++++++++++------- LoRaWAN/App/lora_app.c | 19 ++++++++++++++++--- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/Core/Inc/yunhorn_sts_sensors.h b/Core/Inc/yunhorn_sts_sensors.h index 718ef95..5e530c2 100644 --- a/Core/Inc/yunhorn_sts_sensors.h +++ b/Core/Inc/yunhorn_sts_sensors.h @@ -180,6 +180,7 @@ typedef struct STS_OO_SensorStatusDataTypeDef uint8_t over_stay_state; // sensor 1, door lock or door contact occupancy over time or not 0:1 uint32_t over_stay_duration; // sensor 1, door lock or door contact, time lenght of overstay in seconds uint16_t occupancy_duration; // sensor 3, motion detection duration + uint32_t fall_laydown_duration; // sensor 3, fall down not rise up duration uint8_t occupancy_over_stay_state; // uint8_t battery_Pct; /* % of battery two digits, 88% (00-99)% */ uint8_t dutycycletimelevel; /* level=0,255 */ @@ -188,8 +189,10 @@ typedef struct STS_OO_SensorStatusDataTypeDef uint32_t event_sensor1_duration; uint32_t event_sensor2_start_time; uint32_t event_sensor2_duration; - uint32_t event_sensor3_start_time; - uint32_t event_sensor3_duration; + uint32_t event_sensor3_motion_start_time; + uint32_t event_sensor3_motion_duration; + uint32_t event_sensor3_fall_start_time; + uint32_t event_sensor3_fall_duration; uint32_t event_sensor4_start_time; uint32_t event_sensor4_duration; uint8_t alarm_indictor_mute_state; diff --git a/Core/Src/yunhorn_sts_presence_rss.c b/Core/Src/yunhorn_sts_presence_rss.c index b56f8a8..034bad2 100644 --- a/Core/Src/yunhorn_sts_presence_rss.c +++ b/Core/Src/yunhorn_sts_presence_rss.c @@ -369,12 +369,12 @@ int sts_presence_rss_fall_rise_detection(void) uint8_t average_result = 0; float average_distance =0.0f; float average_score =0.0f; - uint8_t k=0; + //uint8_t k=0; uint16_t motion_in_zone[10]={0x0}; uint16_t detected_zone=0; //for (k=0; k<5; k++) {motion_in_zone[k]=0;} #if 1 - for (int i = 0; i < (iterations); i++) + for (int i = 0; i < (iterations/2); i++) { success = acc_detector_presence_get_next(handle, &result); if (!success) @@ -483,7 +483,13 @@ int sts_presence_rss_fall_rise_detection(void) sts_rss_result = (average_result > 1)? 1: 0; - if (sts_rss_result) {LED1_ON;} else {LED1_OFF;} + if (sts_rss_result) { + LED1_ON; + OnSensor3StateChanged(); + } else { + LED1_OFF; + + } /* TODO XXXX 2024-06-06 @@ -494,7 +500,7 @@ int sts_presence_rss_fall_rise_detection(void) */ #ifdef LOG_RSS - for (k=0; k<10; k++) { + for (uint8_t k=0; k<10; k++) { if (motion_in_zone[k]>0) { APP_LOG(TS_OFF, VLEVEL_M,"\r\nMotion Distance Zone: %2u %4u %4d cm", k, motion_in_zone[k], (80+k*40)); } diff --git a/Core/Src/yunhorn_sts_process.c b/Core/Src/yunhorn_sts_process.c index 5aff5fb..6186e72 100644 --- a/Core/Src/yunhorn_sts_process.c +++ b/Core/Src/yunhorn_sts_process.c @@ -509,8 +509,10 @@ void STS_PRESENCE_SENSOR_Init_Send_Data(void) sts_o7_sensorData.event_sensor1_duration = 0x0; sts_o7_sensorData.event_sensor2_start_time = 0x0; sts_o7_sensorData.event_sensor2_duration = 0x0; - sts_o7_sensorData.event_sensor3_start_time = 0x0; - sts_o7_sensorData.event_sensor3_duration = 0x0; + sts_o7_sensorData.event_sensor3_motion_start_time = 0x0; + sts_o7_sensorData.event_sensor3_motion_duration = 0x0; + sts_o7_sensorData.event_sensor3_fall_start_time = 0x0; + sts_o7_sensorData.event_sensor3_fall_duration = 0x0; sts_o7_sensorData.event_sensor4_start_time = 0x0; sts_o7_sensorData.event_sensor4_duration = 0x0; @@ -586,8 +588,10 @@ void STS_PRESENCE_SENSOR_Init(void) sts_o7_sensorData.event_sensor1_duration = 0; sts_o7_sensorData.event_sensor2_start_time = 0; sts_o7_sensorData.event_sensor2_duration = 0; - sts_o7_sensorData.event_sensor3_start_time = 0; - sts_o7_sensorData.event_sensor3_duration = 0; + sts_o7_sensorData.event_sensor3_motion_start_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_duration = 0; sts_o7_sensorData.event_sensor4_start_time = 0; sts_o7_sensorData.event_sensor4_duration = 0; @@ -826,7 +830,7 @@ void STS_O5_SENSOR_Read(STS_OO_SensorDataTypeDef *oo_data) #endif - +/* reedswitch 1 on off */ void OnSensor1StateChanged(void) { SysTime_t sensor_event_time = SysTimeGetMcuTime(); @@ -837,6 +841,7 @@ void OnSensor1StateChanged(void) } } +/* SOS emergency button on off */ void OnSensor2StateChanged(void) { SysTime_t sensor_event_time = SysTimeGetMcuTime(); @@ -847,6 +852,7 @@ void OnSensor2StateChanged(void) } } +/* motion sensor RSS ON-OFF */ void OnSensor3StateChanged(void) { SysTime_t sensor_event_time = SysTimeGetMcuTime(); @@ -858,10 +864,15 @@ void OnSensor3StateChanged(void) #endif if (sts_rss_result == STS_RESULT_MOTION) { - sts_o7_sensorData.event_sensor3_start_time = sensor_event_time.Seconds; - sts_o7_sensorData.event_sensor3_duration = 0; + sts_o7_sensorData.event_sensor3_motion_start_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) + { + sts_o7_sensorData.event_sensor3_fall_start_time = sensor_event_time.Seconds; + sts_o7_sensorData.event_sensor3_fall_duration = 0; + } } void OnSensor4StateChanged(void) diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index e5023e2..d395de1 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -1114,12 +1114,13 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) if (sts_rss_result==STS_RESULT_MOTION) - sts_o7_sensorData.event_sensor3_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_start_time; - if (sts_o7_sensorData.event_sensor3_duration > sts_occupancy_overtime_threshold) + sts_o7_sensorData.event_sensor3_motion_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_motion_start_time; + if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold) { sts_o7_sensorData.occupancy_over_stay_state = 1; - sts_o7_sensorData.occupancy_duration =sts_o7_sensorData.event_sensor3_duration; + sts_o7_sensorData.occupancy_duration =sts_o7_sensorData.event_sensor3_motion_duration; } + /* STS_PRESENCE_NONE=0, STS_PRESENCE_FALL, @@ -1130,8 +1131,20 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) */ switch (sts_fall_rising_detected_result){ case STS_PRESENCE_NONE: + sts_o7_sensorData.fall_state = 0; + sts_o7_sensorData.fall_laydown_duration=0; + sts_o7_sensorData.unconcious_state =0; + sts_o7_sensorData.unconcious_duration =0; break; case STS_PRESENCE_FALL: + sts_o7_sensorData.event_sensor3_fall_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_fall_start_time; + if (sts_o7_sensorData.event_sensor3_fall_duration > sts_cfg_nvm.falldown_confirm_threshold_in_Sec) + { + //sts_o7_sensorData.occupancy_over_stay_state = 1; + sts_o7_sensorData.fall_state = 1; + sts_o7_sensorData.fall_laydown_duration =sts_o7_sensorData.event_sensor3_fall_duration; + } + break; case STS_PRESENCE_RISING: break;