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.
Dependencies: X_NUCLEO_IKS01A2 mbed
Fork of HelloWorld_IKS01A2 by
Revision 2:f23b144da50a, committed 2016-08-19
- Comitter:
- cparata
- Date:
- Fri Aug 19 12:13:37 2016 +0000
- Parent:
- 1:4c13def99152
- Child:
- 3:2199488c9e4b
- Commit message:
- Add interfaces for all components
Changed in this revision
--- a/X_NUCLEO_IKS01A2/Components/HTS221Sensor/HTS221Sensor.cpp Fri Aug 12 13:57:55 2016 +0000
+++ b/X_NUCLEO_IKS01A2/Components/HTS221Sensor/HTS221Sensor.cpp Fri Aug 19 12:13:37 2016 +0000
@@ -52,24 +52,7 @@
*/
HTS221Sensor::HTS221Sensor(DevI2C &i2c) : dev_i2c(i2c)
{
- address = HTS221_I2C_ADDRESS;
-
- /* Power down the device */
- if ( HTS221_DeActivate( (void *)this ) == HTS221_ERROR )
- {
- return;
- }
-
- /* Enable BDU */
- if ( HTS221_Set_BduMode( (void *)this, HTS221_ENABLE ) == HTS221_ERROR )
- {
- return;
- }
-
- if(SetODR(1.0f) == HTS221_STATUS_ERROR)
- {
- return;
- }
+ address = HTS221_I2C_ADDRESS;
};
@@ -79,149 +62,166 @@
*/
HTS221Sensor::HTS221Sensor(DevI2C &i2c, uint8_t address) : dev_i2c(i2c), address(address)
{
- /* Power down the device */
+
+};
+
+/**
+ * @brief Initializing the component.
+ * @param[in] init pointer to device specific initalization structure.
+ * @retval "0" in case of success, an error code otherwise.
+ */
+int HTS221Sensor::Init(void *init)
+{
+ /* Power down the device */
if ( HTS221_DeActivate( (void *)this ) == HTS221_ERROR )
{
- return;
+ return 1;
}
/* Enable BDU */
if ( HTS221_Set_BduMode( (void *)this, HTS221_ENABLE ) == HTS221_ERROR )
{
- return;
+ return 1;
}
- if(SetODR(1.0f) == HTS221_STATUS_ERROR)
+ if(Set_ODR(1.0f) == 1)
{
- return;
+ return 1;
}
-};
+
+ return 0;
+}
/**
* @brief Enable HTS221
- * @retval HTS221_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-HTS221StatusTypeDef HTS221Sensor::Enable(void)
+int HTS221Sensor::Enable(void)
{
/* Power up the device */
if ( HTS221_Activate( (void *)this ) == HTS221_ERROR )
{
- return HTS221_STATUS_ERROR;
+ return 1;
}
- return HTS221_STATUS_OK;
+ return 0;
}
/**
* @brief Disable HTS221
- * @retval HTS221_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-HTS221StatusTypeDef HTS221Sensor::Disable(void)
+int HTS221Sensor::Disable(void)
{
/* Power up the device */
if ( HTS221_DeActivate( (void *)this ) == HTS221_ERROR )
{
- return HTS221_STATUS_ERROR;
+ return 1;
}
- return HTS221_STATUS_OK;
+ return 0;
}
/**
* @brief Read ID address of HTS221
- * @param ht_id the pointer where the ID of the device is stored
- * @retval HTS221_STATUS_OK in case of success, an error code otherwise
+ * @param id the pointer where the ID of the device is stored
+ * @retval 0 in case of success, an error code otherwise
*/
-HTS221StatusTypeDef HTS221Sensor::ReadID(uint8_t *ht_id)
+int HTS221Sensor::ReadID(uint8_t *id)
{
+ if(!id)
+ {
+ return 1;
+ }
+
/* Read WHO AM I register */
- if ( HTS221_Get_DeviceID( (void *)this, ht_id ) == HTS221_ERROR )
+ if ( HTS221_Get_DeviceID( (void *)this, id ) == HTS221_ERROR )
{
- return HTS221_STATUS_ERROR;
+ return 1;
}
- return HTS221_STATUS_OK;
+ return 0;
}
/**
* @brief Reboot memory content of HTS221
* @param None
- * @retval HTS221_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-HTS221StatusTypeDef HTS221Sensor::Reset(void)
+int HTS221Sensor::Reset(void)
{
uint8_t tmpreg;
/* Read CTRL_REG2 register */
- if (ReadReg(HTS221_CTRL_REG2, &tmpreg) != HTS221_STATUS_OK)
+ if (ReadReg(HTS221_CTRL_REG2, &tmpreg) != 0)
{
- return HTS221_STATUS_ERROR;
+ return 1;
}
/* Enable or Disable the reboot memory */
tmpreg |= (0x01 << HTS221_BOOT_BIT);
/* Write value to MEMS CTRL_REG2 regsister */
- if (WriteReg(HTS221_CTRL_REG2, tmpreg) != HTS221_STATUS_OK)
+ if (WriteReg(HTS221_CTRL_REG2, tmpreg) != 0)
{
- return HTS221_STATUS_ERROR;
+ return 1;
}
- return HTS221_STATUS_OK;
+ return 0;
}
/**
* @brief Read HTS221 output register, and calculate the humidity
* @param pfData the pointer to data output
- * @retval HTS221_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-HTS221StatusTypeDef HTS221Sensor::GetHumidity(float* pfData)
+int HTS221Sensor::GetHumidity(float* pfData)
{
uint16_t uint16data = 0;
/* Read data from HTS221. */
if ( HTS221_Get_Humidity( (void *)this, &uint16data ) == HTS221_ERROR )
{
- return HTS221_STATUS_ERROR;
+ return 1;
}
*pfData = ( float )uint16data / 10.0f;
- return HTS221_STATUS_OK;
+ return 0;
}
/**
* @brief Read HTS221 output register, and calculate the temperature
* @param pfData the pointer to data output
- * @retval HTS221_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-HTS221StatusTypeDef HTS221Sensor::GetTemperature(float* pfData)
+int HTS221Sensor::GetTemperature(float* pfData)
{
int16_t int16data = 0;
/* Read data from HTS221. */
if ( HTS221_Get_Temperature( (void *)this, &int16data ) == HTS221_ERROR )
{
- return HTS221_STATUS_ERROR;
+ return 1;
}
*pfData = ( float )int16data / 10.0f;
- return HTS221_STATUS_OK;
+ return 0;
}
/**
* @brief Read HTS221 output register, and calculate the humidity
* @param odr the pointer to the output data rate
- * @retval HTS221_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-HTS221StatusTypeDef HTS221Sensor::GetODR(float* odr)
+int HTS221Sensor::Get_ODR(float* odr)
{
HTS221_Odr_et odr_low_level;
if ( HTS221_Get_Odr( (void *)this, &odr_low_level ) == HTS221_ERROR )
{
- return HTS221_STATUS_ERROR;
+ return 1;
}
switch( odr_low_level )
@@ -240,18 +240,18 @@
break;
default :
*odr = -1.0f;
- return HTS221_STATUS_ERROR;
+ return 1;
}
- return HTS221_STATUS_OK;
+ return 0;
}
/**
* @brief Set ODR
* @param odr the output data rate to be set
- * @retval HTS221_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-HTS221StatusTypeDef HTS221Sensor::SetODR(float odr)
+int HTS221Sensor::Set_ODR(float odr)
{
HTS221_Odr_et new_odr;
@@ -261,10 +261,10 @@
if ( HTS221_Set_Odr( (void *)this, new_odr ) == HTS221_ERROR )
{
- return HTS221_STATUS_ERROR;
+ return 1;
}
- return HTS221_STATUS_OK;
+ return 0;
}
@@ -272,36 +272,36 @@
* @brief Read the data from register
* @param reg register address
* @param data register data
- * @retval HTS221_STATUS_OK in case of success
- * @retval HTS221_STATUS_ERROR in case of failure
+ * @retval 0 in case of success
+ * @retval 1 in case of failure
*/
-HTS221StatusTypeDef HTS221Sensor::ReadReg( uint8_t reg, uint8_t *data )
+int HTS221Sensor::ReadReg( uint8_t reg, uint8_t *data )
{
if ( HTS221_ReadReg( (void *)this, reg, 1, data ) == HTS221_ERROR )
{
- return HTS221_STATUS_ERROR;
+ return 1;
}
- return HTS221_STATUS_OK;
+ return 0;
}
/**
* @brief Write the data to register
* @param reg register address
* @param data register data
- * @retval HTS221_STATUS_OK in case of success
- * @retval HTS221_STATUS_ERROR in case of failure
+ * @retval 0 in case of success
+ * @retval 1 in case of failure
*/
-HTS221StatusTypeDef HTS221Sensor::WriteReg( uint8_t reg, uint8_t data )
+int HTS221Sensor::WriteReg( uint8_t reg, uint8_t data )
{
if ( HTS221_WriteReg( (void *)this, reg, 1, &data ) == HTS221_ERROR )
{
- return HTS221_STATUS_ERROR;
+ return 1;
}
- return HTS221_STATUS_OK;
+ return 0;
}
uint8_t HTS221_IO_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite )
--- a/X_NUCLEO_IKS01A2/Components/HTS221Sensor/HTS221Sensor.h Fri Aug 12 13:57:55 2016 +0000
+++ b/X_NUCLEO_IKS01A2/Components/HTS221Sensor/HTS221Sensor.h Fri Aug 19 12:13:37 2016 +0000
@@ -46,37 +46,32 @@
#include "DevI2C.h"
#include "HTS221_Driver.h"
-
+#include "HumiditySensor.h"
+#include "TempSensor.h"
-/* Typedefs ------------------------------------------------------------------*/
-typedef enum
-{
- HTS221_STATUS_OK = 0,
- HTS221_STATUS_ERROR,
- HTS221_STATUS_TIMEOUT,
- HTS221_STATUS_NOT_IMPLEMENTED
-} HTS221StatusTypeDef;
/* Class Declaration ---------------------------------------------------------*/
/**
* Abstract class of an HTS221 Humidity and Temperature sensor.
*/
-class HTS221Sensor
+class HTS221Sensor : public HumiditySensor, public TempSensor
{
public:
- HTS221Sensor (DevI2C &i2c);
- HTS221Sensor (DevI2C &i2c, uint8_t address);
- HTS221StatusTypeDef Enable (void);
- HTS221StatusTypeDef Disable (void);
- HTS221StatusTypeDef ReadID (uint8_t *ht_id);
- HTS221StatusTypeDef Reset (void);
- HTS221StatusTypeDef GetHumidity (float *pfData);
- HTS221StatusTypeDef GetTemperature (float *pfData);
- HTS221StatusTypeDef GetODR (float *odr);
- HTS221StatusTypeDef SetODR (float odr);
- HTS221StatusTypeDef ReadReg (uint8_t reg, uint8_t *data);
- HTS221StatusTypeDef WriteReg (uint8_t reg, uint8_t data);
+
+ HTS221Sensor(DevI2C &i2c);
+ HTS221Sensor(DevI2C &i2c, uint8_t address);
+ virtual int Init(void *init);
+ virtual int ReadID(uint8_t *id);
+ virtual int GetHumidity(float *pfData);
+ virtual int GetTemperature(float *pfData);
+ int Enable(void);
+ int Disable(void);
+ int Reset(void);
+ int Get_ODR(float *odr);
+ int Set_ODR(float odr);
+ int ReadReg(uint8_t reg, uint8_t *data);
+ int WriteReg(uint8_t reg, uint8_t data);
/**
* @brief Utility function to read data.
* @param pBuffer: pointer to data to be read.
@@ -108,6 +103,7 @@
/* Configuration */
uint8_t address;
+
};
#ifdef __cplusplus
--- a/X_NUCLEO_IKS01A2/Components/LPS22HBSensor/LPS22HBSensor.cpp Fri Aug 12 13:57:55 2016 +0000
+++ b/X_NUCLEO_IKS01A2/Components/LPS22HBSensor/LPS22HBSensor.cpp Fri Aug 19 12:13:37 2016 +0000
@@ -53,44 +53,6 @@
LPS22HBSensor::LPS22HBSensor(DevI2C &i2c) : dev_i2c(i2c)
{
address = LPS22HB_ADDRESS_HIGH;
-
- if ( LPS22HB_Set_PowerMode( (void *)this, LPS22HB_LowPower) == LPS22HB_ERROR )
- {
- return;
- }
-
- /* Power down the device */
- if ( LPS22HB_Set_Odr( (void *)this, LPS22HB_ODR_ONE_SHOT ) == LPS22HB_ERROR )
- {
- return;
- }
-
- /* Disable low-pass filter on LPS22HB pressure data */
- if( LPS22HB_Set_LowPassFilter( (void *)this, LPS22HB_DISABLE) == LPS22HB_ERROR )
- {
- return;
- }
-
- /* Set low-pass filter cutoff configuration*/
- if( LPS22HB_Set_LowPassFilterCutoff( (void *)this, LPS22HB_ODR_9) == LPS22HB_ERROR )
- {
- return;
- }
-
- /* Set block data update mode */
- if ( LPS22HB_Set_Bdu( (void *)this, LPS22HB_BDU_NO_UPDATE ) == LPS22HB_ERROR )
- {
- return;
- }
-
- /* Set automatic increment for multi-byte read/write */
- if( LPS22HB_Set_AutomaticIncrementRegAddress( (void *)this, LPS22HB_ENABLE) == LPS22HB_ERROR )
- {
- return;
- }
-
- isEnabled = 0;
- Last_ODR = 25.0f;
};
@@ -100,180 +62,192 @@
*/
LPS22HBSensor::LPS22HBSensor(DevI2C &i2c, uint8_t address) : dev_i2c(i2c), address(address)
{
+
+};
+
+/**
+ * @brief Initializing the component.
+ * @param[in] init pointer to device specific initalization structure.
+ * @retval "0" in case of success, an error code otherwise.
+ */
+int LPS22HBSensor::Init(void *init)
+{
if ( LPS22HB_Set_PowerMode( (void *)this, LPS22HB_LowPower) == LPS22HB_ERROR )
{
- return;
+ return 1;
}
/* Power down the device */
if ( LPS22HB_Set_Odr( (void *)this, LPS22HB_ODR_ONE_SHOT ) == LPS22HB_ERROR )
{
- return;
+ return 1;
}
/* Disable low-pass filter on LPS22HB pressure data */
if( LPS22HB_Set_LowPassFilter( (void *)this, LPS22HB_DISABLE) == LPS22HB_ERROR )
{
- return;
+ return 1;
}
/* Set low-pass filter cutoff configuration*/
if( LPS22HB_Set_LowPassFilterCutoff( (void *)this, LPS22HB_ODR_9) == LPS22HB_ERROR )
{
- return;
+ return 1;
}
/* Set block data update mode */
if ( LPS22HB_Set_Bdu( (void *)this, LPS22HB_BDU_NO_UPDATE ) == LPS22HB_ERROR )
{
- return;
+ return 1;
}
/* Set automatic increment for multi-byte read/write */
if( LPS22HB_Set_AutomaticIncrementRegAddress( (void *)this, LPS22HB_ENABLE) == LPS22HB_ERROR )
{
- return;
+ return 1;
}
isEnabled = 0;
Last_ODR = 25.0f;
-};
+
+ return 0;
+}
/**
* @brief Enable LPS22HB
- * @retval LPS22HB_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LPS22HBStatusTypeDef LPS22HBSensor::Enable(void)
+int LPS22HBSensor::Enable(void)
{
/* Check if the component is already enabled */
if ( isEnabled == 1 )
{
- return LPS22HB_STATUS_OK;
+ return 0;
}
- if(SetODR_When_Enabled(Last_ODR) == LPS22HB_STATUS_ERROR)
+ if(Set_ODR_When_Enabled(Last_ODR) == 1)
{
- return LPS22HB_STATUS_ERROR;
+ return 1;
}
isEnabled = 1;
- return LPS22HB_STATUS_OK;
+ return 0;
}
/**
* @brief Disable LPS22HB
- * @retval LPS22HB_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LPS22HBStatusTypeDef LPS22HBSensor::Disable(void)
+int LPS22HBSensor::Disable(void)
{
/* Check if the component is already disabled */
if ( isEnabled == 0 )
{
- return LPS22HB_STATUS_OK;
+ return 0;
}
/* Power down the device */
if ( LPS22HB_Set_Odr( (void *)this, LPS22HB_ODR_ONE_SHOT ) == LPS22HB_ERROR )
{
- return LPS22HB_STATUS_ERROR;
+ return 1;
}
isEnabled = 0;
- return LPS22HB_STATUS_OK;
+ return 0;
}
/**
* @brief Read ID address of LPS22HB
- * @param ht_id the pointer where the ID of the device is stored
- * @retval LPS22HB_STATUS_OK in case of success, an error code otherwise
+ * @param id the pointer where the ID of the device is stored
+ * @retval 0 in case of success, an error code otherwise
*/
-LPS22HBStatusTypeDef LPS22HBSensor::ReadID(uint8_t *p_id)
+int LPS22HBSensor::ReadID(uint8_t *id)
{
- if(!p_id)
+ if(!id)
{
- return LPS22HB_STATUS_ERROR;
+ return 1;
}
/* Read WHO AM I register */
- if ( LPS22HB_Get_DeviceID( (void *)this, p_id ) == LPS22HB_ERROR )
+ if ( LPS22HB_Get_DeviceID( (void *)this, id ) == LPS22HB_ERROR )
{
- return LPS22HB_STATUS_ERROR;
+ return 1;
}
- return LPS22HB_STATUS_OK;
+ return 0;
}
/**
* @brief Reboot memory content of LPS22HB
* @param None
- * @retval LPS22HB_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LPS22HBStatusTypeDef LPS22HBSensor::Reset(void)
+int LPS22HBSensor::Reset(void)
{
/* Read WHO AM I register */
if ( LPS22HB_MemoryBoot((void *)this) == LPS22HB_ERROR )
{
- return LPS22HB_STATUS_ERROR;
+ return 1;
}
- return LPS22HB_STATUS_OK;
+ return 0;
}
/**
* @brief Read LPS22HB output register, and calculate the pressure in mbar
* @param pfData the pressure value in mbar
- * @retval LPS22HB_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LPS22HBStatusTypeDef LPS22HBSensor::GetPressure(float* pfData)
+int LPS22HBSensor::GetPressure(float* pfData)
{
int32_t int32data = 0;
/* Read data from LPS22HB. */
if ( LPS22HB_Get_Pressure( (void *)this, &int32data ) == LPS22HB_ERROR )
{
- return LPS22HB_STATUS_ERROR;
+ return 1;
}
*pfData = ( float )int32data / 100.0f;
- return LPS22HB_STATUS_OK;
+ return 0;
}
/**
* @brief Read LPS22HB output register, and calculate the temperature
* @param pfData the temperature value
- * @retval LPS22HB_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LPS22HBStatusTypeDef LPS22HBSensor::GetTemperature(float *pfData)
+int LPS22HBSensor::GetTemperature(float *pfData)
{
int16_t int16data = 0;
/* Read data from LPS22HB. */
if ( LPS22HB_Get_Temperature( (void *)this, &int16data ) == LPS22HB_ERROR )
{
- return LPS22HB_STATUS_ERROR;
+ return 1;
}
*pfData = ( float )int16data / 10.0f;
- return LPS22HB_STATUS_OK;
+ return 0;
}
/**
* @brief Read LPS22HB output data rate
* @param odr the pointer to the output data rate
- * @retval LPS22HB_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LPS22HBStatusTypeDef LPS22HBSensor::GetODR(float* odr)
+int LPS22HBSensor::Get_ODR(float* odr)
{
LPS22HB_Odr_et odr_low_level;
if ( LPS22HB_Get_Odr( (void *)this, &odr_low_level ) == LPS22HB_ERROR )
{
- return LPS22HB_STATUS_ERROR;
+ return 1;
}
switch( odr_low_level )
@@ -298,45 +272,45 @@
break;
default:
*odr = -1.0f;
- return LPS22HB_STATUS_ERROR;
+ return 1;
}
- return LPS22HB_STATUS_OK;
+ return 0;
}
/**
* @brief Set ODR
* @param odr the output data rate to be set
- * @retval LPS22HB_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LPS22HBStatusTypeDef LPS22HBSensor::SetODR(float odr)
+int LPS22HBSensor::Set_ODR(float odr)
{
if(isEnabled == 1)
{
- if(SetODR_When_Enabled(odr) == LPS22HB_STATUS_ERROR)
+ if(Set_ODR_When_Enabled(odr) == 1)
{
- return LPS22HB_STATUS_ERROR;
+ return 1;
}
}
else
{
- if(SetODR_When_Disabled(odr) == LPS22HB_STATUS_ERROR)
+ if(Set_ODR_When_Disabled(odr) == 1)
{
- return LPS22HB_STATUS_ERROR;
+ return 1;
}
}
- return LPS22HB_STATUS_OK;
+ return 0;
}
/**
* @brief Set the LPS22HB sensor output data rate when enabled
* @param odr the functional output data rate to be set
- * @retval LPS22HB_STATUS_OK in case of success
- * @retval LPS22HB_STATUS_ERROR in case of failure
+ * @retval 0 in case of success
+ * @retval 1 in case of failure
*/
-LPS22HBStatusTypeDef LPS22HBSensor::SetODR_When_Enabled( float odr )
+int LPS22HBSensor::Set_ODR_When_Enabled( float odr )
{
LPS22HB_Odr_et new_odr;
@@ -348,24 +322,24 @@
if ( LPS22HB_Set_Odr( (void *)this, new_odr ) == LPS22HB_ERROR )
{
- return LPS22HB_STATUS_ERROR;
+ return 1;
}
- if ( GetODR( &Last_ODR ) == LPS22HB_STATUS_ERROR )
+ if ( Get_ODR( &Last_ODR ) == 1 )
{
- return LPS22HB_STATUS_ERROR;
+ return 1;
}
- return LPS22HB_STATUS_OK;
+ return 0;
}
/**
* @brief Set the LPS22HB sensor output data rate when disabled
* @param odr the functional output data rate to be set
- * @retval LPS22HB_STATUS_OK in case of success
- * @retval LPS22HB_STATUS_ERROR in case of failure
+ * @retval 0 in case of success
+ * @retval 1 in case of failure
*/
-LPS22HBStatusTypeDef LPS22HBSensor::SetODR_When_Disabled( float odr )
+int LPS22HBSensor::Set_ODR_When_Disabled( float odr )
{
Last_ODR = ( odr <= 1.0f ) ? 1.0f
: ( odr <= 10.0f ) ? 10.0f
@@ -373,7 +347,7 @@
: ( odr <= 50.0f ) ? 50.0f
: 75.0f;
- return LPS22HB_STATUS_OK;
+ return 0;
}
@@ -381,36 +355,36 @@
* @brief Read the data from register
* @param reg register address
* @param data register data
- * @retval LPS22HB_STATUS_OK in case of success
- * @retval LPS22HB_STATUS_ERROR in case of failure
+ * @retval 0 in case of success
+ * @retval 1 in case of failure
*/
-LPS22HBStatusTypeDef LPS22HBSensor::ReadReg( uint8_t reg, uint8_t *data )
+int LPS22HBSensor::ReadReg( uint8_t reg, uint8_t *data )
{
if ( LPS22HB_ReadReg( (void *)this, reg, 1, data ) == LPS22HB_ERROR )
{
- return LPS22HB_STATUS_ERROR;
+ return 1;
}
- return LPS22HB_STATUS_OK;
+ return 0;
}
/**
* @brief Write the data to register
* @param reg register address
* @param data register data
- * @retval LPS22HB_STATUS_OK in case of success
- * @retval LPS22HB_STATUS_ERROR in case of failure
+ * @retval 0 in case of success
+ * @retval 1 in case of failure
*/
-LPS22HBStatusTypeDef LPS22HBSensor::WriteReg( uint8_t reg, uint8_t data )
+int LPS22HBSensor::WriteReg( uint8_t reg, uint8_t data )
{
if ( LPS22HB_WriteReg( (void *)this, reg, 1, &data ) == LPS22HB_ERROR )
{
- return LPS22HB_STATUS_ERROR;
+ return 1;
}
- return LPS22HB_STATUS_OK;
+ return 0;
}
--- a/X_NUCLEO_IKS01A2/Components/LPS22HBSensor/LPS22HBSensor.h Fri Aug 12 13:57:55 2016 +0000
+++ b/X_NUCLEO_IKS01A2/Components/LPS22HBSensor/LPS22HBSensor.h Fri Aug 19 12:13:37 2016 +0000
@@ -46,37 +46,30 @@
#include "DevI2C.h"
#include "LPS22HB_Driver.h"
-
-/* Typedefs ------------------------------------------------------------------*/
-typedef enum
-{
- LPS22HB_STATUS_OK = 0,
- LPS22HB_STATUS_ERROR,
- LPS22HB_STATUS_TIMEOUT,
- LPS22HB_STATUS_NOT_IMPLEMENTED
-} LPS22HBStatusTypeDef;
-
+#include "PressureSensor.h"
+#include "TempSensor.h"
/* Class Declaration ---------------------------------------------------------*/
/**
* Abstract class of an LPS22HB Pressure sensor.
*/
-class LPS22HBSensor
+class LPS22HBSensor : public PressureSensor, public TempSensor
{
public:
- LPS22HBSensor (DevI2C &i2c);
- LPS22HBSensor (DevI2C &i2c, uint8_t address);
- LPS22HBStatusTypeDef Enable (void);
- LPS22HBStatusTypeDef Disable (void);
- LPS22HBStatusTypeDef ReadID (uint8_t *ht_id);
- LPS22HBStatusTypeDef Reset (void);
- LPS22HBStatusTypeDef GetPressure (float *pfData);
- LPS22HBStatusTypeDef GetTemperature (float *pfData);
- LPS22HBStatusTypeDef GetODR (float *odr);
- LPS22HBStatusTypeDef SetODR (float odr);
- LPS22HBStatusTypeDef ReadReg (uint8_t reg, uint8_t *data);
- LPS22HBStatusTypeDef WriteReg (uint8_t reg, uint8_t data);
+ LPS22HBSensor(DevI2C &i2c);
+ LPS22HBSensor(DevI2C &i2c, uint8_t address);
+ virtual int Init(void *init);
+ virtual int ReadID(uint8_t *id);
+ virtual int GetPressure(float *pfData);
+ virtual int GetTemperature(float *pfData);
+ int Enable(void);
+ int Disable(void);
+ int Reset(void);
+ int Get_ODR(float *odr);
+ int Set_ODR(float odr);
+ int ReadReg(uint8_t reg, uint8_t *data);
+ int WriteReg(uint8_t reg, uint8_t data);
/**
* @brief Utility function to read data.
@@ -103,8 +96,8 @@
}
private:
- LPS22HBStatusTypeDef SetODR_When_Enabled(float odr);
- LPS22HBStatusTypeDef SetODR_When_Disabled(float odr);
+ int Set_ODR_When_Enabled(float odr);
+ int Set_ODR_When_Disabled(float odr);
/* Helper classes. */
DevI2C &dev_i2c;
--- a/X_NUCLEO_IKS01A2/Components/LSM303AGRSensor/LSM303AGR_ACC_Sensor.cpp Fri Aug 12 13:57:55 2016 +0000
+++ b/X_NUCLEO_IKS01A2/Components/LSM303AGRSensor/LSM303AGR_ACC_Sensor.cpp Fri Aug 19 12:13:37 2016 +0000
@@ -52,51 +52,6 @@
LSM303AGR_ACC_Sensor::LSM303AGR_ACC_Sensor(DevI2C &i2c) : dev_i2c(i2c)
{
address = LSM303AGR_ACC_I2C_ADDRESS;
-
- /* Enable BDU */
- if ( LSM303AGR_ACC_W_BlockDataUpdate( (void *)this, LSM303AGR_ACC_BDU_ENABLED ) == MEMS_ERROR )
- {
- return;
- }
-
- /* FIFO mode selection */
- if ( LSM303AGR_ACC_W_FifoMode( (void *)this, LSM303AGR_ACC_FM_BYPASS ) == MEMS_ERROR )
- {
- return;
- }
-
- /* Output data rate selection - power down. */
- if ( LSM303AGR_ACC_W_ODR( (void *)this, LSM303AGR_ACC_ODR_DO_PWR_DOWN ) == MEMS_ERROR )
- {
- return;
- }
-
- /* Full scale selection. */
- if ( SetFS( 2.0f ) == LSM303AGR_ACC_STATUS_ERROR )
- {
- return;
- }
-
- /* Enable axes. */
- if ( LSM303AGR_ACC_W_XEN( (void *)this, LSM303AGR_ACC_XEN_ENABLED ) == MEMS_ERROR )
- {
- return;
- }
-
- if ( LSM303AGR_ACC_W_YEN ( (void *)this, LSM303AGR_ACC_YEN_ENABLED ) == MEMS_ERROR )
- {
- return;
- }
-
- if ( LSM303AGR_ACC_W_ZEN ( (void *)this, LSM303AGR_ACC_ZEN_ENABLED ) == MEMS_ERROR )
- {
- return;
- }
-
- /* Select default output data rate. */
- Last_ODR = 100.0f;
-
- isEnabled = 0;
};
/** Constructor
@@ -105,138 +60,150 @@
*/
LSM303AGR_ACC_Sensor::LSM303AGR_ACC_Sensor(DevI2C &i2c, uint8_t address) : dev_i2c(i2c), address(address)
{
+
+};
+
+/**
+ * @brief Initializing the component.
+ * @param[in] init pointer to device specific initalization structure.
+ * @retval "0" in case of success, an error code otherwise.
+ */
+int LSM303AGR_ACC_Sensor::Init(void *init)
+{
/* Enable BDU */
if ( LSM303AGR_ACC_W_BlockDataUpdate( (void *)this, LSM303AGR_ACC_BDU_ENABLED ) == MEMS_ERROR )
{
- return;
+ return 1;
}
/* FIFO mode selection */
if ( LSM303AGR_ACC_W_FifoMode( (void *)this, LSM303AGR_ACC_FM_BYPASS ) == MEMS_ERROR )
{
- return;
+ return 1;
}
/* Output data rate selection - power down. */
if ( LSM303AGR_ACC_W_ODR( (void *)this, LSM303AGR_ACC_ODR_DO_PWR_DOWN ) == MEMS_ERROR )
{
- return;
+ return 1;
}
/* Full scale selection. */
- if ( SetFS( 2.0f ) == LSM303AGR_ACC_STATUS_ERROR )
+ if ( Set_X_FS( 2.0f ) == 1 )
{
- return;
+ return 1;
}
/* Enable axes. */
if ( LSM303AGR_ACC_W_XEN( (void *)this, LSM303AGR_ACC_XEN_ENABLED ) == MEMS_ERROR )
{
- return;
+ return 1;
}
if ( LSM303AGR_ACC_W_YEN ( (void *)this, LSM303AGR_ACC_YEN_ENABLED ) == MEMS_ERROR )
{
- return;
+ return 1;
}
if ( LSM303AGR_ACC_W_ZEN ( (void *)this, LSM303AGR_ACC_ZEN_ENABLED ) == MEMS_ERROR )
{
- return;
+ return 1;
}
/* Select default output data rate. */
Last_ODR = 100.0f;
isEnabled = 0;
-};
+
+ return 0;
+}
/**
* @brief Enable LSM303AGR Accelerator
- * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::Enable(void)
+int LSM303AGR_ACC_Sensor::Enable(void)
{
/* Check if the component is already enabled */
if ( isEnabled == 1 )
{
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/* Output data rate selection. */
- if ( SetODR_When_Enabled( Last_ODR ) == LSM303AGR_ACC_STATUS_ERROR )
+ if ( Set_X_ODR_When_Enabled( Last_ODR ) == 1 )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
isEnabled = 1;
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/**
* @brief Disable LSM303AGR Accelerator
- * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::Disable(void)
+int LSM303AGR_ACC_Sensor::Disable(void)
{
/* Check if the component is already disabled */
if ( isEnabled == 0 )
{
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/* Store actual output data rate. */
- if ( GetODR( &Last_ODR ) == LSM303AGR_ACC_STATUS_ERROR )
+ if ( Get_X_ODR( &Last_ODR ) == 1 )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
/* Output data rate selection - power down. */
if ( LSM303AGR_ACC_W_ODR( (void *)this, LSM303AGR_ACC_ODR_DO_PWR_DOWN ) == MEMS_ERROR )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
isEnabled = 0;
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/**
* @brief Read ID of LSM303AGR Accelerometer
* @param p_id the pointer where the ID of the device is stored
- * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::ReadID(uint8_t *p_id)
+int LSM303AGR_ACC_Sensor::ReadID(uint8_t *id)
{
- if(!p_id)
+ if(!id)
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
/* Read WHO AM I register */
- if ( LSM303AGR_ACC_R_WHO_AM_I( (void *)this, p_id ) == MEMS_ERROR )
+ if ( LSM303AGR_ACC_R_WHO_AM_I( (void *)this, id ) == MEMS_ERROR )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/**
* @brief Read data from LSM303AGR Accelerometer
* @param pData the pointer where the accelerometer data are stored
- * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetAxes(int32_t *pData)
+int LSM303AGR_ACC_Sensor::Get_X_Axes(int32_t *pData)
{
int data[3];
/* Read data from LSM303AGR. */
if ( !LSM303AGR_ACC_Get_Acceleration((void *)this, data) )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
/* Calculate the data. */
@@ -244,15 +211,15 @@
pData[1] = (int32_t)data[1];
pData[2] = (int32_t)data[2];
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/**
* @brief Read Accelerometer Sensitivity
* @param pfData the pointer where the accelerometer sensitivity is stored
- * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetSensitivity(float *pfData)
+int LSM303AGR_ACC_Sensor::Get_X_Sensitivity(float *pfData)
{
LSM303AGR_ACC_LPEN_t lp_value;
LSM303AGR_ACC_HR_t hr_value;
@@ -260,47 +227,47 @@
/* Read low power flag */
if( LSM303AGR_ACC_R_LOWPWR_EN( (void *)this, &lp_value ) == MEMS_ERROR )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
/* Read high performance flag */
if( LSM303AGR_ACC_R_HiRes( (void *)this, &hr_value ) == MEMS_ERROR )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
if( lp_value == LSM303AGR_ACC_LPEN_DISABLED && hr_value == LSM303AGR_ACC_HR_DISABLED )
{
/* Normal Mode */
- return GetSensitivity_Normal_Mode( pfData );
+ return Get_X_Sensitivity_Normal_Mode( pfData );
} else if ( lp_value == LSM303AGR_ACC_LPEN_ENABLED && hr_value == LSM303AGR_ACC_HR_DISABLED )
{
/* Low Power Mode */
- return GetSensitivity_LP_Mode( pfData );
+ return Get_X_Sensitivity_LP_Mode( pfData );
} else if ( lp_value == LSM303AGR_ACC_LPEN_DISABLED && hr_value == LSM303AGR_ACC_HR_ENABLED )
{
/* High Resolution Mode */
- return GetSensitivity_HR_Mode( pfData );
+ return Get_X_Sensitivity_HR_Mode( pfData );
} else
{
/* Not allowed */
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
}
/**
* @brief Read Accelerometer Sensitivity in Normal Mode
* @param sensitivity the pointer where the accelerometer sensitivity is stored
- * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetSensitivity_Normal_Mode( float *sensitivity )
+int LSM303AGR_ACC_Sensor::Get_X_Sensitivity_Normal_Mode( float *sensitivity )
{
LSM303AGR_ACC_FS_t fullScale;
/* Read actual full scale selection from sensor. */
if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fullScale ) == MEMS_ERROR )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
/* Store the sensitivity based on actual full scale. */
@@ -320,25 +287,25 @@
break;
default:
*sensitivity = -1.0f;
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/**
* @brief Read Accelerometer Sensitivity in LP Mode
* @param sensitivity the pointer where the accelerometer sensitivity is stored
- * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetSensitivity_LP_Mode( float *sensitivity )
+int LSM303AGR_ACC_Sensor::Get_X_Sensitivity_LP_Mode( float *sensitivity )
{
LSM303AGR_ACC_FS_t fullScale;
/* Read actual full scale selection from sensor. */
if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fullScale ) == MEMS_ERROR )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
/* Store the sensitivity based on actual full scale. */
@@ -358,25 +325,25 @@
break;
default:
*sensitivity = -1.0f;
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/**
* @brief Read Accelerometer Sensitivity in HR Mode
* @param sensitivity the pointer where the accelerometer sensitivity is stored
- * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetSensitivity_HR_Mode( float *sensitivity )
+int LSM303AGR_ACC_Sensor::Get_X_Sensitivity_HR_Mode( float *sensitivity )
{
LSM303AGR_ACC_FS_t fullScale;
/* Read actual full scale selection from sensor. */
if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fullScale ) == MEMS_ERROR )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
/* Store the sensitivity based on actual full scale. */
@@ -396,18 +363,18 @@
break;
default:
*sensitivity = -1.0f;
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/**
* @brief Read raw data from LSM303AGR Accelerometer
* @param pData the pointer where the accelerometer raw data are stored
- * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetAxesRaw(int16_t *pData)
+int LSM303AGR_ACC_Sensor::Get_X_AxesRaw(int16_t *pData)
{
uint8_t regValue[6] = {0, 0, 0, 0, 0, 0};
u8_t shift = 0;
@@ -416,11 +383,11 @@
/* Determine which operational mode the acc is set */
if(!LSM303AGR_ACC_R_HiRes( (void *)this, &hr )) {
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
if(!LSM303AGR_ACC_R_LOWPWR_EN( (void *)this, &lp )) {
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
if (lp == LSM303AGR_ACC_LPEN_ENABLED && hr == LSM303AGR_ACC_HR_DISABLED) {
@@ -433,13 +400,13 @@
/* op mode is HR 12-bit */
shift = 4;
} else {
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
/* Read output registers from LSM303AGR_ACC_GYRO_OUTX_L_XL to LSM303AGR_ACC_GYRO_OUTZ_H_XL. */
if (!LSM303AGR_ACC_Get_Raw_Acceleration( (void *)this, ( uint8_t* )regValue ))
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
/* Format the data. */
@@ -447,21 +414,21 @@
pData[1] = ( ( ( ( ( int16_t )regValue[3] ) << 8 ) + ( int16_t )regValue[2] ) >> shift );
pData[2] = ( ( ( ( ( int16_t )regValue[5] ) << 8 ) + ( int16_t )regValue[4] ) >> shift );
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/**
* @brief Read LSM303AGR Accelerometer output data rate
* @param odr the pointer to the output data rate
- * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetODR(float* odr)
+int LSM303AGR_ACC_Sensor::Get_X_ODR(float* odr)
{
LSM303AGR_ACC_ODR_t odr_low_level;
if ( LSM303AGR_ACC_R_ODR( (void *)this, &odr_low_level ) == MEMS_ERROR )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
switch( odr_low_level )
@@ -492,43 +459,43 @@
break;
default:
*odr = -1.0f;
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/**
* @brief Set ODR
* @param odr the output data rate to be set
- * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::SetODR(float odr)
+int LSM303AGR_ACC_Sensor::Set_X_ODR(float odr)
{
if(isEnabled == 1)
{
- if(SetODR_When_Enabled(odr) == LSM303AGR_ACC_STATUS_ERROR)
+ if(Set_X_ODR_When_Enabled(odr) == 1)
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
}
else
{
- if(SetODR_When_Disabled(odr) == LSM303AGR_ACC_STATUS_ERROR)
+ if(Set_X_ODR_When_Disabled(odr) == 1)
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
}
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/**
* @brief Set ODR when enabled
* @param odr the output data rate to be set
- * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::SetODR_When_Enabled(float odr)
+int LSM303AGR_ACC_Sensor::Set_X_ODR_When_Enabled(float odr)
{
LSM303AGR_ACC_ODR_t new_odr;
@@ -542,18 +509,18 @@
if ( LSM303AGR_ACC_W_ODR( (void *)this, new_odr ) == MEMS_ERROR )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/**
* @brief Set ODR when disabled
* @param odr the output data rate to be set
- * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::SetODR_When_Disabled(float odr)
+int LSM303AGR_ACC_Sensor::Set_X_ODR_When_Disabled(float odr)
{
Last_ODR = ( odr <= 1.0f ) ? 1.0f
: ( odr <= 10.0f ) ? 10.0f
@@ -563,22 +530,22 @@
: ( odr <= 200.0f ) ? 200.0f
: 400.0f;
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/**
* @brief Read LSM303AGR Accelerometer full scale
* @param fullScale the pointer to the full scale
- * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::GetFS(float* fullScale)
+int LSM303AGR_ACC_Sensor::Get_X_FS(float* fullScale)
{
LSM303AGR_ACC_FS_t fs_low_level;
if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fs_low_level ) == MEMS_ERROR )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
switch( fs_low_level )
@@ -597,18 +564,18 @@
break;
default:
*fullScale = -1.0f;
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/**
* @brief Set full scale
* @param fullScale the full scale to be set
- * @retval LSM303AGR_ACC_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::SetFS(float fullScale)
+int LSM303AGR_ACC_Sensor::Set_X_FS(float fullScale)
{
LSM303AGR_ACC_FS_t new_fs;
@@ -619,46 +586,46 @@
if ( LSM303AGR_ACC_W_FullScale( (void *)this, new_fs ) == MEMS_ERROR )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/**
* @brief Read accelerometer data from register
* @param reg register address
* @param data register data
- * @retval LSM303AGR_ACC_STATUS_OK in case of success
- * @retval LSM303AGR_ACC_STATUS_ERROR in case of failure
+ * @retval 0 in case of success
+ * @retval 1 in case of failure
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::ReadReg( uint8_t reg, uint8_t *data )
+int LSM303AGR_ACC_Sensor::ReadReg( uint8_t reg, uint8_t *data )
{
if ( LSM303AGR_ACC_ReadReg( (void *)this, reg, data ) == MEMS_ERROR )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
/**
* @brief Write accelerometer data to register
* @param reg register address
* @param data register data
- * @retval LSM303AGR_ACC_STATUS_OK in case of success
- * @retval LSM303AGR_ACC_STATUS_ERROR in case of failure
+ * @retval 0 in case of success
+ * @retval 1 in case of failure
*/
-LSM303AGR_ACC_StatusTypeDef LSM303AGR_ACC_Sensor::WriteReg( uint8_t reg, uint8_t data )
+int LSM303AGR_ACC_Sensor::WriteReg( uint8_t reg, uint8_t data )
{
if ( LSM303AGR_ACC_WriteReg( (void *)this, reg, data ) == MEMS_ERROR )
{
- return LSM303AGR_ACC_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_ACC_STATUS_OK;
+ return 0;
}
uint8_t LSM303AGR_ACC_IO_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite )
--- a/X_NUCLEO_IKS01A2/Components/LSM303AGRSensor/LSM303AGR_ACC_Sensor.h Fri Aug 12 13:57:55 2016 +0000
+++ b/X_NUCLEO_IKS01A2/Components/LSM303AGRSensor/LSM303AGR_ACC_Sensor.h Fri Aug 19 12:13:37 2016 +0000
@@ -46,6 +46,7 @@
#include "DevI2C.h"
#include "LSM303AGR_ACC_driver.h"
+#include "MotionSensor.h"
/* Defines -------------------------------------------------------------------*/
#define LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_NORMAL_MODE 3.900f /**< Sensitivity value for 2 g full scale and normal mode [mg/LSB] */
@@ -61,40 +62,30 @@
#define LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_HIGH_RESOLUTION_MODE 11.720f /**< Sensitivity value for 16 g full scale and high resolution mode [mg/LSB] */
#define LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_LOW_POWER_MODE 187.580f /**< Sensitivity value for 16 g full scale and low power mode [mg/LSB] */
-
-/* Typedefs ------------------------------------------------------------------*/
-typedef enum
-{
- LSM303AGR_ACC_STATUS_OK = 0,
- LSM303AGR_ACC_STATUS_ERROR,
- LSM303AGR_ACC_STATUS_TIMEOUT,
- LSM303AGR_ACC_STATUS_NOT_IMPLEMENTED
-} LSM303AGR_ACC_StatusTypeDef;
-
-
/* Class Declaration ---------------------------------------------------------*/
/**
* Abstract class of an LSM303AGR Inertial Measurement Unit (IMU) 6 axes
* sensor.
*/
-class LSM303AGR_ACC_Sensor
+class LSM303AGR_ACC_Sensor : public MotionSensor
{
public:
- LSM303AGR_ACC_Sensor (DevI2C &i2c);
- LSM303AGR_ACC_Sensor (DevI2C &i2c, uint8_t address);
- LSM303AGR_ACC_StatusTypeDef Enable (void);
- LSM303AGR_ACC_StatusTypeDef Disable (void);
- LSM303AGR_ACC_StatusTypeDef ReadID (uint8_t *p_id);
- LSM303AGR_ACC_StatusTypeDef GetAxes (int32_t *pData);
- LSM303AGR_ACC_StatusTypeDef GetSensitivity (float *pfData);
- LSM303AGR_ACC_StatusTypeDef GetAxesRaw (int16_t *pData);
- LSM303AGR_ACC_StatusTypeDef GetODR (float *odr);
- LSM303AGR_ACC_StatusTypeDef SetODR (float odr);
- LSM303AGR_ACC_StatusTypeDef GetFS (float *fullScale);
- LSM303AGR_ACC_StatusTypeDef SetFS (float fullScale);
- LSM303AGR_ACC_StatusTypeDef ReadReg (uint8_t reg, uint8_t *data);
- LSM303AGR_ACC_StatusTypeDef WriteReg (uint8_t reg, uint8_t data);
+ LSM303AGR_ACC_Sensor(DevI2C &i2c);
+ LSM303AGR_ACC_Sensor(DevI2C &i2c, uint8_t address);
+ virtual int Init(void *init);
+ virtual int ReadID(uint8_t *id);
+ virtual int Get_X_Axes(int32_t *pData);
+ virtual int Get_X_AxesRaw(int16_t *pData);
+ virtual int Get_X_Sensitivity(float *pfData);
+ virtual int Get_X_ODR(float *odr);
+ virtual int Set_X_ODR(float odr);
+ virtual int Get_X_FS(float *fullScale);
+ virtual int Set_X_FS(float fullScale);
+ int Enable(void);
+ int Disable(void);
+ int ReadReg(uint8_t reg, uint8_t *data);
+ int WriteReg(uint8_t reg, uint8_t data);
/**
* @brief Utility function to read data.
@@ -121,11 +112,11 @@
}
private:
- LSM303AGR_ACC_StatusTypeDef SetODR_When_Enabled(float odr);
- LSM303AGR_ACC_StatusTypeDef SetODR_When_Disabled(float odr);
- LSM303AGR_ACC_StatusTypeDef GetSensitivity_Normal_Mode( float *sensitivity );
- LSM303AGR_ACC_StatusTypeDef GetSensitivity_LP_Mode( float *sensitivity );
- LSM303AGR_ACC_StatusTypeDef GetSensitivity_HR_Mode( float *sensitivity );
+ int Set_X_ODR_When_Enabled(float odr);
+ int Set_X_ODR_When_Disabled(float odr);
+ int Get_X_Sensitivity_Normal_Mode(float *sensitivity );
+ int Get_X_Sensitivity_LP_Mode(float *sensitivity );
+ int Get_X_Sensitivity_HR_Mode(float *sensitivity );
/* Helper classes. */
DevI2C &dev_i2c;
--- a/X_NUCLEO_IKS01A2/Components/LSM303AGRSensor/LSM303AGR_MAG_Sensor.cpp Fri Aug 12 13:57:55 2016 +0000
+++ b/X_NUCLEO_IKS01A2/Components/LSM303AGRSensor/LSM303AGR_MAG_Sensor.cpp Fri Aug 19 12:13:37 2016 +0000
@@ -53,33 +53,6 @@
LSM303AGR_MAG_Sensor::LSM303AGR_MAG_Sensor(DevI2C &i2c) : dev_i2c(i2c)
{
address = LSM303AGR_MAG_I2C_ADDRESS;
-
- /* Operating mode selection - power down */
- if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_IDLE1_MODE ) == MEMS_ERROR )
- {
- return;
- }
-
- /* Enable BDU */
- if ( LSM303AGR_MAG_W_BDU( (void *)this, LSM303AGR_MAG_BDU_ENABLED ) == MEMS_ERROR )
- {
- return;
- }
-
- if ( SetODR( 100.0f ) == LSM303AGR_MAG_STATUS_ERROR )
- {
- return;
- }
-
- if ( SetFS( 50.0f ) == LSM303AGR_MAG_STATUS_ERROR )
- {
- return;
- }
-
- if ( LSM303AGR_MAG_W_ST( (void *)this, LSM303AGR_MAG_ST_DISABLED ) == MEMS_ERROR )
- {
- return;
- }
};
/** Constructor
@@ -88,105 +61,117 @@
*/
LSM303AGR_MAG_Sensor::LSM303AGR_MAG_Sensor(DevI2C &i2c, uint8_t address) : dev_i2c(i2c), address(address)
{
+
+};
+
+/**
+ * @brief Initializing the component.
+ * @param[in] init pointer to device specific initalization structure.
+ * @retval "0" in case of success, an error code otherwise.
+ */
+int LSM303AGR_MAG_Sensor::Init(void *init)
+{
/* Operating mode selection - power down */
if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_IDLE1_MODE ) == MEMS_ERROR )
{
- return;
+ return 1;
}
/* Enable BDU */
if ( LSM303AGR_MAG_W_BDU( (void *)this, LSM303AGR_MAG_BDU_ENABLED ) == MEMS_ERROR )
{
- return;
+ return 1;
}
- if ( SetODR( 100.0f ) == LSM303AGR_MAG_STATUS_ERROR )
+ if ( Set_M_ODR( 100.0f ) == 1 )
{
- return;
+ return 1;
}
- if ( SetFS( 50.0f ) == LSM303AGR_MAG_STATUS_ERROR )
+ if ( Set_M_FS( 50.0f ) == 1 )
{
- return;
+ return 1;
}
if ( LSM303AGR_MAG_W_ST( (void *)this, LSM303AGR_MAG_ST_DISABLED ) == MEMS_ERROR )
{
- return;
+ return 1;
}
-};
+
+ return 0;
+}
/**
* @brief Enable LSM303AGR magnetometer
- * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::Enable(void)
+int LSM303AGR_MAG_Sensor::Enable(void)
{
/* Operating mode selection */
if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_CONTINUOS_MODE ) == MEMS_ERROR )
{
- return LSM303AGR_MAG_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_MAG_STATUS_OK;
+ return 0;
}
/**
* @brief Disable LSM303AGR magnetometer
- * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::Disable(void)
+int LSM303AGR_MAG_Sensor::Disable(void)
{
/* Operating mode selection - power down */
if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_IDLE1_MODE ) == MEMS_ERROR )
{
- return LSM303AGR_MAG_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_MAG_STATUS_OK;
+ return 0;
}
/**
* @brief Read ID of LSM303AGR Magnetometer
* @param p_id the pointer where the ID of the device is stored
- * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::ReadID(uint8_t *p_id)
+int LSM303AGR_MAG_Sensor::ReadID(uint8_t *id)
{
- if(!p_id)
+ if(!id)
{
- return LSM303AGR_MAG_STATUS_ERROR;
+ return 1;
}
/* Read WHO AM I register */
- if ( LSM303AGR_MAG_R_WHO_AM_I( (void *)this, p_id ) == MEMS_ERROR )
+ if ( LSM303AGR_MAG_R_WHO_AM_I( (void *)this, id ) == MEMS_ERROR )
{
- return LSM303AGR_MAG_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_MAG_STATUS_OK;
+ return 0;
}
/**
* @brief Read data from LSM303AGR Magnetometer
* @param pData the pointer where the magnetometer data are stored
- * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetAxes(int32_t *pData)
+int LSM303AGR_MAG_Sensor::Get_M_Axes(int32_t *pData)
{
int16_t pDataRaw[3];
float sensitivity = 0;
/* Read raw data from LSM303AGR output register. */
- if ( GetAxesRaw( pDataRaw ) == LSM303AGR_MAG_STATUS_ERROR )
+ if ( Get_M_AxesRaw( pDataRaw ) == 1 )
{
- return LSM303AGR_MAG_STATUS_ERROR;
+ return 1;
}
/* Get LSM303AGR actual sensitivity. */
- if ( GetSensitivity( &sensitivity ) == LSM303AGR_MAG_STATUS_ERROR )
+ if ( Get_M_Sensitivity( &sensitivity ) == 1 )
{
- return LSM303AGR_MAG_STATUS_ERROR;
+ return 1;
}
/* Calculate the data. */
@@ -194,27 +179,27 @@
pData[1] = ( int32_t )( pDataRaw[1] * sensitivity );
pData[2] = ( int32_t )( pDataRaw[2] * sensitivity );
- return LSM303AGR_MAG_STATUS_OK;
+ return 0;
}
/**
* @brief Read Magnetometer Sensitivity
* @param pfData the pointer where the magnetometer sensitivity is stored
- * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetSensitivity(float *pfData)
+int LSM303AGR_MAG_Sensor::Get_M_Sensitivity(float *pfData)
{
*pfData = 1.5f;
- return LSM303AGR_MAG_STATUS_OK;
+ return 0;
}
/**
* @brief Read raw data from LSM303AGR Magnetometer
* @param pData the pointer where the magnetomer raw data are stored
- * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetAxesRaw(int16_t *pData)
+int LSM303AGR_MAG_Sensor::Get_M_AxesRaw(int16_t *pData)
{
uint8_t regValue[6] = {0, 0, 0, 0, 0, 0};
int16_t *regValueInt16;
@@ -222,7 +207,7 @@
/* Read output registers from LSM303AGR_MAG_OUTX_L to LSM303AGR_MAG_OUTZ_H. */
if ( LSM303AGR_MAG_Get_Raw_Magnetic( (void *)this, regValue ) == MEMS_ERROR )
{
- return LSM303AGR_MAG_STATUS_ERROR;
+ return 1;
}
regValueInt16 = (int16_t *)regValue;
@@ -232,21 +217,21 @@
pData[1] = regValueInt16[1];
pData[2] = regValueInt16[2];
- return LSM303AGR_MAG_STATUS_OK;
+ return 0;
}
/**
* @brief Read LSM303AGR Magnetometer output data rate
* @param odr the pointer to the output data rate
- * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetODR(float* odr)
+int LSM303AGR_MAG_Sensor::Get_M_ODR(float* odr)
{
LSM303AGR_MAG_ODR_t odr_low_level;
if ( LSM303AGR_MAG_R_ODR( (void *)this, &odr_low_level ) == MEMS_ERROR )
{
- return LSM303AGR_MAG_STATUS_ERROR;
+ return 1;
}
switch( odr_low_level )
@@ -265,17 +250,17 @@
break;
default:
*odr = -1.000f;
- return LSM303AGR_MAG_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_MAG_STATUS_OK;
+ return 0;
}
/**
* @brief Set ODR
* @param odr the output data rate to be set
- * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::SetODR(float odr)
+int LSM303AGR_MAG_Sensor::Set_M_ODR(float odr)
{
LSM303AGR_MAG_ODR_t new_odr;
@@ -286,33 +271,33 @@
if ( LSM303AGR_MAG_W_ODR( (void *)this, new_odr ) == MEMS_ERROR )
{
- return LSM303AGR_MAG_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_MAG_STATUS_OK;
+ return 0;
}
/**
* @brief Read LSM303AGR Magnetometer full scale
* @param fullScale the pointer to the output data rate
- * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetFS(float* fullScale)
+int LSM303AGR_MAG_Sensor::Get_M_FS(float* fullScale)
{
*fullScale = 50.0f;
- return LSM303AGR_MAG_STATUS_OK;
+ return 0;
}
/**
* @brief Set full scale
* @param fullScale the full scale to be set
- * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::SetFS(float fullScale)
+int LSM303AGR_MAG_Sensor::Set_M_FS(float fullScale)
{
- return LSM303AGR_MAG_STATUS_OK;
+ return 0;
}
@@ -320,17 +305,17 @@
* @brief Read magnetometer data from register
* @param reg register address
* @param data register data
- * @retval LSM303AGR_MAG_STATUS_OK in case of success
- * @retval LSM303AGR_MAG_STATUS_ERROR in case of failure
+ * @retval 0 in case of success
+ * @retval 1 in case of failure
*/
-LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::ReadReg( uint8_t reg, uint8_t *data )
+int LSM303AGR_MAG_Sensor::ReadReg( uint8_t reg, uint8_t *data )
{
if ( LSM303AGR_MAG_ReadReg( (void *)this, reg, data ) == MEMS_ERROR )
{
- return LSM303AGR_MAG_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_MAG_STATUS_OK;
+ return 0;
}
@@ -338,17 +323,17 @@
* @brief Write magnetometer data to register
* @param reg register address
* @param data register data
- * @retval LSM303AGR_MAG_STATUS_OK in case of success
- * @retval LSM303AGR_MAG_STATUS_ERROR in case of failure
+ * @retval 0 in case of success
+ * @retval 1 in case of failure
*/
-LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::WriteReg( uint8_t reg, uint8_t data )
+int LSM303AGR_MAG_Sensor::WriteReg( uint8_t reg, uint8_t data )
{
if ( LSM303AGR_MAG_WriteReg( (void *)this, reg, data ) == MEMS_ERROR )
{
- return LSM303AGR_MAG_STATUS_ERROR;
+ return 1;
}
- return LSM303AGR_MAG_STATUS_OK;
+ return 0;
}
uint8_t LSM303AGR_MAG_IO_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite )
--- a/X_NUCLEO_IKS01A2/Components/LSM303AGRSensor/LSM303AGR_MAG_Sensor.h Fri Aug 12 13:57:55 2016 +0000
+++ b/X_NUCLEO_IKS01A2/Components/LSM303AGRSensor/LSM303AGR_MAG_Sensor.h Fri Aug 19 12:13:37 2016 +0000
@@ -46,15 +46,7 @@
#include "DevI2C.h"
#include "LSM303AGR_MAG_driver.h"
-
-/* Typedefs ------------------------------------------------------------------*/
-typedef enum
-{
- LSM303AGR_MAG_STATUS_OK = 0,
- LSM303AGR_MAG_STATUS_ERROR,
- LSM303AGR_MAG_STATUS_TIMEOUT,
- LSM303AGR_MAG_STATUS_NOT_IMPLEMENTED
-} LSM303AGR_MAG_StatusTypeDef;
+#include "MagneticSensor.h"
/* Class Declaration ---------------------------------------------------------*/
@@ -66,20 +58,21 @@
class LSM303AGR_MAG_Sensor
{
public:
- LSM303AGR_MAG_Sensor (DevI2C &i2c);
- LSM303AGR_MAG_Sensor (DevI2C &i2c, uint8_t address);
- LSM303AGR_MAG_StatusTypeDef Enable (void);
- LSM303AGR_MAG_StatusTypeDef Disable (void);
- LSM303AGR_MAG_StatusTypeDef ReadID (uint8_t *p_id);
- LSM303AGR_MAG_StatusTypeDef GetAxes (int32_t *pData);
- LSM303AGR_MAG_StatusTypeDef GetSensitivity (float *pfData);
- LSM303AGR_MAG_StatusTypeDef GetAxesRaw (int16_t *pData);
- LSM303AGR_MAG_StatusTypeDef GetODR (float *odr);
- LSM303AGR_MAG_StatusTypeDef SetODR (float odr);
- LSM303AGR_MAG_StatusTypeDef GetFS (float *fullScale);
- LSM303AGR_MAG_StatusTypeDef SetFS (float fullScale);
- LSM303AGR_MAG_StatusTypeDef ReadReg (uint8_t reg, uint8_t *data);
- LSM303AGR_MAG_StatusTypeDef WriteReg (uint8_t reg, uint8_t data);
+ LSM303AGR_MAG_Sensor(DevI2C &i2c);
+ LSM303AGR_MAG_Sensor(DevI2C &i2c, uint8_t address);
+ virtual int Init(void *init);
+ virtual int ReadID(uint8_t *id);
+ virtual int Get_M_Axes(int32_t *pData);
+ virtual int Get_M_AxesRaw(int16_t *pData);
+ int Enable(void);
+ int Disable(void);
+ int Get_M_Sensitivity(float *pfData);
+ int Get_M_ODR(float *odr);
+ int Set_M_ODR(float odr);
+ int Get_M_FS(float *fullScale);
+ int Set_M_FS(float fullScale);
+ int ReadReg(uint8_t reg, uint8_t *data);
+ int WriteReg(uint8_t reg, uint8_t data);
/**
* @brief Utility function to read data.
--- a/X_NUCLEO_IKS01A2/Components/LSM6DSLSensor/LSM6DSLSensor.cpp Fri Aug 12 13:57:55 2016 +0000
+++ b/X_NUCLEO_IKS01A2/Components/LSM6DSLSensor/LSM6DSLSensor.cpp Fri Aug 19 12:13:37 2016 +0000
@@ -54,57 +54,6 @@
LSM6DSLSensor::LSM6DSLSensor(DevI2C &i2c) : dev_i2c(i2c)
{
address = LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH;
-
- /* Enable register address automatically incremented during a multiple byte
- access with a serial interface. */
- if ( LSM6DSL_ACC_GYRO_W_IF_Addr_Incr( (void *)this, LSM6DSL_ACC_GYRO_IF_INC_ENABLED ) == MEMS_ERROR )
- {
- return;
- }
-
- /* Enable BDU */
- if ( LSM6DSL_ACC_GYRO_W_BDU( (void *)this, LSM6DSL_ACC_GYRO_BDU_BLOCK_UPDATE ) == MEMS_ERROR )
- {
- return;
- }
-
- /* FIFO mode selection */
- if ( LSM6DSL_ACC_GYRO_W_FIFO_MODE( (void *)this, LSM6DSL_ACC_GYRO_FIFO_MODE_BYPASS ) == MEMS_ERROR )
- {
- return;
- }
-
- /* Output data rate selection - power down. */
- if ( LSM6DSL_ACC_GYRO_W_ODR_XL( (void *)this, LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN ) == MEMS_ERROR )
- {
- return;
- }
-
- /* Full scale selection. */
- if ( Set_X_FS( 2.0f ) == LSM6DSL_STATUS_ERROR )
- {
- return;
- }
-
- /* Output data rate selection - power down */
- if ( LSM6DSL_ACC_GYRO_W_ODR_G( (void *)this, LSM6DSL_ACC_GYRO_ODR_G_POWER_DOWN ) == MEMS_ERROR )
- {
- return;
- }
-
- /* Full scale selection. */
- if ( Set_G_FS( 2000.0f ) == LSM6DSL_STATUS_ERROR )
- {
- return;
- }
-
- X_Last_ODR = 104.0f;
-
- X_isEnabled = 0;
-
- G_Last_ODR = 104.0f;
-
- G_isEnabled = 0;
};
/** Constructor
@@ -112,48 +61,58 @@
* @param address the address of the component's instance
*/
LSM6DSLSensor::LSM6DSLSensor(DevI2C &i2c, uint8_t address) : dev_i2c(i2c), address(address)
-{
+{
+
+};
+
+/**
+ * @brief Initializing the component.
+ * @param[in] init pointer to device specific initalization structure.
+ * @retval "0" in case of success, an error code otherwise.
+ */
+int LSM6DSLSensor::Init(void *init)
+{
/* Enable register address automatically incremented during a multiple byte
access with a serial interface. */
if ( LSM6DSL_ACC_GYRO_W_IF_Addr_Incr( (void *)this, LSM6DSL_ACC_GYRO_IF_INC_ENABLED ) == MEMS_ERROR )
{
- return;
+ return 1;
}
/* Enable BDU */
if ( LSM6DSL_ACC_GYRO_W_BDU( (void *)this, LSM6DSL_ACC_GYRO_BDU_BLOCK_UPDATE ) == MEMS_ERROR )
{
- return;
+ return 1;
}
/* FIFO mode selection */
if ( LSM6DSL_ACC_GYRO_W_FIFO_MODE( (void *)this, LSM6DSL_ACC_GYRO_FIFO_MODE_BYPASS ) == MEMS_ERROR )
{
- return;
+ return 1;
}
/* Output data rate selection - power down. */
if ( LSM6DSL_ACC_GYRO_W_ODR_XL( (void *)this, LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN ) == MEMS_ERROR )
{
- return;
+ return 1;
}
/* Full scale selection. */
- if ( Set_X_FS( 2.0f ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_X_FS( 2.0f ) == 1 )
{
- return;
+ return 1;
}
/* Output data rate selection - power down */
if ( LSM6DSL_ACC_GYRO_W_ODR_G( (void *)this, LSM6DSL_ACC_GYRO_ODR_G_POWER_DOWN ) == MEMS_ERROR )
{
- return;
+ return 1;
}
/* Full scale selection. */
- if ( Set_G_FS( 2000.0f ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_G_FS( 2000.0f ) == 1 )
{
- return;
+ return 1;
}
X_Last_ODR = 104.0f;
@@ -163,153 +122,155 @@
G_Last_ODR = 104.0f;
G_isEnabled = 0;
-};
+
+ return 0;
+}
/**
* @brief Enable LSM6DSL Accelerator
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_X(void)
+int LSM6DSLSensor::Enable_X(void)
{
/* Check if the component is already enabled */
if ( X_isEnabled == 1 )
{
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/* Output data rate selection. */
- if ( Set_X_ODR_When_Enabled( X_Last_ODR ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_X_ODR_When_Enabled( X_Last_ODR ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
X_isEnabled = 1;
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Enable LSM6DSL Gyroscope
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_G(void)
+int LSM6DSLSensor::Enable_G(void)
{
/* Check if the component is already enabled */
if ( G_isEnabled == 1 )
{
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/* Output data rate selection. */
- if ( Set_G_ODR_When_Enabled( G_Last_ODR ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_G_ODR_When_Enabled( G_Last_ODR ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
G_isEnabled = 1;
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Disable LSM6DSL Accelerator
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_X(void)
+int LSM6DSLSensor::Disable_X(void)
{
/* Check if the component is already disabled */
if ( X_isEnabled == 0 )
{
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/* Store actual output data rate. */
- if ( Get_X_ODR( &X_Last_ODR ) == LSM6DSL_STATUS_ERROR )
+ if ( Get_X_ODR( &X_Last_ODR ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Output data rate selection - power down. */
if ( LSM6DSL_ACC_GYRO_W_ODR_XL( (void *)this, LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
X_isEnabled = 0;
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Disable LSM6DSL Gyroscope
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_G(void)
+int LSM6DSLSensor::Disable_G(void)
{
/* Check if the component is already disabled */
if ( G_isEnabled == 0 )
{
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/* Store actual output data rate. */
- if ( Get_G_ODR( &G_Last_ODR ) == LSM6DSL_STATUS_ERROR )
+ if ( Get_G_ODR( &G_Last_ODR ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Output data rate selection - power down */
if ( LSM6DSL_ACC_GYRO_W_ODR_G( (void *)this, LSM6DSL_ACC_GYRO_ODR_G_POWER_DOWN ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
G_isEnabled = 0;
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Read ID of LSM6DSL Accelerometer and Gyroscope
* @param p_id the pointer where the ID of the device is stored
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::ReadID(uint8_t *p_id)
+int LSM6DSLSensor::ReadID(uint8_t *id)
{
- if(!p_id)
+ if(!id)
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Read WHO AM I register */
- if ( LSM6DSL_ACC_GYRO_R_WHO_AM_I( (void *)this, p_id ) == MEMS_ERROR )
+ if ( LSM6DSL_ACC_GYRO_R_WHO_AM_I( (void *)this, id ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Read data from LSM6DSL Accelerometer
* @param pData the pointer where the accelerometer data are stored
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_X_Axes(int32_t *pData)
+int LSM6DSLSensor::Get_X_Axes(int32_t *pData)
{
int16_t dataRaw[3];
float sensitivity = 0;
/* Read raw data from LSM6DSL output register. */
- if ( Get_X_AxesRaw( dataRaw ) == LSM6DSL_STATUS_ERROR )
+ if ( Get_X_AxesRaw( dataRaw ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Get LSM6DSL actual sensitivity. */
- if ( Get_X_Sensitivity( &sensitivity ) == LSM6DSL_STATUS_ERROR )
+ if ( Get_X_Sensitivity( &sensitivity ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Calculate the data. */
@@ -317,29 +278,29 @@
pData[1] = ( int32_t )( dataRaw[1] * sensitivity );
pData[2] = ( int32_t )( dataRaw[2] * sensitivity );
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Read data from LSM6DSL Gyroscope
* @param pData the pointer where the gyroscope data are stored
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_G_Axes(int32_t *pData)
+int LSM6DSLSensor::Get_G_Axes(int32_t *pData)
{
int16_t dataRaw[3];
float sensitivity = 0;
/* Read raw data from LSM6DSL output register. */
- if ( Get_G_AxesRaw( dataRaw ) == LSM6DSL_STATUS_ERROR )
+ if ( Get_G_AxesRaw( dataRaw ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Get LSM6DSL actual sensitivity. */
- if ( Get_G_Sensitivity( &sensitivity ) == LSM6DSL_STATUS_ERROR )
+ if ( Get_G_Sensitivity( &sensitivity ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Calculate the data. */
@@ -347,22 +308,22 @@
pData[1] = ( int32_t )( dataRaw[1] * sensitivity );
pData[2] = ( int32_t )( dataRaw[2] * sensitivity );
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Read Accelerometer Sensitivity
* @param pfData the pointer where the accelerometer sensitivity is stored
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_X_Sensitivity(float *pfData)
+int LSM6DSLSensor::Get_X_Sensitivity(float *pfData)
{
LSM6DSL_ACC_GYRO_FS_XL_t fullScale;
/* Read actual full scale selection from sensor. */
if ( LSM6DSL_ACC_GYRO_R_FS_XL( (void *)this, &fullScale ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Store the sensitivity based on actual full scale. */
@@ -382,18 +343,18 @@
break;
default:
*pfData = -1.0f;
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Read Gyroscope Sensitivity
* @param pfData the pointer where the gyroscope sensitivity is stored
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_G_Sensitivity(float *pfData)
+int LSM6DSLSensor::Get_G_Sensitivity(float *pfData)
{
LSM6DSL_ACC_GYRO_FS_125_t fullScale125;
LSM6DSL_ACC_GYRO_FS_G_t fullScale;
@@ -401,7 +362,7 @@
/* Read full scale 125 selection from sensor. */
if ( LSM6DSL_ACC_GYRO_R_FS_125( (void *)this, &fullScale125 ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
if ( fullScale125 == LSM6DSL_ACC_GYRO_FS_125_ENABLED )
@@ -415,7 +376,7 @@
/* Read actual full scale selection from sensor. */
if ( LSM6DSL_ACC_GYRO_R_FS_G( (void *)this, &fullScale ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Store the sensitivity based on actual full scale. */
@@ -435,26 +396,26 @@
break;
default:
*pfData = -1.0f;
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Read raw data from LSM6DSL Accelerometer
* @param pData the pointer where the accelerometer raw data are stored
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_X_AxesRaw(int16_t *pData)
+int LSM6DSLSensor::Get_X_AxesRaw(int16_t *pData)
{
uint8_t regValue[6] = {0, 0, 0, 0, 0, 0};
/* Read output registers from LSM6DSL_ACC_GYRO_OUTX_L_XL to LSM6DSL_ACC_GYRO_OUTZ_H_XL. */
if ( LSM6DSL_ACC_GYRO_GetRawAccData( (void *)this, regValue ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Format the data. */
@@ -462,22 +423,22 @@
pData[1] = ( ( ( ( int16_t )regValue[3] ) << 8 ) + ( int16_t )regValue[2] );
pData[2] = ( ( ( ( int16_t )regValue[5] ) << 8 ) + ( int16_t )regValue[4] );
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Read raw data from LSM6DSL Gyroscope
* @param pData the pointer where the gyroscope raw data are stored
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_G_AxesRaw(int16_t *pData)
+int LSM6DSLSensor::Get_G_AxesRaw(int16_t *pData)
{
uint8_t regValue[6] = {0, 0, 0, 0, 0, 0};
/* Read output registers from LSM6DSL_ACC_GYRO_OUTX_L_G to LSM6DSL_ACC_GYRO_OUTZ_H_G. */
if ( LSM6DSL_ACC_GYRO_GetRawGyroData( (void *)this, regValue ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Format the data. */
@@ -485,21 +446,21 @@
pData[1] = ( ( ( ( int16_t )regValue[3] ) << 8 ) + ( int16_t )regValue[2] );
pData[2] = ( ( ( ( int16_t )regValue[5] ) << 8 ) + ( int16_t )regValue[4] );
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Read LSM6DSL Accelerometer output data rate
* @param odr the pointer to the output data rate
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_X_ODR(float* odr)
+int LSM6DSLSensor::Get_X_ODR(float* odr)
{
LSM6DSL_ACC_GYRO_ODR_XL_t odr_low_level;
if ( LSM6DSL_ACC_GYRO_R_ODR_XL( (void *)this, &odr_low_level ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( odr_low_level )
@@ -539,24 +500,24 @@
break;
default:
*odr = -1.0f;
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Read LSM6DSL Gyroscope output data rate
* @param odr the pointer to the output data rate
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_G_ODR(float* odr)
+int LSM6DSLSensor::Get_G_ODR(float* odr)
{
LSM6DSL_ACC_GYRO_ODR_G_t odr_low_level;
if ( LSM6DSL_ACC_GYRO_R_ODR_G( (void *)this, &odr_low_level ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( odr_low_level )
@@ -596,43 +557,43 @@
break;
default:
*odr = -1.0f;
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Set LSM6DSL Accelerometer output data rate
* @param odr the output data rate to be set
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Set_X_ODR(float odr)
+int LSM6DSLSensor::Set_X_ODR(float odr)
{
if(X_isEnabled == 1)
{
- if(Set_X_ODR_When_Enabled(odr) == LSM6DSL_STATUS_ERROR)
+ if(Set_X_ODR_When_Enabled(odr) == 1)
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
}
else
{
- if(Set_X_ODR_When_Disabled(odr) == LSM6DSL_STATUS_ERROR)
+ if(Set_X_ODR_When_Disabled(odr) == 1)
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Set LSM6DSL Accelerometer output data rate when enabled
* @param odr the output data rate to be set
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Set_X_ODR_When_Enabled(float odr)
+int LSM6DSLSensor::Set_X_ODR_When_Enabled(float odr)
{
LSM6DSL_ACC_GYRO_ODR_XL_t new_odr;
@@ -649,18 +610,18 @@
if ( LSM6DSL_ACC_GYRO_W_ODR_XL( (void *)this, new_odr ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Set LSM6DSL Accelerometer output data rate when disabled
* @param odr the output data rate to be set
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Set_X_ODR_When_Disabled(float odr)
+int LSM6DSLSensor::Set_X_ODR_When_Disabled(float odr)
{
X_Last_ODR = ( odr <= 13.0f ) ? 13.0f
: ( odr <= 26.0f ) ? 26.0f
@@ -673,40 +634,40 @@
: ( odr <= 3330.0f ) ? 3330.0f
: 6660.0f;
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Set LSM6DSL Gyroscope output data rate
* @param odr the output data rate to be set
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Set_G_ODR(float odr)
+int LSM6DSLSensor::Set_G_ODR(float odr)
{
if(G_isEnabled == 1)
{
- if(Set_G_ODR_When_Enabled(odr) == LSM6DSL_STATUS_ERROR)
+ if(Set_G_ODR_When_Enabled(odr) == 1)
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
}
else
{
- if(Set_G_ODR_When_Disabled(odr) == LSM6DSL_STATUS_ERROR)
+ if(Set_G_ODR_When_Disabled(odr) == 1)
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Set LSM6DSL Gyroscope output data rate when enabled
* @param odr the output data rate to be set
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Set_G_ODR_When_Enabled(float odr)
+int LSM6DSLSensor::Set_G_ODR_When_Enabled(float odr)
{
LSM6DSL_ACC_GYRO_ODR_G_t new_odr;
@@ -723,18 +684,18 @@
if ( LSM6DSL_ACC_GYRO_W_ODR_G( (void *)this, new_odr ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Set LSM6DSL Gyroscope output data rate when disabled
* @param odr the output data rate to be set
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Set_G_ODR_When_Disabled(float odr)
+int LSM6DSLSensor::Set_G_ODR_When_Disabled(float odr)
{
G_Last_ODR = ( odr <= 13.0f ) ? 13.0f
: ( odr <= 26.0f ) ? 26.0f
@@ -747,21 +708,21 @@
: ( odr <= 3330.0f ) ? 3330.0f
: 6660.0f;
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Read LSM6DSL Accelerometer full scale
* @param fullScale the pointer to the full scale
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_X_FS(float* fullScale)
+int LSM6DSLSensor::Get_X_FS(float* fullScale)
{
LSM6DSL_ACC_GYRO_FS_XL_t fs_low_level;
if ( LSM6DSL_ACC_GYRO_R_FS_XL( (void *)this, &fs_low_level ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( fs_low_level )
@@ -780,29 +741,29 @@
break;
default:
*fullScale = -1.0f;
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Read LSM6DSL Gyroscope full scale
* @param fullScale the pointer to the full scale
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_G_FS(float* fullScale)
+int LSM6DSLSensor::Get_G_FS(float* fullScale)
{
LSM6DSL_ACC_GYRO_FS_G_t fs_low_level;
LSM6DSL_ACC_GYRO_FS_125_t fs_125;
if ( LSM6DSL_ACC_GYRO_R_FS_125( (void *)this, &fs_125 ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
if ( LSM6DSL_ACC_GYRO_R_FS_G( (void *)this, &fs_low_level ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
if ( fs_125 == LSM6DSL_ACC_GYRO_FS_125_ENABLED )
@@ -828,19 +789,19 @@
break;
default:
*fullScale = -1.0f;
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Set LSM6DSL Accelerometer full scale
* @param fullScale the full scale to be set
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Set_X_FS(float fullScale)
+int LSM6DSLSensor::Set_X_FS(float fullScale)
{
LSM6DSL_ACC_GYRO_FS_XL_t new_fs;
@@ -851,18 +812,18 @@
if ( LSM6DSL_ACC_GYRO_W_FS_XL( (void *)this, new_fs ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Set LSM6DSL Gyroscope full scale
* @param fullScale the full scale to be set
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Set_G_FS(float fullScale)
+int LSM6DSLSensor::Set_G_FS(float fullScale)
{
LSM6DSL_ACC_GYRO_FS_G_t new_fs;
@@ -870,7 +831,7 @@
{
if ( LSM6DSL_ACC_GYRO_W_FS_125( (void *)this, LSM6DSL_ACC_GYRO_FS_125_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
}
else
@@ -882,127 +843,127 @@
if ( LSM6DSL_ACC_GYRO_W_FS_125( (void *)this, LSM6DSL_ACC_GYRO_FS_125_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
if ( LSM6DSL_ACC_GYRO_W_FS_G( (void *)this, new_fs ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Enable free fall detection
* @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Free_Fall_Detection(void)
+int LSM6DSLSensor::Enable_Free_Fall_Detection(void)
{
/* Output Data Rate selection */
- if(Set_X_ODR(416.0f) == LSM6DSL_STATUS_ERROR)
+ if(Set_X_ODR(416.0f) == 1)
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Full scale selection */
if ( LSM6DSL_ACC_GYRO_W_FS_XL( (void *)this, LSM6DSL_ACC_GYRO_FS_XL_2g ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* FF_DUR setting */
if ( LSM6DSL_ACC_GYRO_W_FF_Duration( (void *)this, 0x06 ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* WAKE_DUR setting */
if ( LSM6DSL_ACC_GYRO_W_WAKE_DUR( (void *)this, 0x00 ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* TIMER_HR setting */
if ( LSM6DSL_ACC_GYRO_W_TIMER_HR( (void *)this, LSM6DSL_ACC_GYRO_TIMER_HR_6_4ms ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* SLEEP_DUR setting */
if ( LSM6DSL_ACC_GYRO_W_SLEEP_DUR( (void *)this, 0x00 ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* FF_THS setting */
if ( LSM6DSL_ACC_GYRO_W_FF_THS( (void *)this, LSM6DSL_ACC_GYRO_FF_THS_312mg ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable basic Interrupts */
if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* INT1_FF setting */
if ( LSM6DSL_ACC_GYRO_W_FFEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_FF_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Disable free fall detection
* @param None
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_Free_Fall_Detection(void)
+int LSM6DSLSensor::Disable_Free_Fall_Detection(void)
{
/* INT1_FF setting */
if ( LSM6DSL_ACC_GYRO_W_FFEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_FF_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Disable basic Interrupts */
if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* FF_DUR setting */
if ( LSM6DSL_ACC_GYRO_W_FF_Duration( (void *)this, 0x00 ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* FF_THS setting */
if ( LSM6DSL_ACC_GYRO_W_FF_THS( (void *)this, LSM6DSL_ACC_GYRO_FF_THS_156mg ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Get status of free fall detection
* @param status the pointer where the status of free fall detection is stored; 0 means no detection, 1 means detection happened
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_Status_Free_Fall_Detection(uint8_t *status)
+int LSM6DSLSensor::Get_Status_Free_Fall_Detection(uint8_t *status)
{
LSM6DSL_ACC_GYRO_FF_EV_STATUS_t free_fall_status;
if ( LSM6DSL_ACC_GYRO_R_FF_EV_STATUS( (void *)this, &free_fall_status ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( free_fall_status )
@@ -1014,119 +975,119 @@
*status = 0;
break;
default:
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Set the free fall detection threshold for LSM6DSL accelerometer sensor
* @param thr the threshold to be set
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Set_Free_Fall_Threshold(uint8_t thr)
+int LSM6DSLSensor::Set_Free_Fall_Threshold(uint8_t thr)
{
if ( LSM6DSL_ACC_GYRO_W_FF_THS( (void *)this, (LSM6DSL_ACC_GYRO_FF_THS_t)thr ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Enable the pedometer feature for LSM6DSL accelerometer sensor
* @note This function sets the LSM6DSL accelerometer ODR to 26Hz and the LSM6DSL accelerometer full scale to 2g
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Pedometer(void)
+int LSM6DSLSensor::Enable_Pedometer(void)
{
/* Output Data Rate selection */
- if( Set_X_ODR(26.0f) == LSM6DSL_STATUS_ERROR )
+ if( Set_X_ODR(26.0f) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Full scale selection. */
- if( Set_X_FS(2.0f) == LSM6DSL_STATUS_ERROR )
+ if( Set_X_FS(2.0f) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Set pedometer threshold. */
- if ( Set_Pedometer_Threshold(LSM6DSL_PEDOMETER_THRESHOLD_MID_HIGH) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Pedometer_Threshold(LSM6DSL_PEDOMETER_THRESHOLD_MID_HIGH) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable embedded functionalities. */
if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable pedometer algorithm. */
if ( LSM6DSL_ACC_GYRO_W_PEDO( (void *)this, LSM6DSL_ACC_GYRO_PEDO_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable pedometer on INT1. */
if ( LSM6DSL_ACC_GYRO_W_STEP_DET_on_INT1( (void *)this, LSM6DSL_ACC_GYRO_INT1_PEDO_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Disable the pedometer feature for LSM6DSL accelerometer sensor
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_Pedometer(void)
+int LSM6DSLSensor::Disable_Pedometer(void)
{
/* Disable pedometer on INT1. */
if ( LSM6DSL_ACC_GYRO_W_STEP_DET_on_INT1( (void *)this, LSM6DSL_ACC_GYRO_INT1_PEDO_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Disable pedometer algorithm. */
if ( LSM6DSL_ACC_GYRO_W_PEDO( (void *)this, LSM6DSL_ACC_GYRO_PEDO_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Disable embedded functionalities. */
if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Reset pedometer threshold. */
- if ( Set_Pedometer_Threshold(0x0) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Pedometer_Threshold(0x0) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Get the pedometer status for LSM6DSL accelerometer sensor
* @param status the pointer to the pedometer status: 0 means no step detected, 1 means step detected
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_Status_Pedometer(uint8_t *status)
+int LSM6DSLSensor::Get_Status_Pedometer(uint8_t *status)
{
LSM6DSL_ACC_GYRO_PEDO_EV_STATUS_t pedometer_status;
if ( LSM6DSL_ACC_GYRO_R_PEDO_EV_STATUS( (void *)this, &pedometer_status ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( pedometer_status )
@@ -1138,142 +1099,142 @@
*status = 0;
break;
default:
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Get the step counter for LSM6DSL accelerometer sensor
* @param step_count the pointer to the step counter
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_Step_Counter(uint16_t *step_count)
+int LSM6DSLSensor::Get_Step_Counter(uint16_t *step_count)
{
if ( LSM6DSL_ACC_GYRO_Get_GetStepCounter( (void *)this, ( uint8_t* )step_count ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Reset of the step counter for LSM6DSL accelerometer sensor
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Reset_Step_Counter(void)
+int LSM6DSLSensor::Reset_Step_Counter(void)
{
if ( LSM6DSL_ACC_GYRO_W_PedoStepReset( (void *)this, LSM6DSL_ACC_GYRO_PEDO_RST_STEP_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
wait_ms(10);
if ( LSM6DSL_ACC_GYRO_W_PedoStepReset( (void *)this, LSM6DSL_ACC_GYRO_PEDO_RST_STEP_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Set the pedometer threshold for LSM6DSL accelerometer sensor
* @param thr the threshold to be set
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Set_Pedometer_Threshold(uint8_t thr)
+int LSM6DSLSensor::Set_Pedometer_Threshold(uint8_t thr)
{
if ( LSM6DSL_ACC_GYRO_W_PedoThreshold( (void *)this, thr ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Enable the tilt detection for LSM6DSL accelerometer sensor
* @note This function sets the LSM6DSL accelerometer ODR to 26Hz and the LSM6DSL accelerometer full scale to 2g
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Tilt_Detection(void)
+int LSM6DSLSensor::Enable_Tilt_Detection(void)
{
/* Output Data Rate selection */
- if( Set_X_ODR(26.0f) == LSM6DSL_STATUS_ERROR )
+ if( Set_X_ODR(26.0f) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Full scale selection. */
- if( Set_X_FS(2.0f) == LSM6DSL_STATUS_ERROR )
+ if( Set_X_FS(2.0f) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable embedded functionalities */
if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable tilt calculation. */
if ( LSM6DSL_ACC_GYRO_W_TILT( (void *)this, LSM6DSL_ACC_GYRO_TILT_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable tilt event on INT1. */
if ( LSM6DSL_ACC_GYRO_W_TiltEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TILT_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Disable the tilt detection for LSM6DSL accelerometer sensor
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_Tilt_Detection(void)
+int LSM6DSLSensor::Disable_Tilt_Detection(void)
{
/* Disable tilt event on INT1. */
if ( LSM6DSL_ACC_GYRO_W_TiltEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TILT_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Disable tilt calculation. */
if ( LSM6DSL_ACC_GYRO_W_TILT( (void *)this, LSM6DSL_ACC_GYRO_TILT_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Disable embedded functionalities */
if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Get the tilt detection status for LSM6DSL accelerometer sensor
* @param status the pointer to the tilt detection status: 0 means no tilt detected, 1 means tilt detected
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_Status_Tilt_Detection(uint8_t *status)
+int LSM6DSLSensor::Get_Status_Tilt_Detection(uint8_t *status)
{
LSM6DSL_ACC_GYRO_TILT_EV_STATUS_t tilt_status;
if ( LSM6DSL_ACC_GYRO_R_TILT_EV_STATUS( (void *)this, &tilt_status ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( tilt_status )
@@ -1285,103 +1246,103 @@
*status = 0;
break;
default:
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Enable the wake up detection for LSM6DSL accelerometer sensor
* @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Wake_Up_Detection(void)
+int LSM6DSLSensor::Enable_Wake_Up_Detection(void)
{
/* Output Data Rate selection */
- if( Set_X_ODR(416.0f) == LSM6DSL_STATUS_ERROR )
+ if( Set_X_ODR(416.0f) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Full scale selection. */
- if( Set_X_FS(2.0f) == LSM6DSL_STATUS_ERROR )
+ if( Set_X_FS(2.0f) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* WAKE_DUR setting */
if ( LSM6DSL_ACC_GYRO_W_WAKE_DUR( (void *)this, 0x00 ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Set wake up threshold. */
if ( LSM6DSL_ACC_GYRO_W_WK_THS( (void *)this, 0x02 ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable basic Interrupts */
if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* INT1_WU setting */
if ( LSM6DSL_ACC_GYRO_W_WUEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_WU_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Disable the wake up detection for LSM6DSL accelerometer sensor
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_Wake_Up_Detection(void)
+int LSM6DSLSensor::Disable_Wake_Up_Detection(void)
{
/* INT1_WU setting */
if ( LSM6DSL_ACC_GYRO_W_WUEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_WU_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Disable basic Interrupts */
if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* WU_DUR setting */
if ( LSM6DSL_ACC_GYRO_W_WAKE_DUR( (void *)this, 0x00 ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* WU_THS setting */
if ( LSM6DSL_ACC_GYRO_W_WK_THS( (void *)this, 0x00 ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Get the status of the wake up detection for LSM6DSL accelerometer sensor
* @param status the pointer to the status of the wake up detection: 0 means no detection, 1 means detection happened
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_Status_Wake_Up_Detection(uint8_t *status)
+int LSM6DSLSensor::Get_Status_Wake_Up_Detection(uint8_t *status)
{
LSM6DSL_ACC_GYRO_WU_EV_STATUS_t wake_up_status;
if ( LSM6DSL_ACC_GYRO_R_WU_EV_STATUS( (void *)this, &wake_up_status ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( wake_up_status )
@@ -1393,80 +1354,80 @@
*status = 0;
break;
default:
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Set the wake up threshold for LSM6DSL accelerometer sensor
* @param thr the threshold to be set
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Set_Wake_Up_Threshold(uint8_t thr)
+int LSM6DSLSensor::Set_Wake_Up_Threshold(uint8_t thr)
{
if ( LSM6DSL_ACC_GYRO_W_WK_THS( (void *)this, thr ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Enable the single tap detection for LSM6DSL accelerometer sensor
* @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Single_Tap_Detection(void)
+int LSM6DSLSensor::Enable_Single_Tap_Detection(void)
{
/* Output Data Rate selection */
- if( Set_X_ODR(416.0f) == LSM6DSL_STATUS_ERROR )
+ if( Set_X_ODR(416.0f) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Full scale selection. */
- if( Set_X_FS(2.0f) == LSM6DSL_STATUS_ERROR )
+ if( Set_X_FS(2.0f) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable X direction in tap recognition. */
if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable Y direction in tap recognition. */
if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable Z direction in tap recognition. */
if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Set tap threshold. */
- if ( Set_Tap_Threshold( LSM6DSL_TAP_THRESHOLD_MID_LOW ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Tap_Threshold( LSM6DSL_TAP_THRESHOLD_MID_LOW ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Set tap shock time window. */
- if ( Set_Tap_Shock_Time( LSM6DSL_TAP_SHOCK_TIME_MID_HIGH ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Tap_Shock_Time( LSM6DSL_TAP_SHOCK_TIME_MID_HIGH ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Set tap quiet time window. */
- if ( Set_Tap_Quiet_Time( LSM6DSL_TAP_QUIET_TIME_MID_LOW ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Tap_Quiet_Time( LSM6DSL_TAP_QUIET_TIME_MID_LOW ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* _NOTE_: Tap duration time window - don't care for single tap. */
@@ -1476,52 +1437,52 @@
/* Enable basic Interrupts */
if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable single tap interrupt on INT1 pin. */
if ( LSM6DSL_ACC_GYRO_W_SingleTapOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Disable the single tap detection for LSM6DSL accelerometer sensor
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_Single_Tap_Detection(void)
+int LSM6DSLSensor::Disable_Single_Tap_Detection(void)
{
/* Disable single tap interrupt on INT1 pin. */
if ( LSM6DSL_ACC_GYRO_W_SingleTapOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Disable basic Interrupts */
if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Reset tap threshold. */
- if ( Set_Tap_Threshold( 0x0 ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Tap_Threshold( 0x0 ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Reset tap shock time window. */
- if ( Set_Tap_Shock_Time( 0x0 ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Tap_Shock_Time( 0x0 ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Reset tap quiet time window. */
- if ( Set_Tap_Quiet_Time( 0x0 ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Tap_Quiet_Time( 0x0 ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* _NOTE_: Tap duration time window - don't care for single tap. */
@@ -1531,36 +1492,36 @@
/* Disable Z direction in tap recognition. */
if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Disable Y direction in tap recognition. */
if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Disable X direction in tap recognition. */
if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Get the single tap detection status for LSM6DSL accelerometer sensor
* @param status the pointer to the single tap detection status: 0 means no single tap detected, 1 means single tap detected
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_Status_Single_Tap_Detection(uint8_t *status)
+int LSM6DSLSensor::Get_Status_Single_Tap_Detection(uint8_t *status)
{
LSM6DSL_ACC_GYRO_SINGLE_TAP_EV_STATUS_t tap_status;
if ( LSM6DSL_ACC_GYRO_R_SINGLE_TAP_EV_STATUS( (void *)this, &tap_status ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( tap_status )
@@ -1574,175 +1535,175 @@
break;
default:
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Enable the double tap detection for LSM6DSL accelerometer sensor
* @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Double_Tap_Detection(void)
+int LSM6DSLSensor::Enable_Double_Tap_Detection(void)
{
/* Output Data Rate selection */
- if( Set_X_ODR(416.0f) == LSM6DSL_STATUS_ERROR )
+ if( Set_X_ODR(416.0f) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Full scale selection. */
- if( Set_X_FS(2.0f) == LSM6DSL_STATUS_ERROR )
+ if( Set_X_FS(2.0f) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable X direction in tap recognition. */
if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable Y direction in tap recognition. */
if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable Z direction in tap recognition. */
if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Set tap threshold. */
- if ( Set_Tap_Threshold( LSM6DSL_TAP_THRESHOLD_MID_LOW ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Tap_Threshold( LSM6DSL_TAP_THRESHOLD_MID_LOW ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Set tap shock time window. */
- if ( Set_Tap_Shock_Time( LSM6DSL_TAP_SHOCK_TIME_HIGH ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Tap_Shock_Time( LSM6DSL_TAP_SHOCK_TIME_HIGH ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Set tap quiet time window. */
- if ( Set_Tap_Quiet_Time( LSM6DSL_TAP_QUIET_TIME_HIGH ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Tap_Quiet_Time( LSM6DSL_TAP_QUIET_TIME_HIGH ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Set tap duration time window. */
- if ( Set_Tap_Duration_Time( LSM6DSL_TAP_DURATION_TIME_MID ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Tap_Duration_Time( LSM6DSL_TAP_DURATION_TIME_MID ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Single and double tap enabled. */
if ( LSM6DSL_ACC_GYRO_W_SINGLE_DOUBLE_TAP_EV( (void *)this, LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_DOUBLE_TAP ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable basic Interrupts */
if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable double tap interrupt on INT1 pin. */
if ( LSM6DSL_ACC_GYRO_W_TapEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TAP_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Disable the double tap detection for LSM6DSL accelerometer sensor
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_Double_Tap_Detection(void)
+int LSM6DSLSensor::Disable_Double_Tap_Detection(void)
{
/* Disable double tap interrupt on INT1 pin. */
if ( LSM6DSL_ACC_GYRO_W_TapEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TAP_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Disable basic Interrupts */
if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Reset tap threshold. */
- if ( Set_Tap_Threshold( 0x0 ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Tap_Threshold( 0x0 ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Reset tap shock time window. */
- if ( Set_Tap_Shock_Time( 0x0 ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Tap_Shock_Time( 0x0 ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Reset tap quiet time window. */
- if ( Set_Tap_Quiet_Time( 0x0 ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Tap_Quiet_Time( 0x0 ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Reset tap duration time window. */
- if ( Set_Tap_Duration_Time( 0x0 ) == LSM6DSL_STATUS_ERROR )
+ if ( Set_Tap_Duration_Time( 0x0 ) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Only single tap enabled. */
if ( LSM6DSL_ACC_GYRO_W_SINGLE_DOUBLE_TAP_EV( (void *)this, LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_SINGLE_TAP ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Disable Z direction in tap recognition. */
if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Disable Y direction in tap recognition. */
if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Disable X direction in tap recognition. */
if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Get the double tap detection status for LSM6DSL accelerometer sensor
* @param status the pointer to the double tap detection status: 0 means no double tap detected, 1 means double tap detected
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_Status_Double_Tap_Detection(uint8_t *status)
+int LSM6DSLSensor::Get_Status_Double_Tap_Detection(uint8_t *status)
{
LSM6DSL_ACC_GYRO_DOUBLE_TAP_EV_STATUS_t tap_status;
if ( LSM6DSL_ACC_GYRO_R_DOUBLE_TAP_EV_STATUS( (void *)this, &tap_status ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( tap_status )
@@ -1756,151 +1717,151 @@
break;
default:
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Set the tap threshold for LSM6DSL accelerometer sensor
* @param thr the threshold to be set
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Set_Tap_Threshold(uint8_t thr)
+int LSM6DSLSensor::Set_Tap_Threshold(uint8_t thr)
{
if ( LSM6DSL_ACC_GYRO_W_TAP_THS( (void *)this, thr ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Set the tap shock time window for LSM6DSL accelerometer sensor
* @param time the shock time window to be set
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Set_Tap_Shock_Time(uint8_t time)
+int LSM6DSLSensor::Set_Tap_Shock_Time(uint8_t time)
{
if ( LSM6DSL_ACC_GYRO_W_SHOCK_Duration( (void *)this, time ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Set the tap quiet time window for LSM6DSL accelerometer sensor
* @param time the quiet time window to be set
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Set_Tap_Quiet_Time(uint8_t time)
+int LSM6DSLSensor::Set_Tap_Quiet_Time(uint8_t time)
{
if ( LSM6DSL_ACC_GYRO_W_QUIET_Duration( (void *)this, time ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Set the tap duration of the time window for LSM6DSL accelerometer sensor
* @param time the duration of the time window to be set
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Set_Tap_Duration_Time(uint8_t time)
+int LSM6DSLSensor::Set_Tap_Duration_Time(uint8_t time)
{
if ( LSM6DSL_ACC_GYRO_W_DUR( (void *)this, time ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Enable the 6D orientation detection for LSM6DSL accelerometer sensor
* @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_6D_Orientation(void)
+int LSM6DSLSensor::Enable_6D_Orientation(void)
{
/* Output Data Rate selection */
- if( Set_X_ODR(416.0f) == LSM6DSL_STATUS_ERROR )
+ if( Set_X_ODR(416.0f) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Full scale selection. */
- if( Set_X_FS(2.0f) == LSM6DSL_STATUS_ERROR )
+ if( Set_X_FS(2.0f) == 1 )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Set 6D threshold. */
if ( LSM6DSL_ACC_GYRO_W_SIXD_THS( (void *)this, LSM6DSL_ACC_GYRO_SIXD_THS_60_degree ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Enable basic Interrupts */
if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* INT1_6D setting. */
if ( LSM6DSL_ACC_GYRO_W_6DEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_6D_ENABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Disable the 6D orientation detection for LSM6DSL accelerometer sensor
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_6D_Orientation(void)
+int LSM6DSLSensor::Disable_6D_Orientation(void)
{
/* INT1_6D setting. */
if ( LSM6DSL_ACC_GYRO_W_6DEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_6D_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Disable basic Interrupts */
if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
/* Reset 6D threshold. */
if ( LSM6DSL_ACC_GYRO_W_SIXD_THS( (void *)this, LSM6DSL_ACC_GYRO_SIXD_THS_80_degree ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Get the status of the 6D orientation detection for LSM6DSL accelerometer sensor
* @param status the pointer to the status of the 6D orientation detection: 0 means no detection, 1 means detection happened
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_Status_6D_Orientation(uint8_t *status)
+int LSM6DSLSensor::Get_Status_6D_Orientation(uint8_t *status)
{
LSM6DSL_ACC_GYRO_D6D_EV_STATUS_t status_raw;
if ( LSM6DSL_ACC_GYRO_R_D6D_EV_STATUS( (void *)this, &status_raw ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( status_raw )
@@ -1912,24 +1873,24 @@
*status = 0;
break;
default:
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Get the 6D orientation XL axis for LSM6DSL accelerometer sensor
* @param xl the pointer to the 6D orientation XL axis
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_6D_Orientation_XL(uint8_t *xl)
+int LSM6DSLSensor::Get_6D_Orientation_XL(uint8_t *xl)
{
LSM6DSL_ACC_GYRO_DSD_XL_t xl_raw;
if ( LSM6DSL_ACC_GYRO_R_DSD_XL( (void *)this, &xl_raw ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( xl_raw )
@@ -1941,24 +1902,24 @@
*xl = 0;
break;
default:
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Get the 6D orientation XH axis for LSM6DSL accelerometer sensor
* @param xh the pointer to the 6D orientation XH axis
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_6D_Orientation_XH(uint8_t *xh)
+int LSM6DSLSensor::Get_6D_Orientation_XH(uint8_t *xh)
{
LSM6DSL_ACC_GYRO_DSD_XH_t xh_raw;
if ( LSM6DSL_ACC_GYRO_R_DSD_XH( (void *)this, &xh_raw ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( xh_raw )
@@ -1970,24 +1931,24 @@
*xh = 0;
break;
default:
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Get the 6D orientation YL axis for LSM6DSL accelerometer sensor
* @param yl the pointer to the 6D orientation YL axis
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_6D_Orientation_YL(uint8_t *yl)
+int LSM6DSLSensor::Get_6D_Orientation_YL(uint8_t *yl)
{
LSM6DSL_ACC_GYRO_DSD_YL_t yl_raw;
if ( LSM6DSL_ACC_GYRO_R_DSD_YL( (void *)this, &yl_raw ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( yl_raw )
@@ -1999,24 +1960,24 @@
*yl = 0;
break;
default:
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Get the 6D orientation YH axis for LSM6DSL accelerometer sensor
* @param yh the pointer to the 6D orientation YH axis
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_6D_Orientation_YH(uint8_t *yh)
+int LSM6DSLSensor::Get_6D_Orientation_YH(uint8_t *yh)
{
LSM6DSL_ACC_GYRO_DSD_YH_t yh_raw;
if ( LSM6DSL_ACC_GYRO_R_DSD_YH( (void *)this, &yh_raw ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( yh_raw )
@@ -2028,24 +1989,24 @@
*yh = 0;
break;
default:
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Get the 6D orientation ZL axis for LSM6DSL accelerometer sensor
* @param zl the pointer to the 6D orientation ZL axis
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_6D_Orientation_ZL(uint8_t *zl)
+int LSM6DSLSensor::Get_6D_Orientation_ZL(uint8_t *zl)
{
LSM6DSL_ACC_GYRO_DSD_ZL_t zl_raw;
if ( LSM6DSL_ACC_GYRO_R_DSD_ZL( (void *)this, &zl_raw ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( zl_raw )
@@ -2057,24 +2018,24 @@
*zl = 0;
break;
default:
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Get the 6D orientation ZH axis for LSM6DSL accelerometer sensor
* @param zh the pointer to the 6D orientation ZH axis
- * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
+ * @retval 0 in case of success, an error code otherwise
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::Get_6D_Orientation_ZH(uint8_t *zh)
+int LSM6DSLSensor::Get_6D_Orientation_ZH(uint8_t *zh)
{
LSM6DSL_ACC_GYRO_DSD_ZH_t zh_raw;
if ( LSM6DSL_ACC_GYRO_R_DSD_ZH( (void *)this, &zh_raw ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
switch( zh_raw )
@@ -2086,46 +2047,46 @@
*zh = 0;
break;
default:
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Read the data from register
* @param reg register address
* @param data register data
- * @retval LSM6DSL_STATUS_OK in case of success
- * @retval LSM6DSL_STATUS_ERROR in case of failure
+ * @retval 0 in case of success
+ * @retval 1 in case of failure
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::ReadReg( uint8_t reg, uint8_t *data )
+int LSM6DSLSensor::ReadReg( uint8_t reg, uint8_t *data )
{
if ( LSM6DSL_ACC_GYRO_ReadReg( (void *)this, reg, data, 1 ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
/**
* @brief Write the data to register
* @param reg register address
* @param data register data
- * @retval LSM6DSL_STATUS_OK in case of success
- * @retval LSM6DSL_STATUS_ERROR in case of failure
+ * @retval 0 in case of success
+ * @retval 1 in case of failure
*/
-LSM6DSLStatusTypeDef LSM6DSLSensor::WriteReg( uint8_t reg, uint8_t data )
+int LSM6DSLSensor::WriteReg( uint8_t reg, uint8_t data )
{
if ( LSM6DSL_ACC_GYRO_WriteReg( (void *)this, reg, &data, 1 ) == MEMS_ERROR )
{
- return LSM6DSL_STATUS_ERROR;
+ return 1;
}
- return LSM6DSL_STATUS_OK;
+ return 0;
}
--- a/X_NUCLEO_IKS01A2/Components/LSM6DSLSensor/LSM6DSLSensor.h Fri Aug 12 13:57:55 2016 +0000
+++ b/X_NUCLEO_IKS01A2/Components/LSM6DSLSensor/LSM6DSLSensor.h Fri Aug 19 12:13:37 2016 +0000
@@ -47,6 +47,8 @@
#include "DevI2C.h"
#include "LSM6DSL_ACC_GYRO_driver.h"
+#include "MotionSensor.h"
+#include "GyroSensor.h"
/* Defines -------------------------------------------------------------------*/
@@ -95,84 +97,75 @@
#define LSM6DSL_TAP_DURATION_TIME_MID_HIGH 0x0C
#define LSM6DSL_TAP_DURATION_TIME_HIGH 0x0F /**< Highest value of wake up threshold */
-/* Typedefs ------------------------------------------------------------------*/
-typedef enum
-{
- LSM6DSL_STATUS_OK = 0,
- LSM6DSL_STATUS_ERROR,
- LSM6DSL_STATUS_TIMEOUT,
- LSM6DSL_STATUS_NOT_IMPLEMENTED
-} LSM6DSLStatusTypeDef;
-
-
/* Class Declaration ---------------------------------------------------------*/
/**
* Abstract class of an LSM6DSL Inertial Measurement Unit (IMU) 6 axes
* sensor.
*/
-class LSM6DSLSensor
+class LSM6DSLSensor : public MotionSensor, public GyroSensor
{
public:
- LSM6DSLSensor (DevI2C &i2c);
- LSM6DSLSensor (DevI2C &i2c, uint8_t address);
- LSM6DSLStatusTypeDef Enable_X (void);
- LSM6DSLStatusTypeDef Enable_G (void);
- LSM6DSLStatusTypeDef Disable_X (void);
- LSM6DSLStatusTypeDef Disable_G (void);
- LSM6DSLStatusTypeDef ReadID (uint8_t *p_id);
- LSM6DSLStatusTypeDef Get_X_Axes (int32_t *pData);
- LSM6DSLStatusTypeDef Get_G_Axes (int32_t *pData);
- LSM6DSLStatusTypeDef Get_X_Sensitivity (float *pfData);
- LSM6DSLStatusTypeDef Get_G_Sensitivity (float *pfData);
- LSM6DSLStatusTypeDef Get_X_AxesRaw (int16_t *pData);
- LSM6DSLStatusTypeDef Get_G_AxesRaw (int16_t *pData);
- LSM6DSLStatusTypeDef Get_X_ODR (float *odr);
- LSM6DSLStatusTypeDef Get_G_ODR (float *odr);
- LSM6DSLStatusTypeDef Set_X_ODR (float odr);
- LSM6DSLStatusTypeDef Set_G_ODR (float odr);
- LSM6DSLStatusTypeDef Get_X_FS (float *fullScale);
- LSM6DSLStatusTypeDef Get_G_FS (float *fullScale);
- LSM6DSLStatusTypeDef Set_X_FS (float fullScale);
- LSM6DSLStatusTypeDef Set_G_FS (float fullScale);
- LSM6DSLStatusTypeDef Enable_Free_Fall_Detection (void);
- LSM6DSLStatusTypeDef Disable_Free_Fall_Detection (void);
- LSM6DSLStatusTypeDef Get_Status_Free_Fall_Detection (uint8_t *status);
- LSM6DSLStatusTypeDef Set_Free_Fall_Threshold (uint8_t thr);
- LSM6DSLStatusTypeDef Enable_Pedometer (void);
- LSM6DSLStatusTypeDef Disable_Pedometer (void);
- LSM6DSLStatusTypeDef Get_Status_Pedometer (uint8_t *status);
- LSM6DSLStatusTypeDef Get_Step_Counter (uint16_t *step_count);
- LSM6DSLStatusTypeDef Reset_Step_Counter (void);
- LSM6DSLStatusTypeDef Set_Pedometer_Threshold (uint8_t thr);
- LSM6DSLStatusTypeDef Enable_Tilt_Detection (void);
- LSM6DSLStatusTypeDef Disable_Tilt_Detection (void);
- LSM6DSLStatusTypeDef Get_Status_Tilt_Detection (uint8_t *status);
- LSM6DSLStatusTypeDef Enable_Wake_Up_Detection (void);
- LSM6DSLStatusTypeDef Disable_Wake_Up_Detection (void);
- LSM6DSLStatusTypeDef Get_Status_Wake_Up_Detection (uint8_t *status);
- LSM6DSLStatusTypeDef Set_Wake_Up_Threshold (uint8_t thr);
- LSM6DSLStatusTypeDef Enable_Single_Tap_Detection (void);
- LSM6DSLStatusTypeDef Disable_Single_Tap_Detection (void);
- LSM6DSLStatusTypeDef Get_Status_Single_Tap_Detection (uint8_t *status);
- LSM6DSLStatusTypeDef Enable_Double_Tap_Detection (void);
- LSM6DSLStatusTypeDef Disable_Double_Tap_Detection (void);
- LSM6DSLStatusTypeDef Get_Status_Double_Tap_Detection (uint8_t *status);
- LSM6DSLStatusTypeDef Set_Tap_Threshold (uint8_t thr);
- LSM6DSLStatusTypeDef Set_Tap_Shock_Time (uint8_t time);
- LSM6DSLStatusTypeDef Set_Tap_Quiet_Time (uint8_t time);
- LSM6DSLStatusTypeDef Set_Tap_Duration_Time (uint8_t time);
- LSM6DSLStatusTypeDef Enable_6D_Orientation (void);
- LSM6DSLStatusTypeDef Disable_6D_Orientation (void);
- LSM6DSLStatusTypeDef Get_Status_6D_Orientation (uint8_t *status);
- LSM6DSLStatusTypeDef Get_6D_Orientation_XL (uint8_t *xl);
- LSM6DSLStatusTypeDef Get_6D_Orientation_XH (uint8_t *xh);
- LSM6DSLStatusTypeDef Get_6D_Orientation_YL (uint8_t *yl);
- LSM6DSLStatusTypeDef Get_6D_Orientation_YH (uint8_t *yh);
- LSM6DSLStatusTypeDef Get_6D_Orientation_ZL (uint8_t *zl);
- LSM6DSLStatusTypeDef Get_6D_Orientation_ZH (uint8_t *zh);
- LSM6DSLStatusTypeDef ReadReg (uint8_t reg, uint8_t *data);
- LSM6DSLStatusTypeDef WriteReg (uint8_t reg, uint8_t data);
+ LSM6DSLSensor(DevI2C &i2c);
+ LSM6DSLSensor(DevI2C &i2c, uint8_t address);
+ virtual int Init(void *init);
+ virtual int ReadID(uint8_t *id);
+ virtual int Get_X_Axes(int32_t *pData);
+ virtual int Get_G_Axes(int32_t *pData);
+ virtual int Get_X_Sensitivity(float *pfData);
+ virtual int Get_G_Sensitivity(float *pfData);
+ virtual int Get_X_AxesRaw(int16_t *pData);
+ virtual int Get_G_AxesRaw(int16_t *pData);
+ virtual int Get_X_ODR(float *odr);
+ virtual int Get_G_ODR(float *odr);
+ virtual int Set_X_ODR(float odr);
+ virtual int Set_G_ODR(float odr);
+ virtual int Get_X_FS(float *fullScale);
+ virtual int Get_G_FS(float *fullScale);
+ virtual int Set_X_FS(float fullScale);
+ virtual int Set_G_FS(float fullScale);
+ int Enable_X(void);
+ int Enable_G(void);
+ int Disable_X(void);
+ int Disable_G(void);
+ int Enable_Free_Fall_Detection(void);
+ int Disable_Free_Fall_Detection(void);
+ int Get_Status_Free_Fall_Detection(uint8_t *status);
+ int Set_Free_Fall_Threshold(uint8_t thr);
+ int Enable_Pedometer(void);
+ int Disable_Pedometer(void);
+ int Get_Status_Pedometer(uint8_t *status);
+ int Get_Step_Counter(uint16_t *step_count);
+ int Reset_Step_Counter(void);
+ int Set_Pedometer_Threshold(uint8_t thr);
+ int Enable_Tilt_Detection(void);
+ int Disable_Tilt_Detection(void);
+ int Get_Status_Tilt_Detection(uint8_t *status);
+ int Enable_Wake_Up_Detection(void);
+ int Disable_Wake_Up_Detection(void);
+ int Get_Status_Wake_Up_Detection(uint8_t *status);
+ int Set_Wake_Up_Threshold(uint8_t thr);
+ int Enable_Single_Tap_Detection(void);
+ int Disable_Single_Tap_Detection(void);
+ int Get_Status_Single_Tap_Detection(uint8_t *status);
+ int Enable_Double_Tap_Detection(void);
+ int Disable_Double_Tap_Detection(void);
+ int Get_Status_Double_Tap_Detection(uint8_t *status);
+ int Set_Tap_Threshold(uint8_t thr);
+ int Set_Tap_Shock_Time(uint8_t time);
+ int Set_Tap_Quiet_Time(uint8_t time);
+ int Set_Tap_Duration_Time(uint8_t time);
+ int Enable_6D_Orientation(void);
+ int Disable_6D_Orientation(void);
+ int Get_Status_6D_Orientation(uint8_t *status);
+ int Get_6D_Orientation_XL(uint8_t *xl);
+ int Get_6D_Orientation_XH(uint8_t *xh);
+ int Get_6D_Orientation_YL(uint8_t *yl);
+ int Get_6D_Orientation_YH(uint8_t *yh);
+ int Get_6D_Orientation_ZL(uint8_t *zl);
+ int Get_6D_Orientation_ZH(uint8_t *zh);
+ int ReadReg(uint8_t reg, uint8_t *data);
+ int WriteReg(uint8_t reg, uint8_t data);
/**
* @brief Utility function to read data.
@@ -199,10 +192,10 @@
}
private:
- LSM6DSLStatusTypeDef Set_X_ODR_When_Enabled(float odr);
- LSM6DSLStatusTypeDef Set_G_ODR_When_Enabled(float odr);
- LSM6DSLStatusTypeDef Set_X_ODR_When_Disabled(float odr);
- LSM6DSLStatusTypeDef Set_G_ODR_When_Disabled(float odr);
+ int Set_X_ODR_When_Enabled(float odr);
+ int Set_G_ODR_When_Enabled(float odr);
+ int Set_X_ODR_When_Disabled(float odr);
+ int Set_G_ODR_When_Disabled(float odr);
/* Helper classes. */
DevI2C &dev_i2c;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_IKS01A2/X_NUCLEO_INTERFACES.lib Fri Aug 19 12:13:37 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/ST-Expansion-SW-Team/code/X_NUCLEO_INTERFACES/#4bdd6ff149fc
--- a/X_NUCLEO_IKS01A2/x_nucleo_iks01a2.cpp Fri Aug 12 13:57:55 2016 +0000
+++ b/X_NUCLEO_IKS01A2/x_nucleo_iks01a2.cpp Fri Aug 19 12:13:37 2016 +0000
@@ -54,7 +54,11 @@
pt_sensor(new LPS22HBSensor(*dev_i2c)),
acc_gyro(new LSM6DSLSensor(*dev_i2c))
{
-
+ ht_sensor->Init(NULL);
+ magnetometer->Init(NULL);
+ accelerometer->Init(NULL);
+ pt_sensor->Init(NULL);
+ acc_gyro->Init(NULL);
}
/**
--- a/main.cpp Fri Aug 12 13:57:55 2016 +0000
+++ b/main.cpp Fri Aug 19 12:13:37 2016 +0000
@@ -126,10 +126,10 @@
printf("---\r\n");
- magnetometer->GetAxes(axes);
+ magnetometer->Get_M_Axes(axes);
printf("LSM303AGR [mag/mgauss]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
- accelerometer->GetAxes(axes);
+ accelerometer->Get_X_Axes(axes);
printf("LSM303AGR [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
acc_gyro->Get_X_Axes(axes);
