Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Check_VL6180XA1_ToF
Fork of X_NUCLEO_6180XA1 by
Diff: Components/VL6180X/vl6180x_class.h
- Revision:
- 10:4954b09b72d8
- Parent:
- 9:9cbc1736f148
- Child:
- 11:88541229403e
--- a/Components/VL6180X/vl6180x_class.h Tue Sep 29 15:40:08 2015 +0200
+++ b/Components/VL6180X/vl6180x_class.h Tue Oct 06 09:03:10 2015 +0200
@@ -41,11 +41,11 @@
/* Includes ------------------------------------------------------------------*/
#include "RangeSensor.h"
#include "LightSensor.h"
-#include "DevI2C.h" //temporaneo fino alla creazione della classe x_nucleo_6180xa1
-//#include "vl6180x_api.h"
-//#include "vl6180x_cfg.h"
-//#include "vl6180x_def.h"
-//#include "vl6180x_types.h"
+#include "DevI2C.h"
+#include "vl6180x_api.h"
+#include "vl6180x_cfg.h"
+#include "vl6180x_def.h"
+#include "vl6180x_types.h"
#include "vl6180x_platform.h"
//#include "vl6180x_appcfg.h"
#include "STMPE1600_class.h"
@@ -56,6 +56,7 @@
/* Classes -------------------------------------------------------------------*/
/** Class representing a VL6180X sensor component
*/
+ //FIXME verficare se impostare le funzioni come virtual come nel caso IKS
class VL6180X : public RangeSensor, public LightSensor
{
public:
@@ -65,24 +66,24 @@
* @param[in] device address, 0x29 by default
* @param[in] device id, 0 by default
*/
-
-
- VL6180X(DevI2C &i2c, DigitalOut &pin, 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) : RangeSensor(), LightSensor(), dev_i2c(i2c), gpio0(&pin)
{
-// MyDeviceAddress=DevAddr;
- DevData.I2cAddr = DevAddr;
- DevData.Present=0;
- DevData.Ready=0;
- expgpio0 = NULL;
+ MyDevice.I2cAddr=DevAddr;
+ MyDevice.Present=0;
+ MyDevice.Ready=0;
+ Device=&MyDevice;;
+ expgpio0=NULL;
+ //free_fall=new InterruptIn(pin_gpio1);
}
-
- VL6180X(DevI2C &i2c, STMPE1600DigiOut &pin, 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) : RangeSensor(), LightSensor(), dev_i2c(i2c), expgpio0(&pin)
{
-// MyDeviceAddress=DevAddr;
- DevData.I2cAddr = DevAddr;
- DevData.Present=0;
- DevData.Ready=0;
- gpio0 = NULL;
+ MyDevice.I2cAddr=DevAddr;
+ MyDevice.Present=0;
+ MyDevice.Ready=0;
+ Device=&MyDevice;
+ gpio0=NULL;
+ //free_fall=new InterruptIn(pin_gpio1);
}
@@ -100,46 +101,110 @@
if (gpio0) *gpio0=0;
else if (expgpio0) *expgpio0=0;
}
- //Init sensor accende, legge id, inizializza il dispositivo e prepara per le misure (range, als)
- //altrimenti errore e cancello dalla board
-
- /*** Interface Methods ***/
- /*virtual*/ int Init()
+
+ int InitSensor(uint8_t NewAddr)
+ {
+ int status;
+
+ VL6180x_Off();
+ VL6180x_On();
+ status=IsPresent();
+ if(!status)
+ {
+ Device->Present=1;
+ status=Init();
+ if(status)
+ error("Failed to init VL6180X sensor!\n");
+ status=Prepare();
+ if(status)
+ error("Failed to prepare VL6180X!\n");
+ status=SetI2CAddress(NewAddr);
+ if(status)
+ error("Failed to change I2C address!\n");
+ Device->Ready=1;
+ }
+ return status;
+ }
+
+ int Init()
{
- return VL6180x_InitData(DevData); // ritorna 0 se corretto
+ return VL6180x_InitData(Device); // ritorna 0 se corretto
}
-
- /*virtual*/ int ReadID()
- {
- return VL6180X_ReadID(); // ritorna 0 se corretto e -2 se errore
- }
- /*
-
+
+ int IsPresent()
+ {
+ int status;
+
+ status=ReadID();
+ if(!status)
+ error("Failed to read ID device! Device not present!\n");
+ return status;
+ }
+
void SetPresent()
{
- MyDevice.Present=1;
- }
-
- void SetDeviceID(int n)
- {
- MyDevice.DevID=n;
+ Device->Present=1;
}
void SetReady()
{
- MyDevice.Ready=1;
- }
-
- */
-/*
- virtual int GetRange(int *piData) {
- return VL6180X_GetRange(piData);
+ Device->Ready=1;
+ }
+
+ int Prepare()
+ {
+ return VL6180x_Prepare(Device);
+ }
+
+ int SetI2CAddress(int NewAddr)
+ {
+ int status;
+
+ status=VL6180x_SetI2CAddress(Device, NewAddr);
+ if(!status)
+ Device->I2cAddr;
+ return status;
+ }
+
+ int StartMeasurement(int operating_mode)
+ {
+ int status;
+
+ switch(operating_mode)
+ {
+ case(1):
+ return VL6180x_RangePollMeasurement(Device, &RangeData);
+ case(2):
+ return VL6180x_AlsPollMeasurement(Device, &AlsData);
+ case(3): break;
+ case(4): break;
+ case(5): break;
+ case(6): break;
+ case(7): break;
+ default:
+ return INVALID_PARAMS;
+ }
+ }
+ /*
+ int GetRange(int *piData) {
+ return VL6180X_RangeGetMeasurement(piData);
}
- virtual int GetLight(int *piData) {
- return VL6180X_GetLight(piData);
- }
-*/
+ int GetLight(int *piData) {
+ return VL6180X_AlsGetMeasurement(piData);
+ }*/
+
+ int RangePollMeasurement()
+ {
+ return VL6180x_RangePollMeasurement(Device, &RangeData);
+ }
+
+ int AlsPollMeasurement()
+ {
+ return VL6180x_AlsPollMeasurement(Device, &AlsData);
+ }
+
+
/* api.c functions */
int VL6180x_WaitDeviceBooted(VL6180xDev_t dev);
int VL6180x_InitData(VL6180xDev_t dev );
@@ -204,10 +269,8 @@
int _GetRateResult(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
int _DMax_InitData(VL6180xDev_t dev);
- /* Read functions from registers and write functions into registers */
- int VL6180X_ReadID();
- int VL6180X_IO_Read(uint8_t *pBuffer, uint16_t RegisterAddress, uint16_t NumByteToRead);
- int VL6180X_IO_Write(uint8_t *pBuffer, uint16_t RegisterAddress, uint16_t NumByteToWrite);
+ /* Read function of the ID device */
+ int ReadID();
/* Write and read functions from I2C */
int VL6180x_WrByte(VL6180xDev_t dev, uint16_t index, uint8_t data);
@@ -220,20 +283,24 @@
int VL6180x_I2CWrite(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t *pBuffer, uint16_t NumByteToWrite);
int VL6180x_I2CRead(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t *pBuffer, uint16_t NumByteToRead);
- VL6180xDev_t DevData;
+
private:
- /*** Instance Variables ***/
/* IO Device */
DevI2C &dev_i2c;
+ /* Digital out pin */
DigitalOut *gpio0;
- STMPE1600DigiOut *expgpio0;
-
-// VL6180xDev_t DevData;
-// VL6180xDev_t MyDeviceAddress;
-// unsigned Present;
-// unsigned Ready;
-
+ /* GPIO expander */
+ STMPE1600DigiOut *expgpio0;
+ /* Input interrupt */
+ //InterruptIn *free_fall;
+ /* Device data */
+ MyVL6180Dev_t MyDevice;
+ VL6180xDev_t Device;
+ /* Device range data */
+ VL6180x_RangeData_t RangeData;
+ /* Device als data */
+ VL6180x_AlsData_t AlsData;
};
#endif // __VL6180X_CLASS_H
