mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-03 06:27:47 +00:00
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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user