This is the SparkFun_VL53L1X_Arduino_Library translated into mbed, with some elements of Ian Kilburn's VL6180x mbed library.

Dependents:   Hug2Go_ver_2 Nucleo_rtos_basic_f103rb

Committer:
jvfausto
Date:
Fri Jul 27 18:43:58 2018 +0000
Revision:
5:aa8cc9e87216
Parent:
1:0d762892f7af
Child:
6:621552ff1de9
It works now

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jvfausto 0:03b7e8deb3ee 1 #ifndef VL53L1X_H
jvfausto 0:03b7e8deb3ee 2 #define VL53L1X_H
jvfausto 0:03b7e8deb3ee 3
jvfausto 0:03b7e8deb3ee 4 #include "mbed.h"
jvfausto 0:03b7e8deb3ee 5
jvfausto 0:03b7e8deb3ee 6 #include "VL53L1X_register_map.h"
jvfausto 0:03b7e8deb3ee 7
jvfausto 0:03b7e8deb3ee 8 #define I2C_BUFFER_LENGTH 32
jvfausto 0:03b7e8deb3ee 9
jvfausto 0:03b7e8deb3ee 10 const char defaultAddress_VL53L1X = 0x29;
jvfausto 0:03b7e8deb3ee 11
jvfausto 0:03b7e8deb3ee 12 class VL53L1X {
jvfausto 0:03b7e8deb3ee 13 public:
jvfausto 0:03b7e8deb3ee 14 VL53L1X(PinName SDA, PinName SCL);
jvfausto 5:aa8cc9e87216 15 void begin();
jvfausto 0:03b7e8deb3ee 16 void softReset(); //Reset the sensor via software
jvfausto 0:03b7e8deb3ee 17 void startMeasurement(uint8_t offset = 0); //Write a block of bytes to the sensor to configure it to take a measurement
jvfausto 0:03b7e8deb3ee 18 bool newDataReady(); //Polls the measurement completion bit
jvfausto 0:03b7e8deb3ee 19 uint16_t getDistance(); //Returns the results from the last measurement, distance in mm
jvfausto 0:03b7e8deb3ee 20 uint16_t getSignalRate(); //Returns the results from the last measurement, signal rate
jvfausto 0:03b7e8deb3ee 21 void setDistanceMode(uint8_t mode = 2);//Defaults to long range
jvfausto 0:03b7e8deb3ee 22 uint8_t getDistanceMode();
jvfausto 0:03b7e8deb3ee 23 uint8_t getRangeStatus(); //Returns the results from the last measurement, 0 = valid
jvfausto 0:03b7e8deb3ee 24
jvfausto 0:03b7e8deb3ee 25 uint8_t readRegister(uint16_t addr); //Read a byte from a 16-bit address
jvfausto 0:03b7e8deb3ee 26 uint16_t readRegister16(uint16_t addr); //Read two bytes from a 16-bit address
jvfausto 0:03b7e8deb3ee 27 void writeRegister(uint16_t addr, uint8_t val); //Write a byte to a spot
jvfausto 0:03b7e8deb3ee 28 void writeRegister16(uint16_t addr, uint16_t val); //Write two bytes to a spot
jvfausto 0:03b7e8deb3ee 29
jvfausto 0:03b7e8deb3ee 30 private:
jvfausto 0:03b7e8deb3ee 31 I2C _i2c;
jvfausto 0:03b7e8deb3ee 32
jvfausto 0:03b7e8deb3ee 33 uint8_t _deviceAddress;
jvfausto 0:03b7e8deb3ee 34 uint8_t _distanceMode;// = 0; <--- might cause a problem
jvfausto 0:03b7e8deb3ee 35 };
jvfausto 0:03b7e8deb3ee 36
jvfausto 0:03b7e8deb3ee 37
jvfausto 0:03b7e8deb3ee 38 #endif