Time of Flight Sensor
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Dependents: Ultrasound_And_IMU
Fork of X_NUCLEO_6180XA1 by
Revision 46:116dadbc80f1, committed 2016-05-19
- Comitter:
- mapellil
- Date:
- Thu May 19 14:11:25 2016 +0000
- Parent:
- 45:70e4abd970a9
- Child:
- 47:2fc173b227d4
- Commit message:
- Fixed /Components/Interfaces/GenericSensor.h model and its vl6180xa1 inheritors classes.
Changed in this revision
--- a/Components/Interfaces/GenericSensor.h Tue Mar 15 16:26:36 2016 +0000
+++ b/Components/Interfaces/GenericSensor.h Thu May 19 14:11:25 2016 +0000
@@ -54,14 +54,14 @@
* @param[out] ptr Pointer to device specific initalization structure
* @return 0 in case of success, an error code otherwise
*/
- virtual int Init() = 0;
+ virtual int Init(void *ptr) = 0;
/**
* @brief Get ID of sensor
* @param[out] id Pointer to where to store the ID to
* @return 0 in case of success, an error code otherwise
*/
- virtual int ReadID() = 0;
+ virtual int ReadID(uint8_t *id) = 0;
};
#endif /* __GENERIC_SENSOR_CLASS_H */
--- a/Components/VL6180X/vl6180x_class.cpp Tue Mar 15 16:26:36 2016 +0000
+++ b/Components/VL6180X/vl6180x_class.cpp Thu May 19 14:11:25 2016 +0000
@@ -2685,61 +2685,9 @@
}
-int VL6180X::ReadID()
-{
- int status;
- uint8_t rl_id=0;
-
- status=VL6180x_RdByte(Device, IDENTIFICATION_MODEL_ID, &rl_id);
- if((status==0)&&(rl_id==0xB4))
- return status;
- else
- return INVALID_PARAMS;
-}
-
-
-int VL6180X::InitSensor(uint8_t NewAddr)
+int VL6180X::ReadID(uint8_t *id)
{
- int status;
-
- VL6180x_Off();
- VL6180x_On();
- status=VL6180x_WaitDeviceBooted(Device);
- if(status)
- VL6180x_ErrLog("WaitDeviceBooted fail\n\r");
- status=IsPresent();
- if(!status)
- {
- Device->Present=1;
- status=Init();
- if(status)
- {
- printf("Failed to init VL6180X sensor!\n\r");
- return status;
- }
- status=Prepare();
- if(status)
- {
- printf("Failed to prepare VL6180X!\n\r");
- return status;
- }
- if(NewAddr!=DEFAULT_DEVICE_ADDRESS)
- {
- status=SetI2CAddress(NewAddr);
- if(status)
- {
- printf("Failed to change I2C address!\n\r");
- return status;
- }
- }
- else
- {
- printf("Invalid new address!\n\r");
- return INVALID_PARAMS;
- }
- Device->Ready=1;
- }
- return status;
+ return VL6180x_RdByte(Device, IDENTIFICATION_MODEL_ID, id);
}
--- a/Components/VL6180X/vl6180x_class.h Tue Mar 15 16:26:36 2016 +0000
+++ b/Components/VL6180X/vl6180x_class.h Thu May 19 14:11:25 2016 +0000
@@ -165,11 +165,6 @@
*expgpio0=0;
}
- /**
- * @brief Initialize the sensor with default values
- * @return 0 on Success
- */
- int InitSensor(uint8_t NewAddr);
/**
* @brief Start the measure indicated by operating mode
@@ -281,11 +276,51 @@
*
* @param void
* @return 0 on success, @a #CALIBRATION_WARNING if failed
- */
- virtual int Init()
- {
- return VL6180x_InitData(Device);
- }
+*/
+virtual int Init(void * NewAddr)
+{
+ int status;
+
+ VL6180x_Off();
+ VL6180x_On();
+ status=VL6180x_WaitDeviceBooted(Device);
+ if(status)
+ VL6180x_ErrLog("WaitDeviceBooted fail\n\r");
+ status=IsPresent();
+ if(!status)
+ {
+ Device->Present=1;
+ VL6180x_InitData(Device);
+ if(status)
+ {
+ printf("Failed to init VL6180X sensor!\n\r");
+ return status;
+ }
+ status=Prepare();
+ if(status)
+ {
+ printf("Failed to prepare VL6180X!\n\r");
+ return status;
+ }
+ if(*(uint8_t*)NewAddr!=DEFAULT_DEVICE_ADDRESS)
+ {
+ status=SetI2CAddress(*(uint8_t*)NewAddr);
+ if(status)
+ {
+ printf("Failed to change I2C address!\n\r");
+ return status;
+ }
+ }
+ else
+ {
+ printf("Invalid new address!\n\r");
+ return INVALID_PARAMS;
+ }
+ Device->Ready=1;
+ }
+ return status;
+}
+
/**
* @brief Configure GPIO1 function and set polarity.
@@ -1138,7 +1173,7 @@
int _DMax_InitData(VL6180xDev_t dev);
/* Read function of the ID device */
- virtual int ReadID();
+ virtual int ReadID(uint8_t *id);
/* Write and read functions from I2C */
int VL6180x_WrByte(VL6180xDev_t dev, uint16_t index, uint8_t data);
@@ -1154,9 +1189,9 @@
int IsPresent()
{
- int status;
+ int status; uint8_t id;
- status=ReadID();
+ status=ReadID(&id);
if(status)
VL6180x_ErrLog("Failed to read ID device. Device not present!\n\r");
return status;
--- a/x_nucleo_6180xa1.cpp Tue Mar 15 16:26:36 2016 +0000
+++ b/x_nucleo_6180xa1.cpp Thu May 19 14:11:25 2016 +0000
@@ -66,13 +66,14 @@
int X_NUCLEO_6180XA1::InitBoard()
{
- int status, n_dev=0;
+ int status, n_dev=0; uint8_t sensor_address;
sensor_top->VL6180x_Off();
sensor_bottom->VL6180x_Off();
sensor_left->VL6180x_Off();
sensor_right->VL6180x_Off();
- status=sensor_top->InitSensor(NEW_SENSOR_TOP_ADDRESS);
+ sensor_address = NEW_SENSOR_TOP_ADDRESS;
+ status=sensor_top->Init(&sensor_address);
if(status)
{
delete sensor_top;
@@ -86,7 +87,8 @@
printf("Sensor top present\n\r");
n_dev++;
}
- status=sensor_bottom->InitSensor(NEW_SENSOR_BOTTOM_ADDRESS);
+ sensor_address = NEW_SENSOR_BOTTOM_ADDRESS;
+ status=sensor_bottom->Init(&sensor_address);
if(status)
{
delete sensor_bottom;
@@ -100,7 +102,8 @@
printf("Sensor bottom present\n\r");
n_dev++;
}
- status=sensor_left->InitSensor(NEW_SENSOR_LEFT_ADDRESS);
+ sensor_address = NEW_SENSOR_LEFT_ADDRESS;
+ status=sensor_left->Init(&sensor_address);
if(status)
{
delete sensor_left;
@@ -114,7 +117,8 @@
printf("Sensor left present\n\r");
n_dev++;
}
- status=sensor_right->InitSensor(NEW_SENSOR_RIGHT_ADDRESS);
+ sensor_address = NEW_SENSOR_RIGHT_ADDRESS;
+ status=sensor_right->Init(&sensor_address);
if(status)
{
delete sensor_right;
