diff options
| -rw-r--r-- | altosui/AltosAscent.java | 12 | ||||
| -rw-r--r-- | altosui/AltosConfigureUI.java | 27 | ||||
| -rw-r--r-- | altosui/AltosDescent.java | 10 | ||||
| -rw-r--r-- | altosui/AltosDisplayThread.java | 24 | ||||
| -rw-r--r-- | altosui/AltosFlightStatsTable.java | 12 | ||||
| -rw-r--r-- | altosui/AltosFlightStatusTableModel.java | 11 | 
6 files changed, 66 insertions, 30 deletions
| diff --git a/altosui/AltosAscent.java b/altosui/AltosAscent.java index 38b3b30f..a158eb21 100644 --- a/altosui/AltosAscent.java +++ b/altosui/AltosAscent.java @@ -169,14 +169,14 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {  			max_value.setFont(Altos.value_font);  		} -		void show(String format, double v) { +		void show(AltosUnits units, double v) {  			if (v == AltosRecord.MISSING) {  				value.setText("Missing");  				max_value.setText("Missing");  			} else { -				value.setText(String.format(format, v)); +				value.setText(units.show(8, v));  				if (v > max || max == AltosRecord.MISSING) { -					max_value.setText(String.format(format, v)); +					max_value.setText(units.show(8, v));  					max = v;  				}  			} @@ -221,7 +221,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {  	class Height extends AscentValueHold {  		void show (AltosState state, int crc_errors) { -			show("%6.0f m", state.height); +			show(AltosConvert.height, state.height);  		}  		public Height (GridBagLayout layout, int y) {  			super (layout, y, "Height"); @@ -235,7 +235,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {  			double speed = state.speed;  			if (!state.ascent)  				speed = state.baro_speed; -			show("%6.0f m/s", speed); +			show(AltosConvert.speed, speed);  		}  		public Speed (GridBagLayout layout, int y) {  			super (layout, y, "Speed"); @@ -246,7 +246,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {  	class Accel extends AscentValueHold {  		void show (AltosState state, int crc_errors) { -			show("%6.0f m/s²", state.acceleration); +			show(AltosConvert.accel, state.acceleration);  		}  		public Accel (GridBagLayout layout, int y) {  			super (layout, y, "Acceleration"); diff --git a/altosui/AltosConfigureUI.java b/altosui/AltosConfigureUI.java index ace245a0..da82e8e0 100644 --- a/altosui/AltosConfigureUI.java +++ b/altosui/AltosConfigureUI.java @@ -91,6 +91,8 @@ public class AltosConfigureUI  	JLabel		callsign_label;  	JTextField	callsign_value; +	JRadioButton	imperial_units; +  	JLabel		font_size_label;  	JComboBox	font_size_value; @@ -236,6 +238,31 @@ public class AltosConfigureUI  		pane.add(callsign_value, c);  		callsign_value.setToolTipText("Callsign sent in packet mode"); +		/* Imperial units setting */ +		c.gridx = 0; +		c.gridy = row; +		c.gridwidth = 1; +		c.fill = GridBagConstraints.NONE; +		c.anchor = GridBagConstraints.WEST; +		pane.add(new JLabel("Imperial Units"), c); + +		imperial_units = new JRadioButton("Enable", AltosUIPreferences.serial_debug()); +		imperial_units.addActionListener(new ActionListener() { +				public void actionPerformed(ActionEvent e) { +					JRadioButton item = (JRadioButton) e.getSource(); +					boolean enabled = item.isSelected(); +					AltosUIPreferences.set_imperial_units(enabled); +				} +			}); +		imperial_units.setToolTipText("Use Imperial units instead of metric"); + +		c.gridx = 1; +		c.gridy = row++; +		c.gridwidth = 3; +		c.fill = GridBagConstraints.NONE; +		c.anchor = GridBagConstraints.WEST; +		pane.add(imperial_units, c); +  		/* Font size setting */  		c.gridx = 0;  		c.gridy = row; diff --git a/altosui/AltosDescent.java b/altosui/AltosDescent.java index 664c5ea6..62258814 100644 --- a/altosui/AltosDescent.java +++ b/altosui/AltosDescent.java @@ -119,6 +119,10 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {  			value.setVisible(false);  		} +		void show(AltosUnits units, double v) { +			value.setText(units.show(8, v)); +		} +  		void show(String format, double v) {  			value.setText(String.format(format, v));  		} @@ -239,7 +243,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {  	class Height extends DescentValue {  		void show (AltosState state, int crc_errors) { -			show("%6.0f m", state.height); +			show(AltosConvert.height, state.height);  		}  		public Height (GridBagLayout layout, int x, int y) {  			super (layout, x, y, "Height"); @@ -253,7 +257,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {  			double speed = state.speed;  			if (!state.ascent)  				speed = state.baro_speed; -			show("%6.0f m/s", speed); +			show(AltosConvert.speed, speed);  		}  		public Speed (GridBagLayout layout, int x, int y) {  			super (layout, x, y, "Speed"); @@ -346,7 +350,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {  	class Range extends DescentValue {  		void show (AltosState state, int crc_errors) { -			show("%6.0f m", state.range); +			show(AltosConvert.distance, state.range);  		}  		public Range (GridBagLayout layout, int x, int y) {  			super (layout, x, y, "Range"); diff --git a/altosui/AltosDisplayThread.java b/altosui/AltosDisplayThread.java index 03ce4efd..cf69c414 100644 --- a/altosui/AltosDisplayThread.java +++ b/altosui/AltosDisplayThread.java @@ -102,15 +102,15 @@ public class AltosDisplayThread extends Thread {  			    state.state < Altos.ao_flight_landed &&  			    state.range >= 0)  			{ -				voice.speak("Height %d, bearing %s %d, elevation %d, range %d.\n", -					    (int) (state.height + 0.5), -                        state.from_pad.bearing_words( -                            AltosGreatCircle.BEARING_VOICE), +				voice.speak("Height %s, bearing %s %d, elevation %d, range %s.\n", +					    AltosConvert.height.say(state.height), +					    state.from_pad.bearing_words( +						    AltosGreatCircle.BEARING_VOICE),  					    (int) (state.from_pad.bearing + 0.5),  					    (int) (state.elevation + 0.5), -					    (int) (state.range + 0.5)); +					    AltosConvert.distance.say(state.range));  			} else if (state.state > Altos.ao_flight_pad) { -				voice.speak("%d meters", (int) (state.height + 0.5)); +				voice.speak(AltosConvert.height.say_units(state.height));  			} else {  				reported_landing = 0;  			} @@ -129,9 +129,9 @@ public class AltosDisplayThread extends Thread {  				else  					voice.speak("rocket may have crashed");  				if (state.from_pad != null) -					voice.speak("Bearing %d degrees, range %d meters.", +					voice.speak("Bearing %d degrees, range %s.",  						    (int) (state.from_pad.bearing + 0.5), -						    (int) (state.from_pad.distance + 0.5)); +						    AltosConvert.distance.say_units(state.from_pad.distance));  				++reported_landing;  				if (state.state != Altos.ao_flight_landed) {  					state.state = Altos.ao_flight_landed; @@ -202,13 +202,13 @@ public class AltosDisplayThread extends Thread {  			voice.speak(state.data.state());  			if ((old_state == null || old_state.state <= Altos.ao_flight_boost) &&  			    state.state > Altos.ao_flight_boost) { -				voice.speak("max speed: %d meters per second.", -					    (int) (state.max_speed + 0.5)); +				voice.speak("max speed: %s.", +					    AltosConvert.speed.say_units(state.max_speed + 0.5));  				ret = true;  			} else if ((old_state == null || old_state.state < Altos.ao_flight_drogue) &&  				   state.state >= Altos.ao_flight_drogue) { -				voice.speak("max height: %d meters.", -					    (int) (state.max_height + 0.5)); +				voice.speak("max height: %s.", +					    AltosConvert.height.say_units(state.max_height + 0.5));  				ret = true;  			}  		} diff --git a/altosui/AltosFlightStatsTable.java b/altosui/AltosFlightStatsTable.java index 14e3bf8f..87ba6aa8 100644 --- a/altosui/AltosFlightStatsTable.java +++ b/altosui/AltosFlightStatsTable.java @@ -84,17 +84,17 @@ public class AltosFlightStatsTable extends JComponent {  			       String.format("%5.0f ft", AltosConvert.meters_to_feet(stats.max_height)));  		new FlightStat(layout, y++, "Maximum speed",  			       String.format("%5.0f m/s", stats.max_speed), -			       String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.max_speed)), -			       String.format("Mach %5.3f", AltosConvert.meters_to_mach(stats.max_speed))); +			       String.format("%5.0f mph", AltosConvert.meters_to_mph(stats.max_speed)), +			       String.format("Mach %4.1f", AltosConvert.meters_to_mach(stats.max_speed)));  		if (stats.max_acceleration != AltosRecord.MISSING) {  			new FlightStat(layout, y++, "Maximum boost acceleration",  				       String.format("%5.0f m/s²", stats.max_acceleration),  				       String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.max_acceleration)), -				       String.format("%5.2f G", AltosConvert.meters_to_g(stats.max_acceleration))); +				       String.format("%5.0f G", AltosConvert.meters_to_g(stats.max_acceleration)));  			new FlightStat(layout, y++, "Average boost acceleration",  				       String.format("%5.0f m/s²", stats.state_accel[Altos.ao_flight_boost]),  				       String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.state_accel[Altos.ao_flight_boost])), -				       String.format("%5.2f G", AltosConvert.meters_to_g(stats.state_accel[Altos.ao_flight_boost]))); +				       String.format("%5.0f G", AltosConvert.meters_to_g(stats.state_accel[Altos.ao_flight_boost])));  		}  		new FlightStat(layout, y++, "Drogue descent rate",  			       String.format("%5.0f m/s", stats.state_baro_speed[Altos.ao_flight_drogue]), @@ -104,10 +104,10 @@ public class AltosFlightStatsTable extends JComponent {  			       String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_main])));  		for (int s = Altos.ao_flight_boost; s <= Altos.ao_flight_main; s++) {  			new FlightStat(layout, y++, String.format("%s time", AltosLib.state_name_capital(s)), -				       String.format("%6.2f s", stats.state_end[s] - stats.state_start[s])); +				       String.format("%6.0f s", stats.state_end[s] - stats.state_start[s]));  		}  		new FlightStat(layout, y++, "Flight Time", -			       String.format("%6.2f s", stats.state_end[Altos.ao_flight_main] - +			       String.format("%6.0f s", stats.state_end[Altos.ao_flight_main] -  					     stats.state_start[Altos.ao_flight_boost]));  	} diff --git a/altosui/AltosFlightStatusTableModel.java b/altosui/AltosFlightStatusTableModel.java index 75bf16eb..c2cf8cd1 100644 --- a/altosui/AltosFlightStatusTableModel.java +++ b/altosui/AltosFlightStatusTableModel.java @@ -30,7 +30,12 @@ import java.util.concurrent.LinkedBlockingQueue;  import org.altusmetrum.AltosLib.*;  public class AltosFlightStatusTableModel extends AbstractTableModel { -	private String[] columnNames = {"Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" }; +	private String[] columnNames = { +		String.format("Height (%s)", AltosConvert.show_distance_units()), +		"State", +		"RSSI (dBm)", +		String.format("Speed (%s)", AltosConvert.show_speed_unit()) +	};  	private Object[] data = { 0, "idle", 0, 0 };  	public int getColumnCount() { return columnNames.length; } @@ -51,12 +56,12 @@ public class AltosFlightStatusTableModel extends AbstractTableModel {  	}  	public void set(AltosState state) { -		setValueAt(String.format("%1.0f", state.height), 0); +		setValueAt(String.format("%1.0f", AltosConvert.distance(state.height), 0);  		setValueAt(state.data.state(), 1);  		setValueAt(state.data.rssi, 2);  		double speed = state.baro_speed;  		if (state.ascent)  			speed = state.speed; -		setValueAt(String.format("%1.0f", speed), 3); +		setValueAt(String.format("%1.0f", AltosConvert.speed(speed)), 3);  	}  } | 
