INSAT Mini Project
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_6180XA1 by
Revision 48:e799ad44dab7, committed 2016-06-07
- Comitter:
- licio.mapelli@st.com
- Date:
- Tue Jun 07 14:56:36 2016 +0200
- Parent:
- 47:2fc173b227d4
- Child:
- 49:f0dd44dd59c5
- Commit message:
- Fixed I2C address in component descriptor to default val after component PowerOn/Off.
Overridden singleton obj fake copy constructor and (=) assignement operator to avoid multiple singleton instances.
Changed in this revision
--- a/Components/VL6180X/vl6180x_class.cpp Mon May 23 09:59:39 2016 +0000
+++ b/Components/VL6180X/vl6180x_class.cpp Tue Jun 07 14:56:36 2016 +0200
@@ -278,7 +278,7 @@
//static int VL6180x_UpscaleStaticInit(VL6180xDev_t dev);
int VL6180X::VL6180x_WaitDeviceBooted(VL6180xDev_t dev){
- uint8_t FreshOutReset;
+ uint8_t FreshOutReset=0;
int status;
LOG_FUNCTION_START("");
do{
@@ -2532,7 +2532,7 @@
{
int status;
- uint8_t buffer;
+ uint8_t buffer=0;
status=VL6180x_I2CRead(dev->I2cAddr, index, &buffer,1);
if(!status)
{
@@ -2546,6 +2546,7 @@
int status;
uint8_t buffer[2];
+ buffer[0]=buffer[1]=0;
status=VL6180x_I2CRead(dev->I2cAddr, index, buffer, 2);
if(!status)
{
@@ -2558,6 +2559,7 @@
{
int status;
uint8_t buffer[4];
+ buffer[0]=buffer[1]=buffer[2]=buffer[3]=0;
status=VL6180x_I2CRead(dev->I2cAddr, index, buffer,4);
if(!status)
{
@@ -2569,7 +2571,7 @@
int VL6180X::VL6180x_UpdateByte(VL6180xDev_t dev, uint16_t index, uint8_t AndData, uint8_t OrData)
{
int status;
- uint8_t buffer;
+ uint8_t buffer=0;
status=VL6180x_I2CWrite(dev->I2cAddr, index, (uint8_t *)&buffer,(uint8_t)0);
if(!status)
@@ -3507,6 +3509,17 @@
}
+int VL6180X::IsPresent()
+{
+ int status; uint8_t id;
+
+ status=ReadID(&id);
+ if(status)
+ VL6180x_ErrLog("Failed to read ID device. Device not present!\n\r");
+ return status;
+}
+
+
int VL6180X::StopRangeMeasurement(OperatingMode operating_mode)
{
int status;
--- a/Components/VL6180X/vl6180x_class.h Mon May 23 09:59:39 2016 +0000
+++ b/Components/VL6180X/vl6180x_class.h Tue Jun 07 14:56:36 2016 +0200
@@ -133,7 +133,8 @@
*/
virtual ~VL6180X(){
if (gpio1Int != NULL) delete gpio1Int;
- }
+ }
+
/* warning: VL6180X class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor.
The warning should request to introduce a virtual destructor to make sure to delete the object */
@@ -150,6 +151,9 @@
*gpio0=1;
else if(expgpio0)
*expgpio0=1;
+
+ MyDevice.I2cAddr=DEFAULT_DEVICE_ADDRESS;
+ MyDevice.Ready=0;
}
/**
@@ -162,9 +166,11 @@
if(gpio0)
*gpio0=0;
else if(expgpio0)
- *expgpio0=0;
- }
-
+ *expgpio0=0;
+
+ MyDevice.I2cAddr=DEFAULT_DEVICE_ADDRESS;
+ MyDevice.Ready=0;
+ }
/**
* @brief Start the measure indicated by operating mode
@@ -283,9 +289,11 @@
VL6180x_Off();
VL6180x_On();
+
status=VL6180x_WaitDeviceBooted(Device);
- if(status)
- VL6180x_ErrLog("WaitDeviceBooted fail\n\r");
+ if(status) {
+ VL6180x_ErrLog("WaitDeviceBooted fail\n\r");
+ }
status=IsPresent();
if(!status)
{
@@ -311,11 +319,6 @@
return status;
}
}
- else
- {
- printf("Invalid new address!\n\r");
- return INVALID_PARAMS;
- }
Device->Ready=1;
}
return status;
@@ -1186,16 +1189,7 @@
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);
-
- int IsPresent()
- {
- int status; uint8_t id;
-
- status=ReadID(&id);
- if(status)
- VL6180x_ErrLog("Failed to read ID device. Device not present!\n\r");
- return status;
- }
+ int IsPresent();
int StopRangeMeasurement(OperatingMode operating_mode);
int StopAlsMeasurement(OperatingMode operating_mode);
int GetRangeMeas(OperatingMode operating_mode, MeasureData_t *Data);
--- a/x_nucleo_6180xa1.cpp Mon May 23 09:59:39 2016 +0000
+++ b/x_nucleo_6180xa1.cpp Tue Jun 07 14:56:36 2016 +0200
@@ -68,70 +68,54 @@
{
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();
- sensor_address = NEW_SENSOR_TOP_ADDRESS;
- status=sensor_top->Init(&sensor_address);
- if(status)
- {
- delete sensor_top;
- delete gpio0_top;
- sensor_top=NULL;
- gpio0_top=NULL;
- printf("Sensor top not present\n\r");
- }
- else
- {
- printf("Sensor top present\n\r");
- n_dev++;
- }
- sensor_address = NEW_SENSOR_BOTTOM_ADDRESS;
- status=sensor_bottom->Init(&sensor_address);
- if(status)
- {
- delete sensor_bottom;
- delete gpio0_bottom;
- sensor_bottom=NULL;
- gpio0_bottom=NULL;
- printf("Sensor bottom not present\n\r");
- }
- else
- {
- printf("Sensor bottom present\n\r");
- n_dev++;
- }
- sensor_address = NEW_SENSOR_LEFT_ADDRESS;
- status=sensor_left->Init(&sensor_address);
- if(status)
- {
- delete sensor_left;
- delete gpio0_left;
- sensor_left=NULL;
- gpio0_left=NULL;
- printf("Sensor left not present\n\r");
- }
- else
- {
- printf("Sensor left present\n\r");
- n_dev++;
- }
- sensor_address = NEW_SENSOR_RIGHT_ADDRESS;
- status=sensor_right->Init(&sensor_address);
- if(status)
- {
- delete sensor_right;
- delete gpio0_right;
- sensor_right=NULL;
- gpio0_right=NULL;
- printf("Sensor right not present\n\r");
- }
- else
- {
- printf("Sensor right present\n\r");
- n_dev++;
- }
+ sensor_top->VL6180x_Off();
+ sensor_bottom->VL6180x_Off();
+ sensor_left->VL6180x_Off();
+ sensor_right->VL6180x_Off();
+ sensor_address = NEW_SENSOR_TOP_ADDRESS;
+ status=sensor_top->Init(&sensor_address);
+ if(status)
+ {
+ printf("Sensor top not present\n\r");
+ }
+ else
+ {
+ printf("Sensor top present\n\r");
+ n_dev++;
+ }
+ sensor_address = NEW_SENSOR_BOTTOM_ADDRESS;
+ status=sensor_bottom->Init(&sensor_address);
+ if(status)
+ {
+ printf("Sensor bottom not present\n\r");
+ }
+ else
+ {
+ printf("Sensor bottom present\n\r");
+ n_dev++;
+ }
+ sensor_address = NEW_SENSOR_LEFT_ADDRESS;
+ status=sensor_left->Init(&sensor_address);
+ if(status)
+ {
+ printf("Sensor left not present\n\r");
+ }
+ else
+ {
+ printf("Sensor left present\n\r");
+ n_dev++;
+ }
+ sensor_address = NEW_SENSOR_RIGHT_ADDRESS;
+ status=sensor_right->Init(&sensor_address);
+ if(status)
+ {
+ printf("Sensor right not present\n\r");
+ }
+ else
+ {
+ printf("Sensor right present\n\r");
+ n_dev++;
+ }
if(n_dev==0)
return 1;
else
--- a/x_nucleo_6180xa1.h Mon May 23 09:59:39 2016 +0000
+++ b/x_nucleo_6180xa1.h Tue Jun 07 14:56:36 2016 +0200
@@ -57,11 +57,11 @@
/* Classes--------------------------------------------------------------------*/
/* Classes -------------------------------------------------------------------*/
-/** Class representing the X-NUCLEO-VL6180XA1 expansion board
+/** Class representing the X-NUCLEO-VL6180XA1 expansion board singleton obj
*/
class X_NUCLEO_6180XA1
{
- public:
+private:
/** Constructor 1
* @param[in] &i2c device I2C to be used for communication
*/
@@ -124,7 +124,7 @@
if(sensor_top!=NULL)
{
delete sensor_top;
- sensor_top=NULL;
+ sensor_top=NULL;
}
if(gpio0_bottom!=NULL)
{
@@ -134,7 +134,7 @@
if(sensor_bottom!=NULL)
{
delete sensor_bottom;
- sensor_bottom=NULL;
+ sensor_bottom=NULL;
}
if(gpio0_left!=NULL)
{
@@ -144,7 +144,7 @@
if(sensor_left!=NULL)
{
delete sensor_left;
- sensor_left=NULL;
+ sensor_left=NULL;
}
if(gpio0_right!=NULL)
{
@@ -154,26 +154,41 @@
if(sensor_right!=NULL)
{
delete sensor_right;
- sensor_right=NULL;
+ sensor_right=NULL;
}
- delete stmpe1600;
- stmpe1600 = NULL;
- delete Switch;
- Switch = NULL;
- delete display;
- display = NULL;
+ delete stmpe1600;
+ stmpe1600 = NULL;
+ delete Switch;
+ Switch = NULL;
+ delete display;
+ display = NULL;
_instance=NULL;
}
- /**
- * @brief Creates a singleton object instance
+ /**
+ * @brief Override default copy constructor as empty
+ * @param[in] &X_NUCLEO_6180XA1 singleton object reference
+ * @return
+ */
+ X_NUCLEO_6180XA1() {};
+
+ /**
+ * @brief Override default assignement operator to avoid multiple singletons
+ * @param[in] &X_NUCLEO_6180XA1 singleton object reference
+ * @return
+ */
+ void operator = (const X_NUCLEO_6180XA1&);
+
+public:
+ /**
+ * @brief Creates a singleton object instance
* @param[in] &i2c device I2C to be used for communication
- * @return Pointer to the object instance
- */
+ * @return Pointer to the object instance
+ */
static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c);
- /**
- * @brief Creates a singleton object instance
+ /**
+ * @brief Creates a singleton object instance
* @param[in] &i2c device I2C to be used for communication
* @param[in] PinName gpio1_top the pin connected to top sensor INT
* @param[in] PinName gpio1_bottem the pin connected to bottom sensor INT
@@ -184,6 +199,8 @@
static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c, PinName gpio1_top, PinName gpio1_bottom,
PinName gpio1_left, PinName gpio1_right);
+
+
/**
* @brief Initialize the board and sensors with deft values
* @return 0 on success
@@ -203,15 +220,15 @@
VL6180X *sensor_bottom;
VL6180X *sensor_left;
VL6180X *sensor_right;
- STMPE1600 * stmpe1600;
- SWITCH * Switch;
+ STMPE1600 * stmpe1600;
+ SWITCH * Switch;
+ Display *display;
+
+private:
STMPE1600DigiOut *gpio0_top;
STMPE1600DigiOut *gpio0_bottom;
STMPE1600DigiOut *gpio0_left;
STMPE1600DigiOut *gpio0_right;
- Display *display;
-
- private:
static X_NUCLEO_6180XA1 *_instance;
};
