summaryrefslogtreecommitdiffstats
path: root/sensors/gyroscope
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2012-06-15 22:56:00 +0200
committerSebastian Reichel <sre@ring0.de>2012-06-15 22:56:00 +0200
commit8a08b9dce9cfc161494ddb07a1c979c7796780ff (patch)
treee86e8a83212c617da44e1b9aed480fe6b50374af /sensors/gyroscope
parent626580d3a16d01f3ba5481d291c4c0c844ef4c46 (diff)
downloadmicrocopterd-8a08b9dce9cfc161494ddb07a1c979c7796780ff.tar.bz2
restructure code
it is now loading its components from plugins
Diffstat (limited to 'sensors/gyroscope')
-rw-r--r--sensors/gyroscope/Makefile14
-rw-r--r--sensors/gyroscope/itg3200.vala (renamed from sensors/gyroscope/gyroscope-itg3200.vala)17
2 files changed, 30 insertions, 1 deletions
diff --git a/sensors/gyroscope/Makefile b/sensors/gyroscope/Makefile
new file mode 100644
index 0000000..f7add97
--- /dev/null
+++ b/sensors/gyroscope/Makefile
@@ -0,0 +1,14 @@
+include ../../config.mk
+
+all: ITG3200.so
+
+clean:
+ rm -f *.c *.so
+
+itg3200.c: itg3200.vala
+ $(VALAC) -g --pkg gmodule-2.0 --pkg posix --pkg linux -C $< ../gyroscope.vala ../../hw/i2c-device.vala ../../hw/device.vala
+
+ITG3200.so: itg3200.c
+ $(CC) -g -shared -fPIC `pkg-config --cflags --libs glib-2.0 gobject-2.0 gmodule-2.0` -o $@ $<
+
+.PHONY: all clean
diff --git a/sensors/gyroscope/gyroscope-itg3200.vala b/sensors/gyroscope/itg3200.vala
index c57aa55..2b7f03e 100644
--- a/sensors/gyroscope/gyroscope-itg3200.vala
+++ b/sensors/gyroscope/itg3200.vala
@@ -14,8 +14,18 @@
*/
public class ITG3200 : I2CDevice, Gyroscope {
+ public int[] rate { get; set; }
+
public ITG3200(uint8 dev, uint8 addr = 0x68) throws I2CError {
- base(dev, addr);
+ setup(dev, addr);
+ }
+
+ public void init(KeyFile cfg) throws KeyFileError, I2CError {
+ rate = new int[3];
+
+ var adapter = cfg.get_uint64("ITG3200", "i2c-adapter");
+ var address = cfg.get_uint64("ITG3200", "i2c-address");
+ setup((uint8) adapter, (uint8) address);
}
public uint8 get_address() throws I2CError {
@@ -46,3 +56,8 @@ public class ITG3200 : I2CDevice, Gyroscope {
z = (int16) get_big_word(0x21);
}
}
+
+public Type register_plugin (Module module) {
+ // types are registered automatically
+ return typeof(ITG3200);
+}