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.
Fork of X_NUCLEO_IKS01A1 by
Revision 46:badcff0675e8, committed 2015-06-08
- Comitter:
- Wolfgang Betz
- Date:
- Mon Jun 08 17:22:35 2015 +0200
- Parent:
- 44:d757094f6229
- Child:
- 47:a1c273278014
- Child:
- 48:cb18488509a5
- Commit message:
- Add GenericSensor interface
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/Interfaces/GenericSensor.h Mon Jun 08 17:22:35 2015 +0200
@@ -0,0 +1,93 @@
+/**
+ ******************************************************************************
+ * @file GenericSensor.h
+ * @author AST / EST
+ * @version V0.0.1
+ * @date 13-April-2015
+ * @brief This file contains the abstract class describing in general
+ * the interfaces of a generic sensor
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent from recursive inclusion --------------------------------*/
+#ifndef __GENERIC_SENSOR_CLASS_H
+#define __GENERIC_SENSOR_CLASS_H
+
+/* Includes ------------------------------------------------------------------*/
+#include <stdint.h>
+
+/* Classes ------------------------------------------------------------------*/
+/** An abstract class for Generic sensors
+ */
+class GenericSensor
+{
+ public:
+ /**
+ * @brief Initialization of sensor
+ * @param[out] ptr Pointer to device specific initalization structure
+ * @return 0 in case of success, an error code otherwise
+ */
+ virtual int Init(void *ptr) = 0;
+
+ /**
+ * @brief Enter sensor shutdown mode
+ * @return 0 in case of success, an error code otherwise
+ */
+ virtual int PowerOff(void) = 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(uint8_t *id) = 0;
+
+ /**
+ * @brief Reset sensor
+ * @return 0 in case of success, an error code otherwise
+ */
+ virtual int Reset(void) = 0;
+
+ /* Interrupt Interface */
+ /* betzw - TODO: WIP */
+ virtual void ConfigIT(uint16_t) = 0;
+ virtual void EnableIT(uint8_t) = 0;
+ virtual void DisableIT(uint8_t) = 0;
+ virtual uint8_t ITStatus(uint16_t, uint16_t) = 0;
+ virtual void ClearIT(uint16_t, uint16_t) = 0;
+
+ /**
+ * @brief Attach a function to be called when an interrupt occurs
+ * @param[in] fptr A pointer to a void function, or 0 to set as none
+ */
+ virtual void AttachIT(void (*fptr)(void)) = 0;
+};
+
+#endif /* __GENERIC_SENSOR_CLASS_H */
--- a/Components/Interfaces/GyroSensor.h Mon Jun 08 15:36:36 2015 +0200
+++ b/Components/Interfaces/GyroSensor.h Mon Jun 08 17:22:35 2015 +0200
@@ -41,29 +41,15 @@
#define __GYRO_SENSOR_CLASS_H
/* Includes ------------------------------------------------------------------*/
-#include <stdint.h>
+#include <GenericSensor.h>
/* Classes ------------------------------------------------------------------*/
/** An abstract class for a Gyroscope
*/
-class GyroSensor
+class GyroSensor : public GenericSensor
{
public:
/**
- * @brief Initialization of gyroscope
- * @param[out] ptr Pointer to device specific initalization structure
- * @return 0 in case of success, an error code otherwise
- */
- virtual int Init(void *ptr) = 0;
-
- /**
- * @brief Get ID of gyroscope
- * @param[out] id Pointer to where to store the ID to
- * @return 0 in case of success, an error code otherwise
- */
- virtual int ReadID(uint8_t *id) = 0;
-
- /**
* @brief Get current gyroscope angular rate X/Y/Z-axes values
* in standard data units [mdps]
* @param[out] pData Pointer to where to store angular rates to.
--- a/Components/Interfaces/HumiditySensor.h Mon Jun 08 15:36:36 2015 +0200
+++ b/Components/Interfaces/HumiditySensor.h Mon Jun 08 17:22:35 2015 +0200
@@ -41,58 +41,20 @@
#define __HUMIDITY_SENSOR_CLASS_H
/* Includes ------------------------------------------------------------------*/
-#include <stdint.h>
+#include <GenericSensor.h>
/* Classes ------------------------------------------------------------------*/
/** An abstract class for Humidity sensors
*/
-class HumiditySensor
+class HumiditySensor : public GenericSensor
{
public:
/**
- * @brief Initialization of humidity sensor
- * @param[out] ptr Pointer to device specific initalization structure
- * @return 0 in case of success, an error code otherwise
- */
- virtual int Init(void *ptr) = 0;
-
- /**
- * @brief Enter sensor shutdown mode
- * @return 0 in case of success, an error code otherwise
- */
- virtual int PowerOff(void) = 0;
-
- /**
- * @brief Get ID of humidity 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(uint8_t *id) = 0;
-
- /**
- * @brief Reset sensor
- * @return 0 in case of success, an error code otherwise
- */
- virtual int Reset(void) = 0;
-
- /**
* @brief Get current humidity [%]
* @param[out] pfData Pointer to where to store humidity to
* @return 0 in case of success, an error code otherwise
*/
virtual int GetHumidity(float *pfData) = 0;
-
- virtual void ConfigIT(uint16_t) = 0;
- virtual void EnableIT(uint8_t) = 0;
- virtual void DisableIT(uint8_t) = 0;
- virtual uint8_t ITStatus(uint16_t, uint16_t) = 0;
- virtual void ClearIT(uint16_t, uint16_t) = 0;
-
- /**
- * @brief Attach a function to be called when an interrupt occurs
- * @param[in] fptr A pointer to a void function, or 0 to set as none
- */
- virtual void AttachIT(void (*fptr)(void)) = 0;
};
#endif /* __HUMIDITY_SENSOR_CLASS_H */
--- a/Components/Interfaces/MagneticSensor.h Mon Jun 08 15:36:36 2015 +0200
+++ b/Components/Interfaces/MagneticSensor.h Mon Jun 08 17:22:35 2015 +0200
@@ -41,29 +41,15 @@
#define __MAGNETIC_SENSOR_CLASS_H
/* Includes ------------------------------------------------------------------*/
-#include <stdint.h>
+#include <GenericSensor.h>
/* Classes ------------------------------------------------------------------*/
/** An abstract class for a magnetometer
*/
-class MagneticSensor
+class MagneticSensor : public GenericSensor
{
public:
/**
- * @brief Initialization of magnetometer
- * @param[out] ptr Pointer to device specific initalization structure
- * @return 0 in case of success, an error code otherwise
- */
- virtual int Init(void *ptr) = 0;
-
- /**
- * @brief Get ID of magnetometer
- * @param[out] id Pointer to where to store the ID to
- * @return 0 in case of success, an error code otherwise
- */
- virtual int ReadID(uint8_t *id) = 0;
-
- /**
* @brief Get current magnetometer magnetic X/Y/Z-axes values
* in standard data units [mgauss]
* @param[out] pData Pointer to where to store magnetic values to.
--- a/Components/Interfaces/MotionSensor.h Mon Jun 08 15:36:36 2015 +0200
+++ b/Components/Interfaces/MotionSensor.h Mon Jun 08 17:22:35 2015 +0200
@@ -41,29 +41,15 @@
#define __MOTION_SENSOR_CLASS_H
/* Includes ------------------------------------------------------------------*/
-#include <stdint.h>
+#include <GenericSensor.h>
/* Classes ------------------------------------------------------------------*/
/** An abstract class for an Accelerometer
*/
-class MotionSensor
+class MotionSensor : public GenericSensor
{
public:
/**
- * @brief Initialization of accelerometer
- * @param[out] ptr Pointer to device specific initalization structure
- * @return 0 in case of success, an error code otherwise
- */
- virtual int Init(void *ptr) = 0;
-
- /**
- * @brief Get ID of accelerometer
- * @param[out] id Pointer to where to store the ID to
- * @return 0 in case of success, an error code otherwise
- */
- virtual int ReadID(uint8_t *id) = 0;
-
- /**
* @brief Get current accelerometer linear acceleration X/Y/Z-axes values
* in standard data units [mg]
* @param[out] pData Pointer to where to store linear accelerations to.
--- a/Components/Interfaces/PressureSensor.h Mon Jun 08 15:36:36 2015 +0200
+++ b/Components/Interfaces/PressureSensor.h Mon Jun 08 17:22:35 2015 +0200
@@ -41,7 +41,7 @@
#define __PRESSURE_SENSOR_CLASS_H
/* Includes ------------------------------------------------------------------*/
-#include <stdint.h>
+#include <GenericSensor.h>
/* Classes ------------------------------------------------------------------*/
/** An abstract class for a Pressure Sensor
@@ -50,49 +50,11 @@
{
public:
/**
- * @brief Initialization of pressure sensor
- * @param[out] ptr Pointer to device specific initalization structure
- * @return 0 in case of success, an error code otherwise
- */
- virtual int Init(void *ptr) = 0;
-
- /**
- * @brief Enter sensor shutdown mode
- * @return 0 in case of success, an error code otherwise
- */
- virtual int PowerOff(void) = 0;
-
- /**
- * @brief Get ID of pressure 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(uint8_t *id) = 0;
-
- /**
- * @brief Reset sensor
- * @return 0 in case of success, an error code otherwise
- */
- virtual int Reset(void) = 0;
-
- /**
* @brief Get current pressure [mbar]
* @param[out] pfData Pointer to where to store pressure to
* @return 0 in case of success, an error code otherwise
*/
virtual int GetPressure(float *pfData) = 0;
-
- virtual void ConfigIT(uint16_t) = 0;
- virtual void EnableIT(uint8_t) = 0;
- virtual void DisableIT(uint8_t) = 0;
- virtual uint8_t ITStatus(uint16_t, uint16_t) = 0;
- virtual void ClearIT(uint16_t, uint16_t) = 0;
-
- /**
- * @brief Attach a function to be called when an interrupt occurs
- * @param[in] fptr A pointer to a void function, or 0 to set as none
- */
- virtual void AttachIT(void (*fptr)(void)) = 0;
};
#endif /* __PRESSURE_SENSOR_CLASS_H */
--- a/Components/Interfaces/TempSensor.h Mon Jun 08 15:36:36 2015 +0200
+++ b/Components/Interfaces/TempSensor.h Mon Jun 08 17:22:35 2015 +0200
@@ -41,41 +41,15 @@
#define __TEMP_SENSOR_CLASS_H
/* Includes ------------------------------------------------------------------*/
-#include <stdint.h>
+#include <GenericSensor.h>
/* Classes ------------------------------------------------------------------*/
/** An abstract class for Temperature sensors
*/
-class TempSensor
+class TempSensor : public GenericSensor
{
public:
/**
- * @brief Initialization of temperature sensor
- * @param[out] ptr Pointer to device specific initalization structure
- * @return 0 in case of success, an error code otherwise
- */
- virtual int Init(void *ptr) = 0;
-
- /**
- * @brief Enter sensor shutdown mode
- * @return 0 in case of success, an error code otherwise
- */
- virtual int PowerOff(void) = 0;
-
- /**
- * @brief Get ID of temperature 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(uint8_t *id) = 0;
-
- /**
- * @brief Reset sensor
- * @return 0 in case of success, an error code otherwise
- */
- virtual int Reset(void) = 0;
-
- /**
* @brief Get current temperature in degrees Celsius [°C]
* @param[out] pfData Pointer to where to store temperature to
* @return 0 in case of success, an error code otherwise
@@ -97,18 +71,6 @@
*pfData = ((celsius * 1.8f) + 32.0f);
return 0;
}
-
- virtual void ConfigIT(uint16_t) = 0;
- virtual void EnableIT(uint8_t) = 0;
- virtual void DisableIT(uint8_t) = 0;
- virtual uint8_t ITStatus(uint16_t, uint16_t) = 0;
- virtual void ClearIT(uint16_t, uint16_t) = 0;
-
- /**
- * @brief Attach a function to be called when an interrupt occurs
- * @param[in] fptr A pointer to a void function, or 0 to set as none
- */
- virtual void AttachIT(void (*fptr)(void)) = 0;
};
#endif /* __TEMP_SENSOR_CLASS_H */
--- a/Components/hts221/hts221_class.h Mon Jun 08 15:36:36 2015 +0200
+++ b/Components/hts221/hts221_class.h Mon Jun 08 17:22:35 2015 +0200
@@ -79,12 +79,6 @@
return HTS221_RebootCmd();
}
- virtual void ConfigIT(uint16_t) { /* not yet implemented */ }
- virtual void EnableIT(uint8_t) { /* not yet implemented */ }
- virtual void DisableIT(uint8_t) { /* not yet implemented */ }
- virtual uint8_t ITStatus(uint16_t, uint16_t) { /* not yet implemented */ return 0; }
- virtual void ClearIT(uint16_t, uint16_t) { /* not yet implemented */ }
-
virtual int GetHumidity(float *pfData) {
return HTS221_GetHumidity(pfData);
}
@@ -93,6 +87,11 @@
return HTS221_GetTemperature(pfData);
}
+ virtual void ConfigIT(uint16_t) { /* not yet implemented */ }
+ virtual void EnableIT(uint8_t) { /* not yet implemented */ }
+ virtual void DisableIT(uint8_t) { /* not yet implemented */ }
+ virtual uint8_t ITStatus(uint16_t, uint16_t) { /* not yet implemented */ return 0; }
+ virtual void ClearIT(uint16_t, uint16_t) { /* not yet implemented */ }
virtual void AttachIT(void (*fptr)(void)) { /* not yet implemented */ }
protected:
--- a/Components/lis3mdl/lis3mdl_class.h Mon Jun 08 15:36:36 2015 +0200
+++ b/Components/lis3mdl/lis3mdl_class.h Mon Jun 08 17:22:35 2015 +0200
@@ -76,6 +76,16 @@
return LIS3MDL_M_GetAxesRaw(pData);
}
+ virtual int PowerOff(void) { /* not yet implemented */ return 0; }
+ virtual int Reset(void) { /* not yet implemented */ return 0; }
+
+ virtual void ConfigIT(uint16_t) { /* not yet implemented */ }
+ virtual void EnableIT(uint8_t) { /* not yet implemented */ }
+ virtual void DisableIT(uint8_t) { /* not yet implemented */ }
+ virtual uint8_t ITStatus(uint16_t, uint16_t) { /* not yet implemented */ return 0; }
+ virtual void ClearIT(uint16_t, uint16_t) { /* not yet implemented */ }
+ virtual void AttachIT(void (*fptr)(void)) { /* not yet implemented */ }
+
protected:
/*** Methods ***/
MAGNETO_StatusTypeDef LIS3MDL_Init(MAGNETO_InitTypeDef *LIS3MDL_Init);
--- a/Components/lsm6ds0/lsm6ds0_class.h Mon Jun 08 15:36:36 2015 +0200
+++ b/Components/lsm6ds0/lsm6ds0_class.h Mon Jun 08 17:22:35 2015 +0200
@@ -125,6 +125,16 @@
return LSM6DS0_G_Set_FS(fullScale);
}
+ virtual int PowerOff(void) { /* not yet implemented */ return 0; }
+ virtual int Reset(void) { /* not yet implemented */ return 0; }
+
+ virtual void ConfigIT(uint16_t) { /* not yet implemented */ }
+ virtual void EnableIT(uint8_t) { /* not yet implemented */ }
+ virtual void DisableIT(uint8_t) { /* not yet implemented */ }
+ virtual uint8_t ITStatus(uint16_t, uint16_t) { /* not yet implemented */ return 0; }
+ virtual void ClearIT(uint16_t, uint16_t) { /* not yet implemented */ }
+ virtual void AttachIT(void (*fptr)(void)) { /* not yet implemented */ }
+
protected:
/*** Methods ***/
IMU_6AXES_StatusTypeDef LSM6DS0_Init(IMU_6AXES_InitTypeDef *LSM6DS0_Init);
--- a/Components/lsm6ds3/lsm6ds3_class.h Mon Jun 08 15:36:36 2015 +0200
+++ b/Components/lsm6ds3/lsm6ds3_class.h Mon Jun 08 17:22:35 2015 +0200
@@ -138,6 +138,16 @@
return LSM6DS3_Get_Status_Free_Fall_Detection(status);
}
+ virtual int PowerOff(void) { /* not yet implemented */ return 0; }
+ virtual int Reset(void) { /* not yet implemented */ return 0; }
+
+ virtual void ConfigIT(uint16_t) { /* not yet implemented */ }
+ virtual void EnableIT(uint8_t) { /* not yet implemented */ }
+ virtual void DisableIT(uint8_t) { /* not yet implemented */ }
+ virtual uint8_t ITStatus(uint16_t, uint16_t) { /* not yet implemented */ return 0; }
+ virtual void ClearIT(uint16_t, uint16_t) { /* not yet implemented */ }
+ virtual void AttachIT(void (*fptr)(void)) { /* not yet implemented */ }
+
protected:
/*** Methods ***/
IMU_6AXES_StatusTypeDef LSM6DS3_Init(IMU_6AXES_InitTypeDef *LSM6DS3_Init);
--- a/x_nucleo_iks01a1.cpp Mon Jun 08 15:36:36 2015 +0200
+++ b/x_nucleo_iks01a1.cpp Mon Jun 08 17:22:35 2015 +0200
@@ -190,7 +190,7 @@
uint8_t xg_id = 0;
/* Check presence */
- if((gyro_lsm6ds3 != NULL) ||
+ if((gyro_lsm6ds3 != NULL) || // by default do not instantiate two gyroscopes
(gyro_lsm6ds0->ReadID(&xg_id) != IMU_6AXES_OK) ||
(xg_id != I_AM_LSM6DS0_XG))
{
