LSM303DLHC Full Driver: Readings For Acc, Mag and Temp; Class Method for frequently-used 13 sensor parameters; Class Method to direct modify registers; Support Calibration (offset+scale);

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Airium
Date:
Thu Jun 09 15:19:00 2016 +0000
Parent:
3:522d01930e6a
Commit message:
Add offset calibration for specific use in HPF-on situation and therefore remove (bool) HPF_state and isHPFEn() and associated code

Changed in this revision

LSM303DLHC.cpp Show annotated file Show diff for this revision Revisions of this file
LSM303DLHC.h Show annotated file Show diff for this revision Revisions of this file
--- a/LSM303DLHC.cpp	Tue Jun 07 15:18:48 2016 +0000
+++ b/LSM303DLHC.cpp	Thu Jun 09 15:19:00 2016 +0000
@@ -4,8 +4,6 @@
 LSM303DLHC::LSM303DLHC(PinName sda, PinName scl) : i2c(sda, scl){
     i2c.frequency(400000);
     
-    HPF_state = false; // reg default value corresponds to this
-    
     // HERE GIVES DEVICE DEFAULT
     ACtrl(LP_OFF);      // ACC Normal Power Mode
     ACtrl(ADR3);        // ACC ON and Date Rate 25Hz
@@ -45,16 +43,9 @@
     i2c.write(ACC_ADDRESS, data, 1);
     i2c.read(ACC_ADDRESS, data, 6);
     
-    // return the raw acceleration
-    if (HPF_state == HPF_ON){ // HPF has no offset
-        arr[0] = acc_scale[0]*((short)(data[1]<<8 | data[0])>>4);
-        arr[1] = acc_scale[1]*((short)(data[3]<<8 | data[2])>>4);
-        arr[2] = acc_scale[2]*((short)(data[5]<<8 | data[4])>>4);
-    }else{
-        arr[0] = acc_scale[0]*(acc_offset[0]+((short)(data[1]<<8 | data[0])>>4));
-        arr[1] = acc_scale[1]*(acc_offset[1]+((short)(data[3]<<8 | data[2])>>4));
-        arr[2] = acc_scale[2]*(acc_offset[2]+((short)(data[5]<<8 | data[4])>>4));
-    }
+    arr[0] = acc_scale[0]*(acc_offset[0]+((short)(data[1]<<8 | data[0])>>4));
+    arr[1] = acc_scale[1]*(acc_offset[1]+((short)(data[3]<<8 | data[2])>>4));
+    arr[2] = acc_scale[2]*(acc_offset[2]+((short)(data[5]<<8 | data[4])>>4));
 }
 
 void LSM303DLHC::GetMag(float arr[3]){
@@ -119,7 +110,6 @@
     i2c.read(ACC_ADDRESS, &data[1], 1);
     data[1] = data[1] & (0b11110111) | (cmd<<3);
     i2c.write(ACC_ADDRESS, data, 2); 
-    (cmd == HPF_ON)?(HPF_state = true):(HPF_state = false);
 }
 
 void LSM303DLHC::ACtrl(ACC_BDU cmd){
@@ -203,8 +193,4 @@
 void LSM303DLHC::TCal(float offset[1], float scale[1]){
     temp_offset[0] = offset[0];
     temp_scale[0] = scale[0];
-}
-
-bool LSM303DLHC::isHPFEn(){
-    return HPF_state;
 }
\ No newline at end of file
--- a/LSM303DLHC.h	Tue Jun 07 15:18:48 2016 +0000
+++ b/LSM303DLHC.h	Thu Jun 09 15:19:00 2016 +0000
@@ -20,8 +20,6 @@
     // affect data of GetAcc() by output = scale * ( offset + original )
     // but if internal HPF enable then output = scale * original
     // note linear acc has no offset
-bool isHPFEn(); // report HPF ON/OFF state for output
-    return bool = true if ACC_FDS = HPF_ON and vice versa
 
 -- MAGNETOMETER PART
 void GetMag( float arr[3] );  // Get magnetic flux density
@@ -144,10 +142,7 @@
         void MCal(float offset[3], float scale[3]); // Mag Calibration
         void TCal(float offset[1], float scale[1]); // Mag Calibration    
         
-        //// Other functions
-        bool isHPFEn(); // report HPF ON/OFF state for output
-        // return HPF_state
-        
+          
         //// Not implemented function
         bool isAccRdy(); // Check if acc has new data 
         // one way is to use high freq ticker to check STATUS_REG_A (27h)
@@ -161,7 +156,6 @@
         I2C i2c;
         
         char data[6];       // used as main data exchange
-        bool HPF_state;     // state of internal HPF
                
         // use offset to calibrate zero reading
         float acc_offset[3];