diff options
author | Sebastian Reichel <sre@ring0.de> | 2012-10-14 05:51:55 +0200 |
---|---|---|
committer | Sebastian Reichel <sre@ring0.de> | 2012-10-14 05:51:55 +0200 |
commit | 271cf418418278f23976e2c009f792500d7fa597 (patch) | |
tree | 655708457678ffcec2f2a127a825725d4c58ca76 | |
parent | 752952a611c5d8dad1dea6f272621292b1f79b13 (diff) | |
download | microcopterd-271cf418418278f23976e2c009f792500d7fa597.tar.bz2 |
fix ADXL345 driver
-rw-r--r-- | main.vala | 4 | ||||
-rw-r--r-- | sensors/accelerometer.vala | 2 | ||||
-rw-r--r-- | sensors/accelerometer/adxl345.vala | 14 |
3 files changed, 13 insertions, 7 deletions
@@ -27,8 +27,8 @@ Kinematics kinematics; bool loop() { try { /* get sensor data */ - int16 gx, gy, gz; - uint16 ax, ay, az, mx, my, mz; + int16 gx, gy, gz, ax, ay, az; + uint16 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/accelerometer.vala b/sensors/accelerometer.vala index d9563f9..b1f9607 100644 --- a/sensors/accelerometer.vala +++ b/sensors/accelerometer.vala @@ -15,5 +15,5 @@ public interface Accelerometer : 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/accelerometer/adxl345.vala b/sensors/accelerometer/adxl345.vala index 199903e..4761178 100644 --- a/sensors/accelerometer/adxl345.vala +++ b/sensors/accelerometer/adxl345.vala @@ -16,6 +16,11 @@ public class ADXL345 : I2CDevice, Accelerometer { public ADXL345(uint8 dev, uint8 addr = 0x53) throws I2CError { setup(dev, addr); + + set_byte(0x2D, 0x00); /* reset */ + set_byte(0x31, 0x01); /* +/- 4g */ + set_byte(0x2C, 0x0b); /* 200hz */ + set_byte(0x2D, 0x18); /* mode: measurement + auto sleep */ } public void init(KeyFile cfg) throws KeyFileError, I2CError { @@ -42,10 +47,11 @@ public class ADXL345 : I2CDevice, Accelerometer { set_byte(0x20, z); } - public void get_data(out uint16 x, out uint16 y, out uint16 z) throws I2CError { - x = get_big_word(0x32); - y = get_big_word(0x34); - z = get_big_word(0x36); + public void get_data(out int16 x, out int16 y, out int16 z) throws I2CError { + var data = get_block(0x32, 6); + x = data[0] | data[1] << 8; + y = data[2] | data[3] << 8; + z = data[4] | data[5] << 8; } } |