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
Revision 6:621552ff1de9, committed 2018-07-27
- Comitter:
- jvfausto
- Date:
- Fri Jul 27 19:02:07 2018 +0000
- Parent:
- 5:aa8cc9e87216
- Commit message:
- Now begin() is a boolean
Changed in this revision
VL53L1X.cpp | Show annotated file Show diff for this revision Revisions of this file |
VL53L1X.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r aa8cc9e87216 -r 621552ff1de9 VL53L1X.cpp --- a/VL53L1X.cpp Fri Jul 27 18:43:58 2018 +0000 +++ b/VL53L1X.cpp Fri Jul 27 19:02:07 2018 +0000 @@ -30,12 +30,12 @@ _deviceAddress = defaultAddress_VL53L1X << 1; } -void VL53L1X::begin() +bool VL53L1X::begin() { //Check the device ID uint16_t modelID = readRegister16(VL53L1_IDENTIFICATION__MODEL_ID); if (modelID != 0xEACC){ - return;// (false); + return (false); } softReset(); @@ -47,7 +47,7 @@ { Firmware = readRegister16(VL53L1_FIRMWARE__SYSTEM_STATUS); printf("Firmware = %x\r\n", Firmware); - if (counter++ == 100) return; //(false); //Sensor timed out + if (counter++ == 100) return (false); //Sensor timed out wait(.1); } @@ -63,17 +63,16 @@ } startMeasurement(); - printf("It Blinks!!! \r\n"); -// return (true); //Sensor online! + return (true); //Sensor online! } void VL53L1X::startMeasurement(uint8_t offset) { -offset = 0; //Start at a location within the configBlock array + offset = 0; //Start at a location within the configBlock array uint8_t address = 1 + offset; //Start at memory location 0x01, add offset - char data_write[2]; + char data_write[32]; uint8_t leftToSend = sizeof(configBlock) - offset; while (leftToSend > 0) { @@ -97,7 +96,6 @@ bool VL53L1X::newDataReady(void) { int read = readRegister(VL53L1_GPIO__TIO_HV_STATUS); - if (read != 0x03) return(true); //New measurement! return(false); //No new data }
diff -r aa8cc9e87216 -r 621552ff1de9 VL53L1X.h --- a/VL53L1X.h Fri Jul 27 18:43:58 2018 +0000 +++ b/VL53L1X.h Fri Jul 27 19:02:07 2018 +0000 @@ -12,7 +12,7 @@ class VL53L1X { public: VL53L1X(PinName SDA, PinName SCL); - void begin(); + bool begin(); void softReset(); //Reset the sensor via software void startMeasurement(uint8_t offset = 0); //Write a block of bytes to the sensor to configure it to take a measurement bool newDataReady(); //Polls the measurement completion bit