去掉exit,防止程序退出
authorzwj <645281962@qq.com>
Thu, 25 May 2023 08:42:13 +0000 (16:42 +0800)
committerzwj <645281962@qq.com>
Thu, 25 May 2023 08:42:13 +0000 (16:42 +0800)
tof/inc/tof.h
tof/src/tof.c

index 8fa8da7d8408a7dd051e4b002fa09fe070567154..6a9e814b5599b8fecfbe927ddeb5fb719ea762b2 100644 (file)
@@ -52,7 +52,7 @@ mg_tof_t * mg_tof_open(uint32_t distance);
 void mg_tof_close( mg_tof_t * tof_ctrl );
 
 /*测试程序*/
-void Obtain_distance_parameters();
+int32_t Obtain_distance_parameters();
 
 /*状态查询函数*/
 int32_t mg_tof_read( mg_tof_t *tof_ctrl, tof_info_t *info );
index c1b661bf5354b9ffcfd150c22f16f4d1c82841ad..a01381475ae8022e8ca7e3d8581f01deccda1cd3 100644 (file)
@@ -1293,7 +1293,7 @@ void set_dev_name(void){
  * open the currently set device dev no / dev_name if needed
  *  it exit if that fail
  */
-void open_dev_or_die(){
+int open_dev_or_die(){
        // open if not yet open
        if( dev_fd<0 ){
                set_dev_name();//ensure device name  match current dev no
@@ -1302,12 +1302,12 @@ void open_dev_or_die(){
                verbose("open fd %d for %s", dev_fd, dev_fi_name);
                if (dev_fd < 0) {
                        error("open of %s", dev_fi_name);
-                       exit(1);
+                       return -1;
                }
        }else{
                verbose("keep using fd %d", dev_fd);
        }
-
+       return 0;
 }
 
 static char *roiStatus2string(VL53L1_RoiStatus st)
@@ -2057,12 +2057,16 @@ TOF 启用
 int32_t mg_tof_enable(mg_tof_t *tof_ctrl)
 {
     int rc = 0;
-    open_dev_or_die();
+    rc=open_dev_or_die();
+    if(rc != 0)
+    {
+       return -1;
+    }
     rc = stmvl53l1_prestart_checks(dev_fd);
     rc = stmvl53l1_start(dev_fd);
        tof_status = 1;
        verbose("Enable status %d", tof_status);
-    return rc;
+    return 0;
 }
 
 /*
@@ -2076,14 +2080,18 @@ TOF 停用
 int32_t mg_tof_disable(mg_tof_t *tof_ctrl)
 {
        int rc = 0;
-       open_dev_or_die();
+       rc=open_dev_or_die();
+       if(rc != 0)
+    {
+       return -1;
+    }
        rc=stmvl53l1_stop(dev_fd);
        tof_status = 0;
        verbose("Disable status %d", tof_status);
-       return rc;
+       return 0;
 }
 
-void Obtain_distance_parameters()
+int32_t Obtain_distance_parameters()
 {
        uint32_t u32;
        int rc = 0;
@@ -2095,7 +2103,11 @@ void Obtain_distance_parameters()
        if(rc >= 0){
                verbose("%d roi to set", u32);
                dump_roi(stdout,dev_rois, u32);
-               open_dev_or_die();
+               rc=open_dev_or_die();
+               if(rc != 0)
+       {
+               return -1;
+       }
                rc = stmvl53l1_set_roi(dev_fd, dev_rois,u32);
        }
        else{
@@ -2106,6 +2118,7 @@ void Obtain_distance_parameters()
 
        open_dev_or_die();
        run_meas_loop1();
+       return 0;
 }
 
 
@@ -2199,7 +2212,11 @@ mg_tof_t * mg_tof_open( uint32_t distance)
        /*固定测量坐标*/
        const char *buffer = "0 15 15 0";
 
-       mg_tof_disable(NULL);
+       rc = mg_tof_disable(NULL);
+       if(rc != 0)
+       {
+               goto error;
+       }
        HANDLE_PARAMETER_MY_DATA(mode,"mode",4);
        rc= parse_roi_arg(buffer, dev_rois, &u32);
        if(rc >= 0){
@@ -2209,10 +2226,14 @@ mg_tof_t * mg_tof_open( uint32_t distance)
        }
        else{
                error("set roi");
+               goto error;
        }
        HANDLE_PARAMETER_MY_DATA(timing_budget, "timing budget",60000);
-       mg_tof_enable(NULL);
-
+       rc = mg_tof_enable(NULL);
+       if(rc != 0)
+       {
+               goto error;
+       }
        open_input_subsystem();
        if (rc < 0){
                printf("open_input_subsystem failed!!\n");
@@ -2238,6 +2259,7 @@ error:
 void mg_tof_close( mg_tof_t * tof_ctrl )
 {
        stop = 0;
+       usleep(30);
        mg_tof_disable(NULL);
        free(my_tof);
        free(my_info);