ケンタ ミヤザキ / X_NUCLEO_53L0A1

Dependencies:   VL53L0X

Fork of X_NUCLEO_53L0A1 by ST

Files at this revision

API Documentation at this revision

Comitter:
johnAlexander
Date:
Wed Jun 07 14:58:36 2017 +0000
Parent:
9:367d1f390cb2
Child:
11:ceaa5a026412
Commit message:
Ensure that GetDistance() is populated in the VL53L0X class.

Changed in this revision

Components/VL53L0X/vl53l0x_class.h Show annotated file Show diff for this revision Revisions of this file
--- a/Components/VL53L0X/vl53l0x_class.h	Wed Jun 07 12:53:53 2017 +0000
+++ b/Components/VL53L0X/vl53l0x_class.h	Wed Jun 07 14:58:36 2017 +0000
@@ -42,6 +42,7 @@
 
 
 /* Includes ------------------------------------------------------------------*/
+#include "mbed.h"
 #include "RangeSensor.h"
 #include "DevI2C.h" 
 
@@ -327,7 +328,7 @@
        Device=&MyDevice;
        gpio0=NULL;		
        if (pin_gpio1 != NC) { gpio1Int = new InterruptIn(pin_gpio1); }
-       	else { gpio1Int = NULL; } 		 
+       	else { gpio1Int = NULL; }
     }  	 
     
    /** Destructor
@@ -371,9 +372,10 @@
 	/**
 	 * @brief       Initialize the sensor with default values
 	 * @return      0 on Success
-	 */					 
+	 */
+
     int InitSensor(uint8_t NewAddr);
-    
+
     int RawInitSensor(void);
     int initDevice(VL53L0X_DEV Dev);
     int setLongRangePresets(VL53L0X_DEV Dev);
@@ -493,12 +495,9 @@
  * @param void
  * @return     0 on success,  @a #CALIBRATION_WARNING if failed
  */		
-    virtual int Init(void *init)
-//    virtual int Init()
+    virtual int Init(void * NewAddr)
     {
-       return VL53L0X_DataInit(&MyDevice);
-//       return VL53L0X_DataInit(Device);
-//			return 1;
+       return VL53L0X_DataInit(Device);
     }
 
 /**
@@ -539,8 +538,6 @@
   */		
     int Prepare()
     {
-//       return VL6180x_Prepare(Device);
-			// taken from rangingTest() in vl53l0x_SingleRanging_Example.c
 		VL53L0X_Error Status = VL53L0X_ERROR_NONE;
         uint32_t refSpadCount;
         uint8_t isApertureSpads;
@@ -691,10 +688,24 @@
  * @return           0 on success
  */		
     virtual int GetDistance(uint32_t *piData)
-//    virtual int GetRange(int32_t *piData)
     {
-//       return VL6180x_RangeGetResult(Device, piData);
-			return 1;
+        int status=0;
+        VL53L0X_RangingMeasurementData_t pRangingMeasurementData;
+
+        status=StartMeasurement(range_single_shot_polling, NULL);
+        if (!status) {
+            status=GetMeasurement(range_single_shot_polling, &pRangingMeasurementData);
+        }
+        if (pRangingMeasurementData.RangeStatus == 0) {
+        // we have a valid range.
+            *piData = pRangingMeasurementData.RangeMilliMeter;
+        }
+        else {
+            *piData = 0;
+            status = VL53L0X_ERROR_RANGE_ERROR;
+        }
+        StopMeasurement(range_single_shot_polling);
+        return status;
     }
 		
 /**
@@ -1377,9 +1388,6 @@
 		
     /* IO Device */
     DevI2C &dev_i2c;
-    /* GPIO expander */
-//    STMPE1600 &io_expander;
-//    ExpGpioPinName xshutdown;
     /* Digital out pin */
     DigitalOut *gpio0;
     /* GPIO expander */