From 305dc06de590e4319f782d058e3199435a424218 Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Mon, 29 Oct 2012 16:49:57 +0100 Subject: HMC5843 -> HMC5883L --- sensors/compass/Makefile | 6 ++--- sensors/compass/hmc5843.vala | 51 ----------------------------------------- sensors/compass/hmc5883l.vala | 53 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 54 deletions(-) delete mode 100644 sensors/compass/hmc5843.vala create mode 100644 sensors/compass/hmc5883l.vala (limited to 'sensors') diff --git a/sensors/compass/Makefile b/sensors/compass/Makefile index 178ae55..5cecef4 100644 --- a/sensors/compass/Makefile +++ b/sensors/compass/Makefile @@ -1,14 +1,14 @@ include ../../config.mk -all: HMC5843.so +all: HMC5883L.so clean: rm -f *.c *.so -hmc5843.c: hmc5843.vala +hmc5883l.c: hmc5883l.vala $(VALAC) --pkg gmodule-2.0 --pkg posix --pkg linux -C $< ../compass.vala ../../hw/i2c-device.vala ../../hw/device.vala -HMC5843.so: hmc5843.c +HMC5883l.so: hmc5883l.c $(CC) -shared -fPIC `pkg-config --cflags --libs glib-2.0 gobject-2.0 gmodule-2.0` -o $@ $< .PHONY: all clean diff --git a/sensors/compass/hmc5843.vala b/sensors/compass/hmc5843.vala deleted file mode 100644 index 147a730..0000000 --- a/sensors/compass/hmc5843.vala +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright 2012, Sebastian Reichel - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -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.0Ga (default) */ - 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 { - var data = get_block(0x03, 6); - x = data[0] << 8 | data[1]; - y = data[2] << 8 | data[3]; - z = data[4] << 8 | data[5]; - } -} - -public Type register_plugin(Module module) { - // types are registered automatically - return typeof(HMC5843); -} diff --git a/sensors/compass/hmc5883l.vala b/sensors/compass/hmc5883l.vala new file mode 100644 index 0000000..b30a243 --- /dev/null +++ b/sensors/compass/hmc5883l.vala @@ -0,0 +1,53 @@ +/* Copyright 2012, Sebastian Reichel + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +public class HMC5883L : I2CDevice, Compass { + public static const int COUNTS_PER_MGAUSS = 1090; + + 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("HMC5883L", LogLevelFlags.LEVEL_ERROR, @"invalid device id"); + else + log("HMC5883L", LogLevelFlags.LEVEL_DEBUG, @"correct device id"); + + set_byte(0x00, 0x10); /* default mode */ + set_byte(0x01, 0x20); /* set gain: +/- 1.3Ga (default) */ + set_byte(0x02, 0x00); /* continous conversion */ + } + + public void init(KeyFile cfg) throws KeyFileError, I2CError { + var adapter = cfg.get_uint64("HMC5883L", "i2c-adapter"); + var address = cfg.get_uint64("HMC5883L", "i2c-address"); + setup((uint8) adapter, (uint8) address); + devsetup(); + } + + public void get_data(out int16 x, out int16 y, out int16 z) throws I2CError { + var data = get_block(0x03, 6); + x = data[0] << 8 | data[1]; + y = data[2] << 8 | data[3]; + z = data[4] << 8 | data[5]; + } +} + +public Type register_plugin(Module module) { + // types are registered automatically + return typeof(HMC5843); +} -- cgit v1.2.3