添加手势识别关闭时灯光闪烁5s
authorzf zf <2919300294@qq.com>
Tue, 1 Aug 2023 01:56:54 +0000 (09:56 +0800)
committerzf zf <2919300294@qq.com>
Tue, 1 Aug 2023 01:56:54 +0000 (09:56 +0800)
app/src/device_gesture.c
buzzer/src/buzzer.c

index d79face3c823c1e46423caa45703bfbfc5f8c26e..ba8affee3b4293ff65fb1ab09ce3e8714b1c86b4 100644 (file)
@@ -215,8 +215,15 @@ static void gr_ring_disable(light_ctrl_t led_ctrl)
     ring_led_off(led_ctrl, 0, 0, 1);
 }
 
-static void gr_ring_enable(light_ctrl_t led_ctrl)
+static void gr_ring_enable(light_ctrl_t led_ctrl,uint32_t index)
 {
+    if(index)
+    {
+        ring_led_flash(led_ctrl, 1000, 5000);
+        sleep(5);
+        //ring_led_off(led_ctrl, 0, 0, 1);
+        return;
+    }
     ring_led_flash(led_ctrl, 1000, 5000);
     sleep(5);
     ring_led_breath(led_ctrl, 2000, 0);
@@ -311,150 +318,7 @@ static int32_t gr_vi_init_and_setfps(int32_t index)
 }
 
 
-//在上面函数的基础上进行修改,新加的单独开启和关闭相机,但重复启动会报错
-// static uint32_t camera_init = 0;
-// static int32_t last_als_status = -1;
-// static int32_t gr_als_t(gr_ctrl_t *gr_ctrl)
-// {
-//     int ret = 0;
-//     als_info_t *gr_info;
-
-//     if (gr_ctrl == NULL)
-//     {
-//         printf(" gr_ctrl == NULL \n");
-//         goto error;
-//     }
-
-//     if (gr_camera_num == CAMERA_DOUBLE)
-//     {
-//         gr_info = mg_als_read(gr_ctrl->als_ctrl);
-//         if (gr_info != NULL)
-//         {
-//             if (last_als_status != gr_info->status)
-//             {
-//                 last_als_status = gr_info->status;
-//                 if (last_als_status == BRIGHT)
-//                 {
-//                     ret = gr_isp_init(0);
-//                     if(!ret){
-//                         //RK_MPI_SYS_Init(); 
-//                         ret = gr_vi_init_and_setfps(1);
-//                         if(!ret){
-//                             ir_led_off(gr_ctrl->light_ctrl); // 禁用红外补光
-//                             camera_id = 1;
-//                             printf("开启rgb,关闭ir\n");
-//                             usleep(100*1000);
-//                             RK_MPI_VI_DisableChn(0, 0);
-//                             rk_isp_deinit(1);
-//                         }else{
-//                             RK_MPI_VI_DisableChn(1, 1);
-//                             rk_isp_deinit(0);
-//                         }
-//                     }else{
-//                         printf("切换rgb失败\n");
-//                     }
-//                 }
-//                 else if (last_als_status == DARK)
-//                 {
-//                     ret = gr_isp_init(1);
-//                     if(!ret){
-//                         //RK_MPI_SYS_Init(); 
-//                         ret = gr_vi_init_and_setfps(0);
-//                         if(!ret){
-//                             ir_led_on(gr_ctrl->light_ctrl, 100); // 开启红外补光
-//                             camera_id = 0;
-//                             printf("开启ir,关闭rgb\n");
-//                             usleep(100*1000);
-//                             RK_MPI_VI_DisableChn(1, 1);
-//                             rk_isp_deinit(0);
-//                         }else{
-//                             RK_MPI_VI_DisableChn(0, 0);
-//                             rk_isp_deinit(1);
-//                         }
-//                     }else{
-//                         printf("切换ir失败\n");
-
-//                     }
-//                 }
-//             }
-//             gr_info = NULL;
-//         }
-//     }
-// error:
-//     return -1;
-// }
-
-#if 1
-
 int32_t gr_read_gesture(void);
-#else
-static int32_t gr_read_gesture(void)
-{
-    int32_t ret = -1;
-
-    if (mg_detectResult == NULL)
-        goto error;
-
-    if (mg_detectResult->handCount)
-    {
-        switch (mg_detectResult->hands[0].action)
-        {
-        case ST_HAND_ACTION_SHOOT:
-            ret = GS_GUN;
-            break;
-        case ST_HAND_ACTION_LITTLE_FINGER:
-            ret = GS_LITTLE_FINGER;
-            break;
-        case ST_HAND_ACTION_ROCK_ON:
-            ret = GS_HORNED_HAND;
-            break;
-        case ST_HAND_ACTION_I_LOVE_YOU:
-            ret = GS_ILOVEYOU;
-            break;
-        case ST_HAND_ACTION_FOUR:
-            ret = GS_FOUR_FINGERS;
-            break;
-        case ST_HAND_ACTION_THREE:
-            ret = GS_THREE_FINGERS;
-            break;
-        case ST_HAND_ACTION_SIX:
-            ret = GS_WELL_PLAYED;
-            break;
-        case ST_HAND_ACTION_INDEX_FINGER:
-            ret = GS_FINGERTIP;
-            break;
-        case ST_HAND_ACTION_FINGER_HEART:
-            ret = GS_FINGER_HEART;
-            break;
-        case ST_HAND_ACTION_FIST:
-            ret = GS_ROCK;
-            break;
-        case ST_HAND_ACTION_PALM:
-            ret = GS_PAPER;
-            break;
-        case ST_HAND_ACTION_THUMBS_UP:
-            ret = GS_THUMBS_UP;
-            break;
-        case ST_HAND_ACTION_V:
-            ret = GS_SCISSORS;
-            break;
-        case ST_HAND_ACTION_OK:
-            ret = GS_OK;
-            break;
-        default:
-            ret = -1;
-            break;
-        }
-        mg_detectResult = NULL;
-        printf("gesrtue action zzzzzzzzzzzzzzzzzzzzzz %d\n", ret);
-        return ret;
-    }
-error:
-    return -2;
-}
-
-#endif
-
 static int32_t repeating_gestures = -10;
 static int32_t timeout = 0;
 bool no_hands = 1;
@@ -514,7 +378,6 @@ void gr_close(gr_ctrl_t *gr_ctrl)
 void *gr_task(void *param)
 {
     int ret;
-    // uint32_t init = 1;
     uint32_t dp_timeout, gr_time;
     uint32_t time_flasg;
 
@@ -534,14 +397,14 @@ void *gr_task(void *param)
 
         privacy = cfg_privacy_mode_read(p_gr->dev);
         if( my_privacy  != privacy ){
-               printf( "Privacy Mode   %d -> %d\n", my_privacy, privacy );
-               my_privacy = privacy;
-               if( privacy ){
-                       camera_disable();
-               }else{
-                       gr_als_t(p_gr);
-               }
-       }
+               printf( "Privacy Mode   %d -> %d\n", my_privacy, privacy );
+               my_privacy = privacy;
+               if( privacy ){
+                       camera_disable();
+               }else{
+                       gr_als_t(p_gr);
+               }
+           }
 
         if (my_privacy == 1)
         {
@@ -562,22 +425,22 @@ void *gr_task(void *param)
             {
                 printf("Enable gesture mode\n");
                 dp_recognition_running_report(1);
-                gr_ring_enable(p_gr->light_ctrl);
+                gr_ring_enable(p_gr->light_ctrl,0);
                 while (!stop)
                 {
-//--------------------------------------
-//check privacy
-                       privacy = cfg_privacy_mode_read(p_gr->dev);
-                       if( my_privacy  != privacy ){
-                               printf( "Privacy Mode   %d -> %d\n", my_privacy, privacy );
-                               my_privacy = privacy;
-                               if( privacy ){
-                                       camera_disable();
-                                       reportdp_and_close_ring_gr(p_gr->light_ctrl);
-                                       break;
-                               }
-                       }
-//--------------------------------------
+                    //--------------------------------------
+                    //check privacy
+                               privacy = cfg_privacy_mode_read(p_gr->dev);
+                               if( my_privacy  != privacy ){
+                                       printf( "Privacy Mode   %d -> %d\n", my_privacy, privacy );
+                                       my_privacy = privacy;
+                                       if( privacy ){
+                                               camera_disable();
+                                               reportdp_and_close_ring_gr(p_gr->light_ctrl);
+                                               break;
+                                       }
+                               }
+                    //--------------------------------------
                     usleep(100 * 000);
                     if (time_flasg)
                     {
@@ -606,6 +469,7 @@ void *gr_task(void *param)
                         if (gr_ai_detect_palm() == 0)
                         {
                             printf("Turn off gesture mode\n");
+                            gr_ring_enable(p_gr->light_ctrl,1);
                             reportdp_and_close_ring_gr(p_gr->light_ctrl);
                             break;
                         }
@@ -646,133 +510,11 @@ int save_stream_file(char* stream_path,unsigned char *p_data_buf,unsigned int im
 }
 #endif
 
-#if 0
-static void *ai_detect(void *arg)
-{
-
-    int ret;
-    int privacy = 0;
-    MEDIA_BUFFER mb = NULL;
-
-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);
-        return NULL;
-    }
-
-    int nv12_buffer_size = ST_AI_IMAGE_W * ST_AI_IMAGE_H * 3 / 2; // nv12 3/2, rgb 3
-    unsigned char *image_data = (unsigned char *)malloc(nv12_buffer_size);
-
-    if (image_data == NULL)
-        return NULL;
-
-    STImage detectImage = {0};
-
-    detectImage.data = image_data;
-    detectImage.format = ST_PIXEL_FORMAT_NV12;
-    detectImage.width = ST_AI_IMAGE_W;
-    detectImage.height = ST_AI_IMAGE_H;
-
-    while (!quit)
-    {
-        usleep(100 * 1000);
-        if (my_privacy == 0)
-        {
-            if (privacy)
-            {
-                privacy = 0;
-                printf("===============Exit privacy mode================\n");
-            }
-
-            // if(camera_id == -1)
-            //     continue;
-
-            mb = RK_MPI_SYS_GetMediaBuffer(RK_ID_VI, camera_id, -1);
-            if (!mb)
-            {
-                usleep(100 * 1000);
-                continue;
-            }
-            else
-            {
-                memcpy(image_data, RK_MPI_MB_GetPtr(mb), nv12_buffer_size);
-                //printf("zf=========camera_id = %d\n",camera_id);
-                RK_MPI_MB_ReleaseBuffer(mb);
-                STAsteriaDetect(g_SThandle, ST_DETECT_MODE_VIDEO, &detectImage, &mg_detectResult);
-            }
-        }
-        else if (my_privacy == 1)
-        {
-            if (!privacy)
-            {
-                privacy = 1;
-                printf("================== Go to privacy mode ===================\n");
-            }
-        }
-    }
-    if (image_data)
-        free(image_data);
-
-    sentime_ai_deinit();
-
-    return NULL;
-}
-
-static int detect_cameras_num(void)
-{
-    int flag = 0;
-
-    if (!access("/sys/bus/i2c/drivers/gc2053/1-0037", 0))
-    {
-        gr_camera_num = CAMERA_RGB;
-        flag++;
-        printf("Detected rgb camera\n");
-    }
-    else
-    {
-        printf("No rgb camera detected\n");
-    }
-
-    if (!access("/sys/bus/i2c/drivers/gc2053/3-0037", 0))
-    {
-        if (flag == 1)
-        {
-            gr_camera_num = CAMERA_DOUBLE;
-        }
-        else
-        {
-            gr_camera_num = CAMERA_IR;
-        }
-        flag++;
-        printf("Detected IR camera\n");
-    }
-    else
-    {
-        printf("No ir camera detected\n");
-    }
-    return flag;
-}
-#endif
 
 int gr_register(gr_ctrl_t *gr_ctrl, uint32_t threshold_high, uint32_t threshold_low)
 {
     int32_t ret;
-    pthread_t th2;
     pthread_t gr_thread;
-    //zf
-    int32_t flag = 0;
-    als_info_t *gr_info;
-    //zf_end
-    int32_t camera_flag = 0;
 
     gr_ctrl->als_ctrl = mg_als_open();
     if (gr_ctrl->als_ctrl == NULL)
@@ -782,173 +524,21 @@ 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);
 
-#if 0
-    camera_flag = detect_cameras_num();
-
-    if(camera_flag){
-        if(camera_flag == 1){
-            if(gr_camera_num == CAMERA_RGB){
-                ret = rk_isp_init(0, "/etc/iqfiles/");
-                if (ret < 0)
-                {
-                    printf("tw8013 rk_vi_init 1 failed!\n");
-                    goto app_ext1;
-                }else{
-                    RK_MPI_SYS_Init();
-                    rk_vi_init(1, 1, ST_AI_IMAGE_W, ST_AI_IMAGE_H);
-                    rk_vi_setfps(1, 15);
-                    camera_id = 1;  
-                    printf("tw8013 rk_vi_init 1 yes\n");
-                }
-            }else if(gr_camera_num == CAMERA_IR){
-                ret = rk_isp_init(0, "/etc/iqfiles/");
-                if (ret < 0)
-                {
-                    printf("tw8013 rk_vi_init 0 failed!\n");
-                    goto app_ext1;
-                }else{
-                    RK_MPI_SYS_Init();
-                    rk_vi_init(0, 0, ST_AI_IMAGE_W, ST_AI_IMAGE_H);
-                    rk_vi_setfps(0, 15);
-                    camera_id = 0;
-                    ir_led_on(gr_ctrl->light_ctrl, 100);
-                    printf("tw8013 rk_vi_init 0 yes!\n");
-                }
-            }
-        }else{
-            ret = rk_isp_init(0, "/etc/iqfiles/");
-            if (ret < 0)
-            {
-                printf("tw8013 rk_isp_init 0 failed!\n");
-            }else{
-                flag++;
-                gr_camera_num = CAMERA_RGB;
-                printf("tw8013 rk_isp_init 0 yes! \n");
-            }
-           
-            ret = rk_isp_init(1, "/etc/iqfiles/");
-            if (ret < 0)
-            {
-                printf("tw8013 rk_isp_init 1 failed!\n");
-                if(!flag)
-                    goto app_ext1;
-            }else{
-                if(flag == 1){
-                    gr_camera_num = CAMERA_DOUBLE;
-                }else{
-                    gr_camera_num = CAMERA_IR;
-                }
-                printf("3\rk_isp_init 1 yes ==============================================\n");
-            }
-
-            RK_MPI_SYS_Init(); 
-            if(gr_camera_num == CAMERA_DOUBLE){
-                rk_vi_init(0, 0, ST_AI_IMAGE_W, ST_AI_IMAGE_H);
-                rk_vi_setfps(0, 15);
-                rk_vi_init(1, 1, ST_AI_IMAGE_W, ST_AI_IMAGE_H);
-                rk_vi_setfps(1, 15);
-            }else if(gr_camera_num == CAMERA_RGB){
-                rk_vi_init(1, 1, ST_AI_IMAGE_W, ST_AI_IMAGE_H);
-                rk_vi_setfps(1, 15);
-                camera_id = 1;
-            }else{
-                rk_vi_init(0, 0, ST_AI_IMAGE_W, ST_AI_IMAGE_H);
-                rk_vi_setfps(0, 15);
-                camera_id = 0;
-                ir_led_on(gr_ctrl->light_ctrl, 100);
-            }
-        }
-
-        usleep(100 * 1000);
-
-        if (pthread_create(&th2, NULL, ai_detect,NULL))
-        {
-            printf("create GetBuffer thread failed!\n");
-            quit = 1;
-            goto app_ext1;
-        }
-
-        if (pthread_create(&gr_thread, NULL, gr_task, gr_ctrl) != 0)
-        {
-            printf("create hand_ic failed!");
-            stop = 1;
-            goto app_ext1;
-        }
-
-        return 0;
-   }
-#else
-        if (pthread_create(&gr_thread, NULL, gr_task, gr_ctrl) != 0)
-        {
-            printf("create hand_ic failed!");
-            stop = 1;
-            goto app_ext1;
-        }
-
-        return 0;
-#endif
+    if (pthread_create(&gr_thread, NULL, gr_task, gr_ctrl) != 0)
+    {
+        printf("create hand_ic failed!");
+        stop = 1;
+        goto app_ext1;
+    }
+    return 0;
 
 app_ext1:
     gr_close(gr_ctrl);
-    // RK_MPI_VI_DisableChn(0, 0);
-    // RK_MPI_VI_DisableChn(1, 1);
-    // rk_isp_deinit(0);
-    // rk_isp_deinit(1);
-    // mg_als_close(gr_ctrl->als_ctrl);
     return -1;
 }
 
-#if 0
-static gr_ctrl_t gr_ctrl;
-
-static light_ctrl_t  g_led_ctrl;
-// extern mg_dev_t g_mg_dev;
-
-int32_t main( void )
-{
-       int32_t  ret = 0;
-       uint32_t als_th_high = 1000;
-       uint32_t als_th_low = 400;
-
-       memset( &gr_ctrl, 0, sizeof( gr_ctrl ) );
-    //2\跑死的概率更大
-    g_led_ctrl = mg_led_open();
-    if (!g_led_ctrl)
-    {
-        printf("led test..., open led failed\n");
-        return -1;
-    }
-
-       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);
-
-    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");
-               ret = -1;
-       }
-
-    while (!quit)
-    {
-        usleep(100 * 1000);
-    }
-
-    RK_MPI_VI_DisableChn(0, 0);
-    RK_MPI_VI_DisableChn(1, 1);
-    rk_isp_deinit(0);
-    rk_isp_deinit(1);
-}
-
-#else
 
 static gr_ctrl_t gr_ctrl;
-
 int32_t gesture_recognition_start(mg_dev_t *dev)
 {
     int32_t ret = 0;
@@ -974,5 +564,4 @@ int32_t gesture_recognition_start(mg_dev_t *dev)
 
     return ret;
 }
-#endif
 
index 4b4101a5f9d4af47d33bd3f2d66c580f4d756046..709e53bb4604a05b502d46d1e7ac327df396b04b 100644 (file)
@@ -70,7 +70,6 @@ static void mg_buzzer_timer_init()
     if (timer_create(CLOCK_REALTIME, &evp, &timerid) == -1) 
     {   
         MG_LOGE("buzzer fail to timer_create! \r\n"); 
-        exit(-1); 
     }  
        else{
                MG_LOGD( " buzzer create timer OK !\r\n");