summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2010-07-28 13:01:52 -0700
committerKeith Packard <keithp@keithp.com>2010-07-28 13:01:52 -0700
commit71da54a5ce255395376a44586782ab8b6f3b289f (patch)
treeb6dc77d08e3c1dace620249f60e69b7ed0c70b5c
parente76b9cc32bbcc5176d9bdd6f8d79778024627382 (diff)
Make voice and channel menus work.
Stores voice and channel data to preferences. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--ao-tools/altosui/AltosPreferences.java40
-rw-r--r--ao-tools/altosui/AltosSerial.java14
-rw-r--r--ao-tools/altosui/AltosUI.java18
-rw-r--r--ao-tools/altosui/AltosVoice.java9
4 files changed, 74 insertions, 7 deletions
diff --git a/ao-tools/altosui/AltosPreferences.java b/ao-tools/altosui/AltosPreferences.java
index 0296d935..297e1aae 100644
--- a/ao-tools/altosui/AltosPreferences.java
+++ b/ao-tools/altosui/AltosPreferences.java
@@ -31,6 +31,12 @@ class AltosPreferences {
/* logdir preference name */
final static String logdirPreference = "LOGDIR";
+ /* channel preference name */
+ final static String channelPreference = "CHANNEL";
+
+ /* voice preference name */
+ final static String voicePreference = "VOICE";
+
/* Default logdir is ~/TeleMetrum */
final static String logdirName = "TeleMetrum";
@@ -40,6 +46,12 @@ class AltosPreferences {
/* Log directory */
static File logdir;
+ /* Telemetry channel */
+ static int channel;
+
+ /* Voice preference */
+ static boolean voice;
+
public static void init(Component ui) {
preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
@@ -55,6 +67,10 @@ class AltosPreferences {
if (!logdir.exists())
logdir.mkdirs();
}
+
+ channel = preferences.getInt(channelPreference, 0);
+
+ voice = preferences.getBoolean(voicePreference, true);
}
static void flush_preferences() {
@@ -114,4 +130,28 @@ class AltosPreferences {
public static File logdir() {
return logdir;
}
+
+ public static void set_channel(int new_channel) {
+ channel = new_channel;
+ synchronized (preferences) {
+ preferences.putInt(channelPreference, channel);
+ flush_preferences();
+ }
+ }
+
+ public static int channel() {
+ return channel;
+ }
+
+ public static void set_voice(boolean new_voice) {
+ voice = new_voice;
+ synchronized (preferences) {
+ preferences.putBoolean(voicePreference, voice);
+ flush_preferences();
+ }
+ }
+
+ public static boolean voice() {
+ return voice;
+ }
}
diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java
index b016c1d6..f12b31b3 100644
--- a/ao-tools/altosui/AltosSerial.java
+++ b/ao-tools/altosui/AltosSerial.java
@@ -119,7 +119,8 @@ public class AltosSerial implements Runnable {
}
public void putc(char c) {
- libaltos.altos_putchar(altos, c);
+ if (altos != null)
+ libaltos.altos_putchar(altos, c);
}
public void print(String data) {
@@ -138,6 +139,17 @@ public class AltosSerial implements Runnable {
throw new FileNotFoundException(device.getPath());
input_thread = new Thread(this);
input_thread.start();
+ print("\nE 0\nm 1\n");
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException e) {
+ }
+ flush();
+ }
+
+ public void set_channel(int channel) {
+ if (altos != null)
+ printf("m 0\nc r %d\nm 1\n", channel);
}
public AltosSerial() {
diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java
index 5c92b9b4..511c3709 100644
--- a/ao-tools/altosui/AltosUI.java
+++ b/ao-tools/altosui/AltosUI.java
@@ -210,6 +210,7 @@ public class AltosUI extends JFrame {
System.exit(0);
}
});
+ voice.speak("Rocket flight monitor ready.");
}
public void info_reset() {
@@ -490,6 +491,7 @@ public class AltosUI extends JFrame {
try {
serial_line.open(device);
DeviceThread thread = new DeviceThread(serial_line);
+ serial_line.set_channel(AltosPreferences.channel());
run_display(thread);
} catch (FileNotFoundException ee) {
JOptionPane.showMessageDialog(AltosUI.this,
@@ -706,9 +708,16 @@ public class AltosUI extends JFrame {
menu.setMnemonic(KeyEvent.VK_V);
menubar.add(menu);
- radioitem = new JRadioButtonMenuItem("Enable Voice");
+ radioitem = new JRadioButtonMenuItem("Enable Voice", AltosPreferences.voice());
radioitem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
+ JRadioButtonMenuItem item = (JRadioButtonMenuItem) e.getSource();
+ boolean enabled = item.isSelected();
+ AltosPreferences.set_voice(enabled);
+ if (enabled)
+ voice.speak_always("Enable voice.");
+ else
+ voice.speak_always("Disable voice.");
}
});
menu.add(radioitem);
@@ -724,12 +733,13 @@ public class AltosUI extends JFrame {
for (int c = 0; c <= 9; c++) {
radioitem = new JRadioButtonMenuItem(String.format("Channel %1d (%7.3fMHz)", c,
434.550 + c * 0.1),
- c == 0);
+ c == AltosPreferences.channel());
radioitem.setActionCommand(String.format("%d", c));
radioitem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- System.out.println("Command: " + e.getActionCommand() + " param: " +
- e.paramString());
+ int new_channel = Integer.parseInt(e.getActionCommand());
+ AltosPreferences.set_channel(new_channel);
+ serial_line.set_channel(new_channel);
}
});
menu.add(radioitem);
diff --git a/ao-tools/altosui/AltosVoice.java b/ao-tools/altosui/AltosVoice.java
index c39bfb9b..ebe9d5a8 100644
--- a/ao-tools/altosui/AltosVoice.java
+++ b/ao-tools/altosui/AltosVoice.java
@@ -39,7 +39,8 @@ public class AltosVoice implements Runnable {
} catch (InterruptedException e) {
}
}
- public void speak(String s) {
+
+ public void speak_always(String s) {
try {
if (voice != null)
phrases.put(s);
@@ -47,6 +48,11 @@ public class AltosVoice implements Runnable {
}
}
+ public void speak(String s) {
+ if (AltosPreferences.voice())
+ speak_always(s);
+ }
+
public void speak(String format, Object... parameters) {
speak(String.format(format, parameters));
}
@@ -59,7 +65,6 @@ public class AltosVoice implements Runnable {
phrases = new LinkedBlockingQueue<String> ();
thread = new Thread(this);
thread.start();
- speak("Rocket Flight Monitor Ready");
} else {
System.out.printf("Voice manager failed to open %s\n", voice_name);
Voice[] voices = voice_manager.getVoices();