Add option to beep max height in feet rather than just meters
authorKeith Packard <keithp@keithp.com>
Tue, 1 Nov 2022 20:00:22 +0000 (13:00 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 1 Nov 2022 20:03:11 +0000 (13:03 -0700)
Available on all products, plus config UI changes.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosConfigData.java
altoslib/AltosConfigValues.java
altosui/AltosConfigFCUI.java
src/kernel/ao_config.c
src/kernel/ao_config.h
src/kernel/ao_data.h
src/kernel/ao_report.c

index da6e7bfc6d8199b228e0b8918219c3fafb6038b2..5b9ee03120689d829d7f789a40218c143837daa8 100644 (file)
@@ -86,6 +86,8 @@ public class AltosConfigData {
        /* HAS_RADIO_10MW */
        public int              radio_10mw;
 
+       public int              report_feet;
+
        /* Storage info replies */
        public int      storage_size;
        public int      storage_erase_unit;
@@ -320,6 +322,8 @@ public class AltosConfigData {
 
                radio_10mw = AltosLib.MISSING;
 
+               report_feet = AltosLib.MISSING;
+
                tracker_motion = AltosLib.MISSING;
                tracker_interval = AltosLib.MISSING;
 
@@ -513,6 +517,8 @@ public class AltosConfigData {
                /* HAS_RADIO_10MW */
                try { radio_10mw = get_int(line, "Radio 10mw limit:"); } catch (Exception e) {}
 
+               try { report_feet = get_int(line, "Report in feet:"); } catch (Exception e) {}
+
                /* HAS_TRACKER */
                try {
                        int[] values = get_values(line, "Tracker setting:");
@@ -747,6 +753,9 @@ public class AltosConfigData {
                if (radio_10mw != AltosLib.MISSING)
                        radio_10mw = source.radio_10mw();
 
+               if (report_feet != AltosLib.MISSING)
+                       report_feet = source.report_feet();
+
                /* HAS_TRACKER */
                if (tracker_motion != AltosLib.MISSING)
                        tracker_motion = source.tracker_motion();
@@ -803,6 +812,7 @@ public class AltosConfigData {
                dest.set_aprs_offset(aprs_offset);
                dest.set_beep(beep);
                dest.set_radio_10mw(radio_10mw);
+               dest.set_report_feet(report_feet);
                dest.set_tracker_motion(tracker_motion);
                dest.set_tracker_interval(tracker_interval);
        }
@@ -926,6 +936,10 @@ public class AltosConfigData {
                if (radio_10mw != AltosLib.MISSING)
                        link.printf("c p %d\n", radio_10mw);
 
+               /* HAS_RADIO_10MW */
+               if (report_feet != AltosLib.MISSING)
+                       link.printf("c u %d\n", report_feet);
+
                /* HAS_TRACKER */
                if (tracker_motion != AltosLib.MISSING && tracker_interval != AltosLib.MISSING)
                        link.printf("c t %d %d\n", tracker_motion, tracker_interval);
index 65b5f0018de5136fbc48b003c5ff52dd0ded9cf3..8fb302779d188892d541c211ddaca607754fa685 100644 (file)
@@ -123,4 +123,8 @@ public interface AltosConfigValues {
        public abstract int radio_10mw() throws AltosConfigDataException;
 
        public abstract void set_radio_10mw(int radio_10mw);
+
+       public abstract int report_feet() throws AltosConfigDataException;
+
+       public abstract void set_report_feet(int radio_10mw);
 }
index 75b294d9b2c01d5acdd440d80a64350420580045..88f8b0808a92a59c68aab2cf982d43bac124949d 100644 (file)
@@ -43,6 +43,7 @@ public class AltosConfigFCUI
        JLabel                  radio_frequency_label;
        JLabel                  radio_enable_label;
        JLabel                  radio_10mw_label;
+       JLabel                  report_feet_label;
        JLabel                  rate_label;
        JLabel                  aprs_interval_label;
        JLabel                  aprs_ssid_label;
@@ -71,6 +72,7 @@ public class AltosConfigFCUI
        JLabel                  radio_calibration_value;
        JRadioButton            radio_enable_value;
        JRadioButton            radio_10mw_value;
+       JComboBox<String>       report_feet_value;
        AltosUIRateList         rate_value;
        JComboBox<String>       aprs_interval_value;
        JComboBox<Integer>      aprs_ssid_value;
@@ -183,6 +185,11 @@ public class AltosConfigFCUI
                "10"
        };
 
+       static String[]         report_feet_values = {
+               "Meters",
+               "Feet",
+       };
+
        /* A window listener to catch closing events and tell the config code */
        class ConfigListener extends WindowAdapter {
                AltosConfigFCUI ui;
@@ -358,6 +365,13 @@ public class AltosConfigFCUI
                        radio_10mw_value.setToolTipText("Older firmware could not limit radio power");
        }
 
+       void set_report_feet_tool_tip() {
+               if (report_feet_value.isVisible())
+                       report_feet_value.setToolTipText("Units used after landing to beep max height");
+               else
+                       report_feet_value.setToolTipText("Older firmware always beeps max height in meters");
+       }
+
        /* Build the UI using a grid bag */
        public AltosConfigFCUI(JFrame in_owner, boolean remote) {
                super (in_owner, title, false);
@@ -616,6 +630,32 @@ public class AltosConfigFCUI
                set_radio_10mw_tool_tip();
                row++;
 
+               /* Report feet */
+               c = new GridBagConstraints();
+               c.gridx = 0; c.gridy = row;
+               c.gridwidth = 4;
+               c.fill = GridBagConstraints.NONE;
+               c.anchor = GridBagConstraints.LINE_START;
+               c.insets = il;
+               c.ipady = 5;
+               report_feet_label = new JLabel("Beep max height in:");
+               pane.add(report_feet_label, c);
+
+               c = new GridBagConstraints();
+               c.gridx = 4; c.gridy = row;
+               c.gridwidth = 4;
+               c.fill = GridBagConstraints.HORIZONTAL;
+               c.weightx = 1;
+               c.anchor = GridBagConstraints.LINE_START;
+               c.insets = ir;
+               c.ipady = 5;
+               report_feet_value = new JComboBox<String>(report_feet_values);
+               report_feet_value.setEditable(false);
+               report_feet_value.addItemListener(this);
+               pane.add(report_feet_value, c);
+               set_report_feet_tool_tip();
+               row++;
+
                /* Telemetry Rate */
                c = new GridBagConstraints();
                c.gridx = 0; c.gridy = row;
@@ -1488,6 +1528,31 @@ public class AltosConfigFCUI
                        return AltosLib.MISSING;
        }
 
+       public void set_report_feet(int new_report_feet) {
+               if (new_report_feet != AltosLib.MISSING) {
+                       if (new_report_feet >= report_feet_values.length)
+                               new_report_feet = 0;
+                       if (new_report_feet < 0) {
+                               report_feet_value.setEnabled(false);
+                               new_report_feet = 0;
+                       } else {
+                               report_feet_value.setEnabled(true);
+                       }
+                       report_feet_value.setSelectedIndex(new_report_feet);
+               }
+               report_feet_value.setVisible(new_report_feet != AltosLib.MISSING);
+               report_feet_label.setVisible(new_report_feet != AltosLib.MISSING);
+
+               set_report_feet_tool_tip();
+       }
+
+       public int report_feet() {
+               if (report_feet_value.isVisible())
+                       return report_feet_value.getSelectedIndex();
+               else
+                       return AltosLib.MISSING;
+       }
+
        String[] tracker_motion_values() {
                if (AltosConvert.imperial_units)
                        return tracker_motion_values_ft;
index b5dd7ddf8f1c32f47de032be6d65d8904b43944e..be3e8c7222d1bc48746700a8f1ac32d0d7ac6daf 100644 (file)
@@ -55,6 +55,7 @@ uint8_t ao_force_freq;
 #define AO_CONFIG_DEFAULT_PAD_ORIENTATION      AO_PAD_ORIENTATION_ANTENNA_UP
 #define AO_CONFIG_DEFAULT_PYRO_TIME    AO_MS_TO_TICKS(50)
 #define AO_CONFIG_DEFAULT_RADIO_10MW   0
+#define AO_CONFIG_DEFAULT_REPORT_FEET  0
 #if HAS_CONFIG_SAVE
 #ifndef USE_INTERNAL_FLASH
 #error Please define USE_INTERNAL_FLASH
@@ -251,6 +252,8 @@ _ao_config_get(void)
                if (minor < 25)
                        ao_config.radio_10mw = AO_CONFIG_DEFAULT_RADIO_10MW;
 #endif
+               if (minor < 26)
+                       ao_config.report_feet = AO_CONFIG_DEFAULT_REPORT_FEET;
                ao_config.minor = AO_CONFIG_MINOR;
                ao_config_dirty = 1;
        }
@@ -880,6 +883,24 @@ ao_config_radio_10mw_set(void)
 
 #endif
 
+static void
+ao_config_report_feet_show(void)
+{
+       printf ("Report in feet: %d\n", ao_config.report_feet);
+}
+
+static void
+ao_config_report_feet_set(void)
+{
+       uint32_t r = ao_cmd_decimal();
+       if (ao_cmd_status != ao_cmd_success)
+               return;
+       _ao_config_edit_start();
+       ao_config.report_feet = !!r;
+       _ao_config_edit_finish();
+}
+
+
 #if HAS_BEEP
 static void
 ao_config_beep_show(void)
@@ -1131,6 +1152,8 @@ const struct ao_config_var ao_config_vars[] = {
        { "p <0 no limit, 1 limit>\0Limit radio power to 10mW",
          ao_config_radio_10mw_set,     ao_config_radio_10mw_show },
 #endif
+       { "u <0 meters, 1 feet>\0Units to report height after landing",
+         ao_config_report_feet_set,    ao_config_report_feet_show },
        { "s\0Show",
          ao_config_show,               0 },
 #if HAS_CONFIG_SAVE
index f43401be6051a812f0c9854a408f832a64b83ed9..bf57d9543a11102f09dc3d29bdfb4bdf5ffe2b7b 100644 (file)
@@ -58,7 +58,7 @@
 #endif
 
 #define AO_CONFIG_MAJOR        1
-#define AO_CONFIG_MINOR        25
+#define AO_CONFIG_MINOR        26
 
 /* All cc1200 devices support limiting TX power to 10mW */
 #if !defined(HAS_RADIO_10MW) && defined(AO_CC1200_SPI)
@@ -134,6 +134,7 @@ struct ao_config {
 #if HAS_RADIO_10MW
        uint8_t         radio_10mw;             /* minor version 25 */
 #endif
+       uint8_t         report_feet;            /* minor version 26 */
 };
 
 struct ao_config_1_24 {
index 0f96cb897bcf521081c89e6007cc56444697ac73..b49d6a558db2b3b2eb0e18d6c950f42f5e4e04b5 100644 (file)
@@ -182,6 +182,10 @@ extern volatile uint8_t            ao_data_count;
 
 #endif /* AO_DATA_RING */
 
+#define AO_ALT_TYPE    int32_t
+
+typedef AO_ALT_TYPE    alt_t;
+
 #if !HAS_BARO && HAS_MS5607
 
 /* Either an MS5607 or an MS5611 hooked to a SPI port
@@ -191,10 +195,6 @@ extern volatile uint8_t            ao_data_count;
 
 typedef int32_t        pres_t;
 
-#define AO_ALT_TYPE    int32_t
-
-typedef AO_ALT_TYPE    alt_t;
-
 #define ao_data_pres_cook(packet)      ao_ms5607_convert(&packet->ms5607_raw, &packet->ms5607_cooked)
 
 #define ao_data_pres(packet)   ((packet)->ms5607_cooked.pres)
index 4624403a10d61e0a255caf38f56fecdc8bcff4af..977cea854ff1f014e0927a25530b34988e2682a8 100644 (file)
@@ -149,7 +149,7 @@ ao_report_digit(uint8_t digit)
 }
 
 static void
-ao_report_number(ao_v_t n)
+ao_report_number(int32_t n)
 {
        uint8_t digits[10];
        uint8_t ndigits, i;
@@ -171,7 +171,14 @@ ao_report_number(ao_v_t n)
 static void
 ao_report_altitude(void)
 {
-       ao_report_number(ao_max_height);
+       alt_t max_h = ao_max_height;
+       if (ao_config.report_feet) {
+               max_h = max_h * 39 / 12;
+               /* report a leading zero to distinguish */
+               if (max_h)
+                       ao_report_digit(0);
+       }
+       ao_report_number(max_h);
 }
 
 #if HAS_BATTERY_REPORT