My attempt to made a more useful lib. You can get the accelerator and magnetometer.

Fork of LSM303DLH by Michael Shimniok

Revision:
3:9b4ff901b5c9
Parent:
2:aea5caec809c
Child:
4:4f2ed3f8726c
--- a/LSM303DLH.h	Tue Apr 12 18:21:44 2011 +0000
+++ b/LSM303DLH.h	Sun Aug 06 00:43:57 2017 +0000
@@ -1,5 +1,6 @@
 #include "mbed.h"
 #include "vector.h"
+#include "AnsiGraphicalConsole.h"
 
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
@@ -69,7 +70,7 @@
          * @param scl is the pin for the I2C SCL line
          */
         LSM303DLH(PinName sda, PinName scl);
-
+        LSM303DLH(I2C* ptrI2C);
         /** sets the x, y, and z offset corrections for hard iron calibration
          * 
          * Calibration details here:
@@ -102,7 +103,7 @@
          * @param a is the accelerometer 3d vector, written by the function
          * @param m is the magnetometer 3d vector, written by the function
          */
-        void read(vector &a, vector &m);
+        bool read(vector &a, vector &m);
         
         /** returns the magnetic heading with respect to the y axis
          *
@@ -121,7 +122,7 @@
         void frequency(int hz);
     
     private:
-        I2C _compass;
+        I2C* m_ptr_I2C;//_compass;
         float _offset_x;
         float _offset_y;
         float _offset_z;
@@ -132,6 +133,7 @@
         long _filt_ay;
         long _filt_az;
        
+        void init(void) ;
         bool write_reg(int addr_i2c,int addr_reg, char v);
         bool read_reg(int addr_i2c,int addr_reg, char *v);
         bool read_reg_short(int addr_i2c,int addr_reg, short *v);