altos/altosui: Add pad orientation configure option
authorKeith Packard <keithp@keithp.com>
Wed, 3 Aug 2011 02:07:56 +0000 (19:07 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 3 Aug 2011 02:07:56 +0000 (19:07 -0700)
Allow TeleMetrum to be operated with the antenna pointing downwards on
the pad. This provides some additional flexibility when designing an
ebay.

The accelerometer calibration levels are flipped around to match, so
no re-calibration should be required.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosConfig.java
altosui/AltosConfigUI.java
altosui/AltosSerial.java
src/ao.h
src/ao_config.c
src/ao_flight_test.c
src/ao_sample.c

index e3c30d4..04d7552 100644 (file)
@@ -71,6 +71,7 @@ public class AltosConfig implements ActionListener {
        int_ref         radio_calibration;
        int_ref         flight_log_max;
        int_ref         ignite_mode;
+       int_ref         pad_orientation;
        string_ref      version;
        string_ref      product;
        string_ref      callsign;
@@ -132,6 +133,7 @@ public class AltosConfig implements ActionListener {
                config_ui.set_radio_calibration(radio_calibration.get());
                config_ui.set_flight_log_max(flight_log_max.get());
                config_ui.set_ignite_mode(ignite_mode.get());
+               config_ui.set_pad_orientation(pad_orientation.get());
                config_ui.set_callsign(callsign.get());
                config_ui.set_clean();
                config_ui.make_visible();
@@ -139,12 +141,10 @@ public class AltosConfig implements ActionListener {
 
        void process_line(String line) {
                if (line == null) {
-                       System.out.printf("timeout\n");
                        abort();
                        return;
                }
                if (line.equals("done")) {
-                       System.out.printf("done\n");
                        if (serial_line != null)
                                update_ui();
                        return;
@@ -156,6 +156,7 @@ public class AltosConfig implements ActionListener {
                get_int(line, "Radio cal:", radio_calibration);
                get_int(line, "Max flight log:", flight_log_max);
                get_int(line, "Ignite mode:", ignite_mode);
+               get_int(line, "Pad orientation:", pad_orientation);
                get_string(line, "Callsign:", callsign);
                get_string(line,"software-version", version);
                get_string(line,"product", product);
@@ -229,6 +230,8 @@ public class AltosConfig implements ActionListener {
                                        serial_line.printf("c l %d\n", flight_log_max.get());
                                if (ignite_mode.get() >= 0)
                                        serial_line.printf("c i %d\n", ignite_mode.get());
+                               if (pad_orientation.get() >= 0)
+                                       serial_line.printf("c o %d\n", pad_orientation.get());
                                serial_line.printf("c w\n");
                        } catch (InterruptedException ie) {
                        } finally {
@@ -312,6 +315,7 @@ public class AltosConfig implements ActionListener {
                radio_calibration.set(config_ui.radio_calibration());
                flight_log_max.set(config_ui.flight_log_max());
                ignite_mode.set(config_ui.ignite_mode());
+               pad_orientation.set(config_ui.pad_orientation());
                callsign.set(config_ui.callsign());
                run_serial_thread(serial_mode_save);
        }
@@ -347,6 +351,7 @@ public class AltosConfig implements ActionListener {
                radio_calibration = new int_ref(1186611);
                flight_log_max = new int_ref(0);
                ignite_mode = new int_ref(-1);
+               pad_orientation = new int_ref(-1);
                callsign = new string_ref("N0CALL");
                version = new string_ref("unknown");
                product = new string_ref("unknown");
index 6f635b9..1a48c1d 100644 (file)
@@ -47,6 +47,7 @@ public class AltosConfigUI
        JLabel          radio_calibration_label;
        JLabel          flight_log_max_label;
        JLabel          ignite_mode_label;
+       JLabel          pad_orientation_label;
        JLabel          callsign_label;
 
        public boolean          dirty;
@@ -61,6 +62,7 @@ public class AltosConfigUI
        JTextField      radio_calibration_value;
        JComboBox       flight_log_max_value;
        JComboBox       ignite_mode_value;
+       JComboBox       pad_orientation_value;
        JTextField      callsign_value;
 
        JButton         save;
@@ -91,6 +93,11 @@ public class AltosConfigUI
                "Redundant Main",
        };
 
+       static String[] pad_orientation_values = {
+               "Antenna Up",
+               "Antenna Down",
+       };
+
        static String[] radio_channel_values = new String[10];
                {
                        for (int i = 0; i <= 9; i++)
@@ -358,9 +365,33 @@ public class AltosConfigUI
                ignite_mode_value.addItemListener(this);
                pane.add(ignite_mode_value, c);
 
-               /* Buttons */
+               /* Pad orientation */
                c = new GridBagConstraints();
                c.gridx = 0; c.gridy = 10;
+               c.gridwidth = 4;
+               c.fill = GridBagConstraints.NONE;
+               c.anchor = GridBagConstraints.LINE_START;
+               c.insets = il;
+               c.ipady = 5;
+               pad_orientation_label = new JLabel("Pad Orientation:");
+               pane.add(pad_orientation_label, c);
+
+               c = new GridBagConstraints();
+               c.gridx = 4; c.gridy = 10;
+               c.gridwidth = 4;
+               c.fill = GridBagConstraints.HORIZONTAL;
+               c.weightx = 1;
+               c.anchor = GridBagConstraints.LINE_START;
+               c.insets = ir;
+               c.ipady = 5;
+               pad_orientation_value = new JComboBox(pad_orientation_values);
+               pad_orientation_value.setEditable(false);
+               pad_orientation_value.addItemListener(this);
+               pane.add(pad_orientation_value, c);
+
+               /* Buttons */
+               c = new GridBagConstraints();
+               c.gridx = 0; c.gridy = 11;
                c.gridwidth = 2;
                c.fill = GridBagConstraints.NONE;
                c.anchor = GridBagConstraints.LINE_START;
@@ -371,7 +402,7 @@ public class AltosConfigUI
                save.setActionCommand("Save");
 
                c = new GridBagConstraints();
-               c.gridx = 2; c.gridy = 10;
+               c.gridx = 2; c.gridy = 11;
                c.gridwidth = 2;
                c.fill = GridBagConstraints.NONE;
                c.anchor = GridBagConstraints.CENTER;
@@ -382,7 +413,7 @@ public class AltosConfigUI
                reset.setActionCommand("Reset");
 
                c = new GridBagConstraints();
-               c.gridx = 4; c.gridy = 10;
+               c.gridx = 4; c.gridy = 11;
                c.gridwidth = 2;
                c.fill = GridBagConstraints.NONE;
                c.anchor = GridBagConstraints.CENTER;
@@ -393,7 +424,7 @@ public class AltosConfigUI
                reboot.setActionCommand("Reboot");
 
                c = new GridBagConstraints();
-               c.gridx = 6; c.gridy = 10;
+               c.gridx = 6; c.gridy = 11;
                c.gridwidth = 2;
                c.fill = GridBagConstraints.NONE;
                c.anchor = GridBagConstraints.LINE_END;
@@ -538,13 +569,28 @@ public class AltosConfigUI
                } else {
                        ignite_mode_value.setEnabled(true);
                }
-               ignite_mode_value.setSelectedItem(Integer.toString(new_ignite_mode));
+               ignite_mode_value.setSelectedIndex(new_ignite_mode);
        }
 
        public int ignite_mode() {
                return ignite_mode_value.getSelectedIndex();
        }
 
+
+       public void set_pad_orientation(int new_pad_orientation) {
+               if (new_pad_orientation < 0) {
+                       pad_orientation_value.setEnabled(false);
+                       new_pad_orientation = 0;
+               } else {
+                       pad_orientation_value.setEnabled(true);
+               }
+               pad_orientation_value.setSelectedIndex(new_pad_orientation);
+       }
+
+       public int pad_orientation() {
+               return pad_orientation_value.getSelectedIndex();
+       }
+
        public void set_clean() {
                dirty = false;
        }
index cb82a57..f45aa18 100644 (file)
@@ -233,7 +233,6 @@ public class AltosSerial implements Runnable {
                abort = false;
                timeout_started = false;
                for (;;) {
-                       System.out.printf("timeout %d\n", timeout);
                        AltosLine line = reply_queue.poll(timeout, TimeUnit.MILLISECONDS);
                        if (line != null) {
                                stop_timeout_dialog();
index 9cde9cb..b315af7 100644 (file)
--- a/src/ao.h
+++ b/src/ao.h
@@ -1358,7 +1358,7 @@ ao_igniter_init(void);
  */
 
 #define AO_CONFIG_MAJOR        1
-#define AO_CONFIG_MINOR        5
+#define AO_CONFIG_MINOR        6
 
 struct ao_config {
        uint8_t         major;
@@ -1372,12 +1372,16 @@ struct ao_config {
        uint32_t        radio_cal;              /* minor version 3 */
        uint32_t        flight_log_max;         /* minor version 4 */
        uint8_t         ignite_mode;            /* minor version 5 */
+       uint8_t         pad_orientation;        /* minor version 6 */
 };
 
 #define AO_IGNITE_MODE_DUAL            0
 #define AO_IGNITE_MODE_APOGEE          1
 #define AO_IGNITE_MODE_MAIN            2
 
+#define AO_PAD_ORIENTATION_ANTENNA_UP  0
+#define AO_PAD_ORIENTATION_ANTENNA_DOWN        1
+
 extern __xdata struct ao_config ao_config;
 
 #define AO_CONFIG_MAX_SIZE     128
index 4834988..215dda9 100644 (file)
@@ -28,6 +28,7 @@ __xdata uint8_t ao_config_mutex;
 #define AO_CONFIG_DEFAULT_ACCEL_ZERO_G 16000
 #define AO_CONFIG_DEFAULT_APOGEE_DELAY 0
 #define AO_CONFIG_DEFAULT_IGNITE_MODE  AO_IGNITE_MODE_DUAL
+#define AO_CONFIG_DEFAULT_PAD_ORIENTATION      AO_PAD_ORIENTATION_ANTENNA_UP
 #if USE_INTERNAL_EEPROM
 #define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX       ao_storage_config
 #else
@@ -77,6 +78,7 @@ _ao_config_get(void)
                ao_config.radio_cal = ao_radio_cal;
                ao_config.flight_log_max = AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX;
                ao_config.ignite_mode = AO_CONFIG_DEFAULT_IGNITE_MODE;
+               ao_config.pad_orientation = AO_CONFIG_DEFAULT_PAD_ORIENTATION;
                ao_config_dirty = 1;
        }
        if (ao_config.minor < AO_CONFIG_MINOR) {
@@ -97,6 +99,8 @@ _ao_config_get(void)
                /* Fixupes for minor version 5 */
                if (ao_config.minor < 5)
                        ao_config.ignite_mode = AO_CONFIG_DEFAULT_IGNITE_MODE;
+               if (ao_config.minor < 6)
+                       ao_config.pad_orientation = AO_CONFIG_DEFAULT_PAD_ORIENTATION;
                ao_config.minor = AO_CONFIG_MINOR;
                ao_config_dirty = 1;
        }
@@ -357,7 +361,36 @@ ao_config_ignite_mode_set(void) __reentrant
        ao_config.ignite_mode = ao_cmd_lex_i;
        ao_config_dirty = 1;
        ao_mutex_put(&ao_config_mutex);
-       ao_config_log_show();
+       ao_config_ignite_mode_show();
+}
+#endif
+
+#if HAS_IGNITE
+void
+ao_config_pad_orientation_show(void) __reentrant
+{
+       printf("Pad orientation: %d\n", ao_config.pad_orientation);
+}
+
+void
+ao_config_pad_orientation_set(void) __reentrant
+{
+       ao_cmd_decimal();
+       if (ao_cmd_status != ao_cmd_success)
+               return;
+       ao_mutex_get(&ao_config_mutex);
+       _ao_config_get();
+       ao_cmd_lex_i &= 1;
+       if (ao_config.pad_orientation != ao_cmd_lex_i) {
+               uint16_t t;
+               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.pad_orientation = ao_cmd_lex_i;
+       ao_config_dirty = 1;
+       ao_mutex_put(&ao_config_mutex);
+       ao_config_pad_orientation_show();
 }
 #endif
 
@@ -400,6 +433,10 @@ __code struct ao_config_var ao_config_vars[] = {
 #if HAS_IGNITE
        { "i <0 dual, 1 apogee, 2 main>\0Set igniter mode",
          ao_config_ignite_mode_set,    ao_config_ignite_mode_show },
+#endif
+#if HAS_ACCEL
+       { "o <0 antenna up, 1 antenna down>\0Set pad orientation",
+         ao_config_pad_orientation_set,ao_config_pad_orientation_show },
 #endif
        { "s\0Show",
          ao_config_show,               ao_config_show },
index e55d5ad..56733c8 100644 (file)
@@ -179,8 +179,12 @@ struct ao_config {
        uint16_t        main_deploy;
        int16_t         accel_plus_g;
        int16_t         accel_minus_g;
+       uint8_t         pad_orientation;
 };
 
+#define AO_PAD_ORIENTATION_ANTENNA_UP  0
+#define AO_PAD_ORIENTATION_ANTENNA_DOWN        1
+
 #define ao_config_get()
 
 struct ao_config ao_config;
index ac15664..88ba58c 100644 (file)
@@ -179,6 +179,8 @@ ao_sample(void)
                 * just dropped a bit of noise off the low end.
                 */
                ao_sample_accel = (uint16_t) ((((uint32_t) ao_sample_accel << 16) / (ao_accel_ref[ao_sample_adc] << 1))) >> 1;
+               if (ao_config.pad_orientation != AO_PAD_ORIENTATION_ANTENNA_UP)
+                       ao_sample_accel = 0x7fff - ao_sample_accel;
                ao_adc->accel = ao_sample_accel;
 #endif
 #endif