diff options
author | Sebastian Reichel <sre@ring0.de> | 2012-10-14 21:23:03 +0200 |
---|---|---|
committer | Sebastian Reichel <sre@ring0.de> | 2012-10-14 21:23:03 +0200 |
commit | c65b3a61e83ed32df7d2f6ec6d8a071ede867247 (patch) | |
tree | ee927f6f44aca31ac8eeaf334211206c269da339 | |
parent | ae772f26f9e3237aaa352012298bb8c2f62058b7 (diff) | |
download | microcopterd-c65b3a61e83ed32df7d2f6ec6d8a071ede867247.tar.bz2 |
ADXL345: run i2c device setup calls also for init()
-rw-r--r-- | sensors/accelerometer/adxl345.vala | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/sensors/accelerometer/adxl345.vala b/sensors/accelerometer/adxl345.vala index 4761178..2f3927d 100644 --- a/sensors/accelerometer/adxl345.vala +++ b/sensors/accelerometer/adxl345.vala @@ -16,17 +16,26 @@ public class ADXL345 : I2CDevice, Accelerometer { public ADXL345(uint8 dev, uint8 addr = 0x53) throws I2CError { setup(dev, addr); + devsetup(); + } + + private void devsetup() throws I2CError { + if(get_byte(0x00) != 0xe5) + log("ADXL345", LogLevelFlags.LEVEL_ERROR, @"ADXL345: invalid device id"); + else + log("ADXL345", LogLevelFlags.LEVEL_DEBUG, @"ADXL345: correct device id"); - set_byte(0x2D, 0x00); /* reset */ - set_byte(0x31, 0x01); /* +/- 4g */ - set_byte(0x2C, 0x0b); /* 200hz */ - set_byte(0x2D, 0x18); /* mode: measurement + auto sleep */ + 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 { var adapter = cfg.get_uint64("ADXL345", "i2c-adapter"); var address = cfg.get_uint64("ADXL345", "i2c-address"); setup((uint8) adapter, (uint8) address); + devsetup(); } public uint8 get_address() throws I2CError { |