From: kyz Date: Mon, 7 Aug 2023 03:07:49 +0000 (+0800) Subject: 修改人感检测周期判断逻辑 X-Git-Url: http://kyz.pub/gitweb/?a=commitdiff_plain;h=8f0096f8d5038088721972aa00e88238ca7aca21;p=yn%2Falarmmonitor.git 修改人感检测周期判断逻辑 --- diff --git a/app/inc/device.h b/app/inc/device.h index 7aaae4b..d9038b9 100644 --- a/app/inc/device.h +++ b/app/inc/device.h @@ -117,7 +117,7 @@ typedef struct{ dev_cfg_t cfg; uint32_t iot_connect; - uint32_t tof_st; //人感状态 + uint32_t tof_somebody; //人感状态, 1: 有人,0:无人/障碍 uint32_t tof_sync; //人感状态同步 uint32_t mg_active; //moorgen 激活标志 diff --git a/app/src/device_ctrl.c b/app/src/device_ctrl.c index 2813d11..9235bd1 100644 --- a/app/src/device_ctrl.c +++ b/app/src/device_ctrl.c @@ -34,6 +34,8 @@ void * btn_light_ctrl_task( void* para ) time_t tof_check_time; tof_info_t info; + int32_t tof_changed_start_time = 0; + MG_LOGI( "btn light ctrl task run..." ); dev = ( mg_dev_t * )para; @@ -172,14 +174,44 @@ void * btn_light_ctrl_task( void* para ) Distance_parameter_correction(dev->tof, tof_threshold_cm * 10 ); } + int32_t somebody = 0; + int32_t now_secs = device_uptime_sec(); + if( !row_disabled && tof_sync ){ //联排功能,平台设置人感状态 - light_mode_set( dev, LIGHT_MODE_TOF_ACTIVE ); + //light_mode_set( dev, LIGHT_MODE_TOF_ACTIVE ); + somebody = 1; + }else if( !dev->tof ){ //TOF传感器故障,LED按无人显示 - light_mode_set( dev, LIGHT_MODE_TOF_DEACTIVE ); + //light_mode_set( dev, LIGHT_MODE_TOF_DEACTIVE ); + somebody = 0; + }else{ + mg_tof_read( dev->tof, &info ); + somebody = (info.status==TOF_ANYBODY)?1:0; } + if( dev->tof_somebody == somebody ){ + tof_changed_start_time = now_secs; + }else if( somebody == 1){ + //无人到有人, 立即上报 + dev->tof_somebody = somebody; //无人--> 有人 + dp_tof_status_report(1); //状态变化,上报DP + MG_LOGI( "[%d]device tof status - > 1\n", now_secs ); + tof_changed_start_time = now_secs; + }else if( now_secs - tof_changed_start_time > cfg_mg_tof_interval_read( dev ) ){ + //有人到无人,持续时间需达到DP人感检测周期设定时间(10s-20s)后切换 + dev->tof_somebody = somebody; // 有人-->无人 + dp_tof_status_report(0); //状态变化,上报DP + MG_LOGI( "[%d - %d]device tof status - > 0\n", now_secs, tof_changed_start_time ); + tof_changed_start_time = now_secs; + } + if( dev->tof_somebody ){ + light_mode_set( dev, LIGHT_MODE_TOF_ACTIVE ); + }else{ + light_mode_set( dev, LIGHT_MODE_TOF_DEACTIVE ); + } +#if 0 if( dev->tof && device_uptime_sec() - tof_check_time > cfg_mg_tof_interval_read( dev ) ){ //printf( "%d - %d > %d\n", device_uptime_sec(), tof_check_time, cfg_mg_tof_interval_read(dev) ); tof_check_time = device_uptime_sec(); @@ -190,7 +222,8 @@ void * btn_light_ctrl_task( void* para ) static tof_info_t dbg_info; if( dbg_info.enable != info.enable || dbg_info.status != info.status || abs( dbg_info.distance-info.distance)>5 ){ memcpy( &dbg_info, &info, sizeof( dbg_info ) ); - MG_LOGD( "read tof info, enable:%d, status:%d, dist:%d", info.enable, info.status, info.distance ); + MG_LOGD( +"read tof info, enable:%d, status:%d, dist:%d", info.enable, info.status, info.distance ); } }else{ MG_LOGW( "read tof info fail, g_tof:%p", dev->tof ); @@ -211,6 +244,7 @@ void * btn_light_ctrl_task( void* para ) MG_LOGI( "device tof status - > %d \n", tof_st ); } } +#endif } } } diff --git a/app/src/device_netconfig.c b/app/src/device_netconfig.c index ece079a..fcc3df7 100644 --- a/app/src/device_netconfig.c +++ b/app/src/device_netconfig.c @@ -94,8 +94,8 @@ void wifi_setup_success( char * ssid, char *password ) wifi_config_store( ssid, password ); } -extern int open_udp_listen( void ); -extern int close_udp_listen( void ); +//extern int open_udp_listen( void ); +//extern int close_udp_listen( void ); extern char *ble_get_local_ip( char* buf, int32_t buf_sz ); extern void ip_change_notify( char * ip ); @@ -119,13 +119,13 @@ void * device_netconfig_task( void * para ) ble_get_local_ip( ip_str, sizeof( ip_str ) ); ble_start = dev->netconfig; ble_wificonfig_start(); - open_udp_listen(); + //open_udp_listen(); }else if( ble_start && !dev->netconfig ){ //停止配网 MG_LOGD( "ble stop....\n" ); ble_start = dev->netconfig; ble_wificonfig_stop(); - close_udp_listen(); + //close_udp_listen(); } if( ble_start ){