判断逻辑修改
authorzwj <645281962@qq.com>
Wed, 31 May 2023 07:52:29 +0000 (15:52 +0800)
committerzwj <645281962@qq.com>
Wed, 31 May 2023 07:52:29 +0000 (15:52 +0800)
tof/src/tof.c

index a01381475ae8022e8ca7e3d8581f01deccda1cd3..49a618b2848b9109fe4a93a8c5035ea19d646229 100644 (file)
@@ -1258,7 +1258,7 @@ int stmvl53l1_get_auto_config(int fd)
 
 int test_check=0;
 int test_n_err=0;
-int tof_status=0;
+int tof_status=1;
 int dev_no=0;
 int dev_fd=-1;
 int run_loops=1; // run cmd only this numebr of time defautl to run once
@@ -2055,6 +2055,13 @@ TOF 启用
     -1:失败
 */
 int32_t mg_tof_enable(mg_tof_t *tof_ctrl)
+{
+       my_info->enable = 1;
+       tof_status = 1;
+    return 0;
+}
+
+int32_t mg_tof_enable_my(mg_tof_t *tof_ctrl)
 {
     int rc = 0;
     rc=open_dev_or_die();
@@ -2064,8 +2071,7 @@ int32_t mg_tof_enable(mg_tof_t *tof_ctrl)
     }
     rc = stmvl53l1_prestart_checks(dev_fd);
     rc = stmvl53l1_start(dev_fd);
-       tof_status = 1;
-       verbose("Enable status %d", tof_status);
+       my_info->enable = 1;
     return 0;
 }
 
@@ -2078,6 +2084,13 @@ TOF 停用
     -1:失败
 */
 int32_t mg_tof_disable(mg_tof_t *tof_ctrl)
+{
+       my_info->enable = 0;
+       tof_status = 0;
+       return 0;
+}
+
+int32_t mg_tof_disable_my(mg_tof_t *tof_ctrl)
 {
        int rc = 0;
        rc=open_dev_or_die();
@@ -2086,8 +2099,8 @@ int32_t mg_tof_disable(mg_tof_t *tof_ctrl)
        return -1;
     }
        rc=stmvl53l1_stop(dev_fd);
-       tof_status = 0;
-       verbose("Disable status %d", tof_status);
+       my_info->enable = 0;
+       
        return 0;
 }
 
@@ -2097,7 +2110,7 @@ int32_t Obtain_distance_parameters()
        int rc = 0;
        /*固定测量坐标*/
        const char *buffer = "0 15 15 0";
-       mg_tof_disable(NULL);
+       mg_tof_disable_my(NULL);
        HANDLE_PARAMETER_MY_DATA(mode,"mode",4);
        rc= parse_roi_arg(buffer, dev_rois, &u32);
        if(rc >= 0){
@@ -2114,7 +2127,7 @@ int32_t Obtain_distance_parameters()
                error("set roi");
        }
        HANDLE_PARAMETER_MY_DATA(timing_budget, "timing budget",60000);
-       mg_tof_enable(NULL);
+       mg_tof_enable_my(NULL);
 
        open_dev_or_die();
        run_meas_loop1();
@@ -2136,9 +2149,14 @@ void* tof_task(void* data)
        uint32_t prev_ts = -1;
        int range = 0 , range1 = 0;
        while(stop){
+               usleep(10000);
+               if(tof_status == 0){
+                       usleep(100000);
+                       continue;
+               }
                run_meas_loop(1);
                range = (int)dev_1xrange_data.RangeMilliMeter;
-               if(range >= my_tof->default_range)//341  
+               if(range >= my_tof->default_range) 
                {
                        distanceThreshold = my_tof->default_range;
                }
@@ -2152,7 +2170,7 @@ void* tof_task(void* data)
                                }
                        }
 
-               }else if(range > (distanceThreshold -10)){
+               }else if(range > my_tof->default_range){
                        if(my_info->status != TOF_NOBODY){
                                my_info->distance = range;
                                my_info->status = TOF_NOBODY;
@@ -2203,6 +2221,7 @@ mg_tof_t * mg_tof_open( uint32_t distance)
        my_tof->default_range = distance;
        distanceThreshold = distance;
        my_info->status = -1;
+       my_info->enable = 1;
        int rc = 0;
        uint32_t u32;
        uint32_t prev_ts = -1;
@@ -2212,7 +2231,7 @@ mg_tof_t * mg_tof_open( uint32_t distance)
        /*固定测量坐标*/
        const char *buffer = "0 15 15 0";
 
-       rc = mg_tof_disable(NULL);
+       rc = mg_tof_disable_my(NULL);
        if(rc != 0)
        {
                goto error;
@@ -2229,7 +2248,7 @@ mg_tof_t * mg_tof_open( uint32_t distance)
                goto error;
        }
        HANDLE_PARAMETER_MY_DATA(timing_budget, "timing budget",60000);
-       rc = mg_tof_enable(NULL);
+       rc = mg_tof_enable_my(NULL);
        if(rc != 0)
        {
                goto error;
@@ -2260,7 +2279,7 @@ void mg_tof_close( mg_tof_t * tof_ctrl )
 {
        stop = 0;
        usleep(30);
-       mg_tof_disable(NULL);
+       mg_tof_disable_my(NULL);
        free(my_tof);
        free(my_info);
 }
@@ -2280,14 +2299,10 @@ int32_t mg_tof_read( mg_tof_t *tof_ctrl, tof_info_t *info )
        tof_info_t * my_info_t = info;
        int range = 0;
 
-       if(tof_status==1)
-               info->enable = 1;
-        else
-               info->enable = 0;
+
+       info->enable =my_info->enable;
        info->status = my_info->status;
-       run_meas_loop(1);
-       range = (int)dev_1xrange_data.RangeMilliMeter;
-       info->distance = range;
+       info->distance = my_info->distance;
 
        return 0;
 }