diff options
-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 { |