This commit is contained in:
Yunhorn 2024-11-26 23:35:13 +08:00
parent 4b9409207f
commit 7a779177d7
10 changed files with 464 additions and 68 deletions

View File

@ -166,7 +166,7 @@ void MX_GPIO_Init(void)
#if defined(PIR)
/*Configure GPIO pins : PIR_Pin PIR_Pin */
GPIO_InitStruct.Pin = PIR_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL; //GPIO_NOPULL;
HAL_GPIO_Init(PIR_GPIO_Port, &GPIO_InitStruct);
HAL_NVIC_SetPriority(PIR_EXTI_IRQn, 15, 0);

View File

@ -124,6 +124,7 @@ void SystemApp_Init(void)
/*Initialize the Sensors */
EnvSensors_Init();
#if defined(L8)
STS_FHMOS_sensor_config_init();
MX_TOF_Init();
//STS_Lamp_Bar_Self_Test();
#endif

View File

@ -35,7 +35,7 @@
#include "sys_sensors.h"
#include "flash_if.h"
#include "stdio.h"
#include "timer_if.h"
#ifdef CLOCK_SYNC
#include "LmhpClockSync.h"
#endif
@ -74,8 +74,10 @@ extern volatile sts_fhmos_sensor_ambient_height_t fhmos_bg;
extern volatile uint8_t sts_hall1_read, sts_hall2_read; // Above hall1_read == reed_hall_result, hall2_read == emergency_button
extern volatile uint8_t sts_hall3_read, sts_hall4_read;
extern volatile uint8_t sts_pir_state;
volatile uint8_t sts_PIR_read = 0;
volatile bool locklow = true;
volatile uint32_t lowin=0;
volatile bool takelowTime;
/* USER CODE END EV */
/* Private typedef -----------------------------------------------------------*/
@ -655,6 +657,39 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
break;
#endif
case PIR_Pin:
sts_pir_state = PIR_STATE;
printf("\r\n pir state =%u \r\n", sts_pir_state);
if (sts_pir_state)
{
if (locklow) {
sts_PIR_read = 1;
locklow = false;
printf("\r\n Motion detected, PIR state =%d \r\n", sts_PIR_read);
HAL_Delay(50);
}
takelowTime=true;
}
else if (!sts_pir_state)
{
//printf("\r\n pir state =%u \r\n", sts_pir_state);
uint32_t check_time=TIMER_IF_GetTimerValue();
if (takelowTime) {
lowin = check_time;
printf("\r\n lowin start at: %u \r\n", lowin);
takelowTime = false;
}
printf("\r\n low duration=%d \r\n", check_time-lowin);
if ((!locklow && (check_time - lowin >= 5000))) {
printf("\r\n low duration=%d \r\n", check_time-lowin);
sts_PIR_read = 0;
locklow = true;
printf("\r\n Motion End, PIR state =%d \r\n", sts_PIR_read);
}
}
#if 0
HAL_Delay(100);
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
@ -668,6 +703,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
}
//UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
#endif
break;
#if (defined(VL53L0)||defined(VL53LX)||defined(L8))
case TOF_INT_EXTI_PIN:
@ -1076,6 +1112,7 @@ static void SendTxData(void)
AppData.Buffer[i++] = fhmos_data.state_human_movement;
AppData.Buffer[i++] = fhmos_data.state_occupancy;
AppData.Buffer[i++] = fhmos_data.state_sos_alarm;
AppData.Buffer[i++] = fhmos_data.lamp_bar_color;
//(uint8_t)((sts_l8_sensor_data.tof_range_presence_state & 0xFF));

Binary file not shown.

View File

@ -165,7 +165,7 @@ NVM_LEN, //11, 32=0x20
NVM_OCCUPANCY_OVERTIME_THRESHOLD, //38
NVM_MOTIONLESS_DURATION_THRESHOLD, //39
NVM_UNCONSCIOUS_LEVEL_THRESHOLD, //40
NVM_UNCONSCIOUS_LEVEL_THRESHOLD, //40
NVM_FALL_DETECTION_ACC_THRESHOLD, //41
NVM_FALL_DETECTION_DEPTH_THRESHOLD, //42
@ -194,8 +194,6 @@ typedef struct sts_cfg_nvm {
uint8_t reserve03;
uint8_t sensor_install_height_in_10cm;
uint8_t alarm_parameter05;
uint8_t alarm_mute_reset_timer_in_10sec; //60(0x3C) sec alarm_mute_or_reset_expire_timer_in_sec
uint8_t alarm_lamp_bar_flashing_color; //Lamp Bar Flashing color define, 0x20, 2==STS_RED, 0 = STS_DARK, 0x23, 2=STS_RED, 3=STS_BLUE
#ifdef L8
uint8_t fhmos_cfg_1;
uint8_t fhmos_cfg_2;
@ -203,12 +201,14 @@ typedef struct sts_cfg_nvm {
uint8_t fhmos_cfg_4;
uint8_t fhmos_cfg_5;
uint8_t fhmos_cfg_6;
uint8_t fhmos_cfg_7;
uint8_t fhmos_cfg_8;
#else
uint8_t alarm_mute_reset_timer_in_10sec; //60(0x3C) sec alarm_mute_or_reset_expire_timer_in_sec
uint8_t alarm_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 occupancy_overtime_threshold_in_10min; // 0 - 9 0disable, 1-9 occupy over time threshold * 10 min
uint8_t motionless_duration_threshold_in_min; // 10(0x0A) min (2 min.) motionless_duration_threshold_in_min
uint8_t unconscious_or_motionless_level_threshold; // 0 - 9 motion level *128
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_confirm_threshold_in_10sec; // 0-60(0x3C) Sec, or 3*10(0x03) sec default falldown_confirm_threshold_in_10sec
@ -281,21 +281,43 @@ enum {
typedef struct sts_fhmos_sensor_data
{
uint16_t install_height_mm; /*Default distance sensor measured distance */
uint16_t battery_mV; /*mV, 1000mv-5000mv, regular 3300mV - 3600mV --4200mV */
uint16_t install_height_mm; /* Default distance sensor measured distance */
uint16_t battery_mV; /* mV, 1000mv-5000mv, regular 3300mV - 3600mV --4200mV */
uint8_t lamp_bar_color; /* lamp bar LED color */
uint8_t state_fall; /* 0/blue: no occupy, 1/green:occupy yet normal, 2/yellow: suspicious state, 3/red: fall confirmed */
uint8_t state_human_movement; /* 0/blue: no occupy, 1/green:occupy yet normal, 2/yellow: suspicious state, 3/red: fall confirmed */
uint8_t state_occupancy; /* 0/blue: no occupy, 1/green:occupy yet normal, 3/red: over stay */
uint8_t state_sos_alarm; /* 1/green, sos on-duty, 2/yellow, sos button pressed 3/red, alarm */
uint8_t on_off_event; /* 1: liquid sensed, 0: no liquid sensed */
uint8_t state_changed_fall;
uint8_t state_changed_human_movemen;
uint8_t state_changed_occupancy;
uint8_t state_changed_sos;
uint8_t state_hall_1;
uint8_t state_hall_2;
uint8_t state_hall_3;
uint8_t state_PIR;
uint8_t state_hall_4;
bool state_changed_fall;
bool state_changed_human_movemen;
bool state_changed_occupancy;
bool state_changed_sos;
bool state_changed_hall_1;
bool state_changed_hall_2;
bool state_changed_hall_3;
bool state_changed_hall_4;
bool state_changed_PIR;
uint8_t prev_fall;
uint8_t prev_human_movement;
uint8_t prev_occupancy;
uint8_t prev_sos;
uint8_t prev_hall_1;
uint8_t prev_hall_2;
uint8_t prev_PIR;
uint8_t prev_hall_3;
uint8_t prev_hall_4;
} sts_fhmos_sensor_data_t;
typedef struct sts_fhmos_threshold_type
@ -309,12 +331,14 @@ typedef struct sts_fhmos_threshold_type
typedef struct sts_fhmos_sensor_config
{
uint8_t th_head_level_height_cm;
uint8_t th_fall_duration_potential_15sec;
uint8_t th_fall_duration_confirm_15sec;
uint8_t th_motionless_short_15sec;
uint8_t th_motionless_long_15sec;
uint8_t th_occupancy_overstay_15sec;
uint8_t th_head_level_height_cm; // 10 cm - 90 cm
uint8_t th_fall_duration_potential_15sec; // 1 min - 3 min
uint8_t th_fall_duration_confirm_15sec; // 4 min - 10 min
uint8_t th_motionless_short_15sec; // 5 min - 10 min
uint8_t th_motionless_long_15sec; // 10 min - 30 min
uint8_t th_occupancy_overstay_15sec; // 10 min - 30 min
uint8_t th_motion_power_level; // motion power level
uint8_t th_fhmos_cfg_reserve1; // reserved 1
} sts_fhmos_sensor_config_t;
@ -444,6 +468,17 @@ void STS_YunhornSTSEventP7_Process(void);
void STS_YunhornSTSEventRFAC_Process(void);
void STS_YunhornAuthenticationCode_Process(void);
void OnSensor1StateChanged(void);
void OnSensor2StateChanged(void);
void OnSensor3StateChanged(void);
void OnSensor4StateChanged(void);
void OnSensorRSS3AStateChanged(void);
void OnSensorRSS3BStateChanged(void);
void OnSensorRSS3CStateChanged(void);
uint32_t STS_Get_Date_Time_Stamp(void);//uint32_t *time_stamp, uint8_t *datetimestamp);
void STS_Reed_Hall_Presence_Detection(void);
void STS_SENSOR_Upload_Config_Invalid_Message(void);

View File

@ -70,7 +70,7 @@ extern volatile sts_fhmos_sensor_config_t fhmos_cfg;
extern volatile uint8_t sts_status_color, sts_lamp_bar_color;//puColor
extern uint8_t luminance_level;
volatile uint8_t sts_fhmos_state_changed=0;
volatile sts_fhmos_sensor_config_t sts_fhmos_cfg;
extern volatile uint8_t sts_mask_bitmap[8];
#endif
volatile sts_cfg_nvm_t sts_cfg_nvm = {
@ -120,6 +120,25 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = {
0x00, //reserve5 alarm_parameter05
0x06, //reserve6 alarm_mute_or_reset_expire_timer_in_10sec, 60 seconds
0x23, //reserve7 alarm Lamp Bar Flashing color define, 0x20, 2==STS_RED, 0 = STS_DARK, 0x23, 2=STS_RED, 3=STS_BLUE
#ifdef L8
/*
uint8_t fhmos_fall=0, fhmos_human_movement=0, fhmos_occupancy=0, fhmos_sos_alarm=0;
fhmos_cfg.th_head_level_height_cm = 70; // default 700mm
fhmos_cfg.th_fall_duration_potential_15sec = 4; // 4*15=60 sec, 1 min.
fhmos_cfg.th_fall_duration_confirm_15sec = 8; // 8*15 = 120 sec, 2 min.
fhmos_cfg.th_motionless_short_15sec = 4; // 4*15 = 60 sec , 1 min.
fhmos_cfg.th_motionless_long_15sec = 16; // 20*15 = 300 sec, 5 min.
fhmos_cfg.th_occupancy_overstay_15sec = 100; // 80*15 = 1200 sec, 20 min.
fhmos_cfg.th_motion_power = 50;
*/
0x46, // uint8_t fhmos_cfg_1; head level height cm
0x04, // uint8_t fhmos_cfg_2; 04*15 = 60 sec, 1 min.
0x08, // uint8_t fhmos_cfg_3; 08*15 = 120 sec, 2 min.
0x04, // uint8_t fhmos_cfg_4; 04*15 = 60 sec, = 1 min.
0x10, // uint8_t fhmos_cfg_5; 16*15 = 240 sec, = 4 min.
0x64, // uint8_t fhmos_cfg_6; 100*15=1500sec, =25min
#elif
0x03, //reserve8 occupancy over time threshold 3*10 = 30 minutes
0x09, //reserve8 motionless_duration_threshold_in_min+1, normal: 10 min(0x0A) Minutes (2 min.) 1-9== 2-10min
@ -128,6 +147,8 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = {
0x01, //fall_detection_acc_threshold = *10 acceleration measure
0x03, //fall detection_depth_threshold *10cm
0x03, //falldown_confirm_threshold_in_10sec, 0x3=30 sec default
#endif
// below 20 bytes for RFAC code
{0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0}
};
@ -150,7 +171,8 @@ volatile uint8_t sts_rss_result = STS_RESULT_NO_MOTION;
volatile uint8_t sts_rss_2nd_result = STS_RESULT_NO_MOTION; //2nd RSS sensor status
volatile uint8_t sts_tof_result = STS_RESULT_NO_MOTION;
volatile uint8_t last_sts_rss_result=STS_RESULT_NO_MOTION;
volatile uint32_t last_sts_rss_time_stamp=0;
volatile uint8_t sts_fall_rising_detected_result = STS_PRESENCE_NORMAL;
static uint8_t outbuf[128]={0x0};
extern volatile hmac_result_t hmac_result;
extern uint16_t sensor_id;
@ -680,29 +702,37 @@ void USER_APP_Parse_CMD_P(uint8_t *parse_buffer, uint8_t parse_buffer_size)
APP_LOG(TS_OFF, VLEVEL_M, "\r\nCFG_CMD Index=%d, VALUE =0X%02X =%d \r\n", sts_fhmos_cfg_index, sts_fhmos_cfg_value,sts_fhmos_cfg_value);
switch (sts_fhmos_cfg_index) {
case 1: // head level height threshold
sts_fhmos_cfg.th_head_level_height_cm = sts_fhmos_cfg_value;
fhmos_cfg.th_head_level_height_cm = sts_fhmos_cfg_value;
break;
case 2:
sts_fhmos_cfg.th_fall_duration_potential_15sec = sts_fhmos_cfg_value;
fhmos_cfg.th_fall_duration_potential_15sec = sts_fhmos_cfg_value;
break;
case 3:
sts_fhmos_cfg.th_fall_duration_confirm_15sec = sts_fhmos_cfg_value;
fhmos_cfg.th_fall_duration_confirm_15sec = sts_fhmos_cfg_value;
break;
case 4:
sts_fhmos_cfg.th_motionless_short_15sec = sts_fhmos_cfg_value;
fhmos_cfg.th_motionless_short_15sec = sts_fhmos_cfg_value;
break;
case 5:
sts_fhmos_cfg.th_motionless_long_15sec = sts_fhmos_cfg_value;
fhmos_cfg.th_motionless_long_15sec = sts_fhmos_cfg_value;
break;
case 6:
sts_fhmos_cfg.th_occupancy_overstay_15sec = sts_fhmos_cfg_value;
fhmos_cfg.th_occupancy_overstay_15sec = sts_fhmos_cfg_value;
break;
case 7:
fhmos_cfg.th_motion_power_level = sts_fhmos_cfg_value;
break;
case 8:
fhmos_cfg.th_fhmos_cfg_reserve1 = sts_fhmos_cfg_value;;
break;
default:
break;
}
sts_cfg_nvm.fhmos_cfg_1 = fhmos_cfg.th_head_level_height_cm;
@ -711,7 +741,8 @@ void USER_APP_Parse_CMD_P(uint8_t *parse_buffer, uint8_t parse_buffer_size)
sts_cfg_nvm.fhmos_cfg_4 = fhmos_cfg.th_motionless_short_15sec;
sts_cfg_nvm.fhmos_cfg_5 = fhmos_cfg.th_motionless_long_15sec;
sts_cfg_nvm.fhmos_cfg_6 = fhmos_cfg.th_occupancy_overstay_15sec;
sts_cfg_nvm.fhmos_cfg_7 = fhmos_cfg.th_motion_power_level;
sts_cfg_nvm.fhmos_cfg_8 = fhmos_cfg.th_fhmos_cfg_reserve1;
OnStoreSTSCFGContextRequest();
// 2024-11-18
@ -1587,8 +1618,6 @@ void OnStoreSTSCFGContextRequest(void)
to_store__value[i++] = sts_cfg_nvm.reserve03;
to_store__value[i++] = sts_cfg_nvm.sensor_install_height_in_10cm;
to_store__value[i++] = sts_cfg_nvm.alarm_parameter05;
to_store__value[i++] = sts_cfg_nvm.alarm_mute_reset_timer_in_10sec;
to_store__value[i++] = sts_cfg_nvm.alarm_lamp_bar_flashing_color;
#ifdef L8
to_store__value[i++] = sts_cfg_nvm.fhmos_cfg_1;
to_store__value[i++] = sts_cfg_nvm.fhmos_cfg_2;
@ -1596,10 +1625,14 @@ void OnStoreSTSCFGContextRequest(void)
to_store__value[i++] = sts_cfg_nvm.fhmos_cfg_4;
to_store__value[i++] = sts_cfg_nvm.fhmos_cfg_5;
to_store__value[i++] = sts_cfg_nvm.fhmos_cfg_6;
to_store__value[i++] = sts_cfg_nvm.fhmos_cfg_7;
to_store__value[i++] = sts_cfg_nvm.fhmos_cfg_8;
#else
to_store__value[i++] = sts_cfg_nvm.alarm_mute_reset_timer_in_10sec;
to_store__value[i++] = sts_cfg_nvm.alarm_lamp_bar_flashing_color;
to_store__value[i++] = sts_cfg_nvm.occupancy_overtime_threshold_in_10min;
to_store__value[i++] = sts_cfg_nvm.motionless_duration_threshold_in_min;
to_store__value[i++] = sts_cfg_nvm.unconscious_or_motionless_level_threshold;
to_store__value[i++] = sts_cfg_nvm.fall_detection_acc_threshold;
to_store__value[i++] = sts_cfg_nvm.fall_detection_depth_threshold;
@ -1682,16 +1715,19 @@ void STS_REBOOT_CONFIG_Init(void)
sts_cfg_nvm.reserve03 =(uint8_t)nvm_store_value[NVM_RESERVE03];
sts_cfg_nvm.sensor_install_height_in_10cm =(uint8_t)nvm_store_value[NVM_SENSOR_INSTALL_HEIGHT];
sts_cfg_nvm.alarm_parameter05 =(uint8_t)nvm_store_value[NVM_ALARM_PARAMETER05];
#ifdef L8
sts_cfg_nvm.fhmos_cfg_1 =(uint8_t)nvm_store_value[NVM_ALARM_MUTE_RESET_TIMER];
sts_cfg_nvm.fhmos_cfg_2 =(uint8_t)nvm_store_value[NVM_ALARM_LAMP_BAR_FLASHING_COLOR];
sts_cfg_nvm.fhmos_cfg_3 =(uint8_t)nvm_store_value[NVM_OCCUPANCY_OVERTIME_THRESHOLD];
sts_cfg_nvm.fhmos_cfg_4 =(uint8_t)nvm_store_value[NVM_MOTIONLESS_DURATION_THRESHOLD];
sts_cfg_nvm.fhmos_cfg_5 =(uint8_t)nvm_store_value[NVM_UNCONSCIOUS_LEVEL_THRESHOLD];
sts_cfg_nvm.fhmos_cfg_6 =(uint8_t)nvm_store_value[NVM_FALL_DETECTION_ACC_THRESHOLD];
sts_cfg_nvm.fhmos_cfg_7 =(uint8_t)nvm_store_value[NVM_FALL_DETECTION_DEPTH_THRESHOLD];
sts_cfg_nvm.fhmos_cfg_8 =(uint8_t)nvm_store_value[NVM_FALL_CONFIRM_THRESHOLD];
#else
sts_cfg_nvm.alarm_mute_reset_timer_in_10sec = (uint8_t)nvm_store_value[NVM_ALARM_MUTE_RESET_TIMER];
sts_cfg_nvm.alarm_lamp_bar_flashing_color = (uint8_t)nvm_store_value[NVM_ALARM_LAMP_BAR_FLASHING_COLOR];
#ifdef L8
sts_cfg_nvm.fhmos_cfg_1 =(uint8_t)nvm_store_value[NVM_OCCUPANCY_OVERTIME_THRESHOLD];
sts_cfg_nvm.fhmos_cfg_2 =(uint8_t)nvm_store_value[NVM_MOTIONLESS_DURATION_THRESHOLD];
sts_cfg_nvm.fhmos_cfg_3 =(uint8_t)nvm_store_value[NVM_UNCONSCIOUS_LEVEL_THRESHOLD];
sts_cfg_nvm.fhmos_cfg_4 =(uint8_t)nvm_store_value[NVM_FALL_DETECTION_ACC_THRESHOLD];
sts_cfg_nvm.fhmos_cfg_5 =(uint8_t)nvm_store_value[NVM_FALL_DETECTION_DEPTH_THRESHOLD];
sts_cfg_nvm.fhmos_cfg_6 =(uint8_t)nvm_store_value[NVM_FALL_CONFIRM_THRESHOLD];
#else
sts_cfg_nvm.occupancy_overtime_threshold_in_10min = (uint8_t)nvm_store_value[NVM_OCCUPANCY_OVERTIME_THRESHOLD];
sts_cfg_nvm.motionless_duration_threshold_in_min= (uint8_t)nvm_store_value[NVM_MOTIONLESS_DURATION_THRESHOLD];
sts_cfg_nvm.unconscious_or_motionless_level_threshold = (uint8_t)nvm_store_value[NVM_UNCONSCIOUS_LEVEL_THRESHOLD];
@ -1805,24 +1841,28 @@ void OnRestoreSTSCFGContextProcess(void)
void STS_FHMOS_sensor_config_init(void)
{
//uint8_t fhmos_fall=0, fhmos_human_movement=0, fhmos_occupancy=0, fhmos_sos_alarm=0;
sts_fhmos_cfg.th_head_level_height_cm = 70; // default 700mm
sts_fhmos_cfg.th_fall_duration_potential_15sec = 4; // 4*15=60 sec, 1 min.
sts_fhmos_cfg.th_fall_duration_confirm_15sec = 8; // 8*15 = 120 sec, 2 min.
sts_fhmos_cfg.th_motionless_short_15sec = 4; // 4*15 = 60 sec , 1 min.
sts_fhmos_cfg.th_motionless_long_15sec = 16; // 20*15 = 300 sec, 5 min.
sts_fhmos_cfg.th_occupancy_overstay_15sec = 100; // 80*15 = 1200 sec, 20 min.
fhmos_cfg.th_head_level_height_cm = 70; // default 700mm
fhmos_cfg.th_fall_duration_potential_15sec = 4; // 4*15=60 sec, 1 min.
fhmos_cfg.th_fall_duration_confirm_15sec = 8; // 8*15 = 120 sec, 2 min.
fhmos_cfg.th_motionless_short_15sec = 4; // 4*15 = 60 sec , 1 min.
fhmos_cfg.th_motionless_long_15sec = 16; // 20*15 = 300 sec, 5 min.
fhmos_cfg.th_occupancy_overstay_15sec = 100; // 80*15 = 1200 sec, 20 min.
fhmos_cfg.th_motion_power_level = 50; // motion power level average
fhmos_cfg.th_fhmos_cfg_reserve1=0;
}
void STS_FHMOS_sensor_config_update()
{
sts_fhmos_cfg.th_head_level_height_cm = sts_cfg_nvm.fhmos_cfg_1; // default 700mm
sts_fhmos_cfg.th_fall_duration_potential_15sec = sts_cfg_nvm.fhmos_cfg_2; // 4*15=60 sec, 1 min.
sts_fhmos_cfg.th_fall_duration_confirm_15sec = sts_cfg_nvm.fhmos_cfg_3; // 8*15 = 120 sec, 2 min.
sts_fhmos_cfg.th_motionless_short_15sec = sts_cfg_nvm.fhmos_cfg_4; // 4*15 = 60 sec , 1 min.
sts_fhmos_cfg.th_motionless_long_15sec = sts_cfg_nvm.fhmos_cfg_5; // 20*15 = 300 sec, 5 min.
sts_fhmos_cfg.th_occupancy_overstay_15sec = sts_cfg_nvm.fhmos_cfg_6; // 80*15 = 1200 sec, 20 min.
fhmos_cfg.th_head_level_height_cm = sts_cfg_nvm.fhmos_cfg_1; // default 700mm
fhmos_cfg.th_fall_duration_potential_15sec = sts_cfg_nvm.fhmos_cfg_2; // 4*15=60 sec, 1 min.
fhmos_cfg.th_fall_duration_confirm_15sec = sts_cfg_nvm.fhmos_cfg_3; // 8*15 = 120 sec, 2 min.
fhmos_cfg.th_motionless_short_15sec = sts_cfg_nvm.fhmos_cfg_4; // 4*15 = 60 sec , 1 min.
fhmos_cfg.th_motionless_long_15sec = sts_cfg_nvm.fhmos_cfg_5; // 20*15 = 300 sec, 5 min.
fhmos_cfg.th_occupancy_overstay_15sec = sts_cfg_nvm.fhmos_cfg_6; // 80*15 = 1200 sec, 20 min.
fhmos_cfg.th_motion_power_level = sts_cfg_nvm.fhmos_cfg_7;
fhmos_cfg.th_fhmos_cfg_reserve1 = sts_cfg_nvm.fhmos_cfg_8;
}
@ -2259,6 +2299,248 @@ void YunhornSTSDurationCheckTimer(void)
}
}
/* reedswitch 1 on off */
void OnSensor1StateChanged(void)
{
SysTime_t sensor_event_time = SysTimeGetMcuTime();
if (sts_hall1_read == STS_Status_Door_Close)
{
sts_o7_sensorData.event_sensor1_start_time = sensor_event_time.Seconds;
sts_o7_sensorData.event_sensor1_duration = 0;
APP_LOG(TS_OFF, VLEVEL_L, "Door Closed ---Timer start: %u\r\n",sts_o7_sensorData.event_sensor1_start_time );
} else if (sts_hall1_read==STS_Status_Door_Open)
{
sts_o7_sensorData.event_sensor1_start_time = 0;
sts_o7_sensorData.event_sensor1_stop_time = sensor_event_time.Seconds;
//sts_o7_sensorData.event_sensor1_duration = 0;
sts_o7_sensorData.over_stay_state = 0;
}
}
/* SOS emergency button on off */
void OnSensor2StateChanged(void)
{
SysTime_t sensor_event_time = SysTimeGetMcuTime();
uint32_t time_stamp=STS_Get_Date_Time_Stamp();
if (sts_hall2_read==STS_Status_SOS_Pushdown)
{
sts_o7_sensorData.event_sensor2_start_time = sensor_event_time.Seconds;
sts_o7_sensorData.event_sensor2_start_timestamp = time_stamp;
sts_o7_sensorData.event_sensor2_stop_time = 0;
sts_o7_sensorData.event_sensor2_duration = 0;
APP_LOG(TS_OFF, VLEVEL_L, "SOS PushDown ---Timer start: %u\r\n",sts_o7_sensorData.event_sensor2_start_time );
}else if (sts_hall2_read==STS_Status_SOS_Release)
{
sts_o7_sensorData.event_sensor2_start_time = 0;
sts_o7_sensorData.event_sensor2_start_timestamp = 0;
sts_o7_sensorData.event_sensor2_stop_time = sensor_event_time.Seconds;
sts_o7_sensorData.event_sensor2_stop_timestamp = time_stamp;
//sts_o7_sensorData.over_stay_state = 0;
//sts_o7_sensorData.event_sensor2_duration = 0;
}
}
/* motion sensor RSS ON-OFF */
void OnSensorRSS3StateChanged(void)
{
SysTime_t sensor_event_time = SysTimeGetMcuTime();
#if 0
if ((sensor_event_time.Seconds - last_sts_rss_time_stamp) < 3 ) //less than 3 seconds ... return for flipping filter
{
return ;
}
#endif
if (sts_rss_result == STS_RESULT_MOTION)
{
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_start_timestamp = 0;
//sts_o7_sensorData.event_sensor3_motion_duration = 0;
}
last_sts_rss_time_stamp = sensor_event_time.Seconds;
}
/* motion sensor A: Motion/No-Motion Detection, Unconscious Detection */
void OnSensorRSS3AStateChanged(void)
{
SysTime_t sensor_event_time = SysTimeGetMcuTime();
#if 0
if ((sensor_event_time.Seconds - last_sts_rss_time_stamp) < 3 ) //less than 3 seconds ... return for flipping filter
{
return ;
}
#endif
if (sts_rss_result == STS_RESULT_MOTION)
{
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_start_timestamp = 0;
//sts_o7_sensorData.event_sensor3_motion_duration = 0;
}
last_sts_rss_time_stamp = sensor_event_time.Seconds;
}
/* motion sensor B, Fall Detection suggestionF */
void OnSensorRSS3BStateChanged(void)
{
SysTime_t sensor_event_time = SysTimeGetMcuTime();
uint32_t time_stamp=STS_Get_Date_Time_Stamp();
#if 0
if ((sensor_event_time.Seconds - last_sts_rss_time_stamp) < 3 ) //less than 3 seconds ... return for flipping filter
{
return ;
}
#endif
switch (sts_fall_rising_detected_result)
{
case STS_PRESENCE_NORMAL:
sts_o7_sensorData.event_sensor3_motion_stop_time = sensor_event_time.Seconds;
break;
case STS_PRESENCE_FALL:
//if (motion_in_hs_zone[0][motion_detected_count])
{
sts_o7_sensorData.event_sensor3_fall_start_time_stamp = time_stamp;
sts_o7_sensorData.event_sensor3_fall_start_time = sensor_event_time.Seconds;
sts_o7_sensorData.event_sensor3_fall_duration = 0;
}
break;
case STS_PRESENCE_RISING:
sts_o7_sensorData.event_sensor3_fall_stop_time_stamp = time_stamp;
sts_o7_sensorData.event_sensor3_fall_stop_time = sensor_event_time.Seconds;
break;
case STS_PRESENCE_LAYDOWN:
break;
case STS_PRESENCE_STAYSTILL:
case STS_PRESENCE_NO_MOVEMENT:
case STS_PRESENCE_UNCONSCIOUS:
sts_o7_sensorData.event_sensor3_no_movement_start_time = sensor_event_time.Seconds;
sts_o7_sensorData.event_sensor3_unconcious_start_time = sensor_event_time.Seconds;
//sts_o7_sensorData.event_sensor3_unconcious_duration = 0;
//sts_o7_sensorData.event_sensor3_no_movement_duration = 0;
//sts_o7_sensorData.fall_laydown_duration = 0;
break;
default:
break;
}
last_sts_rss_time_stamp = sensor_event_time.Seconds;
}
/* motion sensor C: Over stay detection */
void OnSensorRSS3CStateChanged(void)
{
SysTime_t sensor_event_time = SysTimeGetMcuTime();
#if 0
if ((sensor_event_time.Seconds - last_sts_rss_time_stamp) < 3 ) //less than 3 seconds ... return for flipping filter
{
return ;
}
#endif
if (sts_rss_result == STS_RESULT_MOTION)
{
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;
}
void OnSensor3StateChanged(void)
{
#if 0
SysTime_t sensor_event_time = SysTimeGetMcuTime();
// reserved... to be finalized 2024-06-03
if (sts_xxx_result)
sts_o7_sensorData.event_sensor4_start_time = sensor_event_time.Seconds;
else
sts_o7_sensorData.event_sensor4_stop_time = sensor_event_time.Seconds;
#endif
SysTime_t sensor_event_time = SysTimeGetMcuTime();
uint32_t time_stamp=STS_Get_Date_Time_Stamp();
if (sts_hall3_read==STS_Status_Alarm_Mute_Pushdown)
{
sts_o7_sensorData.event_sensor4_start_time = sensor_event_time.Seconds;
sts_o7_sensorData.event_sensor4_start_timestamp = time_stamp;
sts_o7_sensorData.event_sensor4_stop_time = 0;
sts_o7_sensorData.event_sensor4_duration = 0;
APP_LOG(TS_OFF, VLEVEL_L, "Alarm Mute PushDown ---Timer start: %u\r\n",sts_o7_sensorData.event_sensor4_start_time );
}else if (sts_hall3_read==STS_Status_Alarm_Mute_Release)
{
sts_o7_sensorData.event_sensor4_start_time = 0;
sts_o7_sensorData.event_sensor4_start_timestamp = 0;
sts_o7_sensorData.event_sensor4_stop_time = sensor_event_time.Seconds;
sts_o7_sensorData.event_sensor4_stop_timestamp = time_stamp;
//sts_o7_sensorData.over_stay_state = 0;
//sts_o7_sensorData.event_sensor2_duration = 0;
}
}
void OnSensor4StateChanged(void)
{
#if 0
SysTime_t sensor_event_time = SysTimeGetMcuTime();
// reserved... to be finalized 2024-06-03
if (sts_xxx_result)
sts_o7_sensorData.event_sensor4_start_time = sensor_event_time.Seconds;
else
sts_o7_sensorData.event_sensor4_stop_time = sensor_event_time.Seconds;
#endif
SysTime_t sensor_event_time = SysTimeGetMcuTime();
uint32_t time_stamp=STS_Get_Date_Time_Stamp();
if (sts_hall4_read==STS_Status_Alarm_Mute_Pushdown)
{
sts_o7_sensorData.event_sensor5_start_time = sensor_event_time.Seconds;
sts_o7_sensorData.event_sensor5_start_timestamp = time_stamp;
sts_o7_sensorData.event_sensor5_stop_time = 0;
sts_o7_sensorData.event_sensor5_duration = 0;
APP_LOG(TS_OFF, VLEVEL_L, "Alarm RESET PushDown ---Timer start: %u\r\n",sts_o7_sensorData.event_sensor5_start_time );
}else if (sts_hall4_read==STS_Status_Alarm_Mute_Release)
{
sts_o7_sensorData.event_sensor5_start_time = 0;
sts_o7_sensorData.event_sensor5_start_timestamp = 0;
sts_o7_sensorData.event_sensor5_stop_time = sensor_event_time.Seconds;
sts_o7_sensorData.event_sensor5_stop_timestamp = time_stamp;
//sts_o7_sensorData.over_stay_state = 0;
//sts_o7_sensorData.event_sensor2_duration = 0;
}
}
/* USER CODE BEGIN EF */
/* USER CODE END EF */

View File

@ -321,6 +321,8 @@ void STS_TOF_L8_Process(void)
if (status == BSP_ERROR_NONE)
{
print_result(&Result);
} else {
printf("\r\n x \r\n");
}
}
}
@ -453,6 +455,30 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
static uint8_t prev_occupy_state=0;
uint32_t center_range_distance=0;
uint8_t center_roi[4] = {27,28,35,36};
static uint32_t prev_distance[64]={0};
uint32_t motion_diff=0, motion_power=0;
uint32_t motion_power_threshold = 3200; // 64*50mm
//printf("\r\n Motion level Calculation \r\n");
for (j=0; j<64; j++)
{
if (prev_distance[j] > (uint32_t)Result->ZoneResult[j].Distance[0])
motion_diff = (prev_distance[j] - (uint32_t)Result->ZoneResult[j].Distance[0]);
else motion_diff = (uint32_t)Result->ZoneResult[j].Distance[0] - prev_distance[j];
//printf("\r\nj=%d, diff=%d ", j, motion_diff);
motion_power += motion_diff;
prev_distance[j] = (uint16_t)Result->ZoneResult[j].Distance[0];
}
if (motion_power > fhmos_cfg.th_motion_power_level)
{
fhmos_human_movement =1;
} else {
fhmos_human_movement =0;
}
//printf("\r\n Motion Power =%d Average=%d Human Movement =%d\r\n", motion_power, motion_power/64, fhmos_human_movement);
zones_per_line = ((Profile.RangingProfile == RS_PROFILE_8x8_AUTONOMOUS) ||
(Profile.RangingProfile == RS_PROFILE_8x8_CONTINUOUS)) ? 8 : 4;
@ -470,23 +496,32 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
int32_t roi_distance =(uint32_t)center_range_distance/4;
/* state tree */
if ((roi_distance < sts_high_threshold) && (roi_distance > (sts_high_threshold - fhmos_cfg.th_head_level_height_cm*10))) // TODO XXX
{
printf("\r\n Suspicious Fall state: roi_distance =%d -----[high=%4d mm Head Level =%d mm\r\n", roi_distance, sts_high_threshold, 10*fhmos_cfg.th_head_level_height_cm);
printf("\r\nThreshold: low =%d occupy=%d head level=%d high=%d\r\n", sts_low_threshold, sts_occupancy_threshold, fhmos_cfg.th_head_level_height_cm*10, sts_high_threshold);
printf("\r\n YELLOW OR RED Distance=%d \r\n", roi_distance);
fhmos_data.state_fall = 1;
fhmos_data.state_human_movement = 1;
sts_lamp_bar_color = STS_OCCUPY_COLOR; // HOLD THIS COLOR BEFORE ENTER YELLOW STATUS
fhmos_fall_counter ++; // TODO XXX Timer for confirmation
if ((fhmos_fall_counter >60)&& (fhmos_fall_counter < 200))
if ((fhmos_fall_counter >= 15*fhmos_cfg.th_fall_duration_potential_15sec)&& (fhmos_fall_counter < 15*fhmos_cfg.th_fall_duration_confirm_15sec))
{
printf("\r\n [YELLOW **] Suspicious Fall: distance=%d [high - head level=[%d]] <= distance <= [high-100 =%d] \r\n",
roi_distance, (sts_high_threshold - 10*fhmos_cfg.th_head_level_height_cm), (sts_high_threshold - 100));
printf("\r\n duration =%d sec, threshold=%d sec\r\n", fhmos_fall_counter, 15*fhmos_cfg.th_fall_duration_potential_15sec);
printf("\r\n Fall state --- Yellow \r\n");
fhmos_fall =2;
sts_lamp_bar_color = STS_FALL_SUSPICIOUS_COLOR;
fhmos_data.state_changed_fall = STS_FHMOS_FALL_STATE_POTENTIAL;
} else if (fhmos_fall_counter >= 200)
} else if (fhmos_fall_counter >= 15*fhmos_cfg.th_fall_duration_confirm_15sec)
{
printf("\r\n [RED **] Configmed Fall: distance=%d [high - head level=[%d]] <= distance <= [high-100 =%d] \r\n",
roi_distance, (sts_high_threshold - 10*fhmos_cfg.th_head_level_height_cm), (sts_high_threshold - 100));
printf("\r\n duration =%d sec, threshold=%d sec\r\n", fhmos_fall_counter, 15*fhmos_cfg.th_fall_duration_confirm_15sec);
printf("\r\n Fall state --- Red \r\n");
printf("\r\n [RED ***] Confirmed Fall state: roi_distance =%d -----[high=%4d mm Head Level =%d mm\r\n", roi_distance, sts_high_threshold, 10*fhmos_cfg.th_head_level_height_cm);
fhmos_fall =3;
sts_lamp_bar_color = STS_FALL_CONFIRMED_COLOR;
fhmos_data.state_changed_fall = STS_FHMOS_FALL_STATE_CONFIRMED;
@ -498,28 +533,34 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
fhmos_fall_counter = 0;
fhmos_fall = 0;
fhmos_human_movement = 1;
printf("\r\nNormal Occupy state: rio distance =%d, low =%d occupy=%d \r\n", roi_distance, sts_low_threshold, sts_occupancy_threshold);
printf("\r\nThreshold: low =%d occupy=%d head level=%d high=%d\r\n", sts_low_threshold, sts_occupancy_threshold, fhmos_cfg.th_head_level_height_cm*10, sts_high_threshold);
printf("\r\n [GREEN ** ]Normal Occupy state: rio distance =%d, low =%d occupy=%d head level=%d high=%d\r\n", roi_distance, sts_low_threshold, sts_occupancy_threshold, fhmos_cfg.th_head_level_height_cm*10, sts_high_threshold);
//fhmos_occupancy = STS_FHMOS_OCCUPANCY_NORMAL;
fhmos_data.state_occupancy = STS_FHMOS_OCCUPANCY_NORMAL;
if (fhmos_data.prev_occupancy != fhmos_data.state_occupancy)
//if (fhmos_data.prev_occupancy != fhmos_data.state_occupancy)
{
sts_lamp_bar_color = STS_OCCUPY_COLOR;
}
}else
{
printf("\r\nThreshold: low =%d occupy=%d head level=%d high=%d\r\n", sts_low_threshold, sts_occupancy_threshold, fhmos_cfg.th_head_level_height_cm*10, sts_high_threshold);
printf("\r\n [BLUE *] No occupy status , distance=%d \r\n", roi_distance);
fhmos_data.state_occupancy = STS_FHMOS_OCCUPANCY_NO_OCCUPY;
fhmos_fall_counter =0;
fhmos_data.state_human_movement =STS_FHMOS_HUMAN_MOVEMENT_NO_OCCUPY;
fhmos_data.state_human_movement = fhmos_human_movement | STS_FHMOS_HUMAN_MOVEMENT_NO_OCCUPY;
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_NO_OCCUPY;
if (fhmos_data.prev_occupancy != fhmos_data.state_occupancy)
//if (fhmos_data.prev_occupancy != fhmos_data.state_occupancy)
sts_lamp_bar_color = STS_VACANT_COLOR;
}
fhmos_data.prev_occupancy = fhmos_data.state_occupancy;
fhmos_data.lamp_bar_color = sts_lamp_bar_color;
#if 0
@ -688,14 +729,14 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
* # height is configurable from 10cm to 90 cm, with interval of 1cm
* # the period of time is configurable, from 1 min to 30 mins, with 15 sec as interval
*
* sts_height_threshold (10cm --90 cm, 1cm interval) (10cm=10, 90cm=90, "P11T1XXX"
* sts_height_threshold (10cm --90 cm, 1cm interval) (10cm=10, 90cm=90, "P11T1XXX"
* sts_fall_duration_threshold_potential (1 min to 30 min. 15 sec interval, 1800 sec. 1800=15*120, 60=15*4) "P11T2XXX"
* sts_fall_duration_threshold_confirm (1 min to 30 min. 15 sec interval, 1800 sec. 1800=15*120, 60=15*4) "P11T3XXX"
*
* sts_motionless_threshold_short (1 min to 30 min. 15 sec interval, 1800 sec. 1800=15*120, 60=15*4) "P11T4XXX"
* sts_motionless_threshold_long (1 min to 30 min. 15 sec interval, 1800 sec. 1800=15*120, 60=15*4) "P11T5XXX"
* sts_motionless_threshold_short (1 min to 30 min. 15 sec interval, 1800 sec. 1800=15*120, 60=15*4) "P11T4XXX"
* sts_motionless_threshold_long (1 min to 30 min. 15 sec interval, 1800 sec. 1800=15*120, 60=15*4) "P11T5XXX"
*
* sts_occupancy_threshold_overstay (1 min to 30 min. 15 sec interval, 1800 sec. 1800=15*120, 60=15*4) "P11T6XXX"
* sts_occupancy_threshold_overstay (1 min to 30 min. 15 sec interval, 1800 sec. 1800=15*120, 60=15*4) "P11T6XXX"
*
*/