It's used as aid for inertial measurement system

Dependents:   M-G354PDH0_serial_echo_2 M-G354PDH0_serial_echo_1 M-G354PDH0_serial_Lib

Revision:
6:37d4c4e18227
Parent:
4:2620ae5391a6
Child:
7:4136b94b5cb9
--- a/QMC5883L.cpp	Thu Oct 11 17:46:43 2018 +0000
+++ b/QMC5883L.cpp	Tue Nov 06 16:40:11 2018 +0000
@@ -34,7 +34,7 @@
 {
 }
 
-float QMC5883L::setMagRange(MagScale Mscale)
+float QMC5883L::setMagRange(TypeMagScale Mscale)
 {
     float mRes; // Varies with gain
     
@@ -73,9 +73,9 @@
 }
 
 void QMC5883L::init()
-{   
+{
     setMagRange(MagScale_8G);
-    QMC5883L_WriteByte(CONTROL_A, 0x0D | MagScale_8G);  // Range: 8G, ODR: 200 Hz, mode:Continuous-Measurement
+    change_odr_state(MagScale_8G, F200, Continuous_MODE);
     QMC5883L_WriteByte(SET_RESET, 0x01);
     wait_ms(10);
 }
@@ -110,4 +110,25 @@
     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