ffcvv

Dependencies:   vl53l0x_api libxDot-mbed5

Files at this revision

API Documentation at this revision

Comitter:
mohamedachour
Date:
Tue Apr 23 14:27:14 2019 +0000
Parent:
2:8ac50bd2c7a1
Child:
4:596e420afdc4
Commit message:
hh

Changed in this revision

README.md Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed_settings.py Show annotated file Show diff for this revision Revisions of this file
mbed_settings.pyc Show annotated file Show diff for this revision Revisions of this file
vl53l0x_api.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Tue Apr 23 14:27:14 2019 +0000
@@ -0,0 +1,1 @@
+mbed-OS example program and API libraries for VL53L0X Time of Flight distance range sensor.
--- a/main.cpp	Fri Apr 21 11:22:11 2017 +0000
+++ b/main.cpp	Tue Apr 23 14:27:14 2019 +0000
@@ -3,38 +3,17 @@
 #include "vl53l0x_platform.h"
 #include "vl53l0x_i2c_platform.h"
 
+#define USE_I2C_2V8
+
 Serial pc(USBTX, USBRX);
 DigitalOut led(LED1);
 
-void print_pal_error(VL53L0X_Error Status){
-    char buf[VL53L0X_MAX_STRING_LENGTH];
-    VL53L0X_GetPalErrorString(Status, buf);
-    printf("API Status: %i : %s\n", Status, buf);
-}
-
-void print_range_status(VL53L0X_RangingMeasurementData_t* pRangingMeasurementData){
-    char buf[VL53L0X_MAX_STRING_LENGTH];
-    uint8_t RangeStatus;
-
-    /*
-     * New Range Status: data is valid when pRangingMeasurementData->RangeStatus = 0
-     */
-
-    RangeStatus = pRangingMeasurementData->RangeStatus;
-
-    VL53L0X_GetRangeStatusString(RangeStatus, buf);
-    printf("Range Status: %i : %s\n", RangeStatus, buf);
-
-}
-
 
 VL53L0X_Error WaitMeasurementDataReady(VL53L0X_DEV Dev) {
     VL53L0X_Error Status = VL53L0X_ERROR_NONE;
     uint8_t NewDatReady=0;
     uint32_t LoopNb;
-
-    // Wait until it finished
-    // use timeout to avoid deadlock
+    
     if (Status == VL53L0X_ERROR_NONE) {
         LoopNb = 0;
         do {
@@ -59,8 +38,6 @@
     uint32_t StopCompleted=0;
     uint32_t LoopNb;
 
-    // Wait until it finished
-    // use timeout to avoid deadlock
     if (Status == VL53L0X_ERROR_NONE) {
         LoopNb = 0;
         do {
@@ -82,176 +59,65 @@
 }
 
 
+
 int main()
 {
-  
+    int x=1, measure=0;
+    int ave=0, sum=0;
     VL53L0X_Error Status = VL53L0X_ERROR_NONE;
     VL53L0X_Dev_t MyDevice;
     VL53L0X_Dev_t *pMyDevice = &MyDevice;
+    VL53L0X_RangingMeasurementData_t    RangingMeasurementData;
+    VL53L0X_RangingMeasurementData_t   *pRangingMeasurementData    = &RangingMeasurementData;
     VL53L0X_Version_t                   Version;
-    VL53L0X_Version_t                  *pVersion   = &Version;
-    VL53L0X_DeviceInfo_t                DeviceInfo; 
-    
-    int32_t status_int;
-    
-    pc.printf("VL53L0X API Simple Ranging Example\r\n");
     
     // Initialize Comms
     pMyDevice->I2cDevAddr      = 0x52;
     pMyDevice->comms_type      =  1;
     pMyDevice->comms_speed_khz =  400;
     
-    pc.printf("Init comms\r\n");
+    
+    VL53L0X_ERROR_CONTROL_INTERFACE;
+    VL53L0X_RdWord(&MyDevice, VL53L0X_REG_OSC_CALIBRATE_VAL,0);
+    VL53L0X_DataInit(&MyDevice); // Data initialization
+    Status = VL53L0X_ERROR_NONE;
+    uint32_t refSpadCount;
+    uint8_t isApertureSpads;
+    uint8_t VhvSettings;
+    uint8_t PhaseCal;
     
-    if(Status == VL53L0X_ERROR_NONE)
-    {
-        status_int = VL53L0X_GetVersion(pVersion);
-        if (status_int != 0)
-            Status = VL53L0X_ERROR_CONTROL_INTERFACE;
-    }
-    pc.printf("VL53L0X API Version: %d.%d.%d (revision %d)\r\n", pVersion->major, pVersion->minor ,pVersion->build, pVersion->revision);
-        
-        int addr;
-        
-        addr = VL53L0X_scan();
-        printf("Device found at: %i\r\n", addr);
-        //uint8_t data;
-        //data=0;
-        if(Status == VL53L0X_ERROR_NONE)
-    {
-            printf ("Call of VL53L0X_DataInit\n");
-            uint16_t osc_calibrate_val=0;
-            Status = VL53L0X_RdWord(&MyDevice, VL53L0X_REG_OSC_CALIBRATE_VAL,&osc_calibrate_val);
-            printf("%i\n",osc_calibrate_val);
-      Status = VL53L0X_DataInit(&MyDevice); // Data initialization
-      print_pal_error(Status);
-    }
+    VL53L0X_StaticInit(pMyDevice); // Device Initialization
+    VL53L0X_PerformRefSpadManagement(pMyDevice, &refSpadCount, &isApertureSpads); // Device Initialization
+    VL53L0X_PerformRefCalibration(pMyDevice, &VhvSettings, &PhaseCal); // Device Initialization
+    VL53L0X_SetDeviceMode(pMyDevice, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING); // Setup in single ranging mode
+    VL53L0X_SetLimitCheckValue(pMyDevice, VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, (FixPoint1616_t)(0.25*65536)); //High Accuracy mode, see API PDF
+    VL53L0X_SetLimitCheckValue(pMyDevice, VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, (FixPoint1616_t)(18*65536)); //High Accuracy mode, see API PDF
+    VL53L0X_SetMeasurementTimingBudgetMicroSeconds(pMyDevice, 200000); //High Accuracy mode, see API PDF
+    VL53L0X_StartMeasurement(pMyDevice);
 
-        if(Status == VL53L0X_ERROR_NONE)
-    {
-        Status = VL53L0X_GetDeviceInfo(&MyDevice, &DeviceInfo);
-        if(Status == VL53L0X_ERROR_NONE)
-        {
-            printf("VL53L0X_GetDeviceInfo:\n");
-            printf("Device Name : %s\n", DeviceInfo.Name);
-            printf("Device Type : %s\n", DeviceInfo.Type);
-            printf("Device ID : %s\n", DeviceInfo.ProductId);
-            printf("ProductRevisionMajor : %d\n", DeviceInfo.ProductRevisionMajor);
-        printf("ProductRevisionMinor : %d\n", DeviceInfo.ProductRevisionMinor);
-
-        if ((DeviceInfo.ProductRevisionMinor != 1) && (DeviceInfo.ProductRevisionMinor != 1)) {
-            printf("Error expected cut 1.1 but found cut %d.%d\n",
-                       DeviceInfo.ProductRevisionMajor, DeviceInfo.ProductRevisionMinor);
-                Status = VL53L0X_ERROR_NOT_SUPPORTED;
-            }
+    while (1){
+        while(x<=50){
+        WaitMeasurementDataReady(pMyDevice);
+        VL53L0X_GetRangingMeasurementData(pMyDevice, pRangingMeasurementData);
+        measure=pRangingMeasurementData->RangeMilliMeter;
+        //printf("In loop measurement %d\n", mea);
+        sum=sum+measure;
+        led=!led;
+        // Clear the interrupt
+        VL53L0X_ClearInterruptMask(pMyDevice, VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY);
+        VL53L0X_PollingDelay(pMyDevice);
+        x++;
         }
-        print_pal_error(Status);
+        ave=sum/x;
+        pc.printf("Average is %d\n", ave);
+        x=1;
+        sum=0;
+        wait(20);
     }
 
-        VL53L0X_RangingMeasurementData_t    RangingMeasurementData;
-        VL53L0X_RangingMeasurementData_t   *pRangingMeasurementData    = &RangingMeasurementData;
-        Status = VL53L0X_ERROR_NONE;
-        uint32_t refSpadCount;
-        uint8_t isApertureSpads;
-        uint8_t VhvSettings;
-        uint8_t PhaseCal;
-
-    if(Status == VL53L0X_ERROR_NONE)
-        {
-            printf ("Call of VL53L0X_StaticInit\n");
-            Status = VL53L0X_StaticInit(pMyDevice); // Device Initialization
-            // StaticInit will set interrupt by default
-            print_pal_error(Status);
-        }
-
-        if(Status == VL53L0X_ERROR_NONE)
-        {
-            printf ("Call of VL53L0X_PerformRefCalibration\n");
-            Status = VL53L0X_PerformRefCalibration(pMyDevice,
-                    &VhvSettings, &PhaseCal); // Device Initialization
-            print_pal_error(Status);
-        }
-
-        if(Status == VL53L0X_ERROR_NONE)
-        {
-            printf ("Call of VL53L0X_PerformRefSpadManagement\n");
-            Status = VL53L0X_PerformRefSpadManagement(pMyDevice,
-                    &refSpadCount, &isApertureSpads); // Device Initialization
-            print_pal_error(Status);
-        }
-
-        if(Status == VL53L0X_ERROR_NONE)
-        {
-
-            printf ("Call of VL53L0X_SetDeviceMode\n");
-            Status = VL53L0X_SetDeviceMode(pMyDevice, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING); // Setup in single ranging mode
-            print_pal_error(Status);
-        }
-
-        if(Status == VL53L0X_ERROR_NONE)
-        {
-            printf ("Call of VL53L0X_StartMeasurement\n");
-            Status = VL53L0X_StartMeasurement(pMyDevice);
-            print_pal_error(Status);
-        }
-
-        if(Status == VL53L0X_ERROR_NONE)
-        {
-            uint32_t measurement;
-            uint32_t no_of_measurements = 6000;
-
-            uint16_t* pResults = (uint16_t*)malloc(sizeof(uint16_t) * no_of_measurements);
-
-            for(measurement=0; measurement<no_of_measurements; measurement++)
-            {
-
-                Status = WaitMeasurementDataReady(pMyDevice);
-
-                if(Status == VL53L0X_ERROR_NONE)
-                {
-                    Status = VL53L0X_GetRangingMeasurementData(pMyDevice, pRangingMeasurementData);
-
-                    *(pResults + measurement) = pRangingMeasurementData->RangeMilliMeter;
-                    printf("In loop measurement %lu: %d\n", measurement, pRangingMeasurementData->RangeMilliMeter);
-                    wait(1);
-                    led=!led;
-                    // Clear the interrupt
-                    VL53L0X_ClearInterruptMask(pMyDevice, VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY);
-                    VL53L0X_PollingDelay(pMyDevice);
-                } else {
-                    break;
-                }
-            }
-
-            if(Status == VL53L0X_ERROR_NONE)
-            {
-                for(measurement=0; measurement<no_of_measurements; measurement++)
-                {
-                    printf("measurement %lu: %d\n", measurement, *(pResults + measurement));
-                }
-            }
-
-            free(pResults);
-        }
-
-
-        if(Status == VL53L0X_ERROR_NONE)
-        {
-            printf ("Call of VL53L0X_StopMeasurement\n");
-            Status = VL53L0X_StopMeasurement(pMyDevice);
-        }
-
-        if(Status == VL53L0X_ERROR_NONE)
-        {
-            printf ("Wait Stop to be competed\n");
-            Status = WaitStopCompleted(pMyDevice);
-        }
-
-        if(Status == VL53L0X_ERROR_NONE)
-        Status = VL53L0X_ClearInterruptMask(pMyDevice,
-            VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY);
-    while (true)
-        if (pc.readable())
-            pc.putc(pc.getc());
+    VL53L0X_StopMeasurement(pMyDevice);
+    WaitStopCompleted(pMyDevice);
+    VL53L0X_ClearInterruptMask(pMyDevice,VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY);
+    
 }
  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_settings.py	Tue Apr 23 14:27:14 2019 +0000
@@ -0,0 +1,45 @@
+"""
+mbed SDK
+Copyright (c) 2016 ARM Limited
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+
+from os.path import join, abspath, dirname
+
+#ROOT = abspath(join(dirname(__file__), "."))
+
+##############################################################################
+# Build System Settings
+##############################################################################
+#BUILD_DIR = abspath(join(ROOT, "build"))
+
+# ARM
+#ARM_PATH = "C:/Program Files/ARM"
+
+# GCC ARM
+#GCC_ARM_PATH = ""
+
+# GCC CodeRed
+#GCC_CR_PATH = "C:/code_red/RedSuite_4.2.0_349/redsuite/Tools/bin"
+
+# IAR
+#IAR_PATH = "C:/Program Files (x86)/IAR Systems/Embedded Workbench 7.0/arm"
+
+# Goanna static analyser. Please overload it in private_settings.py
+#GOANNA_PATH = "c:/Program Files (x86)/RedLizards/Goanna Central 3.2.3/bin"
+
+#BUILD_OPTIONS = []
+
+# mbed.org username
+#MBED_ORG_USER = ""
Binary file mbed_settings.pyc has changed
--- a/vl53l0x_api.lib	Fri Apr 21 11:22:11 2017 +0000
+++ b/vl53l0x_api.lib	Tue Apr 23 14:27:14 2019 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/mjarvisal/code/vl53l0x_api/#e6fcdb78a136
+https://developer.mbed.org/users/andcor02/code/vl53l0x_api/#a1dffa1ff38a