- private boolean check_dir(File dir) {
- if (!dir.exists()) {
- if (!dir.mkdirs()) {
- JOptionPane.showMessageDialog(AltosUI.this,
- dir.getName(),
- "Cannot create directory",
- JOptionPane.ERROR_MESSAGE);
- return false;
+ private void tell(AltosState state, AltosState old_state) {
+ if (old_state == null || old_state.state != state.state) {
+ voice.speak(state.data.state);
+ if ((old_state == null || old_state.state <= AltosTelemetry.ao_flight_boost) &&
+ state.state > AltosTelemetry.ao_flight_boost) {
+ voice.speak("max speed: %d meters per second.",
+ (int) (state.max_speed + 0.5));
+ } else if ((old_state == null || old_state.state < AltosTelemetry.ao_flight_drogue) &&
+ state.state >= AltosTelemetry.ao_flight_drogue) {
+ voice.speak("max height: %d meters.",
+ (int) (state.max_height + 0.5));
+ }
+ }
+ old_state = state;
+ }
+
+ class DisplayThread extends Thread {
+ IdleThread idle_thread;
+
+ String read() throws InterruptedException { return null; }
+
+ void close() { }
+
+ void update(AltosState state) throws InterruptedException { }
+
+ public void run() {
+ String line;
+ AltosState state = null;
+ AltosState old_state = null;
+
+ idle_thread = new IdleThread();
+
+ info_reset();
+ info_finish();
+ idle_thread.start();
+ try {
+ while ((line = read()) != null) {
+ try {
+ AltosTelemetry t = new AltosTelemetry(line);
+ old_state = state;
+ state = new AltosState(t, state);
+ update(state);
+ show(state);
+ tell(state, old_state);
+ idle_thread.notice(state);
+ } catch (ParseException pp) {
+ System.out.printf("Parse error on %s\n", line);
+ System.out.println("exception " + pp);
+ }
+ }
+ } catch (InterruptedException ee) {
+ } finally {
+ close();
+ idle_thread.interrupt();