手势识别功能调试,可以识别到
authorkyz <kongyuzhong@gmail.com>
Mon, 5 Jun 2023 06:49:00 +0000 (14:49 +0800)
committerkyz <kongyuzhong@gmail.com>
Mon, 5 Jun 2023 09:36:12 +0000 (17:36 +0800)
app/inc/mg_version.h
app/src/device_gesture.c
app/src/device_light.c
app/src/iot.c
app/src/iot_dp.c
app/src/main.c
log/log4crc
log/src/mg_log.c

index a02a20a9f6893283b6043b6a0931533aea35c3bc..f04df703a4f2ad790abb70653477fc511ab6b55a 100644 (file)
@@ -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__
 
index b11f404c302cea6a0452c18de4cb74cc9dc04b4d..2b8c730eb182670333e4aae13a0f93128723a91e 100644 (file)
@@ -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
-
index bc042e707abca8d51bb317cca18e43b073b91654..859cd4547b177fd8938d0a0a98cb6c4b09f7dc14 100644 (file)
@@ -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;
 
        }
index a9dba4166445f433f604dc761fe3c749f7b6cbde..e917a47019838180ad339538ed7859cec1292e2f 100644 (file)
@@ -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);
index 4d7827a109629b4e64dd8dcffa5635d6fe2fc7b0..8d9be96190c6e0bdc72237aba11bf88d0f9de15a 100644 (file)
@@ -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" );
 }
 
index 73bb329ac9efac69168540c7becac053c835059f..9718809a64785cfc512dd26c78cc4b0a1becd121 100644 (file)
@@ -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 :启动手势识别子流程
index d0c6aefca14c2ffbca65eb73c90ad1118944e69a..7a18543a1a9fd9b7e60d54f0927e9ba787c04a58 100644 (file)
@@ -13,7 +13,7 @@
     <category name="root" priority="notice"/>
 
     <!-- 输出到文件mylogfilename.x ========================================= -->
-    <category name="log4c.mytest" priority="debug" appender = "myrollingappender"/>
+    <category name="mg_app" priority="debug" appender = "myrollingappender"/>
     <appender name="myrollingappender" type="rollingfile" logdir="./" prefix="mg_app-log" layout="dated" rollingpolicy="myrollingpolicy" />
     <rollingpolicy name="myrollingpolicy" type="sizewin" maxsize="102400" maxnum="3" />
 
index 734cceed1a1a9a7e1b5d8add6d442d71fc81598c..e3c3515f64cbed2aea4f281502ad367be43c4bd8 100644 (file)
@@ -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++ );