diff options
author | Sebastian Reichel <sre@ring0.de> | 2012-10-14 06:18:33 +0200 |
---|---|---|
committer | Sebastian Reichel <sre@ring0.de> | 2012-10-14 06:18:33 +0200 |
commit | 6b17c435c8b614e77a926961ce1ce4975ae35481 (patch) | |
tree | 036bd1d5672c223e6589a8e032908f215493f68d | |
parent | 271cf418418278f23976e2c009f792500d7fa597 (diff) | |
download | microcopterd-6b17c435c8b614e77a926961ce1ce4975ae35481.tar.bz2 |
fix hmc5843 driver
-rw-r--r-- | main.vala | 3 | ||||
-rw-r--r-- | sensors/compass.vala | 2 | ||||
-rw-r--r-- | sensors/compass/hmc5843.vala | 13 |
3 files changed, 11 insertions, 7 deletions
@@ -27,8 +27,7 @@ Kinematics kinematics; bool loop() { try { /* get sensor data */ - int16 gx, gy, gz, ax, ay, az; - uint16 mx, my, mz; + int16 gx, gy, gz, ax, ay, az, mx, my, mz; gyroscope.get_data(out gx, out gy, out gz); accelerometer.get_data(out ax, out ay, out az); compass.get_data(out mx, out my, out mz); diff --git a/sensors/compass.vala b/sensors/compass.vala index 42d43ad..f8104b2 100644 --- a/sensors/compass.vala +++ b/sensors/compass.vala @@ -15,5 +15,5 @@ public interface Compass : Device { public abstract void init(KeyFile cfg) throws Error; - public abstract void get_data(out uint16 x, out uint16 y, out uint16 z) throws Error; + public abstract void get_data(out int16 x, out int16 y, out int16 z) throws Error; } diff --git a/sensors/compass/hmc5843.vala b/sensors/compass/hmc5843.vala index 8248a5a..03cf493 100644 --- a/sensors/compass/hmc5843.vala +++ b/sensors/compass/hmc5843.vala @@ -16,6 +16,10 @@ public class HMC5843 : I2CDevice, Compass { public HMC5843(uint8 dev, uint8 addr = 0x1e) throws I2CError { setup(dev, addr); + + set_byte(0x00, 0x10); /* default mode */ + set_byte(0x01, 0x20); /* set gain: +/- 1.5Ga */ + set_byte(0x02, 0x00); /* continous conversion */ } public void init(KeyFile cfg) throws KeyFileError, I2CError { @@ -24,10 +28,11 @@ public class HMC5843 : I2CDevice, Compass { setup((uint8) adapter, (uint8) address); } - public void get_data(out uint16 x, out uint16 y, out uint16 z) throws I2CError { - x = get_big_word(0x03); - y = get_big_word(0x05); - z = get_big_word(0x07); + public void get_data(out int16 x, out int16 y, out int16 z) throws I2CError { + var data = get_block(0x03, 6); + x = data[0] << 8 | data[1]; + y = data[2] << 8 | data[3]; + z = data[4] << 8 | data[5]; } } |