minor improve

This commit is contained in:
Yunhorn 2024-06-11 19:43:55 +08:00
parent a06377dfc5
commit c5d43191e9
4 changed files with 49 additions and 16 deletions

View File

@ -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 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 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 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 occupancy_over_stay_state; //
uint8_t battery_Pct; /* % of battery two digits, 88% (00-99)% */ uint8_t battery_Pct; /* % of battery two digits, 88% (00-99)% */
uint8_t dutycycletimelevel; /* level=0,255 */ uint8_t dutycycletimelevel; /* level=0,255 */
@ -188,8 +189,10 @@ typedef struct STS_OO_SensorStatusDataTypeDef
uint32_t event_sensor1_duration; uint32_t event_sensor1_duration;
uint32_t event_sensor2_start_time; uint32_t event_sensor2_start_time;
uint32_t event_sensor2_duration; uint32_t event_sensor2_duration;
uint32_t event_sensor3_start_time; uint32_t event_sensor3_motion_start_time;
uint32_t event_sensor3_duration; 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_start_time;
uint32_t event_sensor4_duration; uint32_t event_sensor4_duration;
uint8_t alarm_indictor_mute_state; uint8_t alarm_indictor_mute_state;

View File

@ -369,12 +369,12 @@ int sts_presence_rss_fall_rise_detection(void)
uint8_t average_result = 0; uint8_t average_result = 0;
float average_distance =0.0f; float average_distance =0.0f;
float average_score =0.0f; float average_score =0.0f;
uint8_t k=0; //uint8_t k=0;
uint16_t motion_in_zone[10]={0x0}; uint16_t motion_in_zone[10]={0x0};
uint16_t detected_zone=0; uint16_t detected_zone=0;
//for (k=0; k<5; k++) {motion_in_zone[k]=0;} //for (k=0; k<5; k++) {motion_in_zone[k]=0;}
#if 1 #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); success = acc_detector_presence_get_next(handle, &result);
if (!success) if (!success)
@ -483,7 +483,13 @@ int sts_presence_rss_fall_rise_detection(void)
sts_rss_result = (average_result > 1)? 1: 0; 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 /* TODO XXXX 2024-06-06
@ -494,7 +500,7 @@ int sts_presence_rss_fall_rise_detection(void)
*/ */
#ifdef LOG_RSS #ifdef LOG_RSS
for (k=0; k<10; k++) { for (uint8_t k=0; k<10; k++) {
if (motion_in_zone[k]>0) { 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)); APP_LOG(TS_OFF, VLEVEL_M,"\r\nMotion Distance Zone: %2u %4u %4d cm", k, motion_in_zone[k], (80+k*40));
} }

View File

@ -509,8 +509,10 @@ void STS_PRESENCE_SENSOR_Init_Send_Data(void)
sts_o7_sensorData.event_sensor1_duration = 0x0; sts_o7_sensorData.event_sensor1_duration = 0x0;
sts_o7_sensorData.event_sensor2_start_time = 0x0; sts_o7_sensorData.event_sensor2_start_time = 0x0;
sts_o7_sensorData.event_sensor2_duration = 0x0; sts_o7_sensorData.event_sensor2_duration = 0x0;
sts_o7_sensorData.event_sensor3_start_time = 0x0; sts_o7_sensorData.event_sensor3_motion_start_time = 0x0;
sts_o7_sensorData.event_sensor3_duration = 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_start_time = 0x0;
sts_o7_sensorData.event_sensor4_duration = 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_sensor1_duration = 0;
sts_o7_sensorData.event_sensor2_start_time = 0; sts_o7_sensorData.event_sensor2_start_time = 0;
sts_o7_sensorData.event_sensor2_duration = 0; sts_o7_sensorData.event_sensor2_duration = 0;
sts_o7_sensorData.event_sensor3_start_time = 0; sts_o7_sensorData.event_sensor3_motion_start_time = 0;
sts_o7_sensorData.event_sensor3_duration = 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_start_time = 0;
sts_o7_sensorData.event_sensor4_duration = 0; sts_o7_sensorData.event_sensor4_duration = 0;
@ -826,7 +830,7 @@ void STS_O5_SENSOR_Read(STS_OO_SensorDataTypeDef *oo_data)
#endif #endif
/* reedswitch 1 on off */
void OnSensor1StateChanged(void) void OnSensor1StateChanged(void)
{ {
SysTime_t sensor_event_time = SysTimeGetMcuTime(); SysTime_t sensor_event_time = SysTimeGetMcuTime();
@ -837,6 +841,7 @@ void OnSensor1StateChanged(void)
} }
} }
/* SOS emergency button on off */
void OnSensor2StateChanged(void) void OnSensor2StateChanged(void)
{ {
SysTime_t sensor_event_time = SysTimeGetMcuTime(); SysTime_t sensor_event_time = SysTimeGetMcuTime();
@ -847,6 +852,7 @@ void OnSensor2StateChanged(void)
} }
} }
/* motion sensor RSS ON-OFF */
void OnSensor3StateChanged(void) void OnSensor3StateChanged(void)
{ {
SysTime_t sensor_event_time = SysTimeGetMcuTime(); SysTime_t sensor_event_time = SysTimeGetMcuTime();
@ -858,10 +864,15 @@ void OnSensor3StateChanged(void)
#endif #endif
if (sts_rss_result == STS_RESULT_MOTION) if (sts_rss_result == STS_RESULT_MOTION)
{ {
sts_o7_sensorData.event_sensor3_start_time = sensor_event_time.Seconds; sts_o7_sensorData.event_sensor3_motion_start_time = sensor_event_time.Seconds;
sts_o7_sensorData.event_sensor3_duration = 0; sts_o7_sensorData.event_sensor3_motion_duration = 0;
} }
last_sts_rss_time_stamp = sensor_event_time.Seconds; 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) void OnSensor4StateChanged(void)

View File

@ -1114,12 +1114,13 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context)
if (sts_rss_result==STS_RESULT_MOTION) if (sts_rss_result==STS_RESULT_MOTION)
sts_o7_sensorData.event_sensor3_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_start_time; sts_o7_sensorData.event_sensor3_motion_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_motion_start_time;
if (sts_o7_sensorData.event_sensor3_duration > sts_occupancy_overtime_threshold) if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold)
{ {
sts_o7_sensorData.occupancy_over_stay_state = 1; 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_NONE=0,
STS_PRESENCE_FALL, STS_PRESENCE_FALL,
@ -1130,8 +1131,20 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context)
*/ */
switch (sts_fall_rising_detected_result){ switch (sts_fall_rising_detected_result){
case STS_PRESENCE_NONE: 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; break;
case STS_PRESENCE_FALL: 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; break;
case STS_PRESENCE_RISING: case STS_PRESENCE_RISING:
break; break;