altoslib: six-axis support for easy timer easytimer-sixaxis
authorKeith Packard <keithp@keithp.com>
Tue, 9 Jun 2020 03:56:30 +0000 (20:56 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 9 Jun 2020 04:32:32 +0000 (21:32 -0700)
Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosIMU.java
altoslib/AltosRotation.java
altosui/AltosConfigFCUI.java

index 7f8be40328faa7d848965d233727a08c90dcc05b..07c99cfc6cf2b114bbe69a0153fb330d17d92b18 100644 (file)
@@ -37,6 +37,8 @@ public class AltosIMU implements Cloneable {
        public static final double      counts_per_g_mpu = 2048.0;
        public static final double      counts_per_g_bmx = 2048.0;
 
+       int                     pad_orientation;
+
        private static double counts_per_g(int imu_type) {
                switch (imu_type) {
                case imu_type_telemega_v1_v2:
@@ -112,10 +114,16 @@ public class AltosIMU implements Cloneable {
                return counts / counts_per_gauss(imu_type, imu_axis);
        }
 
-       public boolean parse_string(String line) {
+       public boolean parse_string(String line, AltosLink link) {
                if (!line.startsWith("Accel:"))
                        return false;
 
+               try {
+                       pad_orientation = link.config_data().pad_orientation;
+               } catch (Exception e) {
+                       return false;
+               }
+
                String[] items = line.split("\\s+");
 
                if (items.length >= 8) {
@@ -349,7 +357,7 @@ public class AltosIMU implements Cloneable {
                        if (line == null) {
                                throw new TimeoutException();
                        }
-                       if (parse_string(line))
+                       if (parse_string(line, link))
                                break;
                }
        }
index 85e213b25f5a0ef0700c3151b6723ee8ff34b925..de840b4dd16dd923c9ed7662e3d4ed194b3ac95c 100644 (file)
@@ -97,8 +97,22 @@ public class AltosRotation extends AltosQuaternion {
                             double z,
                             int pad_orientation) {
                AltosQuaternion orient = AltosQuaternion.vector(x, y, z).normalize();
-               double sky = (pad_orientation & 1) == 0 ? 1 : -1;
-               AltosQuaternion up = new AltosQuaternion(0, 0, 0, sky);
+               double sky_x = 0;
+               double sky_y = 0;
+               double sky_z = 0;
+               double sky_sign = (pad_orientation & 1) == 0 ? 1 : -1;
+               switch (pad_orientation & ~1) {
+               case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP:
+                       sky_z = sky_sign;
+                       break;
+               case AltosLib.AO_PAD_ORIENTATION_WORDS_UPRIGHT:
+                       sky_y = sky_sign;
+                       break;
+               case AltosLib.AO_PAD_ORIENTATION_BIG_PARTS_UP:
+                       sky_x = sky_sign;
+                       break;
+               }
+               AltosQuaternion up = new AltosQuaternion(0, sky_x, sky_y, sky_z);
                rotation = up.vectors_to_rotation(orient);
        }
 
index 5ff37366c4d2bd105389134baae253f895dab283..826559c754193b9b38fbdded3441ba185e2672c5 100644 (file)
@@ -142,6 +142,9 @@ public class AltosConfigFCUI
                "4250",
        };
 
+       static String[]         pad_orientation_values_none = {
+       };
+
        static String[]         pad_orientation_values_radio = {
                "Antenna Up",
                "Antenna Down",
@@ -796,14 +799,8 @@ public class AltosConfigFCUI
                c.anchor = GridBagConstraints.LINE_START;
                c.insets = ir;
                c.ipady = 5;
-               if (has_radio())
-                       pad_orientation_values = pad_orientation_values_radio;
-               else if (is_easytimer())
-                       pad_orientation_values = pad_orientation_values_six_axis;
-               else
-                       pad_orientation_values = pad_orientation_values_no_radio;
 
-               pad_orientation_value = new JComboBox<String>(pad_orientation_values);
+               pad_orientation_value = new JComboBox<String>();
                pad_orientation_value.setEditable(false);
                pad_orientation_value.addItemListener(this);
                pane.add(pad_orientation_value, c);
@@ -1105,13 +1102,27 @@ public class AltosConfigFCUI
                listener = l;
        }
 
+       void set_pad_orientation_values()
+       {
+               if (has_radio())
+                       pad_orientation_values = pad_orientation_values_radio;
+               else if (is_easytimer())
+                       pad_orientation_values = pad_orientation_values_six_axis;
+               else
+                       pad_orientation_values = pad_orientation_values_no_radio;
+               pad_orientation_value.removeAllItems();
+               for (String s : pad_orientation_values)
+                       pad_orientation_value.addItem(s);
+               set_pad_orientation_tool_tip();
+       }
+
        /* set and get all of the dialog values */
        public void set_product(String product) {
                radio_frequency_value.set_product(product);
                product_value.setText(product);
-               set_pad_orientation_tool_tip();
                set_accel_tool_tips();
                set_flight_log_max_tool_tip();
+               set_pad_orientation_values();
        }
 
        public void set_version(String version) {