Library for the HMC5883L with 5 pins
Fork of QMC5883L by
Diff: QMC5883L.cpp
- Revision:
- 7:4136b94b5cb9
- Parent:
- 6:37d4c4e18227
--- 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