ST Expansion SW Team / Mbed OS VL53L3CX_NoShield_1Sensor_poll_Mb06x

Dependencies:   VL53L3CX_mbed

Files at this revision

API Documentation at this revision

Comitter:
johnAlexander
Date:
Tue Nov 03 15:17:16 2020 +0000
Parent:
1:302ec451d4d5
Child:
3:57541677b13b
Commit message:
Use updated sensor class lib

Changed in this revision

Main.cpp Show annotated file Show diff for this revision Revisions of this file
VL53L3ExpansionBoard.lib Show diff for this revision Revisions of this file
VL53L3_Lib.lib Show annotated file Show diff for this revision Revisions of this file
--- a/Main.cpp	Mon Oct 19 08:44:53 2020 +0000
+++ b/Main.cpp	Tue Nov 03 15:17:16 2020 +0000
@@ -15,7 +15,8 @@
 #include <stdio.h>
 
 #include "mbed.h"
-#include "NoShield53L3.h"
+//#include "NoShield53L3.h"
+#include "vl53lx_class.h"
 #include "vl53L3_I2c.h"
 #include <time.h>
 
@@ -24,7 +25,8 @@
 #define I2C_SDA   D14 
 #define I2C_SCL   D15 
 
-static NoShield53L3 *board=NULL;
+//static NoShield53L3 *board=NULL;
+static VL53LX *sensor = NULL;
 Serial pc(SERIAL_TX, SERIAL_RX); 
 
 
@@ -41,8 +43,10 @@
 int main()
 {   
     int status;
-    VL53LX * Sensor;
     uint16_t wordData;
+    
+    DigitalOut xshutdown(D7);
+    
 
     static VL53LX_MultiRangingData_t RangingData;
 
@@ -53,80 +57,62 @@
     vl53L3_DevI2C *dev_I2C = new vl53L3_DevI2C(I2C_SDA, I2C_SCL);
     
     /* no expansion board so don't use stmpe1600 */
-    board = NoShield53L3::instance(dev_I2C, A2, D8, D2);
-    printf("board created!\r\n");
+//    board = NoShield53L3::instance(dev_I2C, A2, D8, D2);
+    sensor = new VL53LX(dev_I2C, &xshutdown, A2);
+    
+    printf("sensor created!\r\n");
 
-
-    /* define the shutdown pins */
-    status = board->init_board(D9,D4,D3);
+    status = sensor->InitSensor(0x52);
     if (status) {
-        printf("Failed to init board!\r\n");
+        printf("Failed to init sensor!\r\n");
         return 0;
-    }
-       
-   
-    printf("board initiated! \n");
+    }   
+    
+    printf("sensor initialised! \n");
                                             
-    printf("configuring centre channel \n");
-    Dev=&devCentre;
-    Sensor=board->sensor_centre;
-    Dev->I2cDevAddr = NEW_SENSOR_CENTRE_ADDRESS;
-    printf("configured centre channel \n");
-  
-        
-   // configure the i2c connection     
-    Dev->comms_speed_khz = 400;
-    Dev->comms_type = 1;
-
-/* Device Initialization and setting */
-    printf("VL53LX_DataInit  \n");    
-    status = Sensor->VL53LX_DataInit();
     uint8_t NewDataReady=0;     
-    printf("VL53LX_DataInit %d \n",status);    
     
-    status = Sensor->VL53LX_StartMeasurement();   
+    status = sensor->VL53LX_StartMeasurement();   
     printf("VL53LX_StartMeasurement %d \n",status);         
  
  // loop forever getting measurements       
     while(1) 
     {     
-        status = Sensor->VL53LX_WaitMeasurementDataReady();
+        status = sensor->VL53LX_WaitMeasurementDataReady();
 
         if(!status)
         {
 
-            status = Sensor->VL53LX_GetMultiRangingData( &RangingData);
+            status = sensor->VL53LX_GetMultiRangingData(&RangingData);
 
-            if ( status == 0)
+            if (status == 0)
             {
-                int no_of_object_found=RangingData.NumberOfObjectsFound;
+                int no_of_object_found = RangingData.NumberOfObjectsFound;
                 if ( no_of_object_found < 10 ) 
                 {
-                    for(int j=0;j<no_of_object_found;j++){
+                    for(int j=0;j<no_of_object_found;j++)
+                    {
                         if ((RangingData.RangeData[j].RangeStatus == VL53LX_RANGESTATUS_RANGE_VALID) || 
                             (RangingData.RangeData[j].RangeStatus == VL53LX_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK_FAIL))
-                            {   // print data
-                                printf("centre \t object %d  \t status=%d, \t D=%5dmm, \t Signal=%2.2f Mcps, \t Ambient=%2.2f Mcps \n",
+                        {   // print data
+                            printf("centre \t object %d  \t status=%d, \t D=%5dmm, \t Signal=%2.2f Mcps, \t Ambient=%2.2f Mcps \n",
                                 j,
                                 RangingData.RangeData[j].RangeStatus,
                                 RangingData.RangeData[j].RangeMilliMeter,
                                 RangingData.RangeData[j].SignalRateRtnMegaCps/65536.0,
                                 RangingData.RangeData[j].AmbientRateRtnMegaCps/65536.0);
-                            } //if
+                        } //if
                     } //for
                 } // if  ( no_of_object_found < 10 ) 
-            }   // if status VL53LX_GetMultiRangingData                                                                          
-                                        
-            } // if !status VL53LX_WaitMeasurementDataReady
-            else
-            {
-                printf("VL53L1_WaitMeasurementDataReady failed %d \n",status);
-            }
+            }   // if status VL53LX_GetMultiRangingData                                                                                                      
+        } // if !status VL53LX_WaitMeasurementDataReady
+        else
+        {
+            printf("VL53L1_WaitMeasurementDataReady failed %d \n",status);
+        }
 
-            status = Sensor->VL53LX_ClearInterruptAndStartMeasurement();
+        status = sensor->VL53LX_ClearInterruptAndStartMeasurement();
         
     } // while(1)
     
-//       status = Sensor->VL53LX_StopMeasurement(); 
-    
 }
--- a/VL53L3ExpansionBoard.lib	Mon Oct 19 08:44:53 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://os.mbed.com/users/charlesmn/code/VL53L3ExpansionBoard/#2e644a39daf9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VL53L3_Lib.lib	Tue Nov 03 15:17:16 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/johnAlexander/code/VL53L3_Lib/#316175f392f7