![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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);
Diff: LSM303DLHC.cpp
- Revision:
- 3:522d01930e6a
- Parent:
- 1:e68ce5025dad
- Child:
- 4:8723c07d4c45
--- a/LSM303DLHC.cpp Tue Jun 07 06:25:44 2016 +0000 +++ b/LSM303DLHC.cpp Tue Jun 07 15:18:48 2016 +0000 @@ -6,6 +6,22 @@ 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 + ACtrl(XYZ); // ACC XYZ Axis Enable + ACtrl(HPF_ON); // ACC internal HPF IN USE + ACtrl(HPF_CF0); // ACC HPF Cutoff Freq = option 0 + ACtrl(HPF_NORM_R); // ACC HPF Model = Normal + ACtrl(BDU_CONT); // ACC data continuous + ACtrl(G4); // ACC Range +/-4g + ACtrl(HIGH_R); // ACC in High Prec + MCtrl(MDR4); // MAG DR 15Hz + MCtrl(GN4); // MAG GN 4.0Gauss + MCtrl(MD_CONT); // MAG ON and MD Continuous + TCtrl(TEMP_ON); // TEMP ON + + // DEFAULT CALIBRATION PARAMETER acc_offset[0] = 0; acc_offset[1] = 0; acc_offset[2] = 0; @@ -22,21 +38,6 @@ temp_offset[0] = 0; temp_scale[0] = 1; - - // CUSTOM THE INITIAL CTRL FOR YOURSELF - ACtrl(LP_OFF); // ACC Normal Power Mode - ACtrl(ODR3); // ACC ON and Date Rate 25Hz - ACtrl(XYZ); // ACC XYZ Axis Enable - ACtrl(HPF_ON); // ACC internal HPF In Use - ACtrl(HPF_CF0); // ACC HPF Cutoff Freq = option 0 - ACtrl(HPF_NORM); // ACC HPF Model = Normal - ACtrl(BDU_CONT); // ACC data continuous - ACtrl(G4); // ACC Range +/-4g - ACtrl(HIGH_R); // ACC in High Prec - MCtrl(DR4); // MAG DR 15Hz - MCtrl(GN4); // MAG GN 4.0Gauss - MCtrl(MD_CONT); // MAG ON and MD Continuous - TCtrl(TEMP_ON); // TEMP ON } void LSM303DLHC::GetAcc(float arr[3]){ @@ -181,7 +182,7 @@ i2c.write(sad, d, 2); } -void LSM303DLHC::AccCal(float offset[3], float scale[3]){ +void LSM303DLHC::ACal(float offset[3], float scale[3]){ acc_offset[0] = offset[0]; acc_offset[1] = offset[1]; acc_offset[2] = offset[2]; @@ -190,7 +191,7 @@ acc_scale[2] = scale[2]; } -void LSM303DLHC::MagCal(float offset[3], float scale[3]){ +void LSM303DLHC::MCal(float offset[3], float scale[3]){ mag_offset[0] = offset[0]; mag_offset[1] = offset[1]; mag_offset[2] = offset[2]; @@ -199,7 +200,7 @@ mag_scale[2] = scale[2]; } -void LSM303DLHC::TempCal(float offset[1], float scale[1]){ +void LSM303DLHC::TCal(float offset[1], float scale[1]){ temp_offset[0] = offset[0]; temp_scale[0] = scale[0]; }