Stores voice and channel data to preferences.
Signed-off-by: Keith Packard <keithp@keithp.com>
/* logdir preference name */
final static String logdirPreference = "LOGDIR";
/* 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";
/* Default logdir is ~/TeleMetrum */
final static String logdirName = "TeleMetrum";
/* Log directory */
static File logdir;
/* 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");
public static void init(Component ui) {
preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
if (!logdir.exists())
logdir.mkdirs();
}
if (!logdir.exists())
logdir.mkdirs();
}
+
+ channel = preferences.getInt(channelPreference, 0);
+
+ voice = preferences.getBoolean(voicePreference, true);
}
static void flush_preferences() {
}
static void flush_preferences() {
public static File logdir() {
return logdir;
}
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;
+ }
}
public void putc(char c) {
}
public void putc(char c) {
- libaltos.altos_putchar(altos, c);
+ if (altos != null)
+ libaltos.altos_putchar(altos, c);
}
public void print(String data) {
}
public void print(String data) {
throw new FileNotFoundException(device.getPath());
input_thread = new Thread(this);
input_thread.start();
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);
+ voice.speak("Rocket flight monitor ready.");
}
public void info_reset() {
}
public void info_reset() {
try {
serial_line.open(device);
DeviceThread thread = new DeviceThread(serial_line);
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,
run_display(thread);
} catch (FileNotFoundException ee) {
JOptionPane.showMessageDialog(AltosUI.this,
menu.setMnemonic(KeyEvent.VK_V);
menubar.add(menu);
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) {
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);
}
});
menu.add(radioitem);
for (int c = 0; c <= 9; c++) {
radioitem = new JRadioButtonMenuItem(String.format("Channel %1d (%7.3fMHz)", c,
434.550 + c * 0.1),
for (int c = 0; c <= 9; c++) {
radioitem = new JRadioButtonMenuItem(String.format("Channel %1d (%7.3fMHz)", c,
434.550 + c * 0.1),
+ c == AltosPreferences.channel());
radioitem.setActionCommand(String.format("%d", c));
radioitem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
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);
}
});
menu.add(radioitem);
} catch (InterruptedException e) {
}
}
} catch (InterruptedException e) {
}
}
- public void speak(String s) {
+
+ public void speak_always(String s) {
try {
if (voice != null)
phrases.put(s);
try {
if (voice != null)
phrases.put(s);
+ public void speak(String s) {
+ if (AltosPreferences.voice())
+ speak_always(s);
+ }
+
public void speak(String format, Object... parameters) {
speak(String.format(format, parameters));
}
public void speak(String format, Object... parameters) {
speak(String.format(format, parameters));
}
phrases = new LinkedBlockingQueue<String> ();
thread = new Thread(this);
thread.start();
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();
} else {
System.out.printf("Voice manager failed to open %s\n", voice_name);
Voice[] voices = voice_manager.getVoices();