From 85162c808ee67497685515919bdc824514acda53 Mon Sep 17 00:00:00 2001 From: kyz Date: Mon, 5 Jun 2023 14:49:00 +0800 Subject: [PATCH] =?utf8?q?=E6=89=8B=E5=8A=BF=E8=AF=86=E5=88=AB=E5=8A=9F?= =?utf8?q?=E8=83=BD=E8=B0=83=E8=AF=95=EF=BC=8C=E5=8F=AF=E4=BB=A5=E8=AF=86?= =?utf8?q?=E5=88=AB=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- app/inc/mg_version.h | 2 +- app/src/device_gesture.c | 183 +++++++++++++++++++++++++++++---------- app/src/device_light.c | 4 +- app/src/iot.c | 2 +- app/src/iot_dp.c | 4 +- app/src/main.c | 12 +-- log/log4crc | 2 +- log/src/mg_log.c | 3 +- 8 files changed, 150 insertions(+), 62 deletions(-) diff --git a/app/inc/mg_version.h b/app/inc/mg_version.h index a02a20a..f04df70 100644 --- a/app/inc/mg_version.h +++ b/app/inc/mg_version.h @@ -1,7 +1,7 @@ #ifndef __MG_VERSION_H__ #define __MG_VERSION_H__ -#define SW_VERSION "1.0" +#define SW_VERSION "1.0.1" #endif //__MG_VERION_H__ diff --git a/app/src/device_gesture.c b/app/src/device_gesture.c index b11f404..2b8c730 100644 --- a/app/src/device_gesture.c +++ b/app/src/device_gesture.c @@ -159,13 +159,13 @@ void rk_vi_init(VI_PIPE ViPipe, VI_CHN ViChn,uint32_t video_width,uint32_t video ret |= RK_MPI_VI_EnableChn(ViPipe, ViChn); if (ret) { printf("Create vi[%d] failed! ret=%d\n",ViPipe, ret); - return -1; + return; } ret = RK_MPI_VI_StartStream(ViPipe, ViChn); if (ret) { printf("RK_MPI_VI_StartStream [ViChn] failed! ret=%d\n", ret); - return -1; + return; } } @@ -222,7 +222,7 @@ static void gr_als_t(gr_ctrl_t* gr_ctrl) if(!gr_info){ printf( "malloc als_info failed \n"); - return -1; + return; } mg_als_read(gr_ctrl->als_ctrl,gr_info); @@ -242,7 +242,7 @@ static void gr_als_t(gr_ctrl_t* gr_ctrl) //算法识别 static int32_t gr_read_gesture(void) { - int32_t ret; + int32_t ret = -1; if(!mg_detectResult) goto error; @@ -280,6 +280,7 @@ static int32_t gr_read_gesture(void) ret = GR_PALM; break; default: + ret = -1; break; } mg_detectResult = NULL; //清空是为了避免下次读取的是上一次的值 @@ -298,7 +299,8 @@ static int32_t gr_detect_effective(gesture_ev_t ev) sleep(1); if(gr_read_gesture() == ev){ if(ev != GR_PALM){ - dp_gesture_event_report(ev); + dp_gesture_event_report(ev); + printf("上报dp ===================== %d\n",ev); } return 0; } @@ -326,11 +328,12 @@ void* gr_task( void* param ) gr_ctrl_t *p_gr = ( gr_ctrl_t*)param; + gr_time = time(NULL); + while(!stop){ usleep(1000); dp_timeout = cfg_recognition_duration_read( p_gr->dev); - if(init) gr_als_t(p_gr); @@ -342,12 +345,14 @@ void* gr_task( void* param ) gr_ring_enable(p_gr->light_ctrl); sleep(1); while(!stop){ - usleep(1000); + usleep(100*000); if(time_flasg){ - gr_time = time(NULL) + dp_timeout; + gr_time = time(NULL); time_flasg = 0; } - if(time(NULL) >= gr_time){ + + dp_timeout = cfg_recognition_duration_read( p_gr->dev); + if(time(NULL) - gr_time > dp_timeout){ printf("超时退出\n"); reportdp_and_close_ring_gr(p_gr->light_ctrl); sleep(1); @@ -356,7 +361,7 @@ void* gr_task( void* param ) gr_als_t(p_gr); ret = gr_read_gesture(); - if((ret == -1) || (ret == GS_GUN)){ + if( ret == -1 ){ continue; }else if(ret == GR_PALM){ if(gr_ai_detect_palm() == 0){ @@ -386,8 +391,42 @@ static void* ai_detect(void *arg) struct timespec ts; MEDIA_BUFFER mb = NULL; int ret; +#if 0 + time_t now = 0; + time_t time_2023 = 0; + struct tm tm_2023; + + tm_2023.tm_sec = 0; + tm_2023.tm_min = 0; + tm_2023.tm_hour = 0; + tm_2023.tm_mday = 1; + tm_2023.tm_mon = 6; + tm_2023.tm_year = 123; + tm_2023.tm_wday = 0; + tm_2023.tm_yday = 1; + tm_2023.tm_isdst= 0; + + time_2023 = mktime( &tm_2023 ); + while( 1 ){ + //等待网络时间获取,避免license报错 + now = time( NULL ); + if( now > time_2023 ){ + printf( "------------------wait ntp update, to now [%ld] > [%ld] ......\n",now, time_2023 ); + break; + } + sleep(1); + printf( "wait ntp update, to now [%ld] > [%ld] ......\n",now, time_2023 ); + } +#endif +retry_for_wait_ntp: ret=sentime_ai_init(); + if(ret==-15){ + printf( "sentime_ai_init fail -15, retry...\n" ); + sleep(2); + goto retry_for_wait_ntp; + } + if(ret!=0) { printf("sentime_ai_init fail! ret=%d\n", ret); @@ -398,7 +437,7 @@ static void* ai_detect(void *arg) unsigned char *image_data = (unsigned char *)malloc(nv12_buffer_size); if(image_data==NULL) - return; + return NULL; STImage detectImage = {0}; @@ -412,6 +451,7 @@ static void* ai_detect(void *arg) //mb = RK_MPI_SYS_GetMediaBuffer(RK_ID_VI, camera_id, -1); mb = RK_MPI_SYS_GetMediaBuffer(RK_ID_VI, 0, -1); if (!mb) { + usleep(100*1000); continue; } else @@ -448,20 +488,15 @@ int gr_register(gr_ctrl_t* gr_ctrl, uint32_t threshold_high, uint32_t threshold_ mg_als_cfg(gr_ctrl->als_ctrl,threshold_high,threshold_low); -printf("1 \n"); rk_isp_init(0,"/etc/iqfiles/"); //rk_isp_init(1,"/etc/iqfiles/"); -printf("2 \n"); RK_MPI_SYS_Init(); -printf("3 \n"); rk_vi_init(0,0,ST_AI_IMAGE_W,ST_AI_IMAGE_H); -printf("4 \n"); //rk_vi_init(1,1,ST_AI_IMAGE_W,ST_AI_IMAGE_H); rk_vi_setfps(0,15); //rk_vi_setfps(1,15); -printf("5 \n"); usleep(100*1000); if (pthread_create(&th2, NULL, ai_detect, NULL)) { @@ -510,52 +545,95 @@ void gr_close(gr_ctrl_t* gr_ctrl) -#if 0 + //测试程序 -int main_x(int argc, char *argv[]) +// int main(int argc, char *argv[]) +// { +// int ret; + +// gr_ctrl_t *test = (gr_ctrl_t *)malloc(sizeof(gr_ctrl_t)); + +// light_ctrl_t ctrl = mg_led_open(); +// if (!ctrl) +// { +// printf("led test..., open led failed\n"); +// goto app_ext1; +// } +// printf("led test..., open led, ret:%p\n", ctrl); +// test->light_ctrl = ctrl; + +// printf("zzzzz\n"); + +// signal(SIGINT, sigterm_handler); +// usleep(100 * 1000); + +// ret = gr_register(test, 1000, 400); + +// if (ret) +// { +// printf("gr_register falied === \n"); +// } + +// // sleep(15); +// // gr_close(test); + +// while (!quit) +// { +// usleep(100 * 1000); +// } + +// app_ext1: +// free(test); +// test = NULL; +// return -1; +// } + +#if 0 +static gr_ctrl_t gr_ctrl; + +extern light_ctrl_t g_led_ctrl; +extern mg_dev_t g_mg_dev; + +int32_t main( void ) { - int ret; + int32_t ret = 0; + uint32_t als_th_high = 1000; + uint32_t als_th_low = 400; - gr_ctrl_t *test = (gr_ctrl_t *)malloc(sizeof(gr_ctrl_t)); + memset( &gr_ctrl, 0, sizeof( gr_ctrl ) ); - light_ctrl_t ctrl = mg_led_open(); - if (!ctrl) + g_led_ctrl = mg_led_open(); + if (!g_led_ctrl) { printf("led test..., open led failed\n"); - goto app_ext1; + return -1; } - printf("led test..., open led, ret:%p\n", ctrl); - test->light_ctrl = ctrl; - - printf("zzzzz\n"); - signal(SIGINT, sigterm_handler); - usleep(100 * 1000); + gr_ctrl.light_ctrl = g_led_ctrl; + gr_ctrl.dev = &g_mg_dev; + load_als_threshold( &als_th_high, &als_th_low ); - ret = gr_register(test, 1000, 400); + signal(SIGINT, sigterm_handler); + usleep(100 * 1000); - if (ret) - { - printf("gr_register falied === \n"); - } + printf("als_th_high = %d als_th_low = %d\n",als_th_high,als_th_low); + ret = gr_register( &gr_ctrl, als_th_high, als_th_low ); - // sleep(15); - // gr_close(test); + if (ret){ + MG_LOGE("gr_register falied === \n"); + ret = -1; + } while (!quit) { usleep(100 * 1000); } -app_ext1: - free(test); - test = NULL; - return -1; + return ret; } -#else +#endif static gr_ctrl_t gr_ctrl; -static light_ctrl_t als_ctrl; extern light_ctrl_t g_led_ctrl; extern mg_dev_t g_mg_dev; @@ -563,18 +641,29 @@ extern mg_dev_t g_mg_dev; int32_t gesture_recognition_start( void ) { int32_t ret = 0; - uint32_t als_th_high; - uint32_t als_th_low; + uint32_t als_th_high = 1000; + uint32_t als_th_low = 400; + memset( &gr_ctrl, 0, sizeof( gr_ctrl ) ); + //zf + // g_led_ctrl = mg_led_open(); + // if (!g_led_ctrl) + // { + // printf("led test..., open led failed\n"); + // return -1; + // } + //zf_end gr_ctrl.light_ctrl = g_led_ctrl; gr_ctrl.dev = &g_mg_dev; load_als_threshold( &als_th_high, &als_th_low ); // signal(SIGINT, sigterm_handler); - // usleep(100 * 1000); - ret = gr_register( &g_led_ctrl, als_th_high, als_th_low ); + usleep(100 * 1000); + + //printf("als_th_high = %d als_th_low = %d\n",als_th_high,als_th_low); + ret = gr_register( &gr_ctrl, als_th_high, als_th_low ); if (ret){ MG_LOGE("gr_register falied === \n"); @@ -584,5 +673,3 @@ int32_t gesture_recognition_start( void ) return ret; } -#endif - diff --git a/app/src/device_light.c b/app/src/device_light.c index bc042e7..859cd45 100644 --- a/app/src/device_light.c +++ b/app/src/device_light.c @@ -111,7 +111,7 @@ void light_mode_set( light_mode_t mode ) dur_sec = cfg_led_atmos_off_duration_read( &g_mg_dev ); key_led_on( g_led_ctrl, LED_ID_KEY_ALL&key_mask, 0, 100, dur_sec*1000 ); atmos_led_off( g_led_ctrl, LED_ID_ATMOS_ALL, 100, 0, dur_sec*1000 ); - ring_led_breath( g_led_ctrl, 4000, 10*1000 ); + //ring_led_breath( g_led_ctrl, 4000, 10*1000 ); break; case LIGHT_MODE_TOF_DEACTIVE: // @@ -119,7 +119,7 @@ void light_mode_set( light_mode_t mode ) key_led_off( g_led_ctrl, LED_ID_KEY_ALL, 100, 0, dur_sec*1000 ); //atmos_led_on( g_led_ctrl, LED_ID_ATMOS_ALL, 0, 100, 3*1000 ); atmos_led_on( g_led_ctrl, LED_ID_ATMOS_ALL, 0, 100, dur_sec*1000 ); - ring_led_breath( g_led_ctrl, 2000, 0 ); + //ring_led_breath( g_led_ctrl, 2000, 0 ); break; } diff --git a/app/src/iot.c b/app/src/iot.c index a9dba41..e917a47 100644 --- a/app/src/iot.c +++ b/app/src/iot.c @@ -145,7 +145,7 @@ void* iot_task( void * unused ) } free( msg ); }else{ - usleep(100); + usleep(5*1000); } /* Loop to receive packets, and handles client keepalive */ tuya_mqtt_loop(client); diff --git a/app/src/iot_dp.c b/app/src/iot_dp.c index 4d7827a..8d9be96 100644 --- a/app/src/iot_dp.c +++ b/app/src/iot_dp.c @@ -398,11 +398,11 @@ void dp_button_event_report( button_code_t btn_code, button_event_t btn_evt ) int32_t dp_recognition_running_report( uint32_t run ) //bool { - return dp_property_report_bool( "recogninition_running", run ); + return dp_property_report_bool( "recognition_running", run ); } int32_t dp_recognition_mode_report( uint32_t mode ) //0-"light_mode", 1-"dark_mode" { - return dp_property_report_str( "recogninition_mode", mode?"dark_mode":"light_mode" ); + return dp_property_report_str( "recognition_mode", mode?"dark_mode":"light_mode" ); } diff --git a/app/src/main.c b/app/src/main.c index 73bb329..9718809 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -182,11 +182,16 @@ int main( void ) }else{ mg_device_st_set( DS_AUTH_WIFICONFIG_NO_ACTIVE ); } - //连接涂鸦IOT平台 MG_LOGD( "iot start.."); iot_start(); +{ +extern int32_t gesture_recognition_start( void ); +gesture_recognition_start(); +} + +#if 1 while( !is_iot_connected() ){ //wait iot connect ... MG_LOGD( "wait iot connect..."); @@ -212,10 +217,7 @@ int main( void ) //上报所有dp 信息。 dp_report_all( &g_mg_dev ); -{ -extern int32_t gesture_recognition_start( void ); -gesture_recognition_start(); -} +#endif #if 0 MG_LOGD( "btn light ctrl start.."); //TODO :启动手势识别子流程 diff --git a/log/log4crc b/log/log4crc index d0c6aef..7a18543 100644 --- a/log/log4crc +++ b/log/log4crc @@ -13,7 +13,7 @@ - + diff --git a/log/src/mg_log.c b/log/src/mg_log.c index 734ccee..e3c3515 100644 --- a/log/src/mg_log.c +++ b/log/src/mg_log.c @@ -7,8 +7,7 @@ #include "log4c.h" #include "mg_log.h" -//#define LOG_CATEGORY "log4c.mg_app" -#define LOG_CATEGORY "log4c.stdout" +#define LOG_CATEGORY "mg_app" //log4c_category_log(mytest, LOG4C_PRIORITY_INFO, "hello, world! -- %d\r\n", i++ ); -- 2.34.1