From 444198dc403c68f035431d1bf25a0418512d3bf5 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Mon, 3 Jun 2024 18:26:20 +0800 Subject: [PATCH] minor improve for unconcious --- Core/Inc/yunhorn_sts_sensors.h | 12 ++++++------ Core/Src/yunhorn_sts_presence_rss.c | 6 +++++- Core/Src/yunhorn_sts_process.c | 4 +++- LoRaWAN/App/lora_app.c | 12 ++++++------ 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Core/Inc/yunhorn_sts_sensors.h b/Core/Inc/yunhorn_sts_sensors.h index 58efb3c..e7d3d8b 100644 --- a/Core/Inc/yunhorn_sts_sensors.h +++ b/Core/Inc/yunhorn_sts_sensors.h @@ -538,7 +538,7 @@ enum nvm_order { NVM_LAMP_BAR_FLASHING_COLOR=39, //39, P[27] NVM_FALL_DETECTION_ACC_THRESHOLD=40, //40 NVM_FALL_DETECTION_DEPTH_THRESHOLD, //41 - NVM_FALL_UNCONCIOUS_THRESHOLD, //42 + NVM_UNCONCIOUS_THRESHOLD, //42 NVM_OCCUPANCY_OVERTIME_THRESHOLD, //43 NVM_AC_CODE_START=44 //STORED, NO UPLOAD //63, 20 bytes for AC code @@ -566,12 +566,12 @@ typedef struct sts_cfg_nvm { uint8_t reserve06; uint8_t reserve07; uint8_t reserve08; - uint8_t lamp_bar_flashing_color; //Lamp Bar Flashing color define, 0x20, 2==STS_RED, 0 = STS_DARK, 0x23, 2=STS_RED, 3=STS_BLUE + uint8_t lamp_bar_flashing_color; //Lamp Bar Flashing color define, 0x20, 2==STS_RED, 0 = STS_DARK, 0x23, 2=STS_RED, 3=STS_BLUE uint8_t fall_detection_acc_threshold; // 0 - 9: 0:disable: 1-9 accelaration mg/s2 - uint8_t fall_detection_depth_threshold; // 0 - 9: 0:disable: 1-9 fall down depth * 10 cm - uint8_t fall_unconcious_threshold; //motion level *10 - uint8_t occupancy_overtime_threshold; // 0 - 9: 0:disable, 1-9 occupy over time threshold * 10 min - uint8_t ac[YUNHORN_STS_AC_CODE_SIZE]; // authorization code, 20 bytes MCU UUID coded + uint8_t fall_detection_depth_threshold; // 0 - 9: 0:disable: 1-9 fall down depth * 10 cm + uint8_t unconcious_threshold; // 0 - 9 motion level *10 + uint8_t occupancy_overtime_threshold; // 0 - 9: 0:disable, 1-9 occupy over time threshold * 10 min + uint8_t ac[YUNHORN_STS_AC_CODE_SIZE]; // authorization code, 20 bytes MCU UUID coded } sts_cfg_nvm_t; /** diff --git a/Core/Src/yunhorn_sts_presence_rss.c b/Core/Src/yunhorn_sts_presence_rss.c index 10c6f9e..b59487e 100644 --- a/Core/Src/yunhorn_sts_presence_rss.c +++ b/Core/Src/yunhorn_sts_presence_rss.c @@ -81,6 +81,10 @@ #define DEFAULT_MOTION_FEATURE_LEN (10) //MOTION FEATURE IDENDIFIED #define DEFAULT_UNCONCIOUS_THRESHOLD (250) +#ifndef MIN +# define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif + extern volatile uint8_t sts_fall_detection_acc_threshold, sts_fall_detection_depth_threshold, sts_occupancy_overtime_threshold; volatile uint8_t sts_unconcious_state=0; volatile uint16_t sts_unconcious_threshold=1280, sts_unconcious_duration=0; @@ -614,7 +618,7 @@ void STS_YunhornCheckStandardDeviation(void) (int)(sts_fall_detection_depth_threshold), (int)(sts_fall_rising_pattern_factor2)); #endif - if (standard_variance_presence_score <= DEFAULT_UNCONCIOUS_THRESHOLD) { + if (standard_variance_presence_score <= MIN(DEFAULT_UNCONCIOUS_THRESHOLD, sts_unconcious_threshold)) { sts_fall_rising_detected_result = STS_PRESENCE_STAYSTILL; } diff --git a/Core/Src/yunhorn_sts_process.c b/Core/Src/yunhorn_sts_process.c index eb22e2a..ed44d11 100644 --- a/Core/Src/yunhorn_sts_process.c +++ b/Core/Src/yunhorn_sts_process.c @@ -626,10 +626,12 @@ void STS_PRESENCE_SENSOR_Init(void) sts_o7_sensorData.event_stop_time = 0; sts_o7_sensorData.over_stay_state = 0; sts_o7_sensorData.over_stay_duration = 0; + sts_o7_sensorData.unconcious_duration = 0; + sts_o7_sensorData.unconcious_state = 0; STS_SENSOR_Power_ON(0); STS_PRESENCE_SENSOR_REEDSWITCH_HALL_Init(); - STS_PRESENCE_SENSOR_TOF_Init(); + //STS_PRESENCE_SENSOR_TOF_Init(); STS_PRESENCE_SENSOR_RSS_Init(); mems_int1_detected=0; diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 41f4a1e..c46bfd6 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -116,7 +116,7 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = { 0x23, //Lamp Bar Flashing color define, 0x20, 2==STS_RED, 0 = STS_DARK, 0x23, 2=STS_RED, 3=STS_BLUE 0x01, //fall_detection_acc_threshold = *10 acceleration measure 0x03, //fall detection_depth_threshold *10cm - 0x80, //fall unconcious threshold * 10, 1280 motion level + 0x08, //unconcious threshold * 128, 0-9, 9*128=1280 motion level 0x02, //occupancy over time threshold *10 minutes // below 20 bytes {0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0} @@ -1873,11 +1873,11 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, size_t tlv_buf_size) { sts_fall_detection_acc_threshold = (uint8_t)(tlv_buf[CFG_CMD5] - 0x30)*10; //acc *10 mg/s2 sts_fall_detection_depth_threshold = (uint8_t)(tlv_buf[CFG_CMD6] - 0x30)*10; //depth *10 in cm - sts_unconcious_threshold = (uint8_t)(tlv_buf[CFG_CMD7] - 0x30+10)*10; //motion level over 1000 , less than 1900 *10 in cm + sts_unconcious_threshold = (uint8_t)(tlv_buf[CFG_CMD7] - 0x30+1)*128; //motion level less than 1280 sts_occupancy_overtime_threshold = (uint8_t)(tlv_buf[CFG_CMD8] - 0x30)*10; // overtime *10 min sts_cfg_nvm.fall_detection_acc_threshold = (uint8_t)(tlv_buf[CFG_CMD5] - 0x30); sts_cfg_nvm.fall_detection_depth_threshold = (uint8_t)(tlv_buf[CFG_CMD6] - 0x30); - sts_cfg_nvm.fall_unconcious_threshold = (uint8_t)(tlv_buf[CFG_CMD7] - 0x30+10); + sts_cfg_nvm.unconcious_threshold = (uint8_t)(tlv_buf[CFG_CMD7] - 0x30+1); sts_cfg_nvm.occupancy_overtime_threshold = (uint8_t)(tlv_buf[CFG_CMD8] - 0x30); if ((sts_fall_detection_acc_threshold ==0)&&(sts_fall_detection_depth_threshold==0)) @@ -2185,7 +2185,7 @@ void OnStoreSTSCFGContextRequest(void) nvm_store_value[i++] = sts_cfg_nvm.lamp_bar_flashing_color; nvm_store_value[i++] = sts_cfg_nvm.fall_detection_acc_threshold; nvm_store_value[i++] = sts_cfg_nvm.fall_detection_depth_threshold; - nvm_store_value[i++] = sts_cfg_nvm.fall_unconcious_threshold; + nvm_store_value[i++] = sts_cfg_nvm.unconcious_threshold; nvm_store_value[i++] = sts_cfg_nvm.occupancy_overtime_threshold; if ((sts_cfg_nvm.fall_detection_acc_threshold ==0)&&(sts_cfg_nvm.fall_detection_depth_threshold==0)) { sts_presence_fall_detection =0; @@ -2270,7 +2270,7 @@ void STS_REBOOT_CONFIG_Init(void) sts_cfg_nvm.lamp_bar_flashing_color = (uint8_t)nvm_stored_value[NVM_LAMP_BAR_FLASHING_COLOR]; sts_cfg_nvm.fall_detection_acc_threshold = (uint8_t)nvm_stored_value[NVM_FALL_DETECTION_ACC_THRESHOLD]; sts_cfg_nvm.fall_detection_depth_threshold = (uint8_t)nvm_stored_value[NVM_FALL_DETECTION_DEPTH_THRESHOLD]; - sts_cfg_nvm.fall_unconcious_threshold = (uint8_t)nvm_stored_value[NVM_FALL_UNCONCIOUS_THRESHOLD]; + sts_cfg_nvm.unconcious_threshold = (uint8_t)nvm_stored_value[NVM_UNCONCIOUS_THRESHOLD]; sts_cfg_nvm.occupancy_overtime_threshold = (uint8_t)nvm_stored_value[NVM_OCCUPANCY_OVERTIME_THRESHOLD]; for (uint8_t j=0; j< YUNHORN_STS_AC_CODE_SIZE; j++) { @@ -2338,7 +2338,7 @@ void OnRestoreSTSCFGContextProcess(void) sts_fall_detection_acc_threshold = (uint8_t)sts_cfg_nvm.fall_detection_acc_threshold*10; sts_fall_detection_depth_threshold = (uint8_t)sts_cfg_nvm.fall_detection_depth_threshold*10; //in cm - // **** = sts_cfg_nvm.fall_detection_reserve; + sts_unconcious_threshold = (uint8_t)(sts_cfg_nvm.unconcious_threshold+1)*128; // unconcious threshold sts_occupancy_overtime_threshold = (uint8_t)sts_cfg_nvm.occupancy_overtime_threshold*10; // minutes