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 /sensors/accelerometer/adxl345.vala | |
parent | 752952a611c5d8dad1dea6f272621292b1f79b13 (diff) | |
download | microcopterd-271cf418418278f23976e2c009f792500d7fa597.tar.bz2 |
fix ADXL345 driver
Diffstat (limited to 'sensors/accelerometer/adxl345.vala')
-rw-r--r-- | sensors/accelerometer/adxl345.vala | 14 |
1 files changed, 10 insertions, 4 deletions
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; } } |