summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2012-10-14 21:24:37 +0200
committerSebastian Reichel <sre@ring0.de>2012-10-14 21:24:37 +0200
commit8bb4d4b778d7e27d50f864cd6f242c311480bbe9 (patch)
tree720cafb69130fcecbde63460c4dc13706df4d85d
parentc65b3a61e83ed32df7d2f6ec6d8a071ede867247 (diff)
downloadmicrocopterd-8bb4d4b778d7e27d50f864cd6f242c311480bbe9.tar.bz2
HMC5843: run i2c device setup calls also for init()
-rw-r--r--sensors/compass/hmc5843.vala15
1 files changed, 12 insertions, 3 deletions
diff --git a/sensors/compass/hmc5843.vala b/sensors/compass/hmc5843.vala
index 03cf493..fb39478 100644
--- a/sensors/compass/hmc5843.vala
+++ b/sensors/compass/hmc5843.vala
@@ -16,16 +16,25 @@
public class HMC5843 : I2CDevice, Compass {
public HMC5843(uint8 dev, uint8 addr = 0x1e) throws I2CError {
setup(dev, addr);
+ devsetup();
+ }
+
+ private void devsetup() throws I2CError {
+ if(get_byte(0x0a) != 'H' || get_byte(0x0b) != '4' || get_byte(0x0c) != '3')
+ log("HMC5843", LogLevelFlags.LEVEL_ERROR, @"HMC5843: invalid device id");
+ else
+ log("HMC5843", LogLevelFlags.LEVEL_DEBUG, @"HMC5843: correct device id");
- set_byte(0x00, 0x10); /* default mode */
- set_byte(0x01, 0x20); /* set gain: +/- 1.5Ga */
- set_byte(0x02, 0x00); /* continous conversion */
+ 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 {
var adapter = cfg.get_uint64("HMC5843", "i2c-adapter");
var address = cfg.get_uint64("HMC5843", "i2c-address");
setup((uint8) adapter, (uint8) address);
+ devsetup();
}
public void get_data(out int16 x, out int16 y, out int16 z) throws I2CError {