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;
}
}
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");
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");
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");
JLabel callsign_label;
JTextField callsign_value;
+ JRadioButton imperial_units;
+
JLabel font_size_label;
JComboBox font_size_value;
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;
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));
}
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");
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");
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");
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;
}
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;
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;
}
}
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]),
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]));
}
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; }
}
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);
}
}