summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.vala3
-rw-r--r--sensors/compass.vala2
-rw-r--r--sensors/compass/hmc5843.vala13
3 files changed, 11 insertions, 7 deletions
diff --git a/main.vala b/main.vala
index 6cfe244..f619642 100644
--- a/main.vala
+++ b/main.vala
@@ -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];
}
}