altos: Flip acceleration data consistently for orientation changes
authorKeith Packard <keithp@keithp.com>
Thu, 2 Jan 2014 05:12:20 +0000 (21:12 -0800)
committerKeith Packard <keithp@keithp.com>
Thu, 2 Jan 2014 05:16:34 +0000 (21:16 -0800)
Must flip the acceleration calibration data using the same function as
flipping the actual acceleration data or the calibration will no
longer be valid after changing orientation. For the MMA655x, this
means using 4095 in both places, rather than using 0x7fff for the
calibration data changes and 4095 for the data value changes. For the
MPU6000, this means using 0 in both places.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/core/ao_config.c
src/core/ao_data.h

index 590d8a49c7e37f229975272eee3e4c5ca0a69655..4482f673f59c0fdbbe132f0c52bcd89d1095a762 100644 (file)
@@ -514,6 +514,10 @@ ao_config_pad_orientation_show(void) __reentrant
        printf("Pad orientation: %d\n", ao_config.pad_orientation);
 }
 
        printf("Pad orientation: %d\n", ao_config.pad_orientation);
 }
 
+#ifndef AO_ACCEL_INVERT
+#define AO_ACCEL_INVERT        0x7fff
+#endif
+
 void
 ao_config_pad_orientation_set(void) __reentrant
 {
 void
 ao_config_pad_orientation_set(void) __reentrant
 {
@@ -523,10 +527,10 @@ ao_config_pad_orientation_set(void) __reentrant
        _ao_config_edit_start();
        ao_cmd_lex_i &= 1;
        if (ao_config.pad_orientation != ao_cmd_lex_i) {
        _ao_config_edit_start();
        ao_cmd_lex_i &= 1;
        if (ao_config.pad_orientation != ao_cmd_lex_i) {
-               uint16_t t;
+               int16_t t;
                t = ao_config.accel_plus_g;
                t = ao_config.accel_plus_g;
-               ao_config.accel_plus_g = 0x7fff - ao_config.accel_minus_g;
-               ao_config.accel_minus_g = 0x7fff - t;
+               ao_config.accel_plus_g = AO_ACCEL_INVERT - ao_config.accel_minus_g;
+               ao_config.accel_minus_g = AO_ACCEL_INVERT - t;
        }
        ao_config.pad_orientation = ao_cmd_lex_i;
        _ao_config_edit_finish();
        }
        ao_config.pad_orientation = ao_cmd_lex_i;
        _ao_config_edit_finish();
index e1d8a1392acc537b1925de297caecf0afac93c3c..c4b062fdb1d0f9f4631354ada9b2baa30df9910a 100644 (file)
@@ -273,14 +273,16 @@ typedef int16_t accel_t;
 
 /* MMA655X is hooked up so that positive values represent negative acceleration */
 
 
 /* MMA655X is hooked up so that positive values represent negative acceleration */
 
+#define AO_ACCEL_INVERT                4095
+
 #define ao_data_accel(packet)                  ((packet)->mma655x)
 #if AO_MMA655X_INVERT
 #define ao_data_accel(packet)                  ((packet)->mma655x)
 #if AO_MMA655X_INVERT
-#define ao_data_accel_cook(packet)             (4095 - (packet)->mma655x)
+#define ao_data_accel_cook(packet)             (AO_ACCEL_INVERT - (packet)->mma655x)
 #else
 #define ao_data_accel_cook(packet)             ((packet)->mma655x)
 #endif
 #define ao_data_set_accel(packet, accel)       ((packet)->mma655x = (accel))
 #else
 #define ao_data_accel_cook(packet)             ((packet)->mma655x)
 #endif
 #define ao_data_set_accel(packet, accel)       ((packet)->mma655x = (accel))
-#define ao_data_accel_invert(accel)            (4095 - (accel))
+#define ao_data_accel_invert(accel)            (AO_ACCEL_INVERT - (accel))
 
 #endif
 
 
 #endif
 
@@ -288,6 +290,8 @@ typedef int16_t accel_t;
 
 #define HAS_ACCEL      1
 
 
 #define HAS_ACCEL      1
 
+#define AO_ACCEL_INVERT                0
+
 typedef int16_t accel_t;
 
 /* MPU6000 is hooked up so that positive y is positive acceleration */
 typedef int16_t accel_t;
 
 /* MPU6000 is hooked up so that positive y is positive acceleration */