Library for the HMC5883L with 5 pins

Dependents:   projet_st_connect

Fork of QMC5883L by z jx

Files at this revision

API Documentation at this revision

Comitter:
raminou
Date:
Mon Nov 12 10:24:29 2018 +0000
Parent:
6:37d4c4e18227
Commit message:
nc

Changed in this revision

QMC5883L.cpp Show annotated file Show diff for this revision Revisions of this file
QMC5883L.h Show annotated file Show diff for this revision Revisions of this file
diff -r 37d4c4e18227 -r 4136b94b5cb9 QMC5883L.cpp
--- a/QMC5883L.cpp	Tue Nov 06 16:40:11 2018 +0000
+++ b/QMC5883L.cpp	Mon Nov 12 10:24:29 2018 +0000
@@ -34,7 +34,7 @@
 {
 }
 
-float QMC5883L::setMagRange(TypeMagScale Mscale)
+float QMC5883L::setMagRange(MagScale Mscale)
 {
     float mRes; // Varies with gain
     
@@ -73,9 +73,9 @@
 }
 
 void QMC5883L::init()
-{
+{   
     setMagRange(MagScale_8G);
-    change_odr_state(MagScale_8G, F200, Continuous_MODE);
+    QMC5883L_WriteByte(CONTROL_A, 0x0D | MagScale_8G);  // Range: 8G, ODR: 200 Hz, mode:Continuous-Measurement
     QMC5883L_WriteByte(SET_RESET, 0x01);
     wait_ms(10);
 }
@@ -110,25 +110,4 @@
     LoByte = QMC5883L_ReadByte(TEMP_LSB); // read Accelerometer X_Low  value
     HiByte = QMC5883L_ReadByte(TEMP_MSB); // read Accelerometer X_High value
     return ((HiByte<<8) | LoByte);
-}
-
-void QMC5883L::standby()
-{
-    QMC5883L_WriteByte(CONTROL_A, 0x00);
-}
-
-void QMC5883L::change_odr_state(TypeMagScale mmag_scale, TypeODR modr, TypeState mstate)
-{
-    odr = modr;
-    state = mstate;
-    mag_scale = mmag_scale;
-    printf("id: %d\r\n", ((mag_scale & 0x3) << 4) | ((odr & 0x3)<< 2) | (state & 0x3));
-    QMC5883L_WriteByte(CONTROL_A, ((mag_scale & 0x3) << 4) | ((odr & 0x3)<< 2) | (state & 0x3));
-}
-
-void QMC5883L::soft_reset()
-{
-    // QMC5883L_WriteByte(CONTROL_B, 0x80);
-    QMC5883L_WriteByte(SET_RESET, 0x01);
-    wait_ms(10);
 }
\ No newline at end of file
diff -r 37d4c4e18227 -r 4136b94b5cb9 QMC5883L.h
--- a/QMC5883L.h	Tue Nov 06 16:40:11 2018 +0000
+++ b/QMC5883L.h	Mon Nov 12 10:24:29 2018 +0000
@@ -49,24 +49,10 @@
 #define CHIP_ID      0x0D
 
 /* Magnetometer Gain Settings */
-enum TypeMagScale
-{
-    MagScale_2G =  0,      // +/- 2 Ga
-    MagScale_8G  = 1,     // +/- 8 Ga
-};
-
-enum TypeState
+enum MagScale
 {
-    Standby_MODE = 0,
-    Continuous_MODE = 1
-};
-
-enum TypeODR
-{
-    F10 = 0,
-    F50 = 1,
-    F100 = 2,
-    F200 = 3
+    MagScale_2G =  0x00,      // +/- 2 Ga
+    MagScale_8G  = 0x10,     // +/- 8 Ga
 };
 
 class QMC5883L
@@ -81,14 +67,8 @@
         int16_t getMagZvalue();
         int16_t getMagTemp();
         void    ChipID();
-        void standby();
-        void soft_reset();
     private:
-        TypeState state;
-        TypeODR odr;
-        TypeMagScale mag_scale;
-        float setMagRange(TypeMagScale Mscale);
-        void change_odr_state(TypeMagScale mmag_scale, TypeODR modr, TypeState mstate);
+        float setMagRange(MagScale Mscale);
         uint8_t QMC5883L_ReadByte(uint8_t QMC5883L_reg);
         void QMC5883L_WriteByte(uint8_t QMC5883L_reg, uint8_t QMC5883L_data);
         I2C QMC5883L_i2c;