--- minor changes. bad lamp bar color, no flash

This commit is contained in:
Yunhorn 2024-08-09 19:48:47 +08:00
parent 31a40d52a8
commit 0a49fc5075
3 changed files with 77 additions and 40 deletions

View File

@ -309,7 +309,7 @@ static void print_result(acc_detector_presence_result_t result)
//uint32_t detected_zone = (uint32_t)((float)(result.presence_distance - DEFAULT_START_M) / (float)DEFAULT_ZONE_LENGTH);
// 2024-08-05
uint32_t detected_zone = (uint32_t)((float)(result.presence_distance) / (float)DEFAULT_ZONE_LENGTH);
APP_LOG(TS_OFF, VLEVEL_H,"\r\nMotion in zone: %u, distance: %d, score: %d\n", (unsigned int)detected_zone,
APP_LOG(TS_OFF, VLEVEL_H,"Motion in zone: %u, distance: %d, score: %d\n", (unsigned int)detected_zone,
(int)(result.presence_distance * 1000.0f),
(int)(result.presence_score * 1000.0f));
}
@ -395,6 +395,9 @@ int sts_presence_rss_fall_rise_detection(void)
for (uint8_t k=0;k<12;k++)
motion_in_hs_zone[k][motion_detected_count]=0;
UTIL_MEM_set_8(sts_motion_dataset, 0x0, sizeof(sts_motion_dataset));
motion_count =0;
//memset((void*)motion_in_hs_zone, 0x0, 12*10);
//past 10 times of detection with 5 zones from ground to ceiling
@ -413,9 +416,11 @@ int sts_presence_rss_fall_rise_detection(void)
//print_result(result);
if (!result.data_saturated)
{
APP_LOG(TS_OFF, VLEVEL_H,"\n%u ", i);
print_result(result);
if (result.presence_detected)
{
print_result(result);
//print_result(result);
average_result++;
average_distance += result.presence_distance;
average_score += result.presence_score;
@ -428,7 +433,7 @@ int sts_presence_rss_fall_rise_detection(void)
//if (detected_hs_zone == 0)
//APP_LOG(TS_OFF, VLEVEL_L, "\r\nPresence_Distance=%u \r\n", (int)result.presence_distance*1000.0);
//APP_LOG(TS_OFF, VLEVEL_L, "\r\nHS_ZONE=%u", (int)detected_hs_zone);
detected_hs_zone = 6 - detected_zone;
detected_hs_zone = 10 - detected_zone;
motion_in_hs_zone[detected_hs_zone][(motion_detected_count)]++;
@ -443,6 +448,7 @@ int sts_presence_rss_fall_rise_detection(void)
//acc_integration_sleep_ms(1000 / DEFAULT_UPDATE_RATE_PRESENCE); // 15ms, DEFAULT_UPDATE_RATE);
//acc_integration_sleep_ms(1);
}
APP_LOG(TS_OFF, VLEVEL_M, "\r\n First Half --- Motion Count = %u \r\n", motion_count);
acc_detector_presence_deactivate(handle);
@ -479,12 +485,14 @@ int sts_presence_rss_fall_rise_detection(void)
break;
}
//print_result(result);
if (!result.data_saturated)
{
APP_LOG(TS_OFF, VLEVEL_H,"\n%u ", i);
print_result(result);
if (result.presence_detected)
{
print_result(result);
//print_result(result);
average_result++;
average_distance += result.presence_distance;
average_score += result.presence_score;
@ -498,7 +506,7 @@ int sts_presence_rss_fall_rise_detection(void)
//if (detected_hs_zone == 0)
//APP_LOG(TS_OFF, VLEVEL_L, "\r\nPresence_Distance=%u \r\n", (int)result.presence_distance*1000.0);
//APP_LOG(TS_OFF, VLEVEL_L, "\r\nHS_ZONE=%u", detected_hs_zone);
detected_hs_zone = 6 - detected_zone;
detected_hs_zone = 10 - detected_zone;
motion_in_hs_zone[detected_hs_zone][(motion_detected_count)]++;
sts_motion_dataset[motion_count].presence_distance = 1000*result.presence_distance;
@ -513,21 +521,18 @@ int sts_presence_rss_fall_rise_detection(void)
//acc_integration_sleep_ms(1000 / DEFAULT_UPDATE_RATE_PRESENCE); // 15 ms, DEFAULT_UPDATE_RATE);
//acc_integration_sleep_ms(1);
}
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Second Half --- Motion Count Sum to = %u \r\n", motion_count);
//APP_LOG(TS_OFF, VLEVEL_L,"Second Half, Fall Rise Detection, Motion Count = %u \r\n", (int)motion_count);
motion_count = motion_count%DEFAULT_MOTION_DATASET_LEN; // get all required number of motion data
if (sts_presence_fall_detection == TRUE)
if ((sts_presence_fall_detection == TRUE)&& (motion_count>10))
STS_YunhornCheckStandardDeviation();
uint8_t thiscnt= motion_detected_count;
if (motion_detected_count++ == 10) {
motion_detected_count=0;
} else {
OnSensorRSS3CStateChanged();
}
// RSS feature 1: Motion, No-motion process
sts_rss_result = (average_result > 3)? 1: 0;
if (sts_rss_result) {
LED1_ON;
@ -537,12 +542,13 @@ int sts_presence_rss_fall_rise_detection(void)
}
// RSS feature 2: Fall Detection process
/* TODO XXXX 2024-06-06
* Fall Detection settings
*/
if (sts_fall_rising_detected_result) {
if (sts_fall_rising_detected_result)
{
LED1_ON;
OnSensorRSS3BStateChanged();
} else {
@ -550,6 +556,18 @@ int sts_presence_rss_fall_rise_detection(void)
}
// RSS feature 3: No motion, or stay still , or unconscious process
uint8_t thiscnt= motion_detected_count;
if (motion_detected_count++ == 10) {
motion_detected_count=0;
} else {
OnSensorRSS3CStateChanged();
}
#ifndef MIN
#define MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
#endif
#ifndef MAX
#define MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
#endif
@ -619,25 +637,25 @@ void STS_YunhornCheckStandardDeviation(void)
uint32_t roc_distance[DEFAULT_MOTION_DATASET_LEN]={0}, sum_roc_distance=0, average_roc_distance=0, variance_roc_distance=0, standard_variance_roc_distance=0;
uint32_t roc_acc[DEFAULT_MOTION_DATASET_LEN]={0}, sum_roc_acc=0.0f, average_roc_acc=0.0f, variance_roc_acc=0.0f, standard_variance_roc_acc=0.0f;;
//act as speed of change at given time slot acc_integration_sleep_ms(1000 / DEFAULT_UPDATE_RATE_PRESENCE);
uint8_t SAMPLE_DATASET_NUM = MIN(motion_count,DEFAULT_MOTION_DATASET_LEN );
//SUM of samples
for(i= 0; i< DEFAULT_MOTION_DATASET_LEN; i++)
for(i= 0; i< SAMPLE_DATASET_NUM; i++)
{
sum_presence_distance += (uint32_t)sts_motion_dataset[i].presence_distance;
sum_presence_score += (uint32_t)sts_motion_dataset[i].presence_score;
}
// AVERAGE of all samples ( u (miu) )
average_presence_distance = ((uint32_t)sum_presence_distance/(uint32_t)(DEFAULT_MOTION_DATASET_LEN));
average_presence_score = ((uint32_t)sum_presence_score/(uint32_t)(DEFAULT_MOTION_DATASET_LEN));
average_presence_distance = ((uint32_t)sum_presence_distance/(uint32_t)(SAMPLE_DATASET_NUM));
average_presence_score = ((uint32_t)sum_presence_score/(uint32_t)(SAMPLE_DATASET_NUM));
// 1) VARIANCE
for (j = 0; j < DEFAULT_MOTION_DATASET_LEN; j++)
for (j = 0; j < SAMPLE_DATASET_NUM; j++)
{
variance_presence_distance += (uint32_t)pow(sts_motion_dataset[j].presence_distance - average_presence_distance,2);
variance_presence_score += (uint32_t)pow(sts_motion_dataset[j].presence_score - average_presence_score,2);
}
variance_presence_distance /= (uint32_t)(DEFAULT_MOTION_DATASET_LEN-1);
variance_presence_score /= (uint32_t)(DEFAULT_MOTION_DATASET_LEN-1);
variance_presence_distance /= (uint32_t)(SAMPLE_DATASET_NUM-1);
variance_presence_score /= (uint32_t)(SAMPLE_DATASET_NUM-1);
//STANDARD VARIANCE sigma
standard_variance_presence_distance = (uint32_t)sqrt(variance_presence_distance);
@ -647,20 +665,20 @@ void STS_YunhornCheckStandardDeviation(void)
// ROC distance
// SUM
for(i= 0; i< (DEFAULT_MOTION_DATASET_LEN-1); i++)
for(i= 0; i< (SAMPLE_DATASET_NUM-1); i++)
{
roc_distance[i] = (uint32_t)(labs(sts_motion_dataset[i+1].presence_distance - sts_motion_dataset[i].presence_distance));
sum_roc_distance += ((uint32_t)roc_distance[i]);
}
average_roc_distance = (uint32_t)sum_roc_distance/(DEFAULT_MOTION_DATASET_LEN-1);
average_roc_distance = (uint32_t)sum_roc_distance/(SAMPLE_DATASET_NUM-1);
for (j = 0; j < (DEFAULT_MOTION_DATASET_LEN-1); j++)
for (j = 0; j < (SAMPLE_DATASET_NUM-1); j++)
{
variance_roc_distance += (uint32_t)(pow(roc_distance[j] - average_roc_distance,2));
}
// average
variance_roc_distance /= (uint32_t)(DEFAULT_MOTION_DATASET_LEN-1);
variance_roc_distance /= (uint32_t)(SAMPLE_DATASET_NUM);
//????
standard_variance_roc_distance = (uint32_t)sqrt((uint32_t)variance_roc_distance);
@ -668,20 +686,20 @@ void STS_YunhornCheckStandardDeviation(void)
// ROC Acceleration
for(i= 0; i< (DEFAULT_MOTION_DATASET_LEN-2); i++)
for(i= 0; i< (SAMPLE_DATASET_NUM-2); i++)
{
roc_acc[i] = (uint32_t)(labs((uint32_t)roc_distance[i+1] - (uint32_t)roc_distance[i]));
sum_roc_acc += ((uint32_t)roc_acc[i]);
}
average_roc_acc = (uint32_t)sum_roc_acc/(DEFAULT_MOTION_DATASET_LEN-2);
average_roc_acc = (uint32_t)sum_roc_acc/(SAMPLE_DATASET_NUM-2);
for (j = 0; j < (DEFAULT_MOTION_DATASET_LEN-2); j++)
for (j = 0; j < (SAMPLE_DATASET_NUM-2); j++)
{
variance_roc_acc += (uint32_t)pow((uint32_t)((uint32_t)roc_acc[j] - (uint32_t)average_roc_acc),2);
}
variance_roc_acc /= (uint32_t)(DEFAULT_MOTION_DATASET_LEN-2);
variance_roc_acc /= (uint32_t)(SAMPLE_DATASET_NUM-1);
standard_variance_roc_acc = (uint32_t)sqrt((uint32_t)variance_roc_acc);
@ -712,7 +730,7 @@ void STS_YunhornCheckStandardDeviation(void)
(int)(average_roc_acc), (int)(standard_variance_roc_acc));
//sts_fall_rising_pattern_factor1 = (int)(standard_variance_roc_distance);
sts_fall_rising_pattern_factor1 = (int)(average_roc_distance/10);
sts_fall_rising_pattern_factor1 = (int)(average_roc_distance);
sts_fall_rising_pattern_factor2 = (int)(fabs(average_presence_distance - last_average_presence_distance));
APP_LOG(TS_OFF, VLEVEL_L,"\r\nAvg-Dist =%6u, Last_AVG-Dist =%6u \r\n", (int)(average_presence_distance), (int)(last_average_presence_distance));
@ -735,13 +753,22 @@ void STS_YunhornCheckStandardDeviation(void)
sts_fall_rising_detected_result = STS_PRESENCE_NORMAL;
}
//
// Considering factor #1 --- fall down speed, say > 0.3g or in less than 0.3 seconds
//
if ( sts_fall_rising_pattern_factor1 > (uint16_t)sts_fall_detection_acc_threshold)
{
// if ((average_presence_distance > (sts_motion_feature[motion_feature_count].p_dist_avg + sts_motion_feature[motion_feature_count].p_dist_v)))
// if ((average_presence_distance > (sts_motion_feature[motion_feature_count].p_dist_avg + sts_motion_feature[motion_feature_count].p_dist_v)))
// if ((average_presence_distance > (last_average_presence_distance + sts_fall_detection_depth_threshold*0.1)))
if ((sts_fall_rising_pattern_factor2 > sts_fall_detection_depth_threshold ) && (average_presence_distance > DEFAULT_START_M))
//
// Considering factor #2 --- fall down depth, say > 30 cm 40 cm in given factor 1 time unit
//
if ((sts_fall_rising_pattern_factor2 > sts_fall_detection_depth_threshold ) && (average_presence_distance > 1000*DEFAULT_START_M))
{
sts_fall_rising_detected_result = STS_PRESENCE_FALL;
//last_sts_fall_rising_detected_result = sts_fall_rising_detected_result;

View File

@ -272,7 +272,9 @@ void STS_YunhornSTSEventP2_Process(void)
sts_rss_result_changed_flag = (sts_rss_result == last_sts_rss_result)? 0:1;
last_sts_rss_result = sts_rss_result;
sts_fall_rising_detected_result_changed_flag = (sts_fall_rising_detected_result == last_sts_fall_rising_detected_result)?0:1;
//sts_fall_rising_detected_result_changed_flag = (sts_fall_rising_detected_result == last_sts_fall_rising_detected_result)?0:1;
sts_fall_rising_detected_result_changed_flag = (sts_fall_rising_detected_result != 0)?1:0;
last_sts_fall_rising_detected_result = sts_fall_rising_detected_result;
if (sts_service_mask > 0 ) {
@ -478,6 +480,7 @@ void STS_Combined_Status_Processing(void)
{
case STS_NETWORK_MODE:
sts_status_color = sts_cloud_netcolor;
sts_lamp_bar_color = sts_cloud_netcolor;
break;
case STS_WIRED_MODE: // NO LAMP BAR FOR THOSE WATER LEAKAGE SENSOR OR SOAP CAPACITY SENSORS
sts_status_color = STS_DARK;
@ -642,10 +645,11 @@ void STS_Combined_Status_Processing(void)
}
if ((sts_rss_result_changed_flag)|| (sts_reed_hall_changed_flag))
if ((sts_rss_result_changed_flag)|| (sts_reed_hall_changed_flag)||(sts_fall_rising_detected_result_changed_flag))
{
sts_rss_result_changed_flag =0;
sts_reed_hall_changed_flag =0;
sts_fall_rising_detected_result_changed_flag =0;
//sts_tof_result_changed_flag =0;
sensor_data_ready = 1;
//STS_PRESENCE_SENSOR_Prepare_Send_Data();
@ -1172,7 +1176,8 @@ void OnSensorRSS3BStateChanged(void)
break;
case STS_PRESENCE_FALL:
if (motion_in_hs_zone[0][motion_detected_count]) {
//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;
@ -1180,7 +1185,8 @@ void OnSensorRSS3BStateChanged(void)
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:

View File

@ -62,7 +62,7 @@ extern volatile uint8_t sts_lamp_bar_flashing_color;
volatile uint8_t last_sts_lamp_bar_color=STS_DARK;
extern volatile uint8_t sts_rss_result;
extern volatile uint8_t sts_rss_result_changed_flag, sts_hall1_changed_flag, sts_hall2_changed_flag, sts_reed_hall_changed_flag;
volatile uint8_t sts_fall_detection_acc_threshold = 20,
volatile uint8_t sts_fall_detection_acc_threshold = 30, //0.3g
sts_fall_detection_depth_threshold=20,
sts_fall_confirm_threshold_in_10sec=1,
sts_occupancy_overtime_threshold_in_10min=2;
@ -2281,8 +2281,12 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, uint8_t tlv_buf_size)
APP_LOG(TS_OFF, VLEVEL_L, "\r\n Cloud Color Set to %u \r\n", sts_cloud_netcolor);
}
sts_service_mask = STS_SERVICE_MASK_L0;
if ((sts_cloud_netcolor >= 11)&&(sts_cloud_netcolor<=36)) // 'A'-'Z'
sts_lamp_bar_color = (sts_cloud_netcolor+0x30);
if ((sts_cloud_netcolor >= 11)&&(sts_cloud_netcolor<=42)) // 'A'-'Z'
{
sts_lamp_bar_color = (sts_cloud_netcolor+0x30);
sts_status_color = sts_lamp_bar_color;
sts_cloud_netcolor += 0x30;
}
sts_cfg_nvm.work_mode = (uint8_t)sts_work_mode;
sts_cfg_nvm.sts_service_mask = (uint8_t)sts_service_mask;
OnStoreSTSCFGContextRequest();