lis2mdl: turn on read mode on every read, to ensure that magnetometer data is updated

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2020-08-21 10:12:16 +02:00
parent 4f82c06df9
commit 35a146d60e
+6
View File
@@ -90,6 +90,12 @@ func (d *Device) Configure(cfg Configuration) {
// ReadMagneticField reads the current magnetic field from the device and returns
// it in mG (milligauss). 1 mG = 0.1 µT (microtesla).
func (d *Device) ReadMagneticField() (x int32, y int32, z int32) {
// turn back on read mode, even though it is supposed to be continuous?
cmd := []byte{0}
cmd[0] = byte(0x80 | d.PowerMode<<4 | d.DataRate<<2 | d.SystemMode)
d.bus.WriteRegister(uint8(d.Address), MAG_MR_CFG_REG_A, cmd)
time.Sleep(10 * time.Millisecond)
data := make([]byte, 6)
d.bus.ReadRegister(uint8(d.Address), MAG_OUT_X_L_M, data)