altosui: Handle units in pyro config.
authorKeith Packard <keithp@keithp.com>
Mon, 25 Nov 2013 08:02:06 +0000 (00:02 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 25 Nov 2013 08:02:06 +0000 (00:02 -0800)
This lets you edit the pyro configuration using imperial units if
desired.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosAccel.java
altoslib/AltosConvert.java
altoslib/AltosDistance.java
altoslib/AltosHeight.java
altoslib/AltosPyro.java
altoslib/AltosSpeed.java
altoslib/AltosTemperature.java
altoslib/AltosUnits.java
altosui/AltosConfigPyroUI.java
altosui/AltosConfigUI.java
altosui/AltosGraph.java

index 08eba359c9f6bfb4622be0344d2b957390c8aead..b838d30b23e815581f0d038bff783d6658e4574b 100644 (file)
@@ -19,25 +19,31 @@ package org.altusmetrum.altoslib_2;
 
 public class AltosAccel extends AltosUnits {
 
 
 public class AltosAccel extends AltosUnits {
 
-       public double value(double v) {
-               if (AltosConvert.imperial_units)
+       public double value(double v, boolean imperial_units) {
+               if (imperial_units)
                        return AltosConvert.meters_to_feet(v);
                return v;
        }
 
                        return AltosConvert.meters_to_feet(v);
                return v;
        }
 
-       public String show_units() {
-               if (AltosConvert.imperial_units)
+       public double inverse(double v, boolean imperial_units) {
+               if (imperial_units)
+                       return AltosConvert.feet_to_meters(v);
+               return v;
+       }
+
+       public String show_units(boolean imperial_units) {
+               if (imperial_units)
                        return "ft/s²";
                return "m/s²";
        }
 
                        return "ft/s²";
                return "m/s²";
        }
 
-       public String say_units() {
-               if (AltosConvert.imperial_units)
+       public String say_units(boolean imperial_units) {
+               if (imperial_units)
                        return "feet per second squared";
                return "meters per second squared";
        }
 
                        return "feet per second squared";
                return "meters per second squared";
        }
 
-       public int show_fraction(int width) {
+       public int show_fraction(int width, boolean imperial_units) {
                return width / 9;
        }
 }
\ No newline at end of file
                return width / 9;
        }
 }
\ No newline at end of file
index 760d9eb98c273a0501f15aad1e09b4dc6a6dca67..8d0b74ddf475051c3d587edab328ddf28a6d3a5c 100644 (file)
@@ -290,10 +290,18 @@ public class AltosConvert {
                return meters_to_feet(meters) / 5280;
        }
 
                return meters_to_feet(meters) / 5280;
        }
 
+       public static double miles_to_meters(double miles) {
+               return feet_to_meters(miles * 5280);
+       }
+
        public static double meters_to_mph(double mps) {
                return meters_to_miles(mps) * 3600;
        }
 
        public static double meters_to_mph(double mps) {
                return meters_to_miles(mps) * 3600;
        }
 
+       public static double mph_to_meters(double mps) {
+               return miles_to_meters(mps) / 3600;
+       }
+
        public static double meters_to_mach(double meters) {
                return meters / 343;            /* something close to mach at usual rocket sites */
        }
        public static double meters_to_mach(double meters) {
                return meters / 343;            /* something close to mach at usual rocket sites */
        }
@@ -306,6 +314,10 @@ public class AltosConvert {
                return c * 9/5 + 32;
        }
 
                return c * 9/5 + 32;
        }
 
+       public static double f_to_c(double c) {
+               return (c - 32) * 5/9;
+       }
+
        public static boolean imperial_units = false;
 
        public static AltosDistance distance = new AltosDistance();
        public static boolean imperial_units = false;
 
        public static AltosDistance distance = new AltosDistance();
index 562571657370a81be5a4d28fb620985e6995e06d..8d359feb9a0cacbbd4a270a19600b5551b717cf8 100644 (file)
@@ -19,32 +19,38 @@ package org.altusmetrum.altoslib_2;
 
 public class AltosDistance extends AltosUnits {
 
 
 public class AltosDistance extends AltosUnits {
 
-       public double value(double v) {
-               if (AltosConvert.imperial_units)
+       public double value(double v, boolean imperial_units) {
+               if (imperial_units)
                        return AltosConvert.meters_to_miles(v);
                return v;
        }
 
                        return AltosConvert.meters_to_miles(v);
                return v;
        }
 
-       public String show_units() {
-               if (AltosConvert.imperial_units)
+       public double inverse(double v, boolean imperial_units) {
+               if (imperial_units)
+                       return AltosConvert.miles_to_meters(v);
+               return v;
+       }
+
+       public String show_units(boolean imperial_units) {
+               if (imperial_units)
                        return "miles";
                return "m";
        }
 
                        return "miles";
                return "m";
        }
 
-       public String say_units() {
-               if (AltosConvert.imperial_units)
+       public String say_units(boolean imperial_units) {
+               if (imperial_units)
                        return "miles";
                return "meters";
        }
 
                        return "miles";
                return "meters";
        }
 
-       public int show_fraction(int width) {
-               if (AltosConvert.imperial_units)
+       public int show_fraction(int width, boolean imperial_units) {
+               if (imperial_units)
                        return width / 3;
                return width / 9;
        }
 
                        return width / 3;
                return width / 9;
        }
 
-       public int say_fraction() {
-               if (AltosConvert.imperial_units)
+       public int say_fraction(boolean imperial_units) {
+               if (imperial_units)
                        return 1;
                return 0;
        }
                        return 1;
                return 0;
        }
index 1d2e4dbce499562d9db2a4d73df41efed1454d70..84bd42d91589e1324bf1cb5dc825e5f9ca488269 100644 (file)
@@ -19,32 +19,31 @@ package org.altusmetrum.altoslib_2;
 
 public class AltosHeight extends AltosUnits {
 
 
 public class AltosHeight extends AltosUnits {
 
-       public double value(double v) {
-               if (AltosConvert.imperial_units)
+       public double value(double v, boolean imperial_units) {
+               if (imperial_units)
                        return AltosConvert.meters_to_feet(v);
                return v;
        }
 
                        return AltosConvert.meters_to_feet(v);
                return v;
        }
 
-       public double parse(String s) throws NumberFormatException {
-               double  v = Double.parseDouble(s);
-               if (AltosConvert.imperial_units)
-                       v = AltosConvert.feet_to_meters(v);
+       public double inverse(double v, boolean imperial_units) {
+               if (imperial_units)
+                       return AltosConvert.feet_to_meters(v);
                return v;
        }
 
                return v;
        }
 
-       public String show_units() {
-               if (AltosConvert.imperial_units)
+       public String show_units(boolean imperial_units) {
+               if (imperial_units)
                        return "ft";
                return "m";
        }
 
                        return "ft";
                return "m";
        }
 
-       public String say_units() {
-               if (AltosConvert.imperial_units)
+       public String say_units(boolean imperial_units) {
+               if (imperial_units)
                        return "feet";
                return "meters";
        }
 
                        return "feet";
                return "meters";
        }
 
-       public int show_fraction(int width) {
+       public int show_fraction(int width, boolean imperial_units) {
                return width / 9;
        }
 }
\ No newline at end of file
                return width / 9;
        }
 }
\ No newline at end of file
index 0142eac825a1dcca84b7a3660cc74baeca9162ed..a219468c7468cfe0c6c11607b14073b167c4deeb 100644 (file)
@@ -28,24 +28,24 @@ public class AltosPyro {
        public static final int pyro_accel_greater              = 0x00000002;
        public static final String pyro_accel_less_string       = "a<";
        public static final String pyro_accel_greater_string    = "a>";
        public static final int pyro_accel_greater              = 0x00000002;
        public static final String pyro_accel_less_string       = "a<";
        public static final String pyro_accel_greater_string    = "a>";
-       public static final String pyro_accel_less_name         = "Acceleration less than (m/s²)";
-       public static final String pyro_accel_greater_name      = "Acceleration greater than (m/s²)";
+       public static final String pyro_accel_less_name         = "Acceleration less than";
+       public static final String pyro_accel_greater_name      = "Acceleration greater than";
        public static final double pyro_accel_scale             = 16.0;
 
        public static final int pyro_speed_less                 = 0x00000004;
        public static final int pyro_speed_greater              = 0x00000008;
        public static final String pyro_speed_less_string       = "s<";
        public static final String pyro_speed_greater_string    = "s>";
        public static final double pyro_accel_scale             = 16.0;
 
        public static final int pyro_speed_less                 = 0x00000004;
        public static final int pyro_speed_greater              = 0x00000008;
        public static final String pyro_speed_less_string       = "s<";
        public static final String pyro_speed_greater_string    = "s>";
-       public static final String pyro_speed_less_name         = "Speed less than (m/s)";
-       public static final String pyro_speed_greater_name      = "Speed greater than (m/s)";
+       public static final String pyro_speed_less_name         = "Speed less than";
+       public static final String pyro_speed_greater_name      = "Speed greater than";
        public static final double pyro_speed_scale             = 16.0;
 
        public static final int pyro_height_less                = 0x00000010;
        public static final int pyro_height_greater             = 0x00000020;
        public static final String pyro_height_less_string      = "h<";
        public static final String pyro_height_greater_string   = "h>";
        public static final double pyro_speed_scale             = 16.0;
 
        public static final int pyro_height_less                = 0x00000010;
        public static final int pyro_height_greater             = 0x00000020;
        public static final String pyro_height_less_string      = "h<";
        public static final String pyro_height_greater_string   = "h>";
-       public static final String pyro_height_less_name        = "Height less than (m)";
-       public static final String pyro_height_greater_name     = "Height greater than (m)";
+       public static final String pyro_height_less_name        = "Height less than";
+       public static final String pyro_height_greater_name     = "Height greater than";
        public static final double pyro_height_scale            = 1.0;
 
        public static final int pyro_orient_less                = 0x00000040;
        public static final double pyro_height_scale            = 1.0;
 
        public static final int pyro_orient_less                = 0x00000040;
@@ -102,12 +102,16 @@ public class AltosPyro {
 
        private static HashMap<Integer,String> pyro_to_name = new HashMap<Integer,String>();
 
 
        private static HashMap<Integer,String> pyro_to_name = new HashMap<Integer,String>();
 
+       private static HashMap<Integer,AltosUnits> pyro_to_units = new HashMap<Integer,AltosUnits>();
+
        private static HashMap<Integer,Double> pyro_to_scale = new HashMap<Integer,Double>();
        
        private static HashMap<Integer,Double> pyro_to_scale = new HashMap<Integer,Double>();
        
-       private static void insert_map(int flag, String string, String name, double scale) {
+       private static void insert_map(int flag, String string, String name, AltosUnits units, double scale) {
                string_to_pyro.put(string, flag);
                pyro_to_string.put(flag, string);
                pyro_to_name.put(flag, name);
                string_to_pyro.put(string, flag);
                pyro_to_string.put(flag, string);
                pyro_to_name.put(flag, name);
+               if (units != null)
+                       pyro_to_units.put(flag, units);
                pyro_to_scale.put(flag, scale);
        }
        
                pyro_to_scale.put(flag, scale);
        }
        
@@ -124,8 +128,22 @@ public class AltosPyro {
        }
 
        public static String pyro_to_name(int flag) {
        }
 
        public static String pyro_to_name(int flag) {
-               if (pyro_to_name.containsKey(flag))
-                       return pyro_to_name.get(flag);
+               String          name;
+               AltosUnits      units = null;
+               if (!pyro_to_name.containsKey(flag))
+                       return null;
+
+               name = pyro_to_name.get(flag);
+               if (pyro_to_units.containsKey(flag))
+                       units = pyro_to_units.get(flag);
+               if (units == null)
+                       return name;
+               return String.format ("%s (%s)", name, units.show_units());
+       }
+
+       public static AltosUnits pyro_to_units(int flag) {
+               if (pyro_to_units.containsKey(flag))
+                       return pyro_to_units.get(flag);
                return null;
        }
 
                return null;
        }
 
@@ -136,29 +154,29 @@ public class AltosPyro {
        }
 
        private static void initialize_maps() {
        }
 
        private static void initialize_maps() {
-               insert_map(pyro_accel_less, pyro_accel_less_string, pyro_accel_less_name, pyro_accel_scale);
-               insert_map(pyro_accel_greater, pyro_accel_greater_string, pyro_accel_greater_name, pyro_accel_scale);
+               insert_map(pyro_accel_less, pyro_accel_less_string, pyro_accel_less_name, AltosConvert.accel, pyro_accel_scale);
+               insert_map(pyro_accel_greater, pyro_accel_greater_string, pyro_accel_greater_name, AltosConvert.accel, pyro_accel_scale);
 
 
-               insert_map(pyro_speed_less, pyro_speed_less_string, pyro_speed_less_name, pyro_speed_scale);
-               insert_map(pyro_speed_greater, pyro_speed_greater_string, pyro_speed_greater_name, pyro_speed_scale);
+               insert_map(pyro_speed_less, pyro_speed_less_string, pyro_speed_less_name, AltosConvert.speed, pyro_speed_scale);
+               insert_map(pyro_speed_greater, pyro_speed_greater_string, pyro_speed_greater_name, AltosConvert.speed, pyro_speed_scale);
 
 
-               insert_map(pyro_height_less, pyro_height_less_string, pyro_height_less_name, pyro_height_scale);
-               insert_map(pyro_height_greater, pyro_height_greater_string, pyro_height_greater_name, pyro_height_scale);
+               insert_map(pyro_height_less, pyro_height_less_string, pyro_height_less_name, AltosConvert.height, pyro_height_scale);
+               insert_map(pyro_height_greater, pyro_height_greater_string, pyro_height_greater_name, AltosConvert.height, pyro_height_scale);
 
 
-               insert_map(pyro_orient_less, pyro_orient_less_string, pyro_orient_less_name, pyro_orient_scale);
-               insert_map(pyro_orient_greater, pyro_orient_greater_string, pyro_orient_greater_name, pyro_orient_scale);
+               insert_map(pyro_orient_less, pyro_orient_less_string, pyro_orient_less_name, null, pyro_orient_scale);
+               insert_map(pyro_orient_greater, pyro_orient_greater_string, pyro_orient_greater_name, null, pyro_orient_scale);
 
 
-               insert_map(pyro_time_less, pyro_time_less_string, pyro_time_less_name, pyro_time_scale);
-               insert_map(pyro_time_greater, pyro_time_greater_string, pyro_time_greater_name, pyro_time_scale);
+               insert_map(pyro_time_less, pyro_time_less_string, pyro_time_less_name, null, pyro_time_scale);
+               insert_map(pyro_time_greater, pyro_time_greater_string, pyro_time_greater_name, null, pyro_time_scale);
 
 
-               insert_map(pyro_ascending, pyro_ascending_string, pyro_ascending_name, 1.0);
-               insert_map(pyro_descending, pyro_descending_string, pyro_descending_name, 1.0);
+               insert_map(pyro_ascending, pyro_ascending_string, pyro_ascending_name, null, 1.0);
+               insert_map(pyro_descending, pyro_descending_string, pyro_descending_name, null, 1.0);
 
 
-               insert_map(pyro_after_motor, pyro_after_motor_string, pyro_after_motor_name, 1.0);
-               insert_map(pyro_delay, pyro_delay_string, pyro_delay_name, pyro_delay_scale);
+               insert_map(pyro_after_motor, pyro_after_motor_string, pyro_after_motor_name, null, 1.0);
+               insert_map(pyro_delay, pyro_delay_string, pyro_delay_name, null, pyro_delay_scale);
                
                
-               insert_map(pyro_state_less, pyro_state_less_string, pyro_state_less_name, 1.0);
-               insert_map(pyro_state_greater_or_equal, pyro_state_greater_or_equal_string, pyro_state_greater_or_equal_name, 1.0);
+               insert_map(pyro_state_less, pyro_state_less_string, pyro_state_less_name, null, 1.0);
+               insert_map(pyro_state_greater_or_equal, pyro_state_greater_or_equal_string, pyro_state_greater_or_equal_name, null, 1.0);
        }
 
        {
        }
 
        {
index 9b9f7240e781e4b0e8f3568c3b44b7b51158e722..6618c539eed867c3beda5f993b35796c096e15a0 100644 (file)
@@ -19,25 +19,31 @@ package org.altusmetrum.altoslib_2;
 
 public class AltosSpeed extends AltosUnits {
 
 
 public class AltosSpeed extends AltosUnits {
 
-       public double value(double v) {
-               if (AltosConvert.imperial_units)
+       public double value(double v, boolean imperial_units) {
+               if (imperial_units)
                        return AltosConvert.meters_to_mph(v);
                return v;
        }
 
                        return AltosConvert.meters_to_mph(v);
                return v;
        }
 
-       public String show_units() {
-               if (AltosConvert.imperial_units)
+       public double inverse(double v, boolean imperial_units) {
+               if (imperial_units)
+                       return AltosConvert.mph_to_meters(v);
+               return v;
+       }
+
+       public String show_units(boolean imperial_units) {
+               if (imperial_units)
                        return "mph";
                return "m/s";
        }
 
                        return "mph";
                return "m/s";
        }
 
-       public String say_units() {
-               if (AltosConvert.imperial_units)
+       public String say_units(boolean imperial_units) {
+               if (imperial_units)
                        return "miles per hour";
                return "meters per second";
        }
 
                        return "miles per hour";
                return "meters per second";
        }
 
-       public int show_fraction(int width) {
+       public int show_fraction(int width, boolean imperial_units) {
                return width / 9;
        }
 }
\ No newline at end of file
                return width / 9;
        }
 }
\ No newline at end of file
index 0105fe539f6f992e4e5f8820cd6b748e6d2acc5d..a636533f5e7c95c5cc639906c5d50bb0cbb19ba2 100644 (file)
@@ -19,25 +19,31 @@ package org.altusmetrum.altoslib_2;
 
 public class AltosTemperature extends AltosUnits {
 
 
 public class AltosTemperature extends AltosUnits {
 
-       public double value(double v) {
-               if (AltosConvert.imperial_units)
+       public double value(double v, boolean imperial_units) {
+               if (imperial_units)
                        return AltosConvert.c_to_f(v);
                return v;
        }
 
                        return AltosConvert.c_to_f(v);
                return v;
        }
 
-       public String show_units() {
-               if (AltosConvert.imperial_units)
+       public double inverse(double v, boolean imperial_units) {
+               if (imperial_units)
+                       return AltosConvert.f_to_c(v);
+               return v;
+       }
+
+       public String show_units(boolean imperial_units) {
+               if (imperial_units)
                        return "°F";
                return "°C";
        }
 
                        return "°F";
                return "°C";
        }
 
-       public String say_units() {
-               if (AltosConvert.imperial_units)
+       public String say_units(boolean imperial_units) {
+               if (imperial_units)
                        return "degrees farenheit";
                return "degrees celsius";
        }
 
                        return "degrees farenheit";
                return "degrees celsius";
        }
 
-       public int show_fraction(int width) {
+       public int show_fraction(int width, boolean imperial_units) {
                return width / 3;
        }
 }
                return width / 3;
        }
 }
index ee74f916f373342f8d0f72664598f8d1fbe91d1f..8f9ccded5f4e8659c93085d30c57b709f5ec6150 100644 (file)
@@ -19,43 +19,90 @@ package org.altusmetrum.altoslib_2;
 
 public abstract class AltosUnits {
 
 
 public abstract class AltosUnits {
 
-       public abstract double value(double v);
+       public abstract double value(double v, boolean imperial_units);
 
 
-       public abstract String show_units();
+       public abstract double inverse(double v, boolean imperial_units);
 
 
-       public abstract String say_units();
+       public abstract String show_units(boolean imperial_units);
 
 
-       public abstract int show_fraction(int width);
+       public abstract String say_units(boolean imperial_units);
 
 
-       int say_fraction() {
+       public abstract int show_fraction(int width, boolean imperial_units);
+
+       public double parse(String s, boolean imperial_units) throws NumberFormatException {
+               double v = Double.parseDouble(s);
+               return inverse(v, imperial_units);
+       }
+
+       public double parse(String s) throws NumberFormatException {
+               return parse(s, AltosConvert.imperial_units);
+       }
+
+       public double value(double v) {
+               return value(v, AltosConvert.imperial_units);
+       }
+               
+       public double inverse(double v) {
+               return inverse(v, AltosConvert.imperial_units);
+       }
+
+       public String show_units() {
+               return show_units(AltosConvert.imperial_units);
+       }
+               
+       public String say_units() {
+               return say_units(AltosConvert.imperial_units);
+       }
+               
+       public int show_fraction(int width) {
+               return show_fraction(width, AltosConvert.imperial_units);
+       }
+               
+       int say_fraction(boolean imperial_units) {
                return 0;
        }
 
                return 0;
        }
 
-       private String show_format(int width) {
-               return String.format("%%%d.%df %s", width, show_fraction(width), show_units());
+       private String show_format(int width, boolean imperial_units) {
+               return String.format("%%%d.%df %s", width, show_fraction(width, imperial_units), show_units(imperial_units));
+       }
+
+       private String say_format(boolean imperial_units) {
+               return String.format("%%1.%df", say_fraction(imperial_units));
        }
 
        }
 
-       private String say_format() {
-               return String.format("%%1.%df", say_fraction());
+       private String say_units_format(boolean imperial_units) {
+               return String.format("%%1.%df %s", say_fraction(imperial_units), say_units(imperial_units));
        }
 
        }
 
-       private String say_units_format() {
-               return String.format("%%1.%df %s", say_fraction(), say_units());
+       public String graph_format(int width, boolean imperial_units) {
+               return String.format(String.format("%%%d.%df", width, show_fraction(width, imperial_units)), 0.0);
        }
 
        public String graph_format(int width) {
        }
 
        public String graph_format(int width) {
-               return String.format(String.format("%%%d.%df", width, show_fraction(width)), 0.0);
+               return graph_format(width, AltosConvert.imperial_units);
+       }
+
+       public String show(int width, double v, boolean imperial_units) {
+               return String.format(show_format(width, imperial_units), value(v, imperial_units));
        }
 
        public String show(int width, double v) {
        }
 
        public String show(int width, double v) {
-               return String.format(show_format(width), value(v));
+               return show(width, v, AltosConvert.imperial_units);
+       }
+
+       public String say(double v, boolean imperial_units) {
+               return String.format(say_format(imperial_units), value(v, imperial_units));
        }
 
        public String say(double v) {
        }
 
        public String say(double v) {
-               return String.format(say_format(), value(v));
+               return say(v, AltosConvert.imperial_units);
+       }
+
+       public String say_units(double v, boolean imperial_units) {
+               return String.format(say_units_format(imperial_units), value(v, imperial_units));
        }
 
        public String say_units(double v) {
        }
 
        public String say_units(double v) {
-               return String.format(say_units_format(), value(v));
+               return say_units(v, AltosConvert.imperial_units);
        }
 }
\ No newline at end of file
        }
 }
\ No newline at end of file
index 2f5c199dbd5616c24f68c006c32ad3ea9857c7ea..81d121119acce8c580343078132213a95f9a9bd5 100644 (file)
@@ -26,7 +26,7 @@ import org.altusmetrum.altosuilib_1.*;
 
 public class AltosConfigPyroUI
        extends AltosUIDialog
 
 public class AltosConfigPyroUI
        extends AltosUIDialog
-       implements ItemListener, DocumentListener
+       implements ItemListener, DocumentListener, AltosUnitsListener
 {
        AltosConfigUI   owner;
        Container       pane;
 {
        AltosConfigUI   owner;
        Container       pane;
@@ -45,13 +45,14 @@ public class AltosConfigPyroUI
                }
        }
 
                }
        }
 
-       class PyroItem implements ItemListener, DocumentListener
+       class PyroItem implements ItemListener, DocumentListener, AltosUnitsListener
        {
                public int              flag;
                public JRadioButton     enable;
                public JTextField       value;
                public JComboBox        combo;
                AltosConfigPyroUI       ui;
        {
                public int              flag;
                public JRadioButton     enable;
                public JTextField       value;
                public JComboBox        combo;
                AltosConfigPyroUI       ui;
+               boolean                 setting;
 
                public void set_enable(boolean enable) {
                        if (value != null)
 
                public void set_enable(boolean enable) {
                        if (value != null)
@@ -62,36 +63,59 @@ public class AltosConfigPyroUI
 
                public void itemStateChanged(ItemEvent e) {
                        set_enable(enable.isSelected());
 
                public void itemStateChanged(ItemEvent e) {
                        set_enable(enable.isSelected());
-                       ui.set_dirty();
+                       if (!setting) 
+                               ui.set_dirty();
                }
 
                public void changedUpdate(DocumentEvent e) {
                }
 
                public void changedUpdate(DocumentEvent e) {
-                       ui.set_dirty();
+                       if (!setting) 
+                               ui.set_dirty();
                }
 
                public void insertUpdate(DocumentEvent e) {
                }
 
                public void insertUpdate(DocumentEvent e) {
-                       ui.set_dirty();
+                       if (!setting) 
+                               ui.set_dirty();
                }
 
                public void removeUpdate(DocumentEvent e) {
                }
 
                public void removeUpdate(DocumentEvent e) {
-                       ui.set_dirty();
+                       if (!setting) 
+                               ui.set_dirty();
+               }
+
+               public void units_changed(boolean imperial_units) {
+                       AltosUnits units = AltosPyro.pyro_to_units(flag);
+
+                       if (units != null) {
+                               try {
+                                       double v = units.parse(value.getText(), !imperial_units);
+                                       set(enabled(), v);
+                               } catch (NumberFormatException ne) {
+                                       set(enabled(), 0.0);
+                               }
+                       }
                }
 
                public void set(boolean new_enable, double new_value) {
                }
 
                public void set(boolean new_enable, double new_value) {
+                       setting = true;
                        enable.setSelected(new_enable);
                        set_enable(new_enable);
                        if (value != null) {
                                double  scale = AltosPyro.pyro_to_scale(flag);
                        enable.setSelected(new_enable);
                        set_enable(new_enable);
                        if (value != null) {
                                double  scale = AltosPyro.pyro_to_scale(flag);
+                               double  unit_value = new_value;
+                               AltosUnits units = AltosPyro.pyro_to_units(flag);
+                               if (units != null)
+                                       unit_value = units.value(new_value);
                                String  format = "%6.0f";
                                if (scale >= 10)
                                        format = "%6.1f";
                                else if (scale >= 100)
                                        format = "%6.2f";
                                String  format = "%6.0f";
                                if (scale >= 10)
                                        format = "%6.1f";
                                else if (scale >= 100)
                                        format = "%6.2f";
-                               value.setText(String.format(format, new_value));
+                               value.setText(String.format(format, unit_value));
                        }
                        if (combo != null)
                                if (new_value >= AltosLib.ao_flight_boost && new_value <= AltosLib.ao_flight_landed)
                                        combo.setSelectedIndex((int) new_value - AltosLib.ao_flight_boost);
                        }
                        if (combo != null)
                                if (new_value >= AltosLib.ao_flight_boost && new_value <= AltosLib.ao_flight_landed)
                                        combo.setSelectedIndex((int) new_value - AltosLib.ao_flight_boost);
+                       setting = false;
                }
 
                public boolean enabled() {
                }
 
                public boolean enabled() {
@@ -99,8 +123,12 @@ public class AltosConfigPyroUI
                }
 
                public double value() {
                }
 
                public double value() {
-                       if (value != null)
+                       if (value != null) {
+                               AltosUnits units = AltosPyro.pyro_to_units(flag);
+                               if (units != null)
+                                       return units.parse(value.getText());
                                return Double.parseDouble(value.getText());
                                return Double.parseDouble(value.getText());
+                       }
                        if (combo != null)
                                return combo.getSelectedIndex() + AltosLib.ao_flight_boost;
                        return 0;
                        if (combo != null)
                                return combo.getSelectedIndex() + AltosLib.ao_flight_boost;
                        return 0;
@@ -143,7 +171,7 @@ public class AltosConfigPyroUI
                }
        }
 
                }
        }
 
-       class PyroColumn {
+       class PyroColumn implements AltosUnitsListener {
                public PyroItem[]       items;
                public JLabel           label;
                int                     channel;
                public PyroItem[]       items;
                public JLabel           label;
                int                     channel;
@@ -166,17 +194,25 @@ public class AltosConfigPyroUI
                        for (int flag = 1; flag < AltosPyro.pyro_all; flag <<= 1) {
                                if ((AltosPyro.pyro_all & flag) != 0) {
                                        if (items[row].enabled()) {
                        for (int flag = 1; flag < AltosPyro.pyro_all; flag <<= 1) {
                                if ((AltosPyro.pyro_all & flag) != 0) {
                                        if (items[row].enabled()) {
-                                               System.out.printf ("Flag %x enabled\n", flag);
                                                p.flags |= flag;
                                                p.set_value(flag, items[row].value());
                                        }
                                        row++;
                                }
                        }
                                                p.flags |= flag;
                                                p.set_value(flag, items[row].value());
                                        }
                                        row++;
                                }
                        }
-                       System.out.printf ("Pyro %x %s\n", p.flags, p.toString());
                        return p;
                }
 
                        return p;
                }
 
+               public void units_changed(boolean imperial_units) {
+                       int row = 0;
+                       for (int flag = 1; flag < AltosPyro.pyro_all; flag <<= 1) {
+                               if ((AltosPyro.pyro_all & flag) != 0) {
+                                       items[row].units_changed(imperial_units);
+                                       row++;
+                               }
+                       }
+               }
+
                public PyroColumn(AltosConfigPyroUI ui, int x, int y, int in_channel) {
 
                        channel = in_channel;
                public PyroColumn(AltosConfigPyroUI ui, int x, int y, int in_channel) {
 
                        channel = in_channel;
@@ -209,6 +245,7 @@ public class AltosConfigPyroUI
        }
 
        PyroColumn[]    columns;
        }
 
        PyroColumn[]    columns;
+       JLabel[]        labels;
 
        public void set_pyros(AltosPyro[] pyros) {
                for (int i = 0; i < pyros.length; i++) {
 
        public void set_pyros(AltosPyro[] pyros) {
                for (int i = 0; i < pyros.length; i++) {
@@ -244,6 +281,34 @@ public class AltosConfigPyroUI
                owner.set_dirty();
        }
 
                owner.set_dirty();
        }
 
+       public void units_changed(boolean imperial_units) {
+               for (int c = 0; c < columns.length; c++)
+                       columns[c].units_changed(imperial_units);
+               int r = 0;
+               for (int flag = 1; flag <= AltosPyro.pyro_all; flag <<= 1) {
+                       String n = AltosPyro.pyro_to_name(flag);
+                       if (n != null) {
+                               labels[r].setText(n);
+                               r++;
+                       }
+               }
+       }
+
+       /* A window listener to catch closing events and tell the config code */
+       class ConfigListener extends WindowAdapter {
+               AltosConfigPyroUI       ui;
+               AltosConfigUI           owner;
+
+               public ConfigListener(AltosConfigPyroUI this_ui, AltosConfigUI this_owner) {
+                       ui = this_ui;
+                       owner = this_owner;
+               }
+
+               public void windowClosing(WindowEvent e) {
+                       ui.setVisible(false);
+               }
+       }
+
        public AltosConfigPyroUI(AltosConfigUI in_owner, AltosPyro[] pyros) {
 
                super(in_owner, "Configure Pyro Channels", false);
        public AltosConfigPyroUI(AltosConfigUI in_owner, AltosPyro[] pyros) {
 
                super(in_owner, "Configure Pyro Channels", false);
@@ -255,6 +320,13 @@ public class AltosConfigPyroUI
                pane = getContentPane();
                pane.setLayout(new GridBagLayout());
 
                pane = getContentPane();
                pane.setLayout(new GridBagLayout());
 
+               int     nrow = 0;
+               for (int flag = 1; flag < AltosPyro.pyro_all; flag <<= 1)
+                       if ((flag & AltosPyro.pyro_all) != 0)
+                               nrow++;
+
+               labels = new JLabel[nrow];
+
                int     row = 1;
 
                for (int flag = 1; flag <= AltosPyro.pyro_all; flag <<= 1) {
                int     row = 1;
 
                for (int flag = 1; flag <= AltosPyro.pyro_all; flag <<= 1) {
@@ -270,6 +342,7 @@ public class AltosConfigPyroUI
                                c.insets = il;
                                JLabel label = new JLabel(n);
                                pane.add(label, c);
                                c.insets = il;
                                JLabel label = new JLabel(n);
                                pane.add(label, c);
+                               labels[row-1] = label;
                                row++;
                        }
                }
                                row++;
                        }
                }
@@ -280,6 +353,13 @@ public class AltosConfigPyroUI
                        columns[i] = new PyroColumn(this, i*2 + 1, 0, i);
                        columns[i].set(pyros[i]);
                }
                        columns[i] = new PyroColumn(this, i*2 + 1, 0, i);
                        columns[i].set(pyros[i]);
                }
+               addWindowListener(new ConfigListener(this, owner));
+               AltosPreferences.register_units_listener(this);
+       }
+
+       public void dispose() {
+               AltosPreferences.unregister_units_listener(this);
+               super.dispose();
        }
 
        public void make_visible() {
        }
 
        public void make_visible() {
index a6d27977cd5d41b211f6c1d511adf8e8287b2633..e07984b90edce148e6021da22d720e1b5a5bd670 100644 (file)
@@ -185,7 +185,7 @@ public class AltosConfigUI
 
        void set_pad_orientation_tool_tip() {
                if (pad_orientation_value.isEnabled())
 
        void set_pad_orientation_tool_tip() {
                if (pad_orientation_value.isEnabled())
-                       pad_orientation_value.setToolTipText("How will TeleMetrum be mounted in the airframe");
+                       pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
                else {
                        if (is_telemetrum())
                                pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
                else {
                        if (is_telemetrum())
                                pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
@@ -198,7 +198,7 @@ public class AltosConfigUI
 
        /* Build the UI using a grid bag */
        public AltosConfigUI(JFrame in_owner, boolean remote) {
 
        /* Build the UI using a grid bag */
        public AltosConfigUI(JFrame in_owner, boolean remote) {
-               super (in_owner, "Configure TeleMetrum", false);
+               super (in_owner, "Configure Flight Computer", false);
 
                owner = in_owner;
                GridBagConstraints c;
 
                owner = in_owner;
                GridBagConstraints c;
@@ -661,7 +661,10 @@ public class AltosConfigUI
        AltosConfigPyroUI       pyro_ui;
 
        public void dispose() {
        AltosConfigPyroUI       pyro_ui;
 
        public void dispose() {
+               if (pyro_ui != null)
+                       pyro_ui.dispose();
                AltosPreferences.unregister_units_listener(this);
                AltosPreferences.unregister_units_listener(this);
+               super.dispose();
        }
 
        /* Listen for events from our buttons */
        }
 
        /* Listen for events from our buttons */
@@ -669,10 +672,10 @@ public class AltosConfigUI
                String  cmd = e.getActionCommand();
 
                if (cmd.equals("Pyro")) {
                String  cmd = e.getActionCommand();
 
                if (cmd.equals("Pyro")) {
-                       if (pyro_ui == null && pyros != null) {
+                       if (pyro_ui == null && pyros != null)
                                pyro_ui = new AltosConfigPyroUI(this, pyros);
                                pyro_ui = new AltosConfigPyroUI(this, pyros);
+                       if (pyro_ui != null)
                                pyro_ui.make_visible();
                                pyro_ui.make_visible();
-                       }
                        return;
                }
 
                        return;
                }
 
@@ -757,9 +760,11 @@ public class AltosConfigUI
        }
        
        public void units_changed(boolean imperial_units) {
        }
        
        public void units_changed(boolean imperial_units) {
+               String v = main_deploy_value.getSelectedItem().toString();
                main_deploy_label.setText(get_main_deploy_label());
                set_main_deploy_values();
                main_deploy_label.setText(get_main_deploy_label());
                set_main_deploy_values();
-               listener.actionPerformed(new ActionEvent(this, 0, "Reset"));
+               int m = (int) (AltosConvert.height.parse(v, !imperial_units) + 0.5);
+               set_main_deploy(m);
        }
 
        public void set_apogee_delay(int new_apogee_delay) {
        }
 
        public void set_apogee_delay(int new_apogee_delay) {
index e6cd7bd840c301683e0720ee1c0fcd8446225489..c505d2d8c5dc41771b9cc1d07bd03e8afece8f0e 100644 (file)
@@ -37,76 +37,92 @@ import org.jfree.data.*;
 
 class AltosVoltage extends AltosUnits {
 
 
 class AltosVoltage extends AltosUnits {
 
-       public double value(double v) {
+       public double value(double v, boolean imperial_units) {
                return v;
        }
 
                return v;
        }
 
-       public String show_units() {
+       public double inverse(double v, boolean imperial_units) {
+               return v;
+       }
+
+       public String show_units(boolean imperial_units) {
                return "V";
        }
 
                return "V";
        }
 
-       public String say_units() {
+       public String say_units(boolean imperial_units) {
                return "volts";
        }
 
                return "volts";
        }
 
-       public int show_fraction(int width) {
+       public int show_fraction(int width, boolean imperial_units) {
                return width / 2;
        }
 }
 
 class AltosNsat extends AltosUnits {
 
                return width / 2;
        }
 }
 
 class AltosNsat extends AltosUnits {
 
-       public double value(double v) {
+       public double value(double v, boolean imperial_units) {
+               return v;
+       }
+
+       public double inverse(double v, boolean imperial_units) {
                return v;
        }
 
                return v;
        }
 
-       public String show_units() {
+       public String show_units(boolean imperial_units) {
                return "Sats";
        }
 
                return "Sats";
        }
 
-       public String say_units() {
+       public String say_units(boolean imperial_units) {
                return "Satellites";
        }
 
                return "Satellites";
        }
 
-       public int show_fraction(int width) {
+       public int show_fraction(int width, boolean imperial_units) {
                return 0;
        }
 }
 
 class AltosPressure extends AltosUnits {
 
                return 0;
        }
 }
 
 class AltosPressure extends AltosUnits {
 
-       public double value(double p) {
+       public double value(double p, boolean imperial_units) {
                return p;
        }
 
                return p;
        }
 
-       public String show_units() {
+       public double inverse(double p, boolean imperial_units) {
+               return p;
+       }
+
+       public String show_units(boolean imperial_units) {
                return "Pa";
        }
 
                return "Pa";
        }
 
-       public String say_units() {
+       public String say_units(boolean imperial_units) {
                return "pascals";
        }
 
                return "pascals";
        }
 
-       public int show_fraction(int width) {
+       public int show_fraction(int width, boolean imperial_units) {
                return 0;
        }
 }
 
 class AltosDbm extends AltosUnits {
 
                return 0;
        }
 }
 
 class AltosDbm extends AltosUnits {
 
-       public double value(double d) {
+       public double value(double d, boolean imperial_units) {
+               return d;
+       }
+
+       public double inverse(double d, boolean imperial_units) {
                return d;
        }
 
                return d;
        }
 
-       public String show_units() {
+       public String show_units(boolean imperial_units) {
                return "dBm";
        }
 
                return "dBm";
        }
 
-       public String say_units() {
+       public String say_units(boolean imperial_units) {
                return "D B M";
        }
 
                return "D B M";
        }
 
-       public int show_fraction(int width) {
+       public int show_fraction(int width, boolean imperial_units) {
                return 0;
        }
 }
                return 0;
        }
 }