summaryrefslogtreecommitdiffstats
path: root/sensors
diff options
context:
space:
mode:
Diffstat (limited to 'sensors')
-rw-r--r--sensors/accelerometer.vala1
-rw-r--r--sensors/accelerometer/Makefile14
-rw-r--r--sensors/accelerometer/adxl345.vala (renamed from sensors/accelerometer/accelerometer-adxl345.vala)13
-rw-r--r--sensors/barometer.vala1
-rw-r--r--sensors/barometer/Makefile14
-rw-r--r--sensors/barometer/bmp085.vala (renamed from sensors/barometer/barometer-bmp085.vala)14
-rw-r--r--sensors/compass.vala1
-rw-r--r--sensors/compass/Makefile14
-rw-r--r--sensors/compass/hmc5843.vala (renamed from sensors/compass/compass-hmc5843.vala)13
-rw-r--r--sensors/gyroscope.vala13
-rw-r--r--sensors/gyroscope/Makefile14
-rw-r--r--sensors/gyroscope/itg3200.vala (renamed from sensors/gyroscope/gyroscope-itg3200.vala)17
12 files changed, 124 insertions, 5 deletions
diff --git a/sensors/accelerometer.vala b/sensors/accelerometer.vala
index 27b47f0..d9563f9 100644
--- a/sensors/accelerometer.vala
+++ b/sensors/accelerometer.vala
@@ -14,5 +14,6 @@
*/
public interface Accelerometer : Device {
+ public abstract void init(KeyFile cfg) throws Error;
public abstract void get_data(out uint16 x, out uint16 y, out uint16 z) throws Error;
}
diff --git a/sensors/accelerometer/Makefile b/sensors/accelerometer/Makefile
new file mode 100644
index 0000000..1bd2a03
--- /dev/null
+++ b/sensors/accelerometer/Makefile
@@ -0,0 +1,14 @@
+include ../../config.mk
+
+all: ADXL345.so
+
+clean:
+ rm -f *.c *.so
+
+adxl345.c: adxl345.vala
+ $(VALAC) --pkg gmodule-2.0 --pkg posix --pkg linux -C $< ../accelerometer.vala ../../hw/i2c-device.vala ../../hw/device.vala
+
+ADXL345.so: adxl345.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/accelerometer/accelerometer-adxl345.vala b/sensors/accelerometer/adxl345.vala
index ed9947f..b8aa5e0 100644
--- a/sensors/accelerometer/accelerometer-adxl345.vala
+++ b/sensors/accelerometer/adxl345.vala
@@ -15,7 +15,13 @@
public class ADXL345 : I2CDevice, Accelerometer {
public ADXL345(uint8 dev, uint8 addr = 0x53) throws I2CError {
- base(dev, addr);
+ setup(dev, addr);
+ }
+
+ 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);
}
public uint8 get_address() throws I2CError {
@@ -42,3 +48,8 @@ public class ADXL345 : I2CDevice, Accelerometer {
z = get_big_word(0x36);
}
}
+
+public Type register_plugin (Module module) {
+ // types are registered automatically
+ return typeof(ADXL345);
+}
diff --git a/sensors/barometer.vala b/sensors/barometer.vala
index 5c1f4f9..d891ca0 100644
--- a/sensors/barometer.vala
+++ b/sensors/barometer.vala
@@ -14,6 +14,7 @@
*/
public interface Barometer : Device {
+ public abstract void init(KeyFile cfg) throws Error;
public abstract int32 get_pressure() throws Error;
public double get_altitude(int32 base_pressure) throws Error {
diff --git a/sensors/barometer/Makefile b/sensors/barometer/Makefile
new file mode 100644
index 0000000..9a23671
--- /dev/null
+++ b/sensors/barometer/Makefile
@@ -0,0 +1,14 @@
+include ../../config.mk
+
+all: BMP085.so
+
+clean:
+ rm -f *.c *.so
+
+bmp085.c: bmp085.vala
+ $(VALAC) --pkg gmodule-2.0 --pkg posix --pkg linux -C $< ../barometer.vala ../../hw/i2c-device.vala ../../hw/device.vala
+
+BMP085.so: bmp085.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/barometer/barometer-bmp085.vala b/sensors/barometer/bmp085.vala
index 92ea917..f0da790 100644
--- a/sensors/barometer/barometer-bmp085.vala
+++ b/sensors/barometer/bmp085.vala
@@ -38,10 +38,17 @@ public class BMP085 : I2CDevice, Barometer {
}
public BMP085(uint8 dev, uint8 addr = 0x77) throws I2CError {
- base(dev, addr);
+ setup(dev, addr);
read_calibration_values();
}
+ public void init(KeyFile cfg) throws KeyFileError, I2CError {
+ var adapter = cfg.get_uint64("BMP085", "i2c-adapter");
+ var address = cfg.get_uint64("BMP085", "i2c-address");
+ setup((uint8) adapter, (uint8) address);
+ read_calibration_values();
+ }
+
private void read_calibration_values() throws I2CError {
var data = get_block(0xaa, 22);
cal.AC1 = data[0] << 8 | data[1];
@@ -126,3 +133,8 @@ public class BMP085 : I2CDevice, Barometer {
return (int32) p;
}
}
+
+public Type register_plugin (Module module) {
+ // types are registered automatically
+ return typeof(BMP085);
+}
diff --git a/sensors/compass.vala b/sensors/compass.vala
index b62cb3c..42d43ad 100644
--- a/sensors/compass.vala
+++ b/sensors/compass.vala
@@ -14,5 +14,6 @@
*/
public interface Compass : Device {
+ public abstract void init(KeyFile cfg) throws Error;
public abstract void get_data(out uint16 x, out uint16 y, out uint16 z) throws Error;
}
diff --git a/sensors/compass/Makefile b/sensors/compass/Makefile
new file mode 100644
index 0000000..178ae55
--- /dev/null
+++ b/sensors/compass/Makefile
@@ -0,0 +1,14 @@
+include ../../config.mk
+
+all: HMC5843.so
+
+clean:
+ rm -f *.c *.so
+
+hmc5843.c: hmc5843.vala
+ $(VALAC) --pkg gmodule-2.0 --pkg posix --pkg linux -C $< ../compass.vala ../../hw/i2c-device.vala ../../hw/device.vala
+
+HMC5843.so: hmc5843.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/compass-hmc5843.vala b/sensors/compass/hmc5843.vala
index b09b054..393f985 100644
--- a/sensors/compass/compass-hmc5843.vala
+++ b/sensors/compass/hmc5843.vala
@@ -15,7 +15,13 @@
public class HMC5843 : I2CDevice, Compass {
public HMC5843(uint8 dev, uint8 addr = 0x1e) throws I2CError {
- base(dev, addr);
+ setup(dev, addr);
+ }
+
+ 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);
}
public void get_data(out uint16 x, out uint16 y, out uint16 z) throws I2CError {
@@ -24,3 +30,8 @@ public class HMC5843 : I2CDevice, Compass {
z = get_big_word(0x07);
}
}
+
+public Type register_plugin (Module module) {
+ // types are registered automatically
+ return typeof(HMC5843);
+}
diff --git a/sensors/gyroscope.vala b/sensors/gyroscope.vala
index 165df73..8cdc0cd 100644
--- a/sensors/gyroscope.vala
+++ b/sensors/gyroscope.vala
@@ -14,5 +14,16 @@
*/
public interface Gyroscope : Device {
- public abstract void get_data(out int16 x, out int16 y, out int16 z) throws Error;
+#if 0
+ double[] rate = {0.0, 0.0, 0.0};
+ int[] zero = {0, 0, 0};
+ long[] sample = {0, 0, 0};
+ double smoothFactor = 1.0;
+ double scaleFactor = 0.0;
+ double heading = 0.0;
+ ulong gyroLastMesuredTime = 0;
+#endif
+ public abstract void init(KeyFile cfg) throws Error;
+ public abstract void get_data(out int16 x, out int16 y, out int16 z) throws I2CError;
+ public abstract int[] rate { get; set; }
}
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);
+}