diff options
Diffstat (limited to 'sensors')
-rw-r--r-- | sensors/gyroscope.vala | 2 | ||||
-rw-r--r-- | sensors/gyroscope/itg3200.vala | 11 |
2 files changed, 8 insertions, 5 deletions
diff --git a/sensors/gyroscope.vala b/sensors/gyroscope.vala index 8cdc0cd..07452ec 100644 --- a/sensors/gyroscope.vala +++ b/sensors/gyroscope.vala @@ -24,6 +24,6 @@ public interface Gyroscope : Device { 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 void get_data(out double x, out double y, out double z) throws I2CError; public abstract int[] rate { get; set; } } diff --git a/sensors/gyroscope/itg3200.vala b/sensors/gyroscope/itg3200.vala index d00c853..ac3e2f0 100644 --- a/sensors/gyroscope/itg3200.vala +++ b/sensors/gyroscope/itg3200.vala @@ -16,6 +16,9 @@ public class ITG3200 : I2CDevice, Gyroscope { public int[] rate { get; set; } + /* ITG3200 14.375 LSBs per °/sec in radians */ + private static double scale_factor = (1.0 / 14.375) * (180.0 / Math.PI); + public ITG3200(uint8 dev, uint8 addr = 0x68) throws I2CError { setup(dev, addr); } @@ -50,10 +53,10 @@ public class ITG3200 : I2CDevice, Gyroscope { return 350 + ((raw + 13200) / 28); } - public void get_data(out int16 x, out int16 y, out int16 z) throws I2CError { - x = (int16) get_big_word(0x1d); - y = (int16) get_big_word(0x1f); - z = (int16) get_big_word(0x21); + public void get_data(out double x, out double y, out double z) throws I2CError { + x = ((int16) get_big_word(0x1d) * scale_factor); + y = ((int16) get_big_word(0x1f) * scale_factor); + z = ((int16) get_big_word(0x21) * scale_factor); } } |