summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.vala4
-rw-r--r--sensors/accelerometer.vala2
-rw-r--r--sensors/accelerometer/adxl345.vala11
3 files changed, 10 insertions, 7 deletions
diff --git a/main.vala b/main.vala
index 60b1c17..c198d75 100644
--- a/main.vala
+++ b/main.vala
@@ -27,8 +27,8 @@ Kinematics kinematics;
bool loop() {
try {
/* get sensor data */
- double gx, gy, gz;
- int16 ax, ay, az, mx, my, mz;
+ double gx, gy, gz, ax, ay, az;
+ int16 mx, my, mz;
gyroscope.get_data(out gx, out gy, out gz);
accelerometer.get_data(out ax, out ay, out az);
compass.get_data(out mx, out my, out mz);
diff --git a/sensors/accelerometer.vala b/sensors/accelerometer.vala
index b1f9607..95345ae 100644
--- a/sensors/accelerometer.vala
+++ b/sensors/accelerometer.vala
@@ -15,5 +15,5 @@
public interface Accelerometer : Device {
public abstract void init(KeyFile cfg) throws Error;
- public abstract void get_data(out int16 x, out int16 y, out int16 z) throws Error;
+ public abstract void get_data(out double x, out double y, out double z) throws Error;
}
diff --git a/sensors/accelerometer/adxl345.vala b/sensors/accelerometer/adxl345.vala
index 9c2c58c..3cc8be7 100644
--- a/sensors/accelerometer/adxl345.vala
+++ b/sensors/accelerometer/adxl345.vala
@@ -14,6 +14,9 @@
*/
public class ADXL345 : I2CDevice, Accelerometer {
+ /* ADXL345 3.9mG per LSB */
+ private static const double scale_factor = (3.9 / 1000.0);
+
public ADXL345(uint8 dev, uint8 addr = 0x53) throws I2CError {
setup(dev, addr);
devsetup();
@@ -56,11 +59,11 @@ public class ADXL345 : I2CDevice, Accelerometer {
set_byte(0x20, z);
}
- public void get_data(out int16 x, out int16 y, out int16 z) throws I2CError {
+ public void get_data(out double x, out double y, out double z) throws I2CError {
var data = get_block(0x32, 6);
- x = data[0] | data[1] << 8;
- y = data[2] | data[3] << 8;
- z = data[4] | data[5] << 8;
+ x = (data[0] | data[1] << 8) * scale_factor;
+ y = (data[2] | data[3] << 8) * scale_factor;
+ z = (data[4] | data[5] << 8) * scale_factor;
}
}