Initial release.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   X_NUCLEO_53L1A1_mbed X_NUCLEO_53L1A1_mbed VL53L1X_Ranging_With_Standalone_Satellite_MbedOS X_NUCLEO_53L1A1

Files at this revision

API Documentation at this revision

Comitter:
johnAlexander
Date:
Wed Jul 24 10:36:51 2019 +0000
Parent:
6:aa13392d16bb
Child:
8:744e8b1b9837
Commit message:
Updated for mbed coding style guidelines.

Changed in this revision

VL53L1X_Class.cpp Show annotated file Show diff for this revision Revisions of this file
VL53L1X_Class.h Show annotated file Show diff for this revision Revisions of this file
VL53L1X_I2C.h Show annotated file Show diff for this revision Revisions of this file
vl53L1x_I2c.h Show diff for this revision Revisions of this file
vl53l1x_class.cpp Show diff for this revision Revisions of this file
vl53l1x_class.h Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VL53L1X_Class.cpp	Wed Jul 24 10:36:51 2019 +0000
@@ -0,0 +1,1115 @@
+/**
+ ******************************************************************************
+ * @file    Vl53l1x_Class.cpp
+ * @author  JS
+ * @version V0.0.1
+ * @date    15-January-2019
+ * @brief   Implementation file for the VL53L1 sensor component driver class
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT(c) 2019 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *   1. Redistributions of source code must retain the above copyright notice,
+ *      this list of conditions and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above copyright notice,
+ *      this list of conditions and the following disclaimer in the documentation
+ *      and/or other materials provided with the distribution.
+ *   3. Neither the name of STMicroelectronics nor the names of its contributors
+ *      may be used to endorse or promote products derived from this software
+ *       without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+*/
+
+/* Includes */
+#include <stdlib.h>
+#include "VL53L1X_Class.h"
+
+
+#define ALGO__PART_TO_PART_RANGE_OFFSET_MM  0x001E
+#define MM_CONFIG__INNER_OFFSET_MM          0x0020
+#define MM_CONFIG__OUTER_OFFSET_MM          0x0022
+
+#include "vl53l1x_configuration.h"
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_sw_version(VL53L1X_Version_t *pVersion)
+{
+    VL53L1X_ERROR Status = 0;
+
+    pVersion->major = VL53L1X_IMPLEMENTATION_VER_MAJOR;
+    pVersion->minor = VL53L1X_IMPLEMENTATION_VER_MINOR;
+    pVersion->build = VL53L1X_IMPLEMENTATION_VER_SUB;
+    pVersion->revision = VL53L1X_IMPLEMENTATION_VER_REVISION;
+    return Status;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1x_set_i2c_address(uint8_t new_address)
+{
+    VL53L1X_ERROR status = 0;
+
+    status = vl53l1_wr_byte(Device, VL53L1_I2C_SLAVE__DEVICE_ADDRESS, new_address >> 1);
+    Device->I2cDevAddr = new_address;
+    return status;
+}
+
+int VL53L1X::init_sensor(uint8_t new_addr)
+{
+    Device->I2cDevAddr = new_addr;
+    int status = 0;
+    vl53l1_off();
+    vl53l1_on();
+
+    status = is_present();
+    if (!status) {
+        printf("Failed to init VL53L0X sensor!\n\r");
+        return status;
+    }
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_sensor_init()
+{
+    VL53L1X_ERROR status = 0;
+    uint8_t Addr = 0x00;
+
+    for (Addr = 0x2D; Addr <= 0x87; Addr++){
+        status = vl53l1_wr_byte(Device, Addr, VL51L1X_DEFAULT_CONFIGURATION[Addr - 0x2D]);
+        if (status != 0)
+        {
+            printf("Writing config failed - %d\r\n", status);
+        }
+    }
+    
+    uint16_t sensorID= 0;
+    status = vl53l1x_get_sensor_id(&sensorID);
+    printf("Sensor id is - %d (%X)\r\n", sensorID, sensorID);
+    
+    status = vl53l1x_start_ranging();
+    if (status != 0)
+    {
+        printf("start ranging failed - %d\r\n", status);
+    }
+ 
+    status = vl53l1x_clear_interrupt();
+    status = vl53l1x_stop_ranging();
+    status = vl53l1_wr_byte(Device, VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND, 0x09); /* two bounds VHV */
+    status = vl53l1_wr_byte(Device, 0x0B, 0); /* start VHV from the previous temperature */
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_clear_interrupt()
+{
+    VL53L1X_ERROR status = 0;
+
+    status = vl53l1_wr_byte(Device, SYSTEM__INTERRUPT_CLEAR, 0x01);
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_set_interrupt_polarity(uint8_t NewPolarity)
+{
+    uint8_t Temp;
+    VL53L1X_ERROR status = 0;
+
+    status = vl53l1_rd_byte(Device, GPIO_HV_MUX__CTRL, &Temp);
+    Temp = Temp & 0xEF;
+    status = vl53l1_wr_byte(Device, GPIO_HV_MUX__CTRL, Temp | (!(NewPolarity & 1)) << 4);
+    return status;
+}
+
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_interrupt_polarity(uint8_t *pInterruptPolarity)
+{
+    uint8_t Temp;
+    VL53L1X_ERROR status = 0;
+
+    status = vl53l1_rd_byte(Device, GPIO_HV_MUX__CTRL, &Temp);
+    Temp = Temp & 0x10;
+    *pInterruptPolarity = !(Temp>>4);
+    return status;
+}
+
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_start_ranging()
+{
+    VL53L1X_ERROR status = 0;
+
+    status = vl53l1_wr_byte(Device, SYSTEM__MODE_START, 0x40);   /* Enable VL53L1X */
+    return status;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1x_stop_ranging()
+{
+    VL53L1X_ERROR status = 0;
+
+    status = vl53l1_wr_byte(Device, SYSTEM__MODE_START, 0x00);   /* Disable VL53L1X */
+    return status;
+}
+
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_check_for_data_ready(uint8_t *isDataReady)
+{
+    uint8_t Temp;
+    uint8_t IntPol;
+    VL53L1X_ERROR status = 0;
+
+    status = vl53l1x_get_interrupt_polarity(&IntPol);
+    status = vl53l1_rd_byte(Device, GPIO__TIO_HV_STATUS, &Temp);
+    /* Read in the register to check if a new value is available */
+    if (status == 0){
+        if ((Temp & 1) == IntPol)
+            *isDataReady = 1;
+        else
+            *isDataReady = 0;
+    }
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_set_timing_budget_in_ms(uint16_t TimingBudgetInMs)
+{
+    uint16_t DM;
+    VL53L1X_ERROR  status=0;
+
+    status = vl53l1x_get_distance_mode(&DM);
+    if (DM == 0)
+        return 1;
+    else if (DM == 1) { /* Short DistanceMode */
+        switch (TimingBudgetInMs) {
+        case 15: /* only available in short distance mode */
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
+                    0x01D);
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
+                    0x0027);
+            break;
+        case 20:
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
+                    0x0051);
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
+                    0x006E);
+            break;
+        case 33:
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
+                    0x00D6);
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
+                    0x006E);
+            break;
+        case 50:
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
+                    0x1AE);
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
+                    0x01E8);
+            break;
+        case 100:
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
+                    0x02E1);
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
+                    0x0388);
+            break;
+        case 200:
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
+                    0x03E1);
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
+                    0x0496);
+            break;
+        case 500:
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
+                    0x0591);
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
+                    0x05C1);
+            break;
+        default:
+            status = 1;
+            break;
+        }
+    } else {
+        switch (TimingBudgetInMs) {
+        case 20:
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
+                    0x001E);
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
+                    0x0022);
+            break;
+        case 33:
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
+                    0x0060);
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
+                    0x006E);
+            break;
+        case 50:
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
+                    0x00AD);
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
+                    0x00C6);
+            break;
+        case 100:
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
+                    0x01CC);
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
+                    0x01EA);
+            break;
+        case 200:
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
+                    0x02D9);
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
+                    0x02F8);
+            break;
+        case 500:
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
+                    0x048F);
+            vl53l1_wr_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
+                    0x04A4);
+            break;
+        default:
+            status = 1;
+            break;
+        }
+    }
+    return status;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_timing_budget_in_ms(uint16_t *pTimingBudget)
+{
+    uint16_t Temp;
+    VL53L1X_ERROR status = 0;
+
+    status = vl53l1_rd_word(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI, &Temp);
+    switch (Temp) {
+        case 0x001D :
+            *pTimingBudget = 15;
+            break;
+        case 0x0051 :
+        case 0x001E :
+            *pTimingBudget = 20;
+            break;
+        case 0x00D6 :
+        case 0x0060 :
+            *pTimingBudget = 33;
+            break;
+        case 0x1AE :
+        case 0x00AD :
+            *pTimingBudget = 50;
+            break;
+        case 0x02E1 :
+        case 0x01CC :
+            *pTimingBudget = 100;
+            break;
+        case 0x03E1 :
+        case 0x02D9 :
+            *pTimingBudget = 200;
+            break;
+        case 0x0591 :
+        case 0x048F :
+            *pTimingBudget = 500;
+            break;
+        default:
+            *pTimingBudget = 0;
+            break;
+    }
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_set_distance_mode(uint16_t DM)
+{
+    uint16_t TB;
+    VL53L1X_ERROR status = 0;
+
+    status = vl53l1x_get_timing_budget_in_ms(&TB);
+    
+    
+    switch (DM) {
+    case 1:
+        status = vl53l1_wr_byte(Device, PHASECAL_CONFIG__TIMEOUT_MACROP, 0x14);
+        status = vl53l1_wr_byte(Device, RANGE_CONFIG__VCSEL_PERIOD_A, 0x07);
+        status = vl53l1_wr_byte(Device, RANGE_CONFIG__VCSEL_PERIOD_B, 0x05);
+        status = vl53l1_wr_byte(Device, RANGE_CONFIG__VALID_PHASE_HIGH, 0x38);
+        status = vl53l1_wr_word(Device, SD_CONFIG__WOI_SD0, 0x0705);
+        status = vl53l1_wr_word(Device, SD_CONFIG__INITIAL_PHASE_SD0, 0x0606);
+        break;
+    case 2:
+        status = vl53l1_wr_byte(Device, PHASECAL_CONFIG__TIMEOUT_MACROP, 0x0A);
+        status = vl53l1_wr_byte(Device, RANGE_CONFIG__VCSEL_PERIOD_A, 0x0F);
+        status = vl53l1_wr_byte(Device, RANGE_CONFIG__VCSEL_PERIOD_B, 0x0D);
+        status = vl53l1_wr_byte(Device, RANGE_CONFIG__VALID_PHASE_HIGH, 0xB8);
+        status = vl53l1_wr_word(Device, SD_CONFIG__WOI_SD0, 0x0F0D);
+        status = vl53l1_wr_word(Device, SD_CONFIG__INITIAL_PHASE_SD0, 0x0E0E);
+        break;
+    default:
+        break;
+    }
+    status = vl53l1x_set_timing_budget_in_ms(TB);
+    return status;
+}
+
+
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_distance_mode(uint16_t *DM)
+{
+    uint8_t TempDM, status=0;
+
+    status = vl53l1_rd_byte(Device,PHASECAL_CONFIG__TIMEOUT_MACROP, &TempDM);
+    if (TempDM == 0x14)
+        *DM=1;
+    if(TempDM == 0x0A)
+        *DM=2;
+    return status;
+}
+
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_set_inter_measurement_in_ms(uint16_t InterMeasMs)
+{
+    uint16_t ClockPLL;
+    VL53L1X_ERROR status = 0;
+
+    status = vl53l1_rd_word(Device, VL53L1_RESULT__OSC_CALIBRATE_VAL, &ClockPLL);
+    ClockPLL = ClockPLL&0x3FF;
+    vl53l1_wr_double_word(Device, VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD,
+            (uint32_t)(ClockPLL * InterMeasMs * 1.075));
+    return status;
+
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_inter_measurement_in_ms(uint16_t *pIM)
+{
+    uint16_t ClockPLL;
+    VL53L1X_ERROR status = 0;
+    uint32_t tmp;
+
+    status = vl53l1_rd_double_word(Device,VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD, &tmp);
+    *pIM = (uint16_t)tmp;
+    status = vl53l1_rd_word(Device, VL53L1_RESULT__OSC_CALIBRATE_VAL, &ClockPLL);
+    ClockPLL = ClockPLL&0x3FF;
+    *pIM= (uint16_t)(*pIM/(ClockPLL*1.065));
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_boot_state(uint8_t *state)
+{
+    VL53L1X_ERROR status = 0;
+    uint8_t tmp = 0;
+
+    status = vl53l1_rd_byte(Device,VL53L1_FIRMWARE__SYSTEM_STATUS, &tmp);
+    *state = tmp;
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_sensor_id(uint16_t *sensorId)
+{
+    VL53L1X_ERROR status = 0;
+    uint16_t tmp = 0;
+
+    status = vl53l1_rd_word(Device, VL53L1_IDENTIFICATION__MODEL_ID, &tmp);
+    *sensorId = tmp;
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_distance(uint16_t *distance)
+{
+    VL53L1X_ERROR status = 0;
+    uint16_t tmp;
+
+    status = (vl53l1_rd_word(Device,
+            VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0, &tmp));
+    *distance = tmp;
+    return status;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_signal_per_spad(uint16_t *signalRate)
+{
+    VL53L1X_ERROR status = 0;
+    uint16_t SpNb=1, signal;
+
+    status = vl53l1_rd_word(Device,
+        VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0, &signal);
+    status = vl53l1_rd_word(Device,
+        VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0, &SpNb);
+    *signalRate = (uint16_t) (2000.0*signal/SpNb);
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_ambient_per_spad(uint16_t *ambPerSp)
+{
+    VL53L1X_ERROR status=0;
+    uint16_t AmbientRate, SpNb=1;
+
+    status = vl53l1_rd_word(Device, RESULT__AMBIENT_COUNT_RATE_MCPS_SD, &AmbientRate);
+    status = vl53l1_rd_word(Device, VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0, &SpNb);
+    *ambPerSp=(uint16_t) (2000.0 * AmbientRate / SpNb);
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_signal_rate(uint16_t *signal)
+{
+    VL53L1X_ERROR status = 0;
+    uint16_t tmp;
+
+    status = vl53l1_rd_word(Device,
+        VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0, &tmp);
+    *signal = tmp*8;
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_spad_nb(uint16_t *spNb)
+{
+    VL53L1X_ERROR status = 0;
+    uint16_t tmp;
+
+    status = vl53l1_rd_word(Device,
+                  VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0, &tmp);
+    *spNb = tmp >> 8;
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_ambient_rate(uint16_t *ambRate)
+{
+    VL53L1X_ERROR status = 0;
+    uint16_t tmp;
+
+    status = vl53l1_rd_word(Device, RESULT__AMBIENT_COUNT_RATE_MCPS_SD, &tmp);
+    *ambRate = tmp*8;
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_range_status(uint8_t *rangeStatus)
+{
+    VL53L1X_ERROR status = 0;
+    uint8_t RgSt;
+
+    status = vl53l1_rd_byte(Device, VL53L1_RESULT__RANGE_STATUS, &RgSt);
+    RgSt = RgSt&0x1F;
+    switch (RgSt) {
+    case 9:
+        RgSt = 0;
+        break;
+    case 6:
+        RgSt = 1;
+        break;
+    case 4:
+        RgSt = 2;
+        break;
+    case 8:
+        RgSt = 3;
+        break;
+    case 5:
+        RgSt = 4;
+        break;
+    case 3:
+        RgSt = 5;
+        break;
+    case 19:
+        RgSt = 6;
+        break;
+    case 7:
+        RgSt = 7;
+        break;
+    case 12:
+        RgSt = 9;
+        break;
+    case 18:
+        RgSt = 10;
+        break;
+    case 22:
+        RgSt = 11;
+        break;
+    case 23:
+        RgSt = 12;
+        break;
+    case 13:
+        RgSt = 13;
+        break;
+    default:
+        RgSt = 255;
+        break;
+    }
+    *rangeStatus = RgSt;
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_set_offset(int16_t OffsetValue)
+{
+    VL53L1X_ERROR status = 0;
+    int16_t Temp;
+
+    Temp = (OffsetValue*4);
+    vl53l1_wr_word(Device, ALGO__PART_TO_PART_RANGE_OFFSET_MM,
+            (uint16_t)Temp);
+    vl53l1_wr_word(Device, MM_CONFIG__INNER_OFFSET_MM, 0x0);
+    vl53l1_wr_word(Device, MM_CONFIG__OUTER_OFFSET_MM, 0x0);
+    return status;
+}
+
+
+VL53L1X_ERROR  VL53L1X::vl53l1x_get_offset(int16_t *offset)
+{
+    VL53L1X_ERROR status = 0;
+    uint16_t Temp;
+
+    status = vl53l1_rd_word(Device,ALGO__PART_TO_PART_RANGE_OFFSET_MM, &Temp);
+    Temp = Temp<<3;
+    Temp = Temp >>5;
+    *offset = (int16_t)(Temp);
+    return status;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1x_set_xtalk(uint16_t XtalkValue)
+{
+    /* XTalkValue in count per second to avoid float type */
+    VL53L1X_ERROR status = 0;
+
+    status = vl53l1_wr_word(Device,
+            ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS,
+            0x0000);
+    status = vl53l1_wr_word(Device, ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS,
+            0x0000);
+    status = vl53l1_wr_word(Device, ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS,
+            (XtalkValue<<9)/1000); /* * << 9 (7.9 format) and /1000 to convert cps to kpcs */
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_xtalk(uint16_t *xtalk )
+{
+    VL53L1X_ERROR status = 0;
+    uint16_t tmp;
+
+    status = vl53l1_rd_word(Device,ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS, &tmp);
+    *xtalk = (tmp*1000)>>9; /* * 1000 to convert kcps to cps and >> 9 (7.9 format) */
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_set_distance_threshold(uint16_t ThreshLow,
+                  uint16_t ThreshHigh, uint8_t Window,
+                  uint8_t IntOnNoTarget)
+{
+    VL53L1X_ERROR status = 0;
+    uint8_t Temp = 0;
+
+    status = vl53l1_rd_byte(Device, SYSTEM__INTERRUPT_CONFIG_GPIO, &Temp);
+    Temp = Temp & 0x47;
+    if (IntOnNoTarget == 0) {
+        status = vl53l1_wr_byte(Device, SYSTEM__INTERRUPT_CONFIG_GPIO,
+                   (Temp | (Window & 0x07)));
+    } else {
+        status = vl53l1_wr_byte(Device, SYSTEM__INTERRUPT_CONFIG_GPIO,
+                   ((Temp | (Window & 0x07)) | 0x40));
+    }
+    status = vl53l1_wr_word(Device, SYSTEM__THRESH_HIGH, ThreshHigh);
+    status = vl53l1_wr_word(Device, SYSTEM__THRESH_LOW, ThreshLow);
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_distance_threshold_window(uint16_t *window)
+{
+    VL53L1X_ERROR status = 0;
+    uint8_t tmp;
+    status = vl53l1_rd_byte(Device,SYSTEM__INTERRUPT_CONFIG_GPIO, &tmp);
+    *window = (uint16_t)(tmp & 0x7);
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_distance_threshold_low(uint16_t *low)
+{
+    VL53L1X_ERROR status = 0;
+    uint16_t tmp;
+
+    status = vl53l1_rd_word(Device,SYSTEM__THRESH_LOW, &tmp);
+    *low = tmp;
+    return status;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_distance_threshold_high(uint16_t *high)
+{
+    VL53L1X_ERROR status = 0;
+    uint16_t tmp;
+
+    status = vl53l1_rd_word(Device,SYSTEM__THRESH_HIGH, &tmp);
+    *high = tmp;
+    return status;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1x_set_roi(uint16_t X, uint16_t Y)
+{
+    uint8_t OpticalCenter;
+    VL53L1X_ERROR status = 0;
+
+    status =vl53l1_rd_byte(Device, VL53L1_ROI_CONFIG__MODE_ROI_CENTRE_SPAD, &OpticalCenter);
+    if (X > 16)
+        X = 16;
+    if (Y > 16)
+        Y = 16;
+    if (X > 10 || Y > 10){
+        OpticalCenter = 199;
+    }
+    status = vl53l1_wr_byte(Device, ROI_CONFIG__USER_ROI_CENTRE_SPAD, OpticalCenter);
+    status = vl53l1_wr_byte(Device, ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE,
+               (Y - 1) << 4 | (X - 1));
+    return status;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_roi_xy(uint16_t *ROI_X, uint16_t *ROI_Y)
+{
+    VL53L1X_ERROR status = 0;
+    uint8_t tmp;
+
+    status = vl53l1_rd_byte(Device,ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE, &tmp);
+    *ROI_X = ((uint16_t)tmp & 0x0F) + 1;
+    *ROI_Y = (((uint16_t)tmp & 0xF0) >> 4) + 1;
+    return status;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1x_set_signal_threshold(uint16_t Signal)
+{
+    VL53L1X_ERROR status = 0;
+
+    vl53l1_wr_word(Device,RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS,Signal>>3);
+    return status;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_signal_threshold(uint16_t *signal)
+{
+    VL53L1X_ERROR status = 0;
+    uint16_t tmp;
+
+    status = vl53l1_rd_word(Device,
+                RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS, &tmp);
+    *signal = tmp <<3;
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1x_set_sigma_threshold(uint16_t Sigma)
+{
+    VL53L1X_ERROR status = 0;
+
+    if(Sigma>(0xFFFF>>2)){
+        return 1;
+    }
+    /* 16 bits register 14.2 format */
+    status = vl53l1_wr_word(Device,RANGE_CONFIG__SIGMA_THRESH,Sigma<<2);
+    return status;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1x_get_sigma_threshold(uint16_t *sigma)
+{
+    VL53L1X_ERROR status = 0;
+    uint16_t tmp;
+
+    status = vl53l1_rd_word(Device,RANGE_CONFIG__SIGMA_THRESH, &tmp);
+    *sigma = tmp >> 2;
+    return status;
+
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1x_start_temperature_update()
+{
+    VL53L1X_ERROR status = 0;
+    uint8_t tmp=0;
+
+    status = vl53l1_wr_byte(Device,VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND,0x81); /* full VHV */
+    status = vl53l1_wr_byte(Device,0x0B,0x92);
+    status = vl53l1x_start_ranging();
+    while(tmp==0){
+        status = vl53l1x_check_for_data_ready(&tmp);
+    }
+    tmp  = 0;
+    status = vl53l1x_clear_interrupt();
+    status = vl53l1x_stop_ranging();
+    status = vl53l1_wr_byte(Device, VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND, 0x09); /* two bounds VHV */
+    status = vl53l1_wr_byte(Device, 0x0B, 0); /* start VHV from the previous temperature */
+    return status;
+}
+
+    /* VL53L1X_calibration.h functions */
+    
+int8_t VL53L1X::vl53l1x_calibrate_offset(uint16_t TargetDistInMm, int16_t *offset)
+{
+    uint8_t i = 0, tmp;
+    int16_t AverageDistance = 0;
+    uint16_t distance;
+    VL53L1X_ERROR status = 0;
+
+    status = vl53l1_wr_word(Device, ALGO__PART_TO_PART_RANGE_OFFSET_MM, 0x0);
+    status = vl53l1_wr_word(Device, MM_CONFIG__INNER_OFFSET_MM, 0x0);
+    status = vl53l1_wr_word(Device, MM_CONFIG__OUTER_OFFSET_MM, 0x0);
+    status = vl53l1x_start_ranging();    /* Enable VL53L1X sensor */
+    for (i = 0; i < 50; i++) {
+        while (tmp == 0){
+            status = vl53l1x_check_for_data_ready(&tmp);
+        }
+        tmp = 0;
+        status = vl53l1x_get_distance(&distance);
+        status = vl53l1x_clear_interrupt();
+        AverageDistance = AverageDistance + distance;
+    }
+    status = vl53l1x_stop_ranging();
+    AverageDistance = AverageDistance / 50;
+    *offset = TargetDistInMm - AverageDistance;
+    status = vl53l1_wr_word(Device, ALGO__PART_TO_PART_RANGE_OFFSET_MM, *offset*4);
+    return status;
+}
+
+
+int8_t VL53L1X::vl53l1x_calibrate_xtalk(uint16_t TargetDistInMm, uint16_t *xtalk)
+{
+    uint8_t i, tmp= 0;
+    float AverageSignalRate = 0;
+    float AverageDistance = 0;
+    float AverageSpadNb = 0;
+    uint16_t distance = 0, spadNum;
+    uint16_t sr;
+    VL53L1X_ERROR status = 0;
+
+    status = vl53l1_wr_word(Device, 0x0016,0);
+    status = vl53l1x_start_ranging();
+    for (i = 0; i < 50; i++) {
+        while (tmp == 0){
+            status = vl53l1x_check_for_data_ready(&tmp);
+        }
+        tmp=0;
+        status= vl53l1x_get_signal_rate(&sr);
+        status= vl53l1x_get_distance(&distance);
+        status = vl53l1x_clear_interrupt();
+        AverageDistance = AverageDistance + distance;
+        status = vl53l1x_get_spad_nb(&spadNum);
+        AverageSpadNb = AverageSpadNb + spadNum;
+        AverageSignalRate =
+            AverageSignalRate + sr;
+    }
+    status = vl53l1x_stop_ranging();
+    AverageDistance = AverageDistance / 50;
+    AverageSpadNb = AverageSpadNb / 50;
+    AverageSignalRate = AverageSignalRate / 50;
+    /* Calculate Xtalk value */
+    *xtalk = (uint16_t)(512*(AverageSignalRate*(1-(AverageDistance/TargetDistInMm)))/AverageSpadNb);
+    status = vl53l1_wr_word(Device, 0x0016, *xtalk);
+    return status;
+}
+
+
+
+
+    /* Write and read functions from I2C */
+
+
+VL53L1X_ERROR VL53L1X::vl53l1_write_multi(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count)
+{
+   int  status;
+
+   status = vl53l1_i2c_write(Dev->I2cDevAddr, index, pdata, (uint16_t)count);
+   return status;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1_read_multi(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count)
+{
+    int status;
+
+    status = vl53l1_i2c_read(Dev->I2cDevAddr, index, pdata, (uint16_t)count);
+
+    return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1_wr_byte(VL53L1_DEV Dev, uint16_t index, uint8_t data)
+{
+   int  status;
+
+   status=vl53l1_i2c_write(Dev->I2cDevAddr, index, &data, 1);
+   return status;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1_wr_word(VL53L1_DEV Dev, uint16_t index, uint16_t data)
+{
+   int  status;
+   uint8_t buffer[2];
+
+     buffer[0] = data >> 8;
+     buffer[1] = data & 0x00FF;
+   status=vl53l1_i2c_write(Dev->I2cDevAddr, index, (uint8_t *)buffer, 2);
+   return status;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1_wr_double_word(VL53L1_DEV Dev, uint16_t index, uint32_t data)
+{
+   int  status;
+   uint8_t buffer[4];
+
+     buffer[0] = (data >> 24) & 0xFF;
+     buffer[1] = (data >> 16) & 0xFF;
+     buffer[2] = (data >>  8) & 0xFF;
+     buffer[3] = (data >>  0) & 0xFF;
+   status=vl53l1_i2c_write(Dev->I2cDevAddr, index, (uint8_t *)buffer, 4);
+   return status;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1_rd_byte(VL53L1_DEV Dev, uint16_t index, uint8_t *data)
+{
+   int  status;
+
+   status = vl53l1_i2c_read(Dev->I2cDevAddr, index, data, 1);
+
+   if(status)
+     return -1;
+
+   return 0;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1_rd_word(VL53L1_DEV Dev, uint16_t index, uint16_t *data)
+{
+   int  status;
+   uint8_t buffer[2] = {0,0};
+
+   status = vl53l1_i2c_read(Dev->I2cDevAddr, index, buffer, 2);
+   if (!status)
+   {
+       *data = (buffer[0] << 8) + buffer[1];
+   }
+   return status;
+
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1_rd_double_word(VL53L1_DEV Dev, uint16_t index, uint32_t *data)
+{
+   int status;
+   uint8_t buffer[4] = {0,0,0,0};
+
+   status = vl53l1_i2c_read(Dev->I2cDevAddr, index, buffer, 4);
+   if(!status)
+   {
+       *data = (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3];
+   }
+   return status;
+
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1_update_byte(VL53L1_DEV Dev, uint16_t index, uint8_t AndData, uint8_t OrData)
+{
+   int  status;
+   uint8_t buffer = 0;
+
+   /* read data direct onto buffer */
+   status = vl53l1_i2c_read(Dev->I2cDevAddr, index, &buffer,1);
+   if (!status)
+   {
+      buffer = (buffer & AndData) | OrData;
+      status = vl53l1_i2c_write(Dev->I2cDevAddr, index, &buffer, (uint16_t)1);
+   }
+   return status;
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1_i2c_write(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t* pBuffer, uint16_t NumByteToWrite)
+{
+    int ret;
+    ret = dev_i2c->v53l1x_i2c_write(pBuffer, DeviceAddr, RegisterAddr, NumByteToWrite);
+    if (ret) {
+        return -1;
+    }
+    return 0;
+
+}
+
+VL53L1X_ERROR VL53L1X::vl53l1_i2c_read(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t* pBuffer, uint16_t NumByteToRead)
+{
+    int ret;
+
+    ret = dev_i2c->v53l1x_i2c_read(pBuffer, DeviceAddr, RegisterAddr, NumByteToRead);
+
+    if (ret) {
+        return -1;
+    }
+    return 0;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1_get_tick_count(
+    uint32_t *ptick_count_ms)
+{
+
+    /* Returns current tick count in [ms] */
+
+    VL53L1X_ERROR status  = VL53L1_ERROR_NONE;
+
+    *ptick_count_ms = 0;
+
+    return status;
+}
+
+
+
+VL53L1X_ERROR VL53L1X::vl53l1_wait_us(VL53L1_Dev_t *pdev, int32_t wait_us)
+{
+    return VL53L1_ERROR_NONE;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1_wait_ms(VL53L1_Dev_t *pdev, int32_t wait_ms)
+{
+    return VL53L1_ERROR_NONE;
+}
+
+
+VL53L1X_ERROR VL53L1X::vl53l1_wait_value_mask_ex(
+    VL53L1_Dev_t *pdev,
+    uint32_t      timeout_ms,
+    uint16_t      index,
+    uint8_t       value,
+    uint8_t       mask,
+    uint32_t      poll_delay_ms)
+{
+
+    /*
+     * Platform implementation of WaitValueMaskEx V2WReg script command
+     *
+     * WaitValueMaskEx(
+     *          duration_ms,
+     *          index,
+     *          value,
+     *          mask,
+     *          poll_delay_ms);
+     */
+
+    VL53L1_Error status         = VL53L1_ERROR_NONE;
+    uint32_t     start_time_ms = 0;
+    uint32_t     current_time_ms = 0;
+    uint32_t     polling_time_ms = 0;
+    uint8_t      byte_value      = 0;
+    uint8_t      found           = 0;
+
+
+
+    /* calculate time limit in absolute time */
+
+     vl53l1_get_tick_count(&start_time_ms);
+
+    /* remember current trace functions and temporarily disable
+     * function logging
+     */
+
+
+    /* wait until value is found, timeout reached on error occurred */
+
+    while ((status == VL53L1_ERROR_NONE) &&
+           (polling_time_ms < timeout_ms) &&
+           (found == 0)) {
+
+        if (status == VL53L1_ERROR_NONE)
+            status = vl53l1_rd_byte(
+                            pdev,
+                            index,
+                            &byte_value);
+
+        if ((byte_value & mask) == value)
+            found = 1;
+
+        if (status == VL53L1_ERROR_NONE  &&
+            found == 0 &&
+            poll_delay_ms > 0)
+            status = vl53l1_wait_ms(
+                    pdev,
+                    poll_delay_ms);
+
+        /* Update polling time (Compare difference rather than absolute to
+        negate 32bit wrap around issue) */
+        vl53l1_get_tick_count(&current_time_ms);
+        polling_time_ms = current_time_ms - start_time_ms;
+
+    }
+    
+
+    if (found == 0 && status == VL53L1_ERROR_NONE)
+        status = VL53L1_ERROR_TIME_OUT;
+
+    return status;
+}
+
+int VL53L1X::handle_irq(uint16_t *distance)
+{
+    int status;
+    status = get_measurement(distance);
+    enable_interrupt_measure_detection_irq();
+    return status;
+}
+
+int VL53L1X::get_measurement(uint16_t *distance)
+{
+    int status = 0;
+
+    status = vl53l1x_get_distance(distance);
+    status = vl53l1x_clear_interrupt();
+
+    return status;
+}
+
+int VL53L1X::start_measurement(void (*fptr)(void))
+{
+    int status = 0;
+
+    if (_gpio1Int == NULL) {
+        printf("GPIO1 Error\r\n");
+        return 1;
+    }
+
+    status = vl53l1x_stop_ranging(); // it is safer to do this while sensor is stopped
+
+    if (status == 0) {
+        attach_interrupt_measure_detection_irq(fptr);
+        enable_interrupt_measure_detection_irq();
+    }
+
+    if (status == 0) {
+        status = vl53l1x_start_ranging();
+    }
+
+    return status;
+}
+
+int VL53L1X::stop_measurement()
+{
+    int status = 0;
+
+    if (status == 0) {
+        printf("Call of VL53L0X_StopMeasurement\n");
+        status = vl53l1x_stop_ranging();
+    }
+
+    if (status == 0)
+        status = vl53l1x_clear_interrupt();
+
+    return status;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VL53L1X_Class.h	Wed Jul 24 10:36:51 2019 +0000
@@ -0,0 +1,687 @@
+/*******************************************************************************
+ * @file    VL53L1X_Class.h
+ * @author  JS
+ * @version V0.0.1
+ * @date    15-January-2019
+ * @brief   Header file for VL53L1 sensor component
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT(c) 2019 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *   1. Redistributions of source code must retain the above copyright notice,
+ *      this list of conditions and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above copyright notice,
+ *      this list of conditions and the following disclaimer in the documentation
+ *      and/or other materials provided with the distribution.
+ *   3. Neither the name of STMicroelectronics nor the names of its contributors
+ *      may be used to endorse or promote products derived from this software
+ *       without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *****************************************************************************/
+
+#ifndef __VL53L1X_CLASS_H
+#define __VL53L1X_CLASS_H
+
+
+#ifdef _MSC_VER
+#   ifdef VL53L1X_API_EXPORTS
+#       define VL53L1X_API  __declspec(dllexport)
+#   else
+#       define VL53L1X_API
+#   endif
+#else
+#   define VL53L1X_API
+#endif
+
+
+/* Includes ------------------------------------------------------------------*/
+#include "mbed.h"
+#include "PinNames.h"
+#include "RangeSensor.h"
+#include "vl53l1x_error_codes.h"
+#include "VL53L1X_I2C.h"
+#include "Stmpe1600.h"
+
+
+#define VL53L1X_IMPLEMENTATION_VER_MAJOR       1
+#define VL53L1X_IMPLEMENTATION_VER_MINOR       0
+#define VL53L1X_IMPLEMENTATION_VER_SUB         1
+#define VL53L1X_IMPLEMENTATION_VER_REVISION  0000
+
+typedef int8_t VL53L1X_ERROR;
+
+#define VL53L1_I2C_SLAVE__DEVICE_ADDRESS                    0x0001
+#define VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND        0x0008
+#define ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS      0x0016
+#define ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS  0x0018
+#define ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS  0x001A
+#define ALGO__PART_TO_PART_RANGE_OFFSET_MM                  0x001E
+#define MM_CONFIG__INNER_OFFSET_MM                          0x0020
+#define MM_CONFIG__OUTER_OFFSET_MM                          0x0022
+#define GPIO_HV_MUX__CTRL                                   0x0030
+#define GPIO__TIO_HV_STATUS                                 0x0031
+#define SYSTEM__INTERRUPT_CONFIG_GPIO                       0x0046
+#define PHASECAL_CONFIG__TIMEOUT_MACROP                     0x004B
+#define RANGE_CONFIG__TIMEOUT_MACROP_A_HI                   0x005E
+#define RANGE_CONFIG__VCSEL_PERIOD_A                        0x0060
+#define RANGE_CONFIG__VCSEL_PERIOD_B                        0x0063
+#define RANGE_CONFIG__TIMEOUT_MACROP_B_HI                   0x0061
+#define RANGE_CONFIG__TIMEOUT_MACROP_B_LO                   0x0062
+#define RANGE_CONFIG__SIGMA_THRESH                          0x0064
+#define RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS         0x0066
+#define RANGE_CONFIG__VALID_PHASE_HIGH                      0x0069
+#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD              0x006C
+#define SYSTEM__THRESH_HIGH                                 0x0072
+#define SYSTEM__THRESH_LOW                                  0x0074
+#define SD_CONFIG__WOI_SD0                                  0x0078
+#define SD_CONFIG__INITIAL_PHASE_SD0                        0x007A
+#define ROI_CONFIG__USER_ROI_CENTRE_SPAD                    0x007F
+#define ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE       0x0080
+#define SYSTEM__SEQUENCE_CONFIG                             0x0081
+#define VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD               0x0082
+#define SYSTEM__INTERRUPT_CLEAR                             0x0086
+#define SYSTEM__MODE_START                                  0x0087
+#define VL53L1_RESULT__RANGE_STATUS                         0x0089
+#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0       0x008C
+#define RESULT__AMBIENT_COUNT_RATE_MCPS_SD                  0x0090
+#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0               0x0096
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0  0x0098
+#define VL53L1_RESULT__OSC_CALIBRATE_VAL                    0x00DE
+#define VL53L1_FIRMWARE__SYSTEM_STATUS                      0x00E5
+#define VL53L1_IDENTIFICATION__MODEL_ID                     0x010F
+#define VL53L1_ROI_CONFIG__MODE_ROI_CENTRE_SPAD             0x013E
+
+
+#define VL53L1X_DEFAULT_DEVICE_ADDRESS                      0x52
+
+#define VL53L1X_REG_IDENTIFICATION_MODEL_ID                 0x010F
+/****************************************
+ * PRIVATE define do not edit
+ ****************************************/
+
+/**
+ *  @brief defines SW Version
+ */
+typedef struct {
+    uint8_t      major;    /*!< major number */
+    uint8_t      minor;    /*!< minor number */
+    uint8_t      build;    /*!< build number */
+    uint32_t     revision; /*!< revision number */
+} VL53L1X_Version_t;
+
+
+typedef struct {
+
+    uint8_t   I2cDevAddr;
+
+} VL53L1_Dev_t;
+
+typedef VL53L1_Dev_t *VL53L1_DEV;
+
+
+/* Classes -------------------------------------------------------------------*/
+/** Class representing a VL53L1 sensor component
+ */
+class VL53L1X : public RangeSensor
+{
+ public:
+    /** Constructor
+     * @param[in] &i2c device I2C to be used for communication
+     * @param[in] &pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
+     * @param[in] DevAddr device address, 0x52 by default
+     */
+    VL53L1X(VL53L1X_DevI2C *i2c, DigitalOut *pin, PinName pin_gpio1, uint8_t dev_addr = VL53L1X_DEFAULT_DEVICE_ADDRESS)
+    : RangeSensor(), dev_i2c(i2c), _gpio0(pin)
+    {
+        MyDevice.I2cDevAddr=dev_addr;
+        Device = &MyDevice;
+               
+        _expgpio0 = NULL;
+        if (pin_gpio1 != NC) {
+            _gpio1Int = new InterruptIn(pin_gpio1);
+        } else {
+            _gpio1Int = NULL;
+        }
+    }
+    
+    /** Constructor 2 (STMPE1600DigiOut)
+     * @param[in] i2c device I2C to be used for communication
+     * @param[in] &pin Gpio Expander STMPE1600DigiOut pin to be used as component GPIO_0 CE
+     * @param[in] pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
+     * @param[in] device address, 0x29 by default
+     */
+    VL53L1X(VL53L1X_DevI2C *i2c, Stmpe1600DigiOut *pin, PinName pin_gpio1,
+            uint8_t dev_addr = VL53L1X_DEFAULT_DEVICE_ADDRESS) 
+            : dev_i2c(i2c), _expgpio0(pin)
+    {
+        MyDevice.I2cDevAddr=dev_addr;
+        Device = &MyDevice;
+               
+        _gpio0 = NULL;
+        if (pin_gpio1 != NC) {
+            _gpio1Int = new InterruptIn(pin_gpio1);
+        } else {
+            _gpio1Int = NULL;
+        }
+    }    
+    
+   /** Destructor
+    */
+    virtual ~VL53L1X()
+    {        
+        if (_gpio1Int != NULL) {
+            delete _gpio1Int;
+        }
+    }
+    
+        
+    
+    VL53L1_DEV getDevicePtr() { return Device; }
+
+    
+    /* warning: VL53L1 class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor.
+       The warning should request to introduce a virtual destructor to make sure to delete the object */
+
+    /*** Interface Methods ***/
+    /*** High level API ***/
+    /**
+     * @brief       PowerOn the sensor
+     * @return      void
+     */
+    /* turns on the sensor */
+    virtual void vl53l1_on(void)
+    {
+        printf("VL53L1_On\r\n");
+        if (_gpio0) {
+            *_gpio0 = 1;
+        } else {
+            if (_expgpio0) {
+                *_expgpio0 = 1;
+            }
+        }
+        wait_ms(10);
+    }
+
+    /**
+     * @brief       PowerOff the sensor
+     * @return      void
+     */
+    /* turns off the sensor */
+    virtual void vl53l1_off(void)
+    {
+        printf("VL53L1_Off\r\n");
+        if (_gpio0) {
+            *_gpio0 = 0;
+        } else {
+            if (_expgpio0) {
+                *_expgpio0 = 0;
+            }
+        }
+        wait_ms(10);
+    }
+    
+    int is_present()
+    {
+        int status;
+        uint8_t id = 0;
+
+        status = read_id(&id);
+        if (status) {
+            printf("Failed to read ID device. Device not present!\n\r");
+        }
+        return status;
+    }
+
+    /**
+     * @brief       Initialize the sensor with default values
+     * @return      0 on Success
+     */
+     
+     VL53L1X_ERROR initialise_sensor(uint8_t address){
+        VL53L1X_ERROR status = 0;
+        uint8_t sensorState = 0;
+        vl53l1_off();
+        vl53l1_on();
+        status = vl53l1x_set_i2c_address(address);
+        
+        if(!status){
+            status = vl53l1x_sensor_init();
+        }      
+        
+        while(!status && !sensorState) {
+            status = vl53l1x_boot_state(&sensorState);
+            wait_ms(2);
+        }
+        
+        return status;
+     }
+
+
+
+    /**
+     *
+     * @brief One time device initialization
+     * @param void
+     * @return     0 on success,  @a #CALIBRATION_WARNING if failed
+     */
+    virtual int init(void *init)
+    {
+       return vl53l1x_sensor_init();
+
+    }
+
+    /**
+     * @brief       Initialize the sensor with default values
+     * @return      "0" on success
+     */
+    int init_sensor(uint8_t new_addr);
+
+    /* Read function of the ID device */
+    virtual int read_id(uint8_t *id){
+        int status = 0;
+        uint16_t rl_id = 0;
+    
+        uint8_t ExpanderData[2];
+    
+        ExpanderData[0] = 0;
+        ExpanderData[1] = 0;
+        rl_id = 0;
+        dev_i2c->v53l1x_i2c_read(&ExpanderData[0], Device->I2cDevAddr, VL53L1X_REG_IDENTIFICATION_MODEL_ID, 2);
+    
+        rl_id = (ExpanderData[0] << 8) + ExpanderData[1];
+        printf("Model ID is: %d (%X)  \r\n",rl_id, rl_id);
+    
+        uint8_t tmp = 0;
+        ExpanderData[0] = VL53L1_FIRMWARE__SYSTEM_STATUS >> 8;
+        ExpanderData[1] = VL53L1_FIRMWARE__SYSTEM_STATUS & 0x0FF;
+        dev_i2c->v53l1x_i2c_read(&tmp, Device->I2cDevAddr, VL53L1_FIRMWARE__SYSTEM_STATUS, 1);
+
+        printf("Firmware system is: %d\r\n",tmp);
+    
+        if (rl_id == 0xEACC) {
+            printf("Device is present %d:\r\n", rl_id);
+            return status;
+        }
+        return -1;
+    }
+
+    /**
+     * @brief       Interrupt handling func to be called by user after an INT is occurred
+     * @param[out]  Data pointer to the distance to read data in to
+     * @return      0 on Success
+     */
+    int handle_irq(uint16_t *distance);
+
+    /**
+     * @brief       Start the measure indicated by operating mode
+     * @param[in]   fptr specifies call back function must be !NULL in case of interrupt measure
+     * @return      0 on Success
+     */
+    int start_measurement(void (*fptr)(void));
+    /**
+     * @brief       Stop the currently running measure indicate by operating_mode
+     * @return      0 on Success
+     */
+    int stop_measurement();
+    /**
+     * @brief       Get results for the measure
+     * @param[out]  Data pointer to the distance_data to read data in to
+     * @return      0 on Success
+     */
+    int get_measurement(uint16_t *distance);
+    /**
+     * @brief       Enable interrupt measure IRQ
+     * @return      0 on Success
+     */
+    void enable_interrupt_measure_detection_irq(void)
+    {
+        if (_gpio1Int != NULL)
+            _gpio1Int->enable_irq();
+    }
+
+    /**
+     * @brief       Disable interrupt measure IRQ
+     * @return      0 on Success
+     */
+    void disable_interrupt_measure_detection_irq(void)
+    {
+        if (_gpio1Int != NULL)
+            _gpio1Int->disable_irq();
+    }
+    /**
+     * @brief       Attach a function to call when an interrupt is detected, i.e. measurement is ready
+     * @param[in]   fptr pointer to call back function to be called whenever an interrupt occours
+     * @return      0 on Success
+     */
+    void attach_interrupt_measure_detection_irq(void (*fptr)(void))
+    {
+        if (_gpio1Int != NULL)
+            _gpio1Int->rise(fptr);
+    }
+    /**
+     * @brief Get ranging result and only that
+     * @param pRange_mm  Pointer to range distance
+     * @return           0 on success
+     */
+    virtual int get_distance(uint32_t *piData)
+    {
+    int status;
+    uint16_t distance;
+    status = vl53l1x_get_distance(&distance);
+    *piData = (uint32_t) distance;
+    return status;
+    }
+
+
+    /* VL53L1X_api.h functions */
+
+    /**
+     * @brief This function returns the SW driver version
+     */
+    VL53L1X_ERROR vl53l1x_get_sw_version(VL53L1X_Version_t *pVersion);
+
+    /**
+     * @brief This function sets the sensor I2C address used in case multiple devices application, default address 0x52
+     */
+    VL53L1X_ERROR vl53l1x_set_i2c_address(uint8_t new_address);
+
+    /**
+     * @brief This function loads the 135 bytes default values to initialize the sensor.
+     * @param dev Device address
+     * @return 0:success, != 0:failed
+     */
+    VL53L1X_ERROR vl53l1x_sensor_init();
+
+    /**
+     * @brief This function clears the interrupt, to be called after a ranging data reading
+     * to arm the interrupt for the next data ready event.
+     */
+    VL53L1X_ERROR vl53l1x_clear_interrupt();
+
+    /**
+     * @brief This function programs the interrupt polarity\n
+     * 1=active high (default), 0=active low
+     */
+    VL53L1X_ERROR vl53l1x_set_interrupt_polarity(uint8_t IntPol);
+
+    /**
+     * @brief This function returns the current interrupt polarity\n
+     * 1=active high (default), 0=active low
+     */
+    VL53L1X_ERROR vl53l1x_get_interrupt_polarity(uint8_t *pIntPol);
+
+    /**
+     * @brief This function starts the ranging distance operation\n
+     * The ranging operation is continuous. The clear interrupt has to be done after each get data to allow the interrupt to raise when the next data is ready\n
+     * 1=active high (default), 0=active low, use SetInterruptPolarity() to change the interrupt polarity if required.
+     */
+    VL53L1X_ERROR vl53l1x_start_ranging();
+
+    /**
+     * @brief This function stops the ranging.
+     */
+    VL53L1X_ERROR vl53l1x_stop_ranging();
+
+    /**
+     * @brief This function checks if the new ranging data is available by polling the dedicated register.
+     * @param : isDataReady==0 -> not ready; isDataReady==1 -> ready
+     */
+    VL53L1X_ERROR vl53l1x_check_for_data_ready(uint8_t *isDataReady);
+    
+    /**
+     * @brief This function programs the timing budget in ms.
+     * Predefined values = 15, 20, 33, 50, 100(default), 200, 500.
+     */
+    VL53L1X_ERROR vl53l1x_set_timing_budget_in_ms(uint16_t TimingBudgetInMs);
+
+    /**
+     * @brief This function returns the current timing budget in ms.
+     */
+    VL53L1X_ERROR vl53l1x_get_timing_budget_in_ms(uint16_t *pTimingBudgetInMs);
+
+    /**
+     * @brief This function programs the distance mode (1=short, 2=long(default)).
+     * Short mode max distance is limited to 1.3 m but better ambient immunity.\n
+     * Long mode can range up to 4 m in the dark with 200 ms timing budget.
+     */
+    VL53L1X_ERROR vl53l1x_set_distance_mode(uint16_t DistanceMode);
+
+    /**
+     * @brief This function returns the current distance mode (1=short, 2=long).
+     */
+    VL53L1X_ERROR vl53l1x_get_distance_mode(uint16_t *pDistanceMode);
+
+    /**
+     * @brief This function programs the Intermeasurement period in ms\n
+     * Intermeasurement period must be >/= timing budget. This condition is not checked by the API,
+     * the customer has the duty to check the condition. Default = 100 ms
+     */
+    VL53L1X_ERROR vl53l1x_set_inter_measurement_in_ms(uint16_t InterMeasurementInMs);
+
+    /**
+     * @brief This function returns the Intermeasurement period in ms.
+     */
+    VL53L1X_ERROR vl53l1x_get_inter_measurement_in_ms(uint16_t * pIM);
+
+    /**
+     * @brief This function returns the boot state of the device (1:booted, 0:not booted)
+     */
+    VL53L1X_ERROR vl53l1x_boot_state(uint8_t *state);
+
+    /**
+     * @brief This function returns the sensor id, sensor Id must be 0xEEAC
+     */
+    VL53L1X_ERROR vl53l1x_get_sensor_id(uint16_t *id);
+
+    /**
+     * @brief This function returns the distance measured by the sensor in mm
+     */
+    VL53L1X_ERROR vl53l1x_get_distance(uint16_t *distance);
+
+    /**
+     * @brief This function returns the returned signal per SPAD in kcps/SPAD.
+     * With kcps stands for Kilo Count Per Second
+     */
+    VL53L1X_ERROR vl53l1x_get_signal_per_spad(uint16_t *signalPerSp);
+
+    /**
+     * @brief This function returns the ambient per SPAD in kcps/SPAD
+     */
+    VL53L1X_ERROR vl53l1x_get_ambient_per_spad(uint16_t *amb);
+
+    /**
+     * @brief This function returns the returned signal in kcps.
+     */
+    VL53L1X_ERROR vl53l1x_get_signal_rate(uint16_t *signalRate);
+
+    /**
+     * @brief This function returns the current number of enabled SPADs
+     */
+    VL53L1X_ERROR vl53l1x_get_spad_nb(uint16_t *spNb);
+
+    /**
+     * @brief This function returns the ambient rate in kcps
+     */
+    VL53L1X_ERROR vl53l1x_get_ambient_rate(uint16_t *ambRate);
+
+    /**
+     * @brief This function returns the ranging status error \n
+     * (0:no error, 1:sigma failed, 2:signal failed, ..., 7:wrap-around)
+     */
+    VL53L1X_ERROR vl53l1x_get_range_status(uint8_t *rangeStatus);
+
+    /**
+     * @brief This function programs the offset correction in mm
+     * @param OffsetValue:the offset correction value to program in mm
+     */
+    VL53L1X_ERROR vl53l1x_set_offset(int16_t OffsetValue);
+
+    /**
+     * @brief This function returns the programmed offset correction value in mm
+     */
+    VL53L1X_ERROR vl53l1x_get_offset(int16_t *Offset);
+
+    /**
+     * @brief This function programs the xtalk correction value in cps (Count Per Second).\n
+     * This is the number of photons reflected back from the cover glass in cps.
+     */
+    VL53L1X_ERROR vl53l1x_set_xtalk(uint16_t XtalkValue);
+
+    /**
+     * @brief This function returns the current programmed xtalk correction value in cps
+     */
+    VL53L1X_ERROR vl53l1x_get_xtalk(uint16_t *Xtalk);
+
+    /**
+     * @brief This function programs the threshold detection mode\n
+     * Example:\n
+     * vl53l1x_set_distance_threshold(dev,100,300,0,1): Below 100 \n
+     * vl53l1x_set_distance_threshold(dev,100,300,1,1): Above 300 \n
+     * vl53l1x_set_distance_threshold(dev,100,300,2,1): Out of window \n
+     * vl53l1x_set_distance_threshold(dev,100,300,3,1): In window \n
+     * @param   dev : device address
+     * @param   ThreshLow(in mm) : the threshold under which one the device raises an interrupt if Window = 0
+     * @param   ThreshHigh(in mm) :  the threshold above which one the device raises an interrupt if Window = 1
+     * @param   Window detection mode : 0=below, 1=above, 2=out, 3=in
+     * @param   IntOnNoTarget = 1 (No longer used - just use 1)
+     */
+    VL53L1X_ERROR vl53l1x_set_distance_threshold(uint16_t ThreshLow,
+                      uint16_t ThreshHigh, uint8_t Window,
+                      uint8_t IntOnNoTarget);
+
+    /**
+     * @brief This function returns the window detection mode (0=below; 1=above; 2=out; 3=in)
+     */
+    VL53L1X_ERROR vl53l1x_get_distance_threshold_window(uint16_t *window);
+
+    /**
+     * @brief This function returns the low threshold in mm
+     */
+    VL53L1X_ERROR vl53l1x_get_distance_threshold_low(uint16_t *low);
+
+    /**
+     * @brief This function returns the high threshold in mm
+     */
+    VL53L1X_ERROR vl53l1x_get_distance_threshold_high(uint16_t *high);
+
+    /**
+     * @brief This function programs the ROI (Region of Interest)\n
+     * The ROI position is centered, only the ROI size can be reprogrammed.\n
+     * The smallest acceptable ROI size = 4\n
+     * @param X:ROI Width; Y=ROI Height
+     */
+    VL53L1X_ERROR vl53l1x_set_roi(uint16_t X, uint16_t Y);
+
+    /**
+     *@brief This function returns width X and height Y
+     */
+    VL53L1X_ERROR vl53l1x_get_roi_xy(uint16_t *ROI_X, uint16_t *ROI_Y);
+
+    /**
+     * @brief This function programs a new signal threshold in kcps (default=1024 kcps\n
+     */
+    VL53L1X_ERROR vl53l1x_set_signal_threshold(uint16_t signal);
+
+    /**
+     * @brief This function returns the current signal threshold in kcps
+     */
+    VL53L1X_ERROR vl53l1x_get_signal_threshold(uint16_t *signal);
+
+    /**
+     * @brief This function programs a new sigma threshold in mm (default=15 mm)
+     */
+    VL53L1X_ERROR vl53l1x_set_sigma_threshold(uint16_t sigma);
+
+    /**
+     * @brief This function returns the current sigma threshold in mm
+     */
+    VL53L1X_ERROR vl53l1x_get_sigma_threshold(uint16_t *signal);
+
+    /**
+     * @brief This function performs the temperature calibration.
+     * It is recommended to call this function any time the temperature might have changed by more than 8 deg C
+     * without sensor ranging activity for an extended period.
+     */
+    VL53L1X_ERROR vl53l1x_start_temperature_update();
+
+
+    /* VL53L1X_calibration.h functions */
+    
+        /**
+     * @brief This function performs the offset calibration.\n
+     * The function returns the offset value found and programs the offset compensation into the device.
+     * @param TargetDistInMm target distance in mm, ST recommended 100 mm
+     * Target reflectance = grey17%
+     * @return 0:success, !=0: failed
+     * @return offset pointer contains the offset found in mm
+     */
+    int8_t vl53l1x_calibrate_offset(uint16_t TargetDistInMm, int16_t *offset);
+
+    /**
+     * @brief This function performs the xtalk calibration.\n
+     * The function returns the xtalk value found and programs the xtalk compensation to the device
+     * @param TargetDistInMm target distance in mm\n
+     * The target distance : the distance where the sensor start to "under range"\n
+     * due to the influence of the photons reflected back from the cover glass becoming strong\n
+     * It's also called inflection point\n
+     * Target reflectance = grey 17%
+     * @return 0: success, !=0: failed
+     * @return xtalk pointer contains the xtalk value found in cps (number of photons in count per second)
+     */
+    int8_t vl53l1x_calibrate_xtalk(uint16_t TargetDistInMm, uint16_t *xtalk);
+    
+
+    /* Write and read functions from I2C */
+
+    VL53L1X_ERROR vl53l1_wr_byte(VL53L1_DEV dev, uint16_t index, uint8_t data);
+    VL53L1X_ERROR vl53l1_wr_word(VL53L1_DEV dev, uint16_t index, uint16_t data);
+    VL53L1X_ERROR vl53l1_wr_double_word(VL53L1_DEV dev, uint16_t index, uint32_t data);
+    VL53L1X_ERROR vl53l1_rd_byte(VL53L1_DEV dev, uint16_t index, uint8_t *data);
+    VL53L1X_ERROR vl53l1_rd_word(VL53L1_DEV dev, uint16_t index, uint16_t *data);
+    VL53L1X_ERROR vl53l1_rd_double_word(VL53L1_DEV dev, uint16_t index, uint32_t *data);
+    VL53L1X_ERROR vl53l1_update_byte(VL53L1_DEV dev, uint16_t index, uint8_t AndData, uint8_t OrData);
+
+    VL53L1X_ERROR vl53l1_write_multi(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count);
+    VL53L1X_ERROR vl53l1_read_multi(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count);
+
+    VL53L1X_ERROR vl53l1_i2c_write(uint8_t dev, uint16_t index, uint8_t *data, uint16_t number_of_bytes);
+    VL53L1X_ERROR vl53l1_i2c_read(uint8_t dev, uint16_t index, uint8_t *data, uint16_t number_of_bytes);
+    VL53L1X_ERROR vl53l1_get_tick_count(uint32_t *ptick_count_ms);
+    VL53L1X_ERROR vl53l1_wait_us(VL53L1_Dev_t *pdev, int32_t wait_us);
+    VL53L1X_ERROR vl53l1_wait_ms(VL53L1_Dev_t *pdev, int32_t wait_ms);
+    
+    VL53L1X_ERROR vl53l1_wait_value_mask_ex(VL53L1_Dev_t *pdev, uint32_t timeout_ms, uint16_t index, uint8_t value, uint8_t mask, uint32_t poll_delay_ms);
+
+ protected:
+
+    /* IO Device */
+    VL53L1X_DevI2C *dev_i2c;
+    
+    /* Digital out pin */
+    DigitalOut *_gpio0;
+    /* GPIO expander */
+    Stmpe1600DigiOut *_expgpio0;
+    /* Measure detection IRQ */
+    InterruptIn *_gpio1Int;
+ 
+    /* Device data */
+    VL53L1_Dev_t MyDevice;
+    VL53L1_DEV Device;
+};
+
+
+#endif /* _VL53L1X_CLASS_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VL53L1X_I2C.h	Wed Jul 24 10:36:51 2019 +0000
@@ -0,0 +1,89 @@
+/* Define to prevent from recursive inclusion --------------------------------*/
+#ifndef __DEV_53L1X_I2C_H
+#define __DEV_53L1X_I2C_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "mbed.h"
+#include "pinmap.h"
+
+//Class replacing DevI2C class as it was not implementing a 16bit address registers
+class VL53L1X_DevI2C : public I2C
+{
+public:
+    /** Create a DevI2C Master interface, connected to the specified pins
+     *
+     *  @param sda I2C data line pin
+     *  @param scl I2C clock line pin
+     */
+    VL53L1X_DevI2C(PinName sda, PinName scl) : I2C(sda, scl) {}
+
+    /**
+     * @brief  Writes a buffer towards the I2C peripheral device.
+     * @param  pBuffer pointer to the byte-array data to send
+     * @param  DeviceAddr specifies the peripheral device slave address.
+     * @param  RegisterAddr specifies the internal address register
+     *         where to start writing to (must be correctly masked).
+     * @param  NumByteToWrite number of bytes to be written.
+     * @retval 0 if ok,
+     * @retval -1 if an I2C error has occured, or
+     * @retval -2 on temporary buffer overflow (i.e. NumByteToWrite was too high)
+     * @note   On some devices if NumByteToWrite is greater
+     *         than one, the RegisterAddr must be masked correctly!
+     */
+    int v53l1x_i2c_write(uint8_t *pBuffer, uint8_t DeviceAddr, uint16_t RegisterAddr,
+                         uint16_t NumByteToWrite)
+    {
+        int ret;
+        uint8_t tmp[TEMP_BUF_SIZE];
+
+        if (NumByteToWrite >= TEMP_BUF_SIZE)
+            return -2;
+
+        /* First, send device address. Then, send data and STOP condition */
+        tmp[0] = RegisterAddr >> 8;
+        tmp[1] = RegisterAddr & 0x0FF;
+        memcpy(tmp + 2, pBuffer, NumByteToWrite);
+
+        ret = write(DeviceAddr, (const char *)tmp, NumByteToWrite + 2, false);
+
+        if (ret)
+            return -1;
+        return 0;
+    }
+
+    /**
+     * @brief  Reads a buffer from the I2C peripheral device.
+     * @param  pBuffer pointer to the byte-array to read data in to
+     * @param  DeviceAddr specifies the peripheral device slave address.
+     * @param  RegisterAddr specifies the internal address register
+     *         where to start reading from (must be correctly masked).
+     * @param  NumByteToRead number of bytes to be read.
+     * @retval 0 if ok,
+     * @retval -1 if an I2C error has occured
+     * @note   On some devices if NumByteToWrite is greater
+     *         than one, the RegisterAddr must be masked correctly!
+     */
+    int v53l1x_i2c_read(uint8_t *pBuffer, uint8_t DeviceAddr, uint16_t RegisterAddr,
+                        uint16_t NumByteToRead)
+    {
+        int ret;
+        uint8_t ExpanderData[2];
+        ExpanderData[0] = RegisterAddr >> 8;
+        ExpanderData[1] = RegisterAddr & 0x0FF;
+        /* Send device address, with no STOP condition */
+        ret = write(DeviceAddr, (const char *)ExpanderData, 2, true);
+        if (!ret) {
+            /* Read data, with STOP condition  */
+            ret = read(DeviceAddr, (char *)pBuffer, NumByteToRead, false);
+        }
+
+        if (ret)
+            return -1;
+        return 0;
+    }
+
+private:
+    static const unsigned int TEMP_BUF_SIZE = 32;
+};
+
+#endif /* __DEV_53L1X_I2C_H */
--- a/vl53L1x_I2c.h	Fri May 17 09:07:55 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-/* Define to prevent from recursive inclusion --------------------------------*/
-#ifndef __DEV_53L1X_I2C_H
-#define __DEV_53L1X_I2C_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "mbed.h"
-#include "pinmap.h"
-
-//Class replacing DevI2C class as it was not implementing a 16bit address registers   
-class vl53L1X_DevI2C : public I2C
-{
-public:
-    /** Create a DevI2C Master interface, connected to the specified pins
-     *
-     *  @param sda I2C data line pin
-     *  @param scl I2C clock line pin
-     */
-    vl53L1X_DevI2C(PinName sda, PinName scl) : I2C(sda, scl) {}
-    
-    /**
-     * @brief  Writes a buffer towards the I2C peripheral device.
-     * @param  pBuffer pointer to the byte-array data to send
-     * @param  DeviceAddr specifies the peripheral device slave address.
-     * @param  RegisterAddr specifies the internal address register
-     *         where to start writing to (must be correctly masked).
-     * @param  NumByteToWrite number of bytes to be written.
-     * @retval 0 if ok,
-     * @retval -1 if an I2C error has occured, or
-     * @retval -2 on temporary buffer overflow (i.e. NumByteToWrite was too high)
-     * @note   On some devices if NumByteToWrite is greater
-     *         than one, the RegisterAddr must be masked correctly!
-     */
-    int v53l1x_i2c_write(uint8_t* pBuffer, uint8_t DeviceAddr, uint16_t RegisterAddr,
-                  uint16_t NumByteToWrite) {
-        int ret;
-        uint8_t tmp[TEMP_BUF_SIZE];
-
-        if(NumByteToWrite >= TEMP_BUF_SIZE) return -2;
-
-        /* First, send device address. Then, send data and STOP condition */
-        tmp[0] = RegisterAddr >> 8;
-        tmp[1] = RegisterAddr & 0x0FF;
-        memcpy(tmp+2, pBuffer, NumByteToWrite);
-
-        ret = write(DeviceAddr, (const char*)tmp, NumByteToWrite+2, false);
-
-        if(ret) return -1;
-        return 0;
-    }
-
-    /**
-     * @brief  Reads a buffer from the I2C peripheral device.
-     * @param  pBuffer pointer to the byte-array to read data in to
-     * @param  DeviceAddr specifies the peripheral device slave address.
-     * @param  RegisterAddr specifies the internal address register
-     *         where to start reading from (must be correctly masked).
-     * @param  NumByteToRead number of bytes to be read.
-     * @retval 0 if ok,
-     * @retval -1 if an I2C error has occured
-     * @note   On some devices if NumByteToWrite is greater
-     *         than one, the RegisterAddr must be masked correctly!
-     */
-    int v53l1x_i2c_read(uint8_t* pBuffer, uint8_t DeviceAddr, uint16_t RegisterAddr,
-                 uint16_t NumByteToRead) {
-        int ret;
-        uint8_t ExpanderData[2];
-        ExpanderData[0] = RegisterAddr >> 8;
-        ExpanderData[1] = RegisterAddr & 0x0FF;
-        /* Send device address, with no STOP condition */
-        ret = write(DeviceAddr, (const char*)ExpanderData, 2, true);
-        if(!ret) {
-            /* Read data, with STOP condition  */
-            ret = read(DeviceAddr, (char*)pBuffer, NumByteToRead, false);
-        }
-
-        if(ret) return -1;
-        return 0;
-    }
-
-private:
-    static const unsigned int TEMP_BUF_SIZE = 32;
-};
-
-#endif /* __DEV_53L1X_I2C_H */
\ No newline at end of file
--- a/vl53l1x_class.cpp	Fri May 17 09:07:55 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1115 +0,0 @@
-/**
- ******************************************************************************
- * @file    vl53l1x_class.cpp
- * @author  JS
- * @version V0.0.1
- * @date    15-January-2019
- * @brief   Implementation file for the VL53L1 sensor component driver class
- ******************************************************************************
- * @attention
- *
- * <h2><center>&copy; COPYRIGHT(c) 2018 STMicroelectronics</center></h2>
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *   1. Redistributions of source code must retain the above copyright notice,
- *      this list of conditions and the following disclaimer.
- *   2. Redistributions in binary form must reproduce the above copyright notice,
- *      this list of conditions and the following disclaimer in the documentation
- *      and/or other materials provided with the distribution.
- *   3. Neither the name of STMicroelectronics nor the names of its contributors
- *      may be used to endorse or promote products derived from this software
- *      without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
-*/
-
-/* Includes */
-#include <stdlib.h>
-#include "vl53l1x_class.h"
-
-
-#define ALGO__PART_TO_PART_RANGE_OFFSET_MM  0x001E
-#define MM_CONFIG__INNER_OFFSET_MM          0x0020
-#define MM_CONFIG__OUTER_OFFSET_MM          0x0022
-
-#include "vl53l1x_configuration.h"
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetSWVersion(VL53L1X_Version_t *pVersion)
-{
-    VL53L1X_ERROR Status = 0;
-
-    pVersion->major = VL53L1X_IMPLEMENTATION_VER_MAJOR;
-    pVersion->minor = VL53L1X_IMPLEMENTATION_VER_MINOR;
-    pVersion->build = VL53L1X_IMPLEMENTATION_VER_SUB;
-    pVersion->revision = VL53L1X_IMPLEMENTATION_VER_REVISION;
-    return Status;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1X_SetI2CAddress(uint8_t new_address)
-{
-    VL53L1X_ERROR status = 0;
-
-    status = VL53L1_WrByte(Device, VL53L1_I2C_SLAVE__DEVICE_ADDRESS, new_address >> 1);
-    Device->I2cDevAddr = new_address;
-    return status;
-}
-
-int VL53L1X::init_sensor(uint8_t new_addr)
-{
-    Device->I2cDevAddr = new_addr;
-    int status = 0;
-    VL53L1_Off();
-    VL53L1_On();
-
-    status = is_present();
-    if (!status) {
-        printf("Failed to init VL53L0X sensor!\n\r");
-        return status;
-    }
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_SensorInit()
-{
-    VL53L1X_ERROR status = 0;
-    uint8_t Addr = 0x00;
-
-    for (Addr = 0x2D; Addr <= 0x87; Addr++){
-        status = VL53L1_WrByte(Device, Addr, VL51L1X_DEFAULT_CONFIGURATION[Addr - 0x2D]);
-        if (status != 0)
-        {
-            printf("Writing config failed - %d\r\n", status);
-        }
-    }
-    
-    uint16_t sensorID= 0;
-    status = VL53L1X_GetSensorId(&sensorID);
-    printf("Sensor id is - %d (%X)\r\n", sensorID, sensorID);
-    
-    status = VL53L1X_StartRanging();
-    if (status != 0)
-    {
-        printf("start ranging failed - %d\r\n", status);
-    }
- 
-    status = VL53L1X_ClearInterrupt();
-    status = VL53L1X_StopRanging();
-    status = VL53L1_WrByte(Device, VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND, 0x09); /* two bounds VHV */
-    status = VL53L1_WrByte(Device, 0x0B, 0); /* start VHV from the previous temperature */
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_ClearInterrupt()
-{
-    VL53L1X_ERROR status = 0;
-
-    status = VL53L1_WrByte(Device, SYSTEM__INTERRUPT_CLEAR, 0x01);
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_SetInterruptPolarity(uint8_t NewPolarity)
-{
-    uint8_t Temp;
-    VL53L1X_ERROR status = 0;
-
-    status = VL53L1_RdByte(Device, GPIO_HV_MUX__CTRL, &Temp);
-    Temp = Temp & 0xEF;
-    status = VL53L1_WrByte(Device, GPIO_HV_MUX__CTRL, Temp | (!(NewPolarity & 1)) << 4);
-    return status;
-}
-
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetInterruptPolarity(uint8_t *pInterruptPolarity)
-{
-    uint8_t Temp;
-    VL53L1X_ERROR status = 0;
-
-    status = VL53L1_RdByte(Device, GPIO_HV_MUX__CTRL, &Temp);
-    Temp = Temp & 0x10;
-    *pInterruptPolarity = !(Temp>>4);
-    return status;
-}
-
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_StartRanging()
-{
-    VL53L1X_ERROR status = 0;
-
-    status = VL53L1_WrByte(Device, SYSTEM__MODE_START, 0x40);   /* Enable VL53L1X */
-    return status;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1X_StopRanging()
-{
-    VL53L1X_ERROR status = 0;
-
-    status = VL53L1_WrByte(Device, SYSTEM__MODE_START, 0x00);   /* Disable VL53L1X */
-    return status;
-}
-
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_CheckForDataReady(uint8_t *isDataReady)
-{
-    uint8_t Temp;
-    uint8_t IntPol;
-    VL53L1X_ERROR status = 0;
-
-    status = VL53L1X_GetInterruptPolarity(&IntPol);
-    status = VL53L1_RdByte(Device, GPIO__TIO_HV_STATUS, &Temp);
-    /* Read in the register to check if a new value is available */
-    if (status == 0){
-        if ((Temp & 1) == IntPol)
-            *isDataReady = 1;
-        else
-            *isDataReady = 0;
-    }
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_SetTimingBudgetInMs(uint16_t TimingBudgetInMs)
-{
-    uint16_t DM;
-    VL53L1X_ERROR  status=0;
-
-    status = VL53L1X_GetDistanceMode(&DM);
-    if (DM == 0)
-        return 1;
-    else if (DM == 1) { /* Short DistanceMode */
-        switch (TimingBudgetInMs) {
-        case 15: /* only available in short distance mode */
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
-                    0x01D);
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
-                    0x0027);
-            break;
-        case 20:
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
-                    0x0051);
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
-                    0x006E);
-            break;
-        case 33:
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
-                    0x00D6);
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
-                    0x006E);
-            break;
-        case 50:
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
-                    0x1AE);
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
-                    0x01E8);
-            break;
-        case 100:
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
-                    0x02E1);
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
-                    0x0388);
-            break;
-        case 200:
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
-                    0x03E1);
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
-                    0x0496);
-            break;
-        case 500:
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
-                    0x0591);
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
-                    0x05C1);
-            break;
-        default:
-            status = 1;
-            break;
-        }
-    } else {
-        switch (TimingBudgetInMs) {
-        case 20:
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
-                    0x001E);
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
-                    0x0022);
-            break;
-        case 33:
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
-                    0x0060);
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
-                    0x006E);
-            break;
-        case 50:
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
-                    0x00AD);
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
-                    0x00C6);
-            break;
-        case 100:
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
-                    0x01CC);
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
-                    0x01EA);
-            break;
-        case 200:
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
-                    0x02D9);
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
-                    0x02F8);
-            break;
-        case 500:
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI,
-                    0x048F);
-            VL53L1_WrWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
-                    0x04A4);
-            break;
-        default:
-            status = 1;
-            break;
-        }
-    }
-    return status;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetTimingBudgetInMs(uint16_t *pTimingBudget)
-{
-    uint16_t Temp;
-    VL53L1X_ERROR status = 0;
-
-    status = VL53L1_RdWord(Device, RANGE_CONFIG__TIMEOUT_MACROP_A_HI, &Temp);
-    switch (Temp) {
-        case 0x001D :
-            *pTimingBudget = 15;
-            break;
-        case 0x0051 :
-        case 0x001E :
-            *pTimingBudget = 20;
-            break;
-        case 0x00D6 :
-        case 0x0060 :
-            *pTimingBudget = 33;
-            break;
-        case 0x1AE :
-        case 0x00AD :
-            *pTimingBudget = 50;
-            break;
-        case 0x02E1 :
-        case 0x01CC :
-            *pTimingBudget = 100;
-            break;
-        case 0x03E1 :
-        case 0x02D9 :
-            *pTimingBudget = 200;
-            break;
-        case 0x0591 :
-        case 0x048F :
-            *pTimingBudget = 500;
-            break;
-        default:
-            *pTimingBudget = 0;
-            break;
-    }
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_SetDistanceMode(uint16_t DM)
-{
-    uint16_t TB;
-    VL53L1X_ERROR status = 0;
-
-    status = VL53L1X_GetTimingBudgetInMs(&TB);
-    
-    
-    switch (DM) {
-    case 1:
-        status = VL53L1_WrByte(Device, PHASECAL_CONFIG__TIMEOUT_MACROP, 0x14);
-        status = VL53L1_WrByte(Device, RANGE_CONFIG__VCSEL_PERIOD_A, 0x07);
-        status = VL53L1_WrByte(Device, RANGE_CONFIG__VCSEL_PERIOD_B, 0x05);
-        status = VL53L1_WrByte(Device, RANGE_CONFIG__VALID_PHASE_HIGH, 0x38);
-        status = VL53L1_WrWord(Device, SD_CONFIG__WOI_SD0, 0x0705);
-        status = VL53L1_WrWord(Device, SD_CONFIG__INITIAL_PHASE_SD0, 0x0606);
-        break;
-    case 2:
-        status = VL53L1_WrByte(Device, PHASECAL_CONFIG__TIMEOUT_MACROP, 0x0A);
-        status = VL53L1_WrByte(Device, RANGE_CONFIG__VCSEL_PERIOD_A, 0x0F);
-        status = VL53L1_WrByte(Device, RANGE_CONFIG__VCSEL_PERIOD_B, 0x0D);
-        status = VL53L1_WrByte(Device, RANGE_CONFIG__VALID_PHASE_HIGH, 0xB8);
-        status = VL53L1_WrWord(Device, SD_CONFIG__WOI_SD0, 0x0F0D);
-        status = VL53L1_WrWord(Device, SD_CONFIG__INITIAL_PHASE_SD0, 0x0E0E);
-        break;
-    default:
-        break;
-    }
-    status = VL53L1X_SetTimingBudgetInMs(TB);
-    return status;
-}
-
-
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetDistanceMode(uint16_t *DM)
-{
-    uint8_t TempDM, status=0;
-
-    status = VL53L1_RdByte(Device,PHASECAL_CONFIG__TIMEOUT_MACROP, &TempDM);
-    if (TempDM == 0x14)
-        *DM=1;
-    if(TempDM == 0x0A)
-        *DM=2;
-    return status;
-}
-
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_SetInterMeasurementInMs(uint16_t InterMeasMs)
-{
-    uint16_t ClockPLL;
-    VL53L1X_ERROR status = 0;
-
-    status = VL53L1_RdWord(Device, VL53L1_RESULT__OSC_CALIBRATE_VAL, &ClockPLL);
-    ClockPLL = ClockPLL&0x3FF;
-    VL53L1_WrDWord(Device, VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD,
-            (uint32_t)(ClockPLL * InterMeasMs * 1.075));
-    return status;
-
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetInterMeasurementInMs(uint16_t *pIM)
-{
-    uint16_t ClockPLL;
-    VL53L1X_ERROR status = 0;
-    uint32_t tmp;
-
-    status = VL53L1_RdDWord(Device,VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD, &tmp);
-    *pIM = (uint16_t)tmp;
-    status = VL53L1_RdWord(Device, VL53L1_RESULT__OSC_CALIBRATE_VAL, &ClockPLL);
-    ClockPLL = ClockPLL&0x3FF;
-    *pIM= (uint16_t)(*pIM/(ClockPLL*1.065));
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_BootState(uint8_t *state)
-{
-    VL53L1X_ERROR status = 0;
-    uint8_t tmp = 0;
-
-    status = VL53L1_RdByte(Device,VL53L1_FIRMWARE__SYSTEM_STATUS, &tmp);
-    *state = tmp;
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetSensorId(uint16_t *sensorId)
-{
-    VL53L1X_ERROR status = 0;
-    uint16_t tmp = 0;
-
-    status = VL53L1_RdWord(Device, VL53L1_IDENTIFICATION__MODEL_ID, &tmp);
-    *sensorId = tmp;
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetDistance(uint16_t *distance)
-{
-    VL53L1X_ERROR status = 0;
-    uint16_t tmp;
-
-    status = (VL53L1_RdWord(Device,
-            VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0, &tmp));
-    *distance = tmp;
-    return status;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetSignalPerSpad(uint16_t *signalRate)
-{
-    VL53L1X_ERROR status = 0;
-    uint16_t SpNb=1, signal;
-
-    status = VL53L1_RdWord(Device,
-        VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0, &signal);
-    status = VL53L1_RdWord(Device,
-        VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0, &SpNb);
-    *signalRate = (uint16_t) (2000.0*signal/SpNb);
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetAmbientPerSpad(uint16_t *ambPerSp)
-{
-    VL53L1X_ERROR status=0;
-    uint16_t AmbientRate, SpNb=1;
-
-    status = VL53L1_RdWord(Device, RESULT__AMBIENT_COUNT_RATE_MCPS_SD, &AmbientRate);
-    status = VL53L1_RdWord(Device, VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0, &SpNb);
-    *ambPerSp=(uint16_t) (2000.0 * AmbientRate / SpNb);
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetSignalRate(uint16_t *signal)
-{
-    VL53L1X_ERROR status = 0;
-    uint16_t tmp;
-
-    status = VL53L1_RdWord(Device,
-        VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0, &tmp);
-    *signal = tmp*8;
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetSpadNb(uint16_t *spNb)
-{
-    VL53L1X_ERROR status = 0;
-    uint16_t tmp;
-
-    status = VL53L1_RdWord(Device,
-                  VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0, &tmp);
-    *spNb = tmp >> 8;
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetAmbientRate(uint16_t *ambRate)
-{
-    VL53L1X_ERROR status = 0;
-    uint16_t tmp;
-
-    status = VL53L1_RdWord(Device, RESULT__AMBIENT_COUNT_RATE_MCPS_SD, &tmp);
-    *ambRate = tmp*8;
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetRangeStatus(uint8_t *rangeStatus)
-{
-    VL53L1X_ERROR status = 0;
-    uint8_t RgSt;
-
-    status = VL53L1_RdByte(Device, VL53L1_RESULT__RANGE_STATUS, &RgSt);
-    RgSt = RgSt&0x1F;
-    switch (RgSt) {
-    case 9:
-        RgSt = 0;
-        break;
-    case 6:
-        RgSt = 1;
-        break;
-    case 4:
-        RgSt = 2;
-        break;
-    case 8:
-        RgSt = 3;
-        break;
-    case 5:
-        RgSt = 4;
-        break;
-    case 3:
-        RgSt = 5;
-        break;
-    case 19:
-        RgSt = 6;
-        break;
-    case 7:
-        RgSt = 7;
-        break;
-    case 12:
-        RgSt = 9;
-        break;
-    case 18:
-        RgSt = 10;
-        break;
-    case 22:
-        RgSt = 11;
-        break;
-    case 23:
-        RgSt = 12;
-        break;
-    case 13:
-        RgSt = 13;
-        break;
-    default:
-        RgSt = 255;
-        break;
-    }
-    *rangeStatus = RgSt;
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_SetOffset(int16_t OffsetValue)
-{
-    VL53L1X_ERROR status = 0;
-    int16_t Temp;
-
-    Temp = (OffsetValue*4);
-    VL53L1_WrWord(Device, ALGO__PART_TO_PART_RANGE_OFFSET_MM,
-            (uint16_t)Temp);
-    VL53L1_WrWord(Device, MM_CONFIG__INNER_OFFSET_MM, 0x0);
-    VL53L1_WrWord(Device, MM_CONFIG__OUTER_OFFSET_MM, 0x0);
-    return status;
-}
-
-
-VL53L1X_ERROR  VL53L1X::VL53L1X_GetOffset(int16_t *offset)
-{
-    VL53L1X_ERROR status = 0;
-    uint16_t Temp;
-
-    status = VL53L1_RdWord(Device,ALGO__PART_TO_PART_RANGE_OFFSET_MM, &Temp);
-    Temp = Temp<<3;
-    Temp = Temp >>5;
-    *offset = (int16_t)(Temp);
-    return status;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1X_SetXtalk(uint16_t XtalkValue)
-{
-    /* XTalkValue in count per second to avoid float type */
-    VL53L1X_ERROR status = 0;
-
-    status = VL53L1_WrWord(Device,
-            ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS,
-            0x0000);
-    status = VL53L1_WrWord(Device, ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS,
-            0x0000);
-    status = VL53L1_WrWord(Device, ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS,
-            (XtalkValue<<9)/1000); /* * << 9 (7.9 format) and /1000 to convert cps to kpcs */
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetXtalk(uint16_t *xtalk )
-{
-    VL53L1X_ERROR status = 0;
-    uint16_t tmp;
-
-    status = VL53L1_RdWord(Device,ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS, &tmp);
-    *xtalk = (tmp*1000)>>9; /* * 1000 to convert kcps to cps and >> 9 (7.9 format) */
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_SetDistanceThreshold(uint16_t ThreshLow,
-                  uint16_t ThreshHigh, uint8_t Window,
-                  uint8_t IntOnNoTarget)
-{
-    VL53L1X_ERROR status = 0;
-    uint8_t Temp = 0;
-
-    status = VL53L1_RdByte(Device, SYSTEM__INTERRUPT_CONFIG_GPIO, &Temp);
-    Temp = Temp & 0x47;
-    if (IntOnNoTarget == 0) {
-        status = VL53L1_WrByte(Device, SYSTEM__INTERRUPT_CONFIG_GPIO,
-                   (Temp | (Window & 0x07)));
-    } else {
-        status = VL53L1_WrByte(Device, SYSTEM__INTERRUPT_CONFIG_GPIO,
-                   ((Temp | (Window & 0x07)) | 0x40));
-    }
-    status = VL53L1_WrWord(Device, SYSTEM__THRESH_HIGH, ThreshHigh);
-    status = VL53L1_WrWord(Device, SYSTEM__THRESH_LOW, ThreshLow);
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetDistanceThresholdWindow(uint16_t *window)
-{
-    VL53L1X_ERROR status = 0;
-    uint8_t tmp;
-    status = VL53L1_RdByte(Device,SYSTEM__INTERRUPT_CONFIG_GPIO, &tmp);
-    *window = (uint16_t)(tmp & 0x7);
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetDistanceThresholdLow(uint16_t *low)
-{
-    VL53L1X_ERROR status = 0;
-    uint16_t tmp;
-
-    status = VL53L1_RdWord(Device,SYSTEM__THRESH_LOW, &tmp);
-    *low = tmp;
-    return status;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetDistanceThresholdHigh(uint16_t *high)
-{
-    VL53L1X_ERROR status = 0;
-    uint16_t tmp;
-
-    status = VL53L1_RdWord(Device,SYSTEM__THRESH_HIGH, &tmp);
-    *high = tmp;
-    return status;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1X_SetROI(uint16_t X, uint16_t Y)
-{
-    uint8_t OpticalCenter;
-    VL53L1X_ERROR status = 0;
-
-    status =VL53L1_RdByte(Device, VL53L1_ROI_CONFIG__MODE_ROI_CENTRE_SPAD, &OpticalCenter);
-    if (X > 16)
-        X = 16;
-    if (Y > 16)
-        Y = 16;
-    if (X > 10 || Y > 10){
-        OpticalCenter = 199;
-    }
-    status = VL53L1_WrByte(Device, ROI_CONFIG__USER_ROI_CENTRE_SPAD, OpticalCenter);
-    status = VL53L1_WrByte(Device, ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE,
-               (Y - 1) << 4 | (X - 1));
-    return status;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetROI_XY(uint16_t *ROI_X, uint16_t *ROI_Y)
-{
-    VL53L1X_ERROR status = 0;
-    uint8_t tmp;
-
-    status = VL53L1_RdByte(Device,ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE, &tmp);
-    *ROI_X = ((uint16_t)tmp & 0x0F) + 1;
-    *ROI_Y = (((uint16_t)tmp & 0xF0) >> 4) + 1;
-    return status;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1X_SetSignalThreshold(uint16_t Signal)
-{
-    VL53L1X_ERROR status = 0;
-
-    VL53L1_WrWord(Device,RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS,Signal>>3);
-    return status;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetSignalThreshold(uint16_t *signal)
-{
-    VL53L1X_ERROR status = 0;
-    uint16_t tmp;
-
-    status = VL53L1_RdWord(Device,
-                RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS, &tmp);
-    *signal = tmp <<3;
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1X_SetSigmaThreshold(uint16_t Sigma)
-{
-    VL53L1X_ERROR status = 0;
-
-    if(Sigma>(0xFFFF>>2)){
-        return 1;
-    }
-    /* 16 bits register 14.2 format */
-    status = VL53L1_WrWord(Device,RANGE_CONFIG__SIGMA_THRESH,Sigma<<2);
-    return status;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1X_GetSigmaThreshold(uint16_t *sigma)
-{
-    VL53L1X_ERROR status = 0;
-    uint16_t tmp;
-
-    status = VL53L1_RdWord(Device,RANGE_CONFIG__SIGMA_THRESH, &tmp);
-    *sigma = tmp >> 2;
-    return status;
-
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1X_StartTemperatureUpdate()
-{
-    VL53L1X_ERROR status = 0;
-    uint8_t tmp=0;
-
-    status = VL53L1_WrByte(Device,VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND,0x81); /* full VHV */
-    status = VL53L1_WrByte(Device,0x0B,0x92);
-    status = VL53L1X_StartRanging();
-    while(tmp==0){
-        status = VL53L1X_CheckForDataReady(&tmp);
-    }
-    tmp  = 0;
-    status = VL53L1X_ClearInterrupt();
-    status = VL53L1X_StopRanging();
-    status = VL53L1_WrByte(Device, VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND, 0x09); /* two bounds VHV */
-    status = VL53L1_WrByte(Device, 0x0B, 0); /* start VHV from the previous temperature */
-    return status;
-}
-
-    /* VL53L1X_calibration.h functions */
-    
-int8_t VL53L1X::VL53L1X_CalibrateOffset(uint16_t TargetDistInMm, int16_t *offset)
-{
-    uint8_t i = 0, tmp;
-    int16_t AverageDistance = 0;
-    uint16_t distance;
-    VL53L1X_ERROR status = 0;
-
-    status = VL53L1_WrWord(Device, ALGO__PART_TO_PART_RANGE_OFFSET_MM, 0x0);
-    status = VL53L1_WrWord(Device, MM_CONFIG__INNER_OFFSET_MM, 0x0);
-    status = VL53L1_WrWord(Device, MM_CONFIG__OUTER_OFFSET_MM, 0x0);
-    status = VL53L1X_StartRanging();    /* Enable VL53L1X sensor */
-    for (i = 0; i < 50; i++) {
-        while (tmp == 0){
-            status = VL53L1X_CheckForDataReady(&tmp);
-        }
-        tmp = 0;
-        status = VL53L1X_GetDistance(&distance);
-        status = VL53L1X_ClearInterrupt();
-        AverageDistance = AverageDistance + distance;
-    }
-    status = VL53L1X_StopRanging();
-    AverageDistance = AverageDistance / 50;
-    *offset = TargetDistInMm - AverageDistance;
-    status = VL53L1_WrWord(Device, ALGO__PART_TO_PART_RANGE_OFFSET_MM, *offset*4);
-    return status;
-}
-
-
-int8_t VL53L1X::VL53L1X_CalibrateXtalk(uint16_t TargetDistInMm, uint16_t *xtalk)
-{
-    uint8_t i, tmp= 0;
-    float AverageSignalRate = 0;
-    float AverageDistance = 0;
-    float AverageSpadNb = 0;
-    uint16_t distance = 0, spadNum;
-    uint16_t sr;
-    VL53L1X_ERROR status = 0;
-
-    status = VL53L1_WrWord(Device, 0x0016,0);
-    status = VL53L1X_StartRanging();
-    for (i = 0; i < 50; i++) {
-        while (tmp == 0){
-            status = VL53L1X_CheckForDataReady(&tmp);
-        }
-        tmp=0;
-        status= VL53L1X_GetSignalRate(&sr);
-        status= VL53L1X_GetDistance(&distance);
-        status = VL53L1X_ClearInterrupt();
-        AverageDistance = AverageDistance + distance;
-        status = VL53L1X_GetSpadNb(&spadNum);
-        AverageSpadNb = AverageSpadNb + spadNum;
-        AverageSignalRate =
-            AverageSignalRate + sr;
-    }
-    status = VL53L1X_StopRanging();
-    AverageDistance = AverageDistance / 50;
-    AverageSpadNb = AverageSpadNb / 50;
-    AverageSignalRate = AverageSignalRate / 50;
-    /* Calculate Xtalk value */
-    *xtalk = (uint16_t)(512*(AverageSignalRate*(1-(AverageDistance/TargetDistInMm)))/AverageSpadNb);
-    status = VL53L1_WrWord(Device, 0x0016, *xtalk);
-    return status;
-}
-
-
-
-
-    /* Write and read functions from I2C */
-
-
-VL53L1X_ERROR VL53L1X::VL53L1_WriteMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count)
-{
-   int  status;
-
-   status = VL53L1_I2CWrite(Dev->I2cDevAddr, index, pdata, (uint16_t)count);
-   return status;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1_ReadMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count)
-{
-    int status;
-
-    status = VL53L1_I2CRead(Dev->I2cDevAddr, index, pdata, (uint16_t)count);
-
-    return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1_WrByte(VL53L1_DEV Dev, uint16_t index, uint8_t data)
-{
-   int  status;
-
-   status=VL53L1_I2CWrite(Dev->I2cDevAddr, index, &data, 1);
-   return status;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1_WrWord(VL53L1_DEV Dev, uint16_t index, uint16_t data)
-{
-   int  status;
-   uint8_t buffer[2];
-
-     buffer[0] = data >> 8;
-     buffer[1] = data & 0x00FF;
-   status=VL53L1_I2CWrite(Dev->I2cDevAddr, index, (uint8_t *)buffer, 2);
-   return status;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1_WrDWord(VL53L1_DEV Dev, uint16_t index, uint32_t data)
-{
-   int  status;
-   uint8_t buffer[4];
-
-     buffer[0] = (data >> 24) & 0xFF;
-     buffer[1] = (data >> 16) & 0xFF;
-     buffer[2] = (data >>  8) & 0xFF;
-     buffer[3] = (data >>  0) & 0xFF;
-   status=VL53L1_I2CWrite(Dev->I2cDevAddr, index, (uint8_t *)buffer, 4);
-   return status;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1_RdByte(VL53L1_DEV Dev, uint16_t index, uint8_t *data)
-{
-   int  status;
-
-   status = VL53L1_I2CRead(Dev->I2cDevAddr, index, data, 1);
-
-   if(status)
-     return -1;
-
-   return 0;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1_RdWord(VL53L1_DEV Dev, uint16_t index, uint16_t *data)
-{
-   int  status;
-   uint8_t buffer[2] = {0,0};
-
-   status = VL53L1_I2CRead(Dev->I2cDevAddr, index, buffer, 2);
-   if (!status)
-   {
-       *data = (buffer[0] << 8) + buffer[1];
-   }
-   return status;
-
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1_RdDWord(VL53L1_DEV Dev, uint16_t index, uint32_t *data)
-{
-   int status;
-   uint8_t buffer[4] = {0,0,0,0};
-
-   status = VL53L1_I2CRead(Dev->I2cDevAddr, index, buffer, 4);
-   if(!status)
-   {
-       *data = (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3];
-   }
-   return status;
-
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1_UpdateByte(VL53L1_DEV Dev, uint16_t index, uint8_t AndData, uint8_t OrData)
-{
-   int  status;
-   uint8_t buffer = 0;
-
-   /* read data direct onto buffer */
-   status = VL53L1_I2CRead(Dev->I2cDevAddr, index, &buffer,1);
-   if (!status)
-   {
-      buffer = (buffer & AndData) | OrData;
-      status = VL53L1_I2CWrite(Dev->I2cDevAddr, index, &buffer, (uint16_t)1);
-   }
-   return status;
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1_I2CWrite(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t* pBuffer, uint16_t NumByteToWrite)
-{
-    int ret;
-    ret = dev_i2c->v53l1x_i2c_write(pBuffer, DeviceAddr, RegisterAddr, NumByteToWrite);
-    if (ret) {
-        return -1;
-    }
-    return 0;
-
-}
-
-VL53L1X_ERROR VL53L1X::VL53L1_I2CRead(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t* pBuffer, uint16_t NumByteToRead)
-{
-    int ret;
-
-    ret = dev_i2c->v53l1x_i2c_read(pBuffer, DeviceAddr, RegisterAddr, NumByteToRead);
-
-    if (ret) {
-        return -1;
-    }
-    return 0;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1_GetTickCount(
-    uint32_t *ptick_count_ms)
-{
-
-    /* Returns current tick count in [ms] */
-
-    VL53L1X_ERROR status  = VL53L1_ERROR_NONE;
-
-    *ptick_count_ms = 0;
-
-    return status;
-}
-
-
-
-VL53L1X_ERROR VL53L1X::VL53L1_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us)
-{
-    return VL53L1_ERROR_NONE;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms)
-{
-    return VL53L1_ERROR_NONE;
-}
-
-
-VL53L1X_ERROR VL53L1X::VL53L1_WaitValueMaskEx(
-    VL53L1_Dev_t *pdev,
-    uint32_t      timeout_ms,
-    uint16_t      index,
-    uint8_t       value,
-    uint8_t       mask,
-    uint32_t      poll_delay_ms)
-{
-
-    /*
-     * Platform implementation of WaitValueMaskEx V2WReg script command
-     *
-     * WaitValueMaskEx(
-     *          duration_ms,
-     *          index,
-     *          value,
-     *          mask,
-     *          poll_delay_ms);
-     */
-
-    VL53L1_Error status         = VL53L1_ERROR_NONE;
-    uint32_t     start_time_ms = 0;
-    uint32_t     current_time_ms = 0;
-    uint32_t     polling_time_ms = 0;
-    uint8_t      byte_value      = 0;
-    uint8_t      found           = 0;
-
-
-
-    /* calculate time limit in absolute time */
-
-     VL53L1_GetTickCount(&start_time_ms);
-
-    /* remember current trace functions and temporarily disable
-     * function logging
-     */
-
-
-    /* wait until value is found, timeout reached on error occurred */
-
-    while ((status == VL53L1_ERROR_NONE) &&
-           (polling_time_ms < timeout_ms) &&
-           (found == 0)) {
-
-        if (status == VL53L1_ERROR_NONE)
-            status = VL53L1_RdByte(
-                            pdev,
-                            index,
-                            &byte_value);
-
-        if ((byte_value & mask) == value)
-            found = 1;
-
-        if (status == VL53L1_ERROR_NONE  &&
-            found == 0 &&
-            poll_delay_ms > 0)
-            status = VL53L1_WaitMs(
-                    pdev,
-                    poll_delay_ms);
-
-        /* Update polling time (Compare difference rather than absolute to
-        negate 32bit wrap around issue) */
-        VL53L1_GetTickCount(&current_time_ms);
-        polling_time_ms = current_time_ms - start_time_ms;
-
-    }
-    
-
-    if (found == 0 && status == VL53L1_ERROR_NONE)
-        status = VL53L1_ERROR_TIME_OUT;
-
-    return status;
-}
-
-int VL53L1X::handle_irq(uint16_t *distance)
-{
-    int status;
-    status = get_measurement(distance);
-    enable_interrupt_measure_detection_irq();
-    return status;
-}
-
-int VL53L1X::get_measurement(uint16_t *distance)
-{
-    int status = 0;
-
-    status = VL53L1X_GetDistance(distance);
-    status = VL53L1X_ClearInterrupt();
-
-    return status;
-}
-
-int VL53L1X::start_measurement(void (*fptr)(void))
-{
-    int status = 0;
-
-    if (_gpio1Int == NULL) {
-        printf("GPIO1 Error\r\n");
-        return 1;
-    }
-
-    status = VL53L1X_StopRanging(); // it is safer to do this while sensor is stopped
-
-    if (status == 0) {
-        attach_interrupt_measure_detection_irq(fptr);
-        enable_interrupt_measure_detection_irq();
-    }
-
-    if (status == 0) {
-        status = VL53L1X_StartRanging();
-    }
-
-    return status;
-}
-
-int VL53L1X::stop_measurement()
-{
-    int status = 0;
-
-    if (status == 0) {
-        printf("Call of VL53L0X_StopMeasurement\n");
-        status = VL53L1X_StopRanging();
-    }
-
-    if (status == 0)
-        status = VL53L1X_ClearInterrupt();
-
-    return status;
-}
--- a/vl53l1x_class.h	Fri May 17 09:07:55 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,684 +0,0 @@
-/*******************************************************************************
- * @file    vl53l1x_class.h
- * @author  JS
- * @version V0.0.1
- * @date    15-January-2019
- * @brief   Header file for VL53L1 sensor component
- ******************************************************************************
- Copyright © 2019, STMicroelectronics International N.V.
- All rights reserved.
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of STMicroelectronics nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
- NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
- IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *****************************************************************************/
-
-#ifndef __VL53L1X_CLASS_H
-#define __VL53L1X_CLASS_H
-
-
-#ifdef _MSC_VER
-#   ifdef VL53L1X_API_EXPORTS
-#       define VL53L1X_API  __declspec(dllexport)
-#   else
-#       define VL53L1X_API
-#   endif
-#else
-#   define VL53L1X_API
-#endif
-
-
-/* Includes ------------------------------------------------------------------*/
-#include "mbed.h"
-#include "PinNames.h"
-#include "RangeSensor.h"
-#include "vl53l1x_error_codes.h"
-#include "vl53L1x_I2c.h"
-#include "Stmpe1600.h"
-
-
-#define VL53L1X_IMPLEMENTATION_VER_MAJOR       1
-#define VL53L1X_IMPLEMENTATION_VER_MINOR       0
-#define VL53L1X_IMPLEMENTATION_VER_SUB         1
-#define VL53L1X_IMPLEMENTATION_VER_REVISION  0000
-
-typedef int8_t VL53L1X_ERROR;
-
-#define VL53L1_I2C_SLAVE__DEVICE_ADDRESS                    0x0001
-#define VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND        0x0008
-#define ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS      0x0016
-#define ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS  0x0018
-#define ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS  0x001A
-#define ALGO__PART_TO_PART_RANGE_OFFSET_MM                  0x001E
-#define MM_CONFIG__INNER_OFFSET_MM                          0x0020
-#define MM_CONFIG__OUTER_OFFSET_MM                          0x0022
-#define GPIO_HV_MUX__CTRL                                   0x0030
-#define GPIO__TIO_HV_STATUS                                 0x0031
-#define SYSTEM__INTERRUPT_CONFIG_GPIO                       0x0046
-#define PHASECAL_CONFIG__TIMEOUT_MACROP                     0x004B
-#define RANGE_CONFIG__TIMEOUT_MACROP_A_HI                   0x005E
-#define RANGE_CONFIG__VCSEL_PERIOD_A                        0x0060
-#define RANGE_CONFIG__VCSEL_PERIOD_B                        0x0063
-#define RANGE_CONFIG__TIMEOUT_MACROP_B_HI                   0x0061
-#define RANGE_CONFIG__TIMEOUT_MACROP_B_LO                   0x0062
-#define RANGE_CONFIG__SIGMA_THRESH                          0x0064
-#define RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS         0x0066
-#define RANGE_CONFIG__VALID_PHASE_HIGH                      0x0069
-#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD              0x006C
-#define SYSTEM__THRESH_HIGH                                 0x0072
-#define SYSTEM__THRESH_LOW                                  0x0074
-#define SD_CONFIG__WOI_SD0                                  0x0078
-#define SD_CONFIG__INITIAL_PHASE_SD0                        0x007A
-#define ROI_CONFIG__USER_ROI_CENTRE_SPAD                    0x007F
-#define ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE       0x0080
-#define SYSTEM__SEQUENCE_CONFIG                             0x0081
-#define VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD               0x0082
-#define SYSTEM__INTERRUPT_CLEAR                             0x0086
-#define SYSTEM__MODE_START                                  0x0087
-#define VL53L1_RESULT__RANGE_STATUS                         0x0089
-#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0       0x008C
-#define RESULT__AMBIENT_COUNT_RATE_MCPS_SD                  0x0090
-#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0               0x0096
-#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0  0x0098
-#define VL53L1_RESULT__OSC_CALIBRATE_VAL                    0x00DE
-#define VL53L1_FIRMWARE__SYSTEM_STATUS                      0x00E5
-#define VL53L1_IDENTIFICATION__MODEL_ID                     0x010F
-#define VL53L1_ROI_CONFIG__MODE_ROI_CENTRE_SPAD             0x013E
-
-
-#define VL53L1X_DEFAULT_DEVICE_ADDRESS                      0x52
-
-#define VL53L1X_REG_IDENTIFICATION_MODEL_ID                 0x010F
-/****************************************
- * PRIVATE define do not edit
- ****************************************/
-
-/**
- *  @brief defines SW Version
- */
-typedef struct {
-    uint8_t      major;    /*!< major number */
-    uint8_t      minor;    /*!< minor number */
-    uint8_t      build;    /*!< build number */
-    uint32_t     revision; /*!< revision number */
-} VL53L1X_Version_t;
-
-
-typedef struct {
-
-    uint8_t   I2cDevAddr;
-
-} VL53L1_Dev_t;
-
-typedef VL53L1_Dev_t *VL53L1_DEV;
-
-
-/* Classes -------------------------------------------------------------------*/
-/** Class representing a VL53L1 sensor component
- */
-class VL53L1X : public RangeSensor
-{
- public:
-    /** Constructor
-     * @param[in] &i2c device I2C to be used for communication
-     * @param[in] &pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
-     * @param[in] DevAddr device address, 0x52 by default
-     */
-    VL53L1X(vl53L1X_DevI2C *i2c, DigitalOut *pin, PinName pin_gpio1, uint8_t dev_addr = VL53L1X_DEFAULT_DEVICE_ADDRESS) 
-    : RangeSensor(), dev_i2c(i2c), _gpio0(pin)
-    {
-        MyDevice.I2cDevAddr=dev_addr;
-        Device = &MyDevice;
-               
-        _expgpio0 = NULL;
-        if (pin_gpio1 != NC) {
-            _gpio1Int = new InterruptIn(pin_gpio1);
-        } else {
-            _gpio1Int = NULL;
-        }
-    }
-    
-    /** Constructor 2 (STMPE1600DigiOut)
-     * @param[in] i2c device I2C to be used for communication
-     * @param[in] &pin Gpio Expander STMPE1600DigiOut pin to be used as component GPIO_0 CE
-     * @param[in] pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
-     * @param[in] device address, 0x29 by default
-     */
-    VL53L1X(vl53L1X_DevI2C *i2c, Stmpe1600DigiOut *pin, PinName pin_gpio1,
-            uint8_t dev_addr = VL53L1X_DEFAULT_DEVICE_ADDRESS) 
-            : dev_i2c(i2c), _expgpio0(pin)
-    {
-        MyDevice.I2cDevAddr=dev_addr;
-        Device = &MyDevice;
-               
-        _gpio0 = NULL;
-        if (pin_gpio1 != NC) {
-            _gpio1Int = new InterruptIn(pin_gpio1);
-        } else {
-            _gpio1Int = NULL;
-        }
-    }    
-    
-   /** Destructor
-    */
-    virtual ~VL53L1X()
-    {        
-        if (_gpio1Int != NULL) {
-            delete _gpio1Int;
-        }
-    }
-    
-        
-    
-    VL53L1_DEV getDevicePtr() { return Device; }
-
-    
-    /* warning: VL53L1 class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor.
-       The warning should request to introduce a virtual destructor to make sure to delete the object */
-
-    /*** Interface Methods ***/
-    /*** High level API ***/
-    /**
-     * @brief       PowerOn the sensor
-     * @return      void
-     */
-    /* turns on the sensor */
-    virtual void VL53L1_On(void)
-    {
-        printf("VL53L1_On\r\n");
-        if (_gpio0) {
-            *_gpio0 = 1;
-        } else {
-            if (_expgpio0) {
-                *_expgpio0 = 1;
-            }
-        }
-        wait_ms(10);
-    }
-
-    /**
-     * @brief       PowerOff the sensor
-     * @return      void
-     */
-    /* turns off the sensor */
-    virtual void VL53L1_Off(void)
-    {
-        printf("VL53L1_Off\r\n");
-        if (_gpio0) {
-            *_gpio0 = 0;
-        } else {
-            if (_expgpio0) {
-                *_expgpio0 = 0;
-            }
-        }
-        wait_ms(10);
-    }
-    
-    int is_present()
-    {
-        int status;
-        uint8_t id = 0;
-
-        status = read_id(&id);
-        if (status) {
-            printf("Failed to read ID device. Device not present!\n\r");
-        }
-        return status;
-    }
-
-    /**
-     * @brief       Initialize the sensor with default values
-     * @return      0 on Success
-     */
-     
-     VL53L1X_ERROR InitSensor(uint8_t address){
-        VL53L1X_ERROR status = 0;
-        uint8_t sensorState = 0;
-        VL53L1_Off();
-        VL53L1_On();
-        status = VL53L1X_SetI2CAddress(address);
-        
-        if(!status){
-            status = VL53L1X_SensorInit();
-        }      
-        
-        while(!status && !sensorState) {
-            status = VL53L1X_BootState(&sensorState);
-            wait_ms(2);
-        }
-        
-        return status;
-     }
-
-
-
-    /**
-     *
-     * @brief One time device initialization
-     * @param void
-     * @return     0 on success,  @a #CALIBRATION_WARNING if failed
-     */
-    virtual int init(void *init)
-    {
-       return VL53L1X_SensorInit();
-
-    }
-
-    /**
-     * @brief       Initialize the sensor with default values
-     * @return      "0" on success
-     */
-    int init_sensor(uint8_t new_addr);
-
-    /* Read function of the ID device */
-    virtual int read_id(uint8_t *id){
-        int status = 0;
-        uint16_t rl_id = 0;
-    
-        uint8_t ExpanderData[2];
-    
-        ExpanderData[0] = 0;
-        ExpanderData[1] = 0;
-        rl_id = 0;
-        dev_i2c->v53l1x_i2c_read(&ExpanderData[0], Device->I2cDevAddr, VL53L1X_REG_IDENTIFICATION_MODEL_ID, 2);
-    
-        rl_id = (ExpanderData[0] << 8) + ExpanderData[1];
-        printf("Model ID is: %d (%X)  \r\n",rl_id, rl_id);
-    
-        uint8_t tmp = 0;
-        ExpanderData[0] = VL53L1_FIRMWARE__SYSTEM_STATUS >> 8;
-        ExpanderData[1] = VL53L1_FIRMWARE__SYSTEM_STATUS & 0x0FF;
-        dev_i2c->v53l1x_i2c_read(&tmp, Device->I2cDevAddr, VL53L1_FIRMWARE__SYSTEM_STATUS, 1);
-
-        printf("Firmware system is: %d\r\n",tmp);
-    
-        if (rl_id == 0xEACC) {
-            printf("Device is present %d:\r\n", rl_id);
-            return status;
-        }
-        return -1;
-    }
-
-    /**
-     * @brief       Interrupt handling func to be called by user after an INT is occurred
-     * @param[out]  Data pointer to the distance to read data in to
-     * @return      0 on Success
-     */
-    int handle_irq(uint16_t *distance);
-
-    /**
-     * @brief       Start the measure indicated by operating mode
-     * @param[in]   fptr specifies call back function must be !NULL in case of interrupt measure
-     * @return      0 on Success
-     */
-    int start_measurement(void (*fptr)(void));
-    /**
-     * @brief       Stop the currently running measure indicate by operating_mode
-     * @return      0 on Success
-     */
-    int stop_measurement();
-    /**
-     * @brief       Get results for the measure
-     * @param[out]  Data pointer to the distance_data to read data in to
-     * @return      0 on Success
-     */
-    int get_measurement(uint16_t *distance);
-    /**
-     * @brief       Enable interrupt measure IRQ
-     * @return      0 on Success
-     */
-    void enable_interrupt_measure_detection_irq(void)
-    {
-        if (_gpio1Int != NULL)
-            _gpio1Int->enable_irq();
-    }
-
-    /**
-     * @brief       Disable interrupt measure IRQ
-     * @return      0 on Success
-     */
-    void disable_interrupt_measure_detection_irq(void)
-    {
-        if (_gpio1Int != NULL)
-            _gpio1Int->disable_irq();
-    }
-    /**
-     * @brief       Attach a function to call when an interrupt is detected, i.e. measurement is ready
-     * @param[in]   fptr pointer to call back function to be called whenever an interrupt occours
-     * @return      0 on Success
-     */
-    void attach_interrupt_measure_detection_irq(void (*fptr)(void))
-    {
-        if (_gpio1Int != NULL)
-            _gpio1Int->rise(fptr);
-    }
-    /**
-     * @brief Get ranging result and only that
-     * @param pRange_mm  Pointer to range distance
-     * @return           0 on success
-     */
-    virtual int get_distance(uint32_t *piData)
-    {
-    int status;
-    uint16_t distance;
-    status = VL53L1X_GetDistance(&distance);
-    *piData = (uint32_t) distance;
-    return status;
-    }
-
-
-    /* VL53L1X_api.h functions */
-
-    /**
-     * @brief This function returns the SW driver version
-     */
-    VL53L1X_ERROR VL53L1X_GetSWVersion(VL53L1X_Version_t *pVersion);
-
-    /**
-     * @brief This function sets the sensor I2C address used in case multiple devices application, default address 0x52
-     */
-    VL53L1X_ERROR VL53L1X_SetI2CAddress(uint8_t new_address);
-
-    /**
-     * @brief This function loads the 135 bytes default values to initialize the sensor.
-     * @param dev Device address
-     * @return 0:success, != 0:failed
-     */
-    VL53L1X_ERROR VL53L1X_SensorInit();
-
-    /**
-     * @brief This function clears the interrupt, to be called after a ranging data reading
-     * to arm the interrupt for the next data ready event.
-     */
-    VL53L1X_ERROR VL53L1X_ClearInterrupt();
-
-    /**
-     * @brief This function programs the interrupt polarity\n
-     * 1=active high (default), 0=active low
-     */
-    VL53L1X_ERROR VL53L1X_SetInterruptPolarity(uint8_t IntPol);
-
-    /**
-     * @brief This function returns the current interrupt polarity\n
-     * 1=active high (default), 0=active low
-     */
-    VL53L1X_ERROR VL53L1X_GetInterruptPolarity(uint8_t *pIntPol);
-
-    /**
-     * @brief This function starts the ranging distance operation\n
-     * The ranging operation is continuous. The clear interrupt has to be done after each get data to allow the interrupt to raise when the next data is ready\n
-     * 1=active high (default), 0=active low, use SetInterruptPolarity() to change the interrupt polarity if required.
-     */
-    VL53L1X_ERROR VL53L1X_StartRanging();
-
-    /**
-     * @brief This function stops the ranging.
-     */
-    VL53L1X_ERROR VL53L1X_StopRanging();
-
-    /**
-     * @brief This function checks if the new ranging data is available by polling the dedicated register.
-     * @param : isDataReady==0 -> not ready; isDataReady==1 -> ready
-     */
-    VL53L1X_ERROR VL53L1X_CheckForDataReady(uint8_t *isDataReady);
-    
-    /**
-     * @brief This function programs the timing budget in ms.
-     * Predefined values = 15, 20, 33, 50, 100(default), 200, 500.
-     */
-    VL53L1X_ERROR VL53L1X_SetTimingBudgetInMs(uint16_t TimingBudgetInMs);
-
-    /**
-     * @brief This function returns the current timing budget in ms.
-     */
-    VL53L1X_ERROR VL53L1X_GetTimingBudgetInMs(uint16_t *pTimingBudgetInMs);
-
-    /**
-     * @brief This function programs the distance mode (1=short, 2=long(default)).
-     * Short mode max distance is limited to 1.3 m but better ambient immunity.\n
-     * Long mode can range up to 4 m in the dark with 200 ms timing budget.
-     */
-    VL53L1X_ERROR VL53L1X_SetDistanceMode(uint16_t DistanceMode);
-
-    /**
-     * @brief This function returns the current distance mode (1=short, 2=long).
-     */
-    VL53L1X_ERROR VL53L1X_GetDistanceMode(uint16_t *pDistanceMode);
-
-    /**
-     * @brief This function programs the Intermeasurement period in ms\n
-     * Intermeasurement period must be >/= timing budget. This condition is not checked by the API,
-     * the customer has the duty to check the condition. Default = 100 ms
-     */
-    VL53L1X_ERROR VL53L1X_SetInterMeasurementInMs(uint16_t InterMeasurementInMs);
-
-    /**
-     * @brief This function returns the Intermeasurement period in ms.
-     */
-    VL53L1X_ERROR VL53L1X_GetInterMeasurementInMs(uint16_t * pIM);
-
-    /**
-     * @brief This function returns the boot state of the device (1:booted, 0:not booted)
-     */
-    VL53L1X_ERROR VL53L1X_BootState(uint8_t *state);
-
-    /**
-     * @brief This function returns the sensor id, sensor Id must be 0xEEAC
-     */
-    VL53L1X_ERROR VL53L1X_GetSensorId(uint16_t *id);
-
-    /**
-     * @brief This function returns the distance measured by the sensor in mm
-     */
-    VL53L1X_ERROR VL53L1X_GetDistance(uint16_t *distance);
-
-    /**
-     * @brief This function returns the returned signal per SPAD in kcps/SPAD.
-     * With kcps stands for Kilo Count Per Second
-     */
-    VL53L1X_ERROR VL53L1X_GetSignalPerSpad(uint16_t *signalPerSp);
-
-    /**
-     * @brief This function returns the ambient per SPAD in kcps/SPAD
-     */
-    VL53L1X_ERROR VL53L1X_GetAmbientPerSpad(uint16_t *amb);
-
-    /**
-     * @brief This function returns the returned signal in kcps.
-     */
-    VL53L1X_ERROR VL53L1X_GetSignalRate(uint16_t *signalRate);
-
-    /**
-     * @brief This function returns the current number of enabled SPADs
-     */
-    VL53L1X_ERROR VL53L1X_GetSpadNb(uint16_t *spNb);
-
-    /**
-     * @brief This function returns the ambient rate in kcps
-     */
-    VL53L1X_ERROR VL53L1X_GetAmbientRate(uint16_t *ambRate);
-
-    /**
-     * @brief This function returns the ranging status error \n
-     * (0:no error, 1:sigma failed, 2:signal failed, ..., 7:wrap-around)
-     */
-    VL53L1X_ERROR VL53L1X_GetRangeStatus(uint8_t *rangeStatus);
-
-    /**
-     * @brief This function programs the offset correction in mm
-     * @param OffsetValue:the offset correction value to program in mm
-     */
-    VL53L1X_ERROR VL53L1X_SetOffset(int16_t OffsetValue);
-
-    /**
-     * @brief This function returns the programmed offset correction value in mm
-     */
-    VL53L1X_ERROR VL53L1X_GetOffset(int16_t *Offset);
-
-    /**
-     * @brief This function programs the xtalk correction value in cps (Count Per Second).\n
-     * This is the number of photons reflected back from the cover glass in cps.
-     */
-    VL53L1X_ERROR VL53L1X_SetXtalk(uint16_t XtalkValue);
-
-    /**
-     * @brief This function returns the current programmed xtalk correction value in cps
-     */
-    VL53L1X_ERROR VL53L1X_GetXtalk(uint16_t *Xtalk);
-
-    /**
-     * @brief This function programs the threshold detection mode\n
-     * Example:\n
-     * VL53L1X_SetDistanceThreshold(dev,100,300,0,1): Below 100 \n
-     * VL53L1X_SetDistanceThreshold(dev,100,300,1,1): Above 300 \n
-     * VL53L1X_SetDistanceThreshold(dev,100,300,2,1): Out of window \n
-     * VL53L1X_SetDistanceThreshold(dev,100,300,3,1): In window \n
-     * @param   dev : device address
-     * @param   ThreshLow(in mm) : the threshold under which one the device raises an interrupt if Window = 0
-     * @param   ThreshHigh(in mm) :  the threshold above which one the device raises an interrupt if Window = 1
-     * @param   Window detection mode : 0=below, 1=above, 2=out, 3=in
-     * @param   IntOnNoTarget = 1 (No longer used - just use 1)
-     */
-    VL53L1X_ERROR VL53L1X_SetDistanceThreshold(uint16_t ThreshLow,
-                      uint16_t ThreshHigh, uint8_t Window,
-                      uint8_t IntOnNoTarget);
-
-    /**
-     * @brief This function returns the window detection mode (0=below; 1=above; 2=out; 3=in)
-     */
-    VL53L1X_ERROR VL53L1X_GetDistanceThresholdWindow(uint16_t *window);
-
-    /**
-     * @brief This function returns the low threshold in mm
-     */
-    VL53L1X_ERROR VL53L1X_GetDistanceThresholdLow(uint16_t *low);
-
-    /**
-     * @brief This function returns the high threshold in mm
-     */
-    VL53L1X_ERROR VL53L1X_GetDistanceThresholdHigh(uint16_t *high);
-
-    /**
-     * @brief This function programs the ROI (Region of Interest)\n
-     * The ROI position is centered, only the ROI size can be reprogrammed.\n
-     * The smallest acceptable ROI size = 4\n
-     * @param X:ROI Width; Y=ROI Height
-     */
-    VL53L1X_ERROR VL53L1X_SetROI(uint16_t X, uint16_t Y);
-
-    /**
-     *@brief This function returns width X and height Y
-     */
-    VL53L1X_ERROR VL53L1X_GetROI_XY(uint16_t *ROI_X, uint16_t *ROI_Y);
-
-    /**
-     * @brief This function programs a new signal threshold in kcps (default=1024 kcps\n
-     */
-    VL53L1X_ERROR VL53L1X_SetSignalThreshold(uint16_t signal);
-
-    /**
-     * @brief This function returns the current signal threshold in kcps
-     */
-    VL53L1X_ERROR VL53L1X_GetSignalThreshold(uint16_t *signal);
-
-    /**
-     * @brief This function programs a new sigma threshold in mm (default=15 mm)
-     */
-    VL53L1X_ERROR VL53L1X_SetSigmaThreshold(uint16_t sigma);
-
-    /**
-     * @brief This function returns the current sigma threshold in mm
-     */
-    VL53L1X_ERROR VL53L1X_GetSigmaThreshold(uint16_t *signal);
-
-    /**
-     * @brief This function performs the temperature calibration.
-     * It is recommended to call this function any time the temperature might have changed by more than 8 deg C
-     * without sensor ranging activity for an extended period.
-     */
-    VL53L1X_ERROR VL53L1X_StartTemperatureUpdate();
-
-
-    /* VL53L1X_calibration.h functions */
-    
-        /**
-     * @brief This function performs the offset calibration.\n
-     * The function returns the offset value found and programs the offset compensation into the device.
-     * @param TargetDistInMm target distance in mm, ST recommended 100 mm
-     * Target reflectance = grey17%
-     * @return 0:success, !=0: failed
-     * @return offset pointer contains the offset found in mm
-     */
-    int8_t VL53L1X_CalibrateOffset(uint16_t TargetDistInMm, int16_t *offset);
-
-    /**
-     * @brief This function performs the xtalk calibration.\n
-     * The function returns the xtalk value found and programs the xtalk compensation to the device
-     * @param TargetDistInMm target distance in mm\n
-     * The target distance : the distance where the sensor start to "under range"\n
-     * due to the influence of the photons reflected back from the cover glass becoming strong\n
-     * It's also called inflection point\n
-     * Target reflectance = grey 17%
-     * @return 0: success, !=0: failed
-     * @return xtalk pointer contains the xtalk value found in cps (number of photons in count per second)
-     */
-    int8_t VL53L1X_CalibrateXtalk(uint16_t TargetDistInMm, uint16_t *xtalk);
-    
-
-    /* Write and read functions from I2C */
-
-    VL53L1X_ERROR VL53L1_WrByte(VL53L1_DEV dev, uint16_t index, uint8_t data);
-    VL53L1X_ERROR VL53L1_WrWord(VL53L1_DEV dev, uint16_t index, uint16_t data);
-    VL53L1X_ERROR VL53L1_WrDWord(VL53L1_DEV dev, uint16_t index, uint32_t data);
-    VL53L1X_ERROR VL53L1_RdByte(VL53L1_DEV dev, uint16_t index, uint8_t *data);
-    VL53L1X_ERROR VL53L1_RdWord(VL53L1_DEV dev, uint16_t index, uint16_t *data);
-    VL53L1X_ERROR VL53L1_RdDWord(VL53L1_DEV dev, uint16_t index, uint32_t *data);
-    VL53L1X_ERROR VL53L1_UpdateByte(VL53L1_DEV dev, uint16_t index, uint8_t AndData, uint8_t OrData);
-
-    VL53L1X_ERROR VL53L1_WriteMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count);
-    VL53L1X_ERROR VL53L1_ReadMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count);
-
-    VL53L1X_ERROR VL53L1_I2CWrite(uint8_t dev, uint16_t index, uint8_t *data, uint16_t number_of_bytes);
-    VL53L1X_ERROR VL53L1_I2CRead(uint8_t dev, uint16_t index, uint8_t *data, uint16_t number_of_bytes);
-    VL53L1X_ERROR VL53L1_GetTickCount(uint32_t *ptick_count_ms);
-    VL53L1X_ERROR VL53L1_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us);
-    VL53L1X_ERROR VL53L1_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms);
-    
-    VL53L1X_ERROR VL53L1_WaitValueMaskEx(VL53L1_Dev_t *pdev, uint32_t timeout_ms, uint16_t index, uint8_t value, uint8_t mask, uint32_t poll_delay_ms);
-
- protected:
-
-    /* IO Device */
-    vl53L1X_DevI2C *dev_i2c;
-    
-    /* Digital out pin */
-    DigitalOut *_gpio0;
-    /* GPIO expander */
-    Stmpe1600DigiOut *_expgpio0;
-    /* Measure detection IRQ */
-    InterruptIn *_gpio1Int;
- 
-    /* Device data */
-    VL53L1_Dev_t MyDevice;
-    VL53L1_DEV Device;
-};
-
-
-#endif /* _VL53L1X_CLASS_H_ */