ST / LSM303AGR

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   HelloWorld_ST_Sensors MOTENV_Mbed mbed-os-mqtt-client LSM303AGR_JS ... more

Files at this revision

API Documentation at this revision

Comitter:
mapellil
Date:
Wed Sep 27 16:49:51 2017 +0200
Parent:
0:ec6e59cc6f40
Child:
2:e37be5550633
Commit message:
Fixed NonCopyable

Changed in this revision

LSM303AGRAccSensor.cpp Show annotated file Show diff for this revision Revisions of this file
LSM303AGRAccSensor.h Show annotated file Show diff for this revision Revisions of this file
LSM303AGRMagSensor.cpp Show annotated file Show diff for this revision Revisions of this file
LSM303AGRMagSensor.h Show annotated file Show diff for this revision Revisions of this file
--- a/LSM303AGRAccSensor.cpp	Mon Sep 04 16:08:24 2017 +0000
+++ b/LSM303AGRAccSensor.cpp	Wed Sep 27 16:49:51 2017 +0200
@@ -47,18 +47,10 @@
  * @param i2c object of an helper class which handles the I2C peripheral
  * @param address the address of the component's instance
  */
-LSM303AGRAccSensor::LSM303AGRAccSensor(DevI2C &i2c) : _dev_i2c(i2c)
+LSM303AGRAccSensor::LSM303AGRAccSensor(DevI2C *i2c, uint8_t address, PinName int1_pin, PinName int2_pin) : 
+                                       _dev_i2c(i2c), _address(address), _cs_pin(NC), _int1_pin(int1_pin), _int2_pin(int2_pin)
 {
-  _address = LSM303AGR_ACC_I2C_ADDRESS;
-};
-
-/** Constructor
- * @param i2c object of an helper class which handles the I2C peripheral
- * @param address the address of the component's instance
- */
-LSM303AGRAccSensor::LSM303AGRAccSensor(DevI2C &i2c, uint8_t address) : _dev_i2c(i2c), _address(address)
-{
-
+    assert (i2c);
 };
 
 /**
--- a/LSM303AGRAccSensor.h	Mon Sep 04 16:08:24 2017 +0000
+++ b/LSM303AGRAccSensor.h	Wed Sep 27 16:49:51 2017 +0200
@@ -47,6 +47,7 @@
 #include "DevI2C.h"
 #include "LSM303AGR_acc_driver.h"
 #include "MotionSensor.h"
+#include <assert.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] */
@@ -71,8 +72,7 @@
 class LSM303AGRAccSensor : public MotionSensor
 {
   public:
-    LSM303AGRAccSensor(DevI2C &i2c);
-    LSM303AGRAccSensor(DevI2C &i2c, uint8_t address);
+    LSM303AGRAccSensor(DevI2C *i2c, uint8_t address=LSM303AGR_ACC_I2C_ADDRESS, PinName int1_pin=NC, PinName int2_pin=NC);
     virtual int init(void *init);
     virtual int read_id(uint8_t *id);
     virtual int get_x_axes(int32_t *pData);
@@ -96,7 +96,7 @@
      */
     uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead)
     {
-        return (uint8_t) _dev_i2c.i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead);
+        return (uint8_t) _dev_i2c->i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead);
     }
     
     /**
@@ -108,7 +108,7 @@
      */
     uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite)
     {
-        return (uint8_t) _dev_i2c.i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite);
+        return (uint8_t) _dev_i2c->i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite);
     }
 
   private:
@@ -119,10 +119,13 @@
     int get_x_sensitivity_hr_mode(float *sensitivity );
 
     /* Helper classes. */
-    DevI2C &_dev_i2c;
+    DevI2C *_dev_i2c;
     
     /* Configuration */
     uint8_t _address;
+    DigitalOut  _cs_pin;        
+    InterruptIn _int1_pin; 
+    InterruptIn _int2_pin;  
     
     uint8_t _is_enabled;
     float _last_odr;
--- a/LSM303AGRMagSensor.cpp	Mon Sep 04 16:08:24 2017 +0000
+++ b/LSM303AGRMagSensor.cpp	Wed Sep 27 16:49:51 2017 +0200
@@ -47,18 +47,10 @@
  * @param i2c object of an helper class which handles the I2C peripheral
  * @param address the address of the component's instance
  */
-LSM303AGRMagSensor::LSM303AGRMagSensor(DevI2C &i2c) : _dev_i2c(i2c)
+LSM303AGRMagSensor::LSM303AGRMagSensor(DevI2C *i2c, uint8_t address, PinName intmag_pin) : 
+                                       _dev_i2c(i2c), _address(address), _cs_pin(NC), _intmag_pin(intmag_pin)
 {
-  _address = LSM303AGR_MAG_I2C_ADDRESS;
-};
-
-/** Constructor
- * @param i2c object of an helper class which handles the I2C peripheral
- * @param address the address of the component's instance
- */
-LSM303AGRMagSensor::LSM303AGRMagSensor(DevI2C &i2c, uint8_t address) : _dev_i2c(i2c), _address(address)
-{
-
+    assert (i2c);
 };
 
 /**
--- a/LSM303AGRMagSensor.h	Mon Sep 04 16:08:24 2017 +0000
+++ b/LSM303AGRMagSensor.h	Wed Sep 27 16:49:51 2017 +0200
@@ -47,7 +47,7 @@
 #include "DevI2C.h"
 #include "LSM303AGR_mag_driver.h"
 #include "MagneticSensor.h"
-
+#include <assert.h>
 
 /* Class Declaration ---------------------------------------------------------*/
 
@@ -58,8 +58,7 @@
 class LSM303AGRMagSensor : public MagneticSensor
 {
   public:
-    LSM303AGRMagSensor(DevI2C &i2c);
-    LSM303AGRMagSensor(DevI2C &i2c, uint8_t address);
+   LSM303AGRMagSensor(DevI2C *i2c, uint8_t address=LSM303AGR_MAG_I2C_ADDRESS, PinName intmag_pin=NC);
     virtual int init(void *init);
     virtual int read_id(uint8_t *id);
     virtual int get_m_axes(int32_t *pData);
@@ -83,7 +82,7 @@
      */
     uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead)
     {
-        return (uint8_t) _dev_i2c.i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead);
+        return (uint8_t) _dev_i2c->i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead);
     }
     
     /**
@@ -95,16 +94,18 @@
      */
     uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite)
     {
-        return (uint8_t) _dev_i2c.i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite);
+        return (uint8_t) _dev_i2c->i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite);
     }
 
   private:
 
     /* Helper classes. */
-    DevI2C &_dev_i2c;
+    DevI2C *_dev_i2c;
     
     /* Configuration */
     uint8_t _address;
+    DigitalOut  _cs_pin;
+    InterruptIn _intmag_pin;           
 };
 
 #ifdef __cplusplus