INSAT Mini Project

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Revision:
50:18e064bfb156
Parent:
48:e799ad44dab7
Child:
51:229ea522cff8
--- a/Components/VL6180X/vl6180x_class.h	Wed Jun 15 11:55:18 2016 +0000
+++ b/Components/VL6180X/vl6180x_class.h	Fri Sep 09 09:50:12 2016 +0000
@@ -39,7 +39,7 @@
 #define __VL6180X_CLASS_H
 
 /* Includes ------------------------------------------------------------------*/
-#include "RangeSensor.h"
+#include "DistanceSensor.h"
 #include "LightSensor.h"
 #include "DevI2C.h" 
 //#include "vl6180x_api.h"
@@ -93,7 +93,7 @@
 /* Classes -------------------------------------------------------------------*/
 /** Class representing a VL6180X sensor component
  */
-class VL6180X : public RangeSensor, public LightSensor
+class VL6180X : public DistanceSensor, public LightSensor
 {
  public:
     /** Constructor 1 (DigitalOut)
@@ -102,7 +102,7 @@
      * @param[in] &pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
      * @param[in] DevAddr device address, 0x29 by default  
      */
-    VL6180X(DevI2C &i2c, DigitalOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), LightSensor(), dev_i2c(i2c), gpio0(&pin)
+    VL6180X(DevI2C &i2c, DigitalOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : DistanceSensor(), LightSensor(), dev_i2c(i2c), gpio0(&pin)
     {
        MyDevice.I2cAddr=DevAddr;		 
        MyDevice.Present=0;
@@ -118,7 +118,7 @@
      * @param[in] pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
      * @param[in] device address, 0x29 by default  
      */		
-    VL6180X(DevI2C &i2c, STMPE1600DigiOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), LightSensor(), dev_i2c(i2c), expgpio0(&pin)
+    VL6180X(DevI2C &i2c, STMPE1600DigiOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : DistanceSensor(), LightSensor(), dev_i2c(i2c), expgpio0(&pin)
     {
        MyDevice.I2cAddr=DevAddr;		 
        MyDevice.Present=0;
@@ -471,18 +471,48 @@
  * @par Function Description
  * Unlike @a VL6180x_RangeGetMeasurement() this function only retrieves the range in millimeter \n
  * It does any required up-scale translation\n
- * It can be called after success status polling or in interrupt mode \n
+ * It can be called after having started a measure and after a succes \n
+ * measure is finisched either in polling mode or in interrupt mode \n
  * @warning these function is not doing wrap around filtering \n
  * This function doesn't perform any data ready check!
  *
  * @param pRange_mm  Pointer to range distance
  * @return           0 on success
  */		
-    virtual int GetRange(int32_t *piData)
+    int GetRange(int32_t *piData)
     {
        return VL6180x_RangeGetResult(Device, piData);
     }
-		
+
+/**
+ * @brief Get a single distance measure result
+ *
+ * @par Function Description
+ * It can be called after having initialized a component. It start a single 
+ * distance measure in polling mode and wait until the measure is finisched. 
+ * The function block until the measure is finished, it can blocks indefinitely 
+ * in case the measure never ends for any reason \n
+ *
+ * @param piData  Pointer to distance
+ * @return           0 on success
+ */		
+    virtual int GetDistance(uint32_t *piData)
+    {
+       int status=0; 
+       LOG_FUNCTION_START("");
+       status=StartMeasurement(range_single_shot_polling, NULL, NULL, NULL);
+       if (!status) {
+		  RangeWaitDeviceReady(2000);				 
+          for (status=1; 
+               status!=0; 
+               status=GetRange((int32_t *)piData));
+       }
+       StopMeasurement(range_single_shot_polling);
+       RangeWaitDeviceReady(2000);
+       LOG_FUNCTION_END(status);       
+       return status;
+    }
+			
 /**
  * @brief Configure ranging interrupt reported to application
  *
@@ -1079,12 +1109,38 @@
  * @param *piData The pointer to variable to write in the measure in Lux
  * @return  0       On success
  */				
-    virtual int GetLight(uint32_t *piData)
+    int GetLight(uint32_t *piData)
     {
        return VL6180x_AlsGetLux(Device, piData);
     }
 
 /**
+ * @brief Get a single light (in Lux) measure result
+ *
+ * @par Function Description
+ * It can be called after having initialized a component. It start a single 
+ * light measure in polling mode and wait until the measure is finisched. 
+ * The function block until the measure is finished, it can blocks indefinitely 
+ * in case the measure never ends for any reason \n
+ */				
+    virtual int GetLux(uint32_t *piData)
+    {
+       int status=0; 
+       LOG_FUNCTION_START("");
+       status=StartMeasurement(als_single_shot_polling, NULL, NULL, NULL);
+       if (!status) {
+          AlsWaitDeviceReady(2000);				 
+          for (status=1; 
+               status!=0; 
+               status=GetLight(piData));
+       }
+       StopMeasurement(als_single_shot_polling);
+	   AlsWaitDeviceReady(2000);				 			 
+       LOG_FUNCTION_END(status);       
+       return status;
+    }
+
+/**
  * @brief Start the ALS (light) measure in continous mode
  *
  * @par Function Description