From 69e6df07976a56b49e07c242cd6e5b2cbd2a578d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 23 Feb 2012 17:00:48 +1300 Subject: Move altoslib sources to top dir No sense having them live deep in the file system. Signed-off-by: Keith Packard --- altoslib/AltosPreferences.java | 365 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 365 insertions(+) create mode 100644 altoslib/AltosPreferences.java (limited to 'altoslib/AltosPreferences.java') diff --git a/altoslib/AltosPreferences.java b/altoslib/AltosPreferences.java new file mode 100644 index 00000000..43c7088d --- /dev/null +++ b/altoslib/AltosPreferences.java @@ -0,0 +1,365 @@ +/* + * Copyright © 2010 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.AltosLib; + +import java.io.*; +import java.util.*; +import java.text.*; +import java.util.prefs.*; +import java.util.concurrent.LinkedBlockingQueue; +import java.awt.Component; +import javax.swing.*; +import javax.swing.filechooser.FileSystemView; + +public class AltosPreferences { + public static Preferences preferences; + + /* logdir preference name */ + public final static String logdirPreference = "LOGDIR"; + + /* channel preference name */ + public final static String channelPreferenceFormat = "CHANNEL-%d"; + + /* frequency preference name */ + public final static String frequencyPreferenceFormat = "FREQUENCY-%d"; + + /* telemetry format preference name */ + public final static String telemetryPreferenceFormat = "TELEMETRY-%d"; + + /* voice preference name */ + public final static String voicePreference = "VOICE"; + + /* callsign preference name */ + public final static String callsignPreference = "CALLSIGN"; + + /* firmware directory preference name */ + public final static String firmwaredirPreference = "FIRMWARE"; + + /* serial debug preference name */ + public final static String serialDebugPreference = "SERIAL-DEBUG"; + + /* scanning telemetry preferences name */ + public final static String scanningTelemetryPreference = "SCANNING-TELEMETRY"; + + /* Launcher serial preference name */ + public final static String launcherSerialPreference = "LAUNCHER-SERIAL"; + + /* Launcher channel preference name */ + public final static String launcherChannelPreference = "LAUNCHER-CHANNEL"; + + /* Default logdir is ~/TeleMetrum */ + public final static String logdirName = "TeleMetrum"; + + /* Log directory */ + public static File logdir; + + /* Map directory -- hangs of logdir */ + public static File mapdir; + + /* Frequency (map serial to frequency) */ + public static Hashtable frequencies; + + /* Telemetry (map serial to telemetry format) */ + public static Hashtable telemetries; + + /* Voice preference */ + public static boolean voice; + + /* Callsign preference */ + public static String callsign; + + /* Firmware directory */ + public static File firmwaredir; + + /* Scanning telemetry */ + public static int scanning_telemetry; + + /* List of frequencies */ + public final static String common_frequencies_node_name = "COMMON-FREQUENCIES"; + public static AltosFrequency[] common_frequencies; + + public final static String frequency_count = "COUNT"; + public final static String frequency_format = "FREQUENCY-%d"; + public final static String description_format = "DESCRIPTION-%d"; + + public static AltosFrequency[] load_common_frequencies() { + AltosFrequency[] frequencies = null; + boolean existing = false; + try { + existing = preferences.nodeExists(common_frequencies_node_name); + } catch (BackingStoreException be) { + existing = false; + } + if (existing) { + Preferences node = preferences.node(common_frequencies_node_name); + int count = node.getInt(frequency_count, 0); + + frequencies = new AltosFrequency[count]; + for (int i = 0; i < count; i++) { + double frequency; + String description; + + frequency = node.getDouble(String.format(frequency_format, i), 0.0); + description = node.get(String.format(description_format, i), null); + frequencies[i] = new AltosFrequency(frequency, description); + } + } else { + frequencies = new AltosFrequency[10]; + for (int i = 0; i < 10; i++) { + frequencies[i] = new AltosFrequency(434.550 + i * .1, + String.format("Channel %d", i)); + } + } + return frequencies; + } + + public static void save_common_frequencies(AltosFrequency[] frequencies) { + Preferences node = preferences.node(common_frequencies_node_name); + + node.putInt(frequency_count, frequencies.length); + for (int i = 0; i < frequencies.length; i++) { + node.putDouble(String.format(frequency_format, i), frequencies[i].frequency); + node.put(String.format(description_format, i), frequencies[i].description); + } + } + public static int launcher_serial; + + public static int launcher_channel; + + public static void init() { + preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); + + /* Initialize logdir from preferences */ + String logdir_string = preferences.get(logdirPreference, null); + if (logdir_string != null) + logdir = new File(logdir_string); + else { + /* Use the file system view default directory */ + logdir = new File(FileSystemView.getFileSystemView().getDefaultDirectory(), logdirName); + if (!logdir.exists()) + logdir.mkdirs(); + } + mapdir = new File(logdir, "maps"); + if (!mapdir.exists()) + mapdir.mkdirs(); + + frequencies = new Hashtable(); + + telemetries = new Hashtable(); + + voice = preferences.getBoolean(voicePreference, true); + + callsign = preferences.get(callsignPreference,"N0CALL"); + + scanning_telemetry = preferences.getInt(scanningTelemetryPreference,(1 << AltosLib.ao_telemetry_standard)); + + launcher_serial = preferences.getInt(launcherSerialPreference, 0); + + launcher_channel = preferences.getInt(launcherChannelPreference, 0); + + String firmwaredir_string = preferences.get(firmwaredirPreference, null); + if (firmwaredir_string != null) + firmwaredir = new File(firmwaredir_string); + else + firmwaredir = null; + + common_frequencies = load_common_frequencies(); + + } + + static { init(); } + + public static void flush_preferences() { + try { + preferences.flush(); + } catch (BackingStoreException ee) { +/* + if (component != null) + JOptionPane.showMessageDialog(component, + preferences.absolutePath(), + "Cannot save prefernces", + JOptionPane.ERROR_MESSAGE); + else +*/ + System.err.printf("Cannot save preferences\n"); + } + } + + public static void set_logdir(File new_logdir) { + logdir = new_logdir; + mapdir = new File(logdir, "maps"); + if (!mapdir.exists()) + mapdir.mkdirs(); + synchronized (preferences) { + preferences.put(logdirPreference, logdir.getPath()); + flush_preferences(); + } + } + + public static File logdir() { + return logdir; + } + + public static File mapdir() { + return mapdir; + } + + public static void set_frequency(int serial, double new_frequency) { + frequencies.put(serial, new_frequency); + synchronized (preferences) { + preferences.putDouble(String.format(frequencyPreferenceFormat, serial), new_frequency); + flush_preferences(); + } + } + + public static double frequency(int serial) { + if (frequencies.containsKey(serial)) + return frequencies.get(serial); + double frequency = preferences.getDouble(String.format(frequencyPreferenceFormat, serial), 0); + if (frequency == 0.0) { + int channel = preferences.getInt(String.format(channelPreferenceFormat, serial), 0); + frequency = AltosConvert.radio_channel_to_frequency(channel); + } + frequencies.put(serial, frequency); + return frequency; + } + + public static void set_telemetry(int serial, int new_telemetry) { + telemetries.put(serial, new_telemetry); + synchronized (preferences) { + preferences.putInt(String.format(telemetryPreferenceFormat, serial), new_telemetry); + flush_preferences(); + } + } + + public static int telemetry(int serial) { + if (telemetries.containsKey(serial)) + return telemetries.get(serial); + int telemetry = preferences.getInt(String.format(telemetryPreferenceFormat, serial), + AltosLib.ao_telemetry_standard); + telemetries.put(serial, telemetry); + return telemetry; + } + + public static void set_scanning_telemetry(int new_scanning_telemetry) { + scanning_telemetry = new_scanning_telemetry; + synchronized (preferences) { + preferences.putInt(scanningTelemetryPreference, scanning_telemetry); + flush_preferences(); + } + } + + public static int scanning_telemetry() { + return scanning_telemetry; + } + + 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 static void set_callsign(String new_callsign) { + callsign = new_callsign; + synchronized(preferences) { + preferences.put(callsignPreference, callsign); + flush_preferences(); + } + } + + public static String callsign() { + return callsign; + } + + public static void set_firmwaredir(File new_firmwaredir) { + firmwaredir = new_firmwaredir; + synchronized (preferences) { + preferences.put(firmwaredirPreference, firmwaredir.getPath()); + flush_preferences(); + } + } + + public static File firmwaredir() { + return firmwaredir; + } + + public static void set_launcher_serial(int new_launcher_serial) { + launcher_serial = new_launcher_serial; + System.out.printf("set launcher serial to %d\n", new_launcher_serial); + synchronized (preferences) { + preferences.putInt(launcherSerialPreference, launcher_serial); + flush_preferences(); + } + } + + public static int launcher_serial() { + return launcher_serial; + } + + public static void set_launcher_channel(int new_launcher_channel) { + launcher_channel = new_launcher_channel; + System.out.printf("set launcher channel to %d\n", new_launcher_channel); + synchronized (preferences) { + preferences.putInt(launcherChannelPreference, launcher_channel); + flush_preferences(); + } + } + + public static int launcher_channel() { + return launcher_channel; + } + + public static Preferences bt_devices() { + return preferences.node("bt_devices"); + } + + public static AltosFrequency[] common_frequencies() { + return common_frequencies; + } + + public static void set_common_frequencies(AltosFrequency[] frequencies) { + common_frequencies = frequencies; + synchronized(preferences) { + save_common_frequencies(frequencies); + flush_preferences(); + } + } + + public static void add_common_frequency(AltosFrequency frequency) { + AltosFrequency[] new_frequencies = new AltosFrequency[common_frequencies.length + 1]; + int i; + + for (i = 0; i < common_frequencies.length; i++) { + if (frequency.frequency == common_frequencies[i].frequency) + return; + if (frequency.frequency < common_frequencies[i].frequency) + break; + new_frequencies[i] = common_frequencies[i]; + } + new_frequencies[i] = frequency; + for (; i < common_frequencies.length; i++) + new_frequencies[i+1] = common_frequencies[i]; + set_common_frequencies(new_frequencies); + } +} -- cgit v1.2.3 From f078a591cf2fafe89bb1bb883f49d80750129d44 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 11 Jul 2012 14:28:53 -0700 Subject: altosui: Remove a bunch of debugging printfs These aren't useful at this point. Signed-off-by: Keith Packard --- altoslib/AltosLog.java | 1 - altoslib/AltosPreferences.java | 2 -- altoslib/AltosRecordMM.java | 2 -- altoslib/AltosTelemetryRecordMegaData.java | 2 -- altoslib/AltosTelemetryRecordMegaSensor.java | 4 ---- altosui/AltosBTDevice.java | 2 -- altosui/AltosBTDeviceIterator.java | 2 -- altosui/AltosBTKnown.java | 2 -- altosui/AltosBTManage.java | 3 --- altosui/AltosConfigTD.java | 7 ++----- altosui/AltosConfigureUI.java | 1 - altosui/AltosFlashUI.java | 7 ------- altosui/AltosLaunchUI.java | 1 - 13 files changed, 2 insertions(+), 34 deletions(-) (limited to 'altoslib/AltosPreferences.java') diff --git a/altoslib/AltosLog.java b/altoslib/AltosLog.java index 08c45ca8..55a25bb4 100644 --- a/altoslib/AltosLog.java +++ b/altoslib/AltosLog.java @@ -62,7 +62,6 @@ class AltosLog implements Runnable { boolean open (AltosRecord telem) throws IOException { AltosFile a = new AltosFile(telem); - System.out.printf("open %s\n", a.toString()); log_file = new FileWriter(a, true); if (log_file != null) { while (!pending_queue.isEmpty()) { diff --git a/altoslib/AltosPreferences.java b/altoslib/AltosPreferences.java index 43c7088d..9ab80cf5 100644 --- a/altoslib/AltosPreferences.java +++ b/altoslib/AltosPreferences.java @@ -306,7 +306,6 @@ public class AltosPreferences { public static void set_launcher_serial(int new_launcher_serial) { launcher_serial = new_launcher_serial; - System.out.printf("set launcher serial to %d\n", new_launcher_serial); synchronized (preferences) { preferences.putInt(launcherSerialPreference, launcher_serial); flush_preferences(); @@ -319,7 +318,6 @@ public class AltosPreferences { public static void set_launcher_channel(int new_launcher_channel) { launcher_channel = new_launcher_channel; - System.out.printf("set launcher channel to %d\n", new_launcher_channel); synchronized (preferences) { preferences.putInt(launcherChannelPreference, launcher_channel); flush_preferences(); diff --git a/altoslib/AltosRecordMM.java b/altoslib/AltosRecordMM.java index 8b3d745a..055cf85f 100644 --- a/altoslib/AltosRecordMM.java +++ b/altoslib/AltosRecordMM.java @@ -98,8 +98,6 @@ public class AltosRecordMM extends AltosRecord { } public double acceleration() { - System.out.printf("MM record acceleration %g ground_accel %d accel %d accel_minus_g %d accel_plus_g %d\n", - acceleration, ground_accel, accel, accel_minus_g, accel_plus_g); if (acceleration != MISSING) return acceleration; diff --git a/altoslib/AltosTelemetryRecordMegaData.java b/altoslib/AltosTelemetryRecordMegaData.java index cc35cd83..8f55d238 100644 --- a/altoslib/AltosTelemetryRecordMegaData.java +++ b/altoslib/AltosTelemetryRecordMegaData.java @@ -65,10 +65,8 @@ public class AltosTelemetryRecordMegaData extends AltosTelemetryRecordRaw { AltosRecordMM next; if (!(n instanceof AltosRecordMM)) { - System.out.printf("data making record MM\n"); next = new AltosRecordMM(n); } else { - System.out.printf ("data already has MM\n"); next = (AltosRecordMM) n; } diff --git a/altoslib/AltosTelemetryRecordMegaSensor.java b/altoslib/AltosTelemetryRecordMegaSensor.java index 85a32d12..93c001de 100644 --- a/altoslib/AltosTelemetryRecordMegaSensor.java +++ b/altoslib/AltosTelemetryRecordMegaSensor.java @@ -57,7 +57,6 @@ public class AltosTelemetryRecordMegaSensor extends AltosTelemetryRecordRaw { mag_z = int16(30); rssi = in_rssi; - System.out.printf ("telem record accel: %d\n", accel); } public AltosRecord update_state(AltosRecord previous) { @@ -65,14 +64,11 @@ public class AltosTelemetryRecordMegaSensor extends AltosTelemetryRecordRaw { AltosRecordMM next; if (!(n instanceof AltosRecordMM)) { - System.out.printf("sensor making MM\n"); next = new AltosRecordMM(n); } else { - System.out.printf("sensor has MM\n"); next = (AltosRecordMM) n; } - System.out.printf("telem update_state accel: %d\n", accel); next.accel = accel; next.pres = pres; next.temp = temp; diff --git a/altosui/AltosBTDevice.java b/altosui/AltosBTDevice.java index f6926b10..5e353fdd 100644 --- a/altosui/AltosBTDevice.java +++ b/altosui/AltosBTDevice.java @@ -87,7 +87,6 @@ public class AltosBTDevice extends altos_bt_device implements AltosDevice { public boolean matchProduct(int want_product) { - System.out.printf("matchProduct %s %d\n", toString(), want_product); // if (!isAltusMetrum()) // return false; @@ -107,7 +106,6 @@ public class AltosBTDevice extends altos_bt_device implements AltosDevice { if (!(o instanceof AltosBTDevice)) return false; AltosBTDevice other = (AltosBTDevice) o; - System.out.printf("AltosBTDevice equals %s == %s\n", toString(), other.toString()); return getName().equals(other.getName()) && getAddr().equals(other.getAddr()); } diff --git a/altosui/AltosBTDeviceIterator.java b/altosui/AltosBTDeviceIterator.java index 7c360705..58ed86d5 100644 --- a/altosui/AltosBTDeviceIterator.java +++ b/altosui/AltosBTDeviceIterator.java @@ -26,7 +26,6 @@ public class AltosBTDeviceIterator implements Iterator { SWIGTYPE_p_altos_bt_list list; public boolean hasNext() { - System.out.printf ("BT has next?\n"); if (list == null) return false; if (current != null) @@ -35,7 +34,6 @@ public class AltosBTDeviceIterator implements Iterator { return false; current = new AltosBTDevice(); while (libaltos.altos_bt_list_next(list, current) != 0) { - System.out.printf("Got BT device %s\n", current.toString()); // if (current.matchProduct(product)) return true; } diff --git a/altosui/AltosBTKnown.java b/altosui/AltosBTKnown.java index 021e4d0b..6a8e53cb 100644 --- a/altosui/AltosBTKnown.java +++ b/altosui/AltosBTKnown.java @@ -31,7 +31,6 @@ public class AltosBTKnown implements Iterable { private void set_address(String name, String addr) { bt_pref.put(name, addr); - System.out.printf("saving known %s %s\n", name, addr); } private void remove(String name) { @@ -44,7 +43,6 @@ public class AltosBTKnown implements Iterable { for (int i = 0; i < names.length; i++) { String name = names[i]; String addr = get_address(name); - System.out.printf("Known device %s %s\n", name, addr); devices.add(new AltosBTDevice(name, addr)); } } catch (BackingStoreException be) { diff --git a/altosui/AltosBTManage.java b/altosui/AltosBTManage.java index d2899d65..aeb964bb 100644 --- a/altosui/AltosBTManage.java +++ b/altosui/AltosBTManage.java @@ -126,7 +126,6 @@ public class AltosBTManage extends AltosDialog implements ActionListener, Iterab public void add_known() { for (AltosBTDevice device : visible_devices.selected_list()) { - System.out.printf("Add known %s\n", device.toString()); known_devices.add(device); visible_devices.remove(device); } @@ -134,7 +133,6 @@ public class AltosBTManage extends AltosDialog implements ActionListener, Iterab public void remove_known() { for (AltosBTDevice device : known_devices.selected_list()) { - System.out.printf("Remove known %s\n", device.toString()); known_devices.remove(device); visible_devices.add(device); } @@ -151,7 +149,6 @@ public class AltosBTManage extends AltosDialog implements ActionListener, Iterab public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); - System.out.printf("manage command %s\n", command); if ("ok".equals(command)) { bt_thread.interrupt(); commit(); diff --git a/altosui/AltosConfigTD.java b/altosui/AltosConfigTD.java index 4048166c..324a5988 100644 --- a/altosui/AltosConfigTD.java +++ b/altosui/AltosConfigTD.java @@ -144,10 +144,8 @@ public class AltosConfigTD implements ActionListener { get_string(line, "Config version", config_version); get_int(line, "serial-number", serial); get_int(line, "Radio channel:", radio_channel); - if (get_int(line, "Radio cal:", radio_calibration)) - System.out.printf("got radio cal %d\n", radio_calibration.get()); - if (get_int(line, "Frequency:", radio_frequency)) - System.out.printf("got radio freq %d\n", radio_frequency.get()); + get_int(line, "Radio cal:", radio_calibration); + get_int(line, "Frequency:", radio_frequency); get_int(line, "Radio setting:", radio_setting); get_string(line,"software-version", version); get_string(line,"product", product); @@ -205,7 +203,6 @@ public class AltosConfigTD implements ActionListener { break; } } - System.out.printf("config_version %s\n", config_version.get()); if (been_there) break; if (!config_version.get().equals("0.0")) diff --git a/altosui/AltosConfigureUI.java b/altosui/AltosConfigureUI.java index d0ed9325..ace245a0 100644 --- a/altosui/AltosConfigureUI.java +++ b/altosui/AltosConfigureUI.java @@ -291,7 +291,6 @@ public class AltosConfigureUI final UIManager.LookAndFeelInfo[] look_and_feels = UIManager.getInstalledLookAndFeels(); - System.out.printf("look_and_feels %d\n", look_and_feels.length); look_and_feel_value = new JComboBox(look_and_feels); DelegatingRenderer.install(look_and_feel_value); diff --git a/altosui/AltosFlashUI.java b/altosui/AltosFlashUI.java index 4ab73a6d..66991d10 100644 --- a/altosui/AltosFlashUI.java +++ b/altosui/AltosFlashUI.java @@ -235,22 +235,17 @@ public class AltosFlashUI public void run() { ui.flash = flash; ui.update_rom_config_info(current_config); - System.out.printf("Done updating rom config info\n"); await_rom_config.release(); } }); - System.out.printf("Waiting for rom configuration updates\n"); await_rom_config.acquire(); - System.out.printf("Got rom config update\n"); if (ui.rom_config != null) { - System.out.printf("rom_config not null\n"); flash.set_romconfig(ui.rom_config); flash.flash(); } } catch (InterruptedException ee) { final Exception e = ee; - System.out.printf("exception %s\n", e.toString()); SwingUtilities.invokeLater(new Runnable() { public void run() { ui.exception(e); @@ -258,7 +253,6 @@ public class AltosFlashUI }); } catch (IOException ee) { final Exception e = ee; - System.out.printf("exception %s\n", e.toString()); SwingUtilities.invokeLater(new Runnable() { public void run() { ui.exception(e); @@ -266,7 +260,6 @@ public class AltosFlashUI }); } catch (AltosSerialInUseException ee) { final Exception e = ee; - System.out.printf("exception %s\n", e.toString()); SwingUtilities.invokeLater(new Runnable() { public void run() { ui.exception(e); diff --git a/altosui/AltosLaunchUI.java b/altosui/AltosLaunchUI.java index eb76243d..44481544 100644 --- a/altosui/AltosLaunchUI.java +++ b/altosui/AltosLaunchUI.java @@ -336,7 +336,6 @@ public class AltosLaunchUI public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); - System.out.printf("cmd %s\n", cmd); if (cmd.equals("armed") || cmd.equals("igniter")) { stop_arm_timer(); } -- cgit v1.2.3 From 20bc23ddb90f8a6da1f7ea70f02cf3a038059d32 Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Fri, 7 Sep 2012 17:32:07 +1200 Subject: altoslib: Remove un-needed imports Signed-off-by: Mike Beattie --- altoslib/AltosConfigData.java | 3 --- altoslib/AltosEepromChunk.java | 2 -- altoslib/AltosEepromIterable.java | 2 -- altoslib/AltosEepromLog.java | 3 --- altoslib/AltosEepromMega.java | 4 ---- altoslib/AltosEepromMegaIterable.java | 2 -- altoslib/AltosEepromRecord.java | 4 ---- altoslib/AltosEepromTeleScience.java | 4 ---- altoslib/AltosFile.java | 1 - altoslib/AltosFlightReader.java | 1 - altoslib/AltosFrequency.java | 4 ---- altoslib/AltosGPS.java | 1 - altoslib/AltosIdleMonitor.java | 3 --- altoslib/AltosIdleMonitorListener.java | 6 ------ altoslib/AltosIdleRecordTM.java | 4 ---- altoslib/AltosLib.java | 2 -- altoslib/AltosLink.java | 2 -- altoslib/AltosLog.java | 2 -- altoslib/AltosParse.java | 1 - altoslib/AltosPreferences.java | 4 ---- altoslib/AltosRecord.java | 5 ----- altoslib/AltosReplayReader.java | 3 --- altoslib/AltosTelemetry.java | 2 -- altoslib/AltosTelemetryMap.java | 1 - altoslib/AltosTelemetryReader.java | 1 - altoslib/AltosTelemetryRecordGeneral.java | 2 -- altoslib/AltosTelemetryRecordLegacy.java | 2 -- altoslib/AltosTelemetryRecordRaw.java | 4 ---- 28 files changed, 75 deletions(-) (limited to 'altoslib/AltosPreferences.java') diff --git a/altoslib/AltosConfigData.java b/altoslib/AltosConfigData.java index ecc2d0aa..c6e92e62 100644 --- a/altoslib/AltosConfigData.java +++ b/altoslib/AltosConfigData.java @@ -17,12 +17,9 @@ package org.altusmetrum.AltosLib; -import java.io.*; import java.util.*; import java.text.*; -import java.util.prefs.*; import java.util.concurrent.*; -import org.altusmetrum.AltosLib.*; public class AltosConfigData implements Iterable { diff --git a/altoslib/AltosEepromChunk.java b/altoslib/AltosEepromChunk.java index 6d889723..77b22fe2 100644 --- a/altoslib/AltosEepromChunk.java +++ b/altoslib/AltosEepromChunk.java @@ -17,8 +17,6 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; import java.text.*; import java.util.concurrent.*; diff --git a/altoslib/AltosEepromIterable.java b/altoslib/AltosEepromIterable.java index f8acdc16..fc308c34 100644 --- a/altoslib/AltosEepromIterable.java +++ b/altoslib/AltosEepromIterable.java @@ -20,8 +20,6 @@ package org.altusmetrum.AltosLib; import java.io.*; import java.util.*; import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; /* * AltosRecords with an index field so they can be sorted by tick while preserving diff --git a/altoslib/AltosEepromLog.java b/altoslib/AltosEepromLog.java index 7fca4bd9..e27c382a 100644 --- a/altoslib/AltosEepromLog.java +++ b/altoslib/AltosEepromLog.java @@ -17,10 +17,7 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; import java.text.*; -import java.util.prefs.*; import java.util.concurrent.*; /* diff --git a/altoslib/AltosEepromMega.java b/altoslib/AltosEepromMega.java index 2628279e..26bacf8d 100644 --- a/altoslib/AltosEepromMega.java +++ b/altoslib/AltosEepromMega.java @@ -17,11 +17,7 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.*; public class AltosEepromMega { public int cmd; diff --git a/altoslib/AltosEepromMegaIterable.java b/altoslib/AltosEepromMegaIterable.java index f62cc45b..be20ba63 100644 --- a/altoslib/AltosEepromMegaIterable.java +++ b/altoslib/AltosEepromMegaIterable.java @@ -20,8 +20,6 @@ package org.altusmetrum.AltosLib; import java.io.*; import java.util.*; import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; /* * AltosRecords with an index field so they can be sorted by tick while preserving diff --git a/altoslib/AltosEepromRecord.java b/altoslib/AltosEepromRecord.java index 1e845f46..c7ced6a3 100644 --- a/altoslib/AltosEepromRecord.java +++ b/altoslib/AltosEepromRecord.java @@ -17,11 +17,7 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.*; public class AltosEepromRecord { public int cmd; diff --git a/altoslib/AltosEepromTeleScience.java b/altoslib/AltosEepromTeleScience.java index 1758fa34..02ce4553 100644 --- a/altoslib/AltosEepromTeleScience.java +++ b/altoslib/AltosEepromTeleScience.java @@ -17,11 +17,7 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.*; public class AltosEepromTeleScience { public int type; diff --git a/altoslib/AltosFile.java b/altoslib/AltosFile.java index d2e4f2f7..1ab00b38 100644 --- a/altoslib/AltosFile.java +++ b/altoslib/AltosFile.java @@ -17,7 +17,6 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.io.File; import java.util.*; diff --git a/altoslib/AltosFlightReader.java b/altoslib/AltosFlightReader.java index 3fdea469..cbd64153 100644 --- a/altoslib/AltosFlightReader.java +++ b/altoslib/AltosFlightReader.java @@ -17,7 +17,6 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.text.*; import java.io.*; import java.util.concurrent.*; diff --git a/altoslib/AltosFrequency.java b/altoslib/AltosFrequency.java index f08ff116..e20f03b7 100644 --- a/altoslib/AltosFrequency.java +++ b/altoslib/AltosFrequency.java @@ -17,10 +17,6 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; -import java.text.*; - public class AltosFrequency { public double frequency; public String description; diff --git a/altoslib/AltosGPS.java b/altoslib/AltosGPS.java index f078a469..2c2fd36b 100644 --- a/altoslib/AltosGPS.java +++ b/altoslib/AltosGPS.java @@ -17,7 +17,6 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.text.*; public class AltosGPS { diff --git a/altoslib/AltosIdleMonitor.java b/altoslib/AltosIdleMonitor.java index 27ea3a2b..d83c4450 100644 --- a/altoslib/AltosIdleMonitor.java +++ b/altoslib/AltosIdleMonitor.java @@ -18,9 +18,6 @@ package org.altusmetrum.AltosLib; import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; import java.util.concurrent.*; class AltosSensorTM extends AltosRecordTM { diff --git a/altoslib/AltosIdleMonitorListener.java b/altoslib/AltosIdleMonitorListener.java index 3c18bfaa..9f9ababf 100644 --- a/altoslib/AltosIdleMonitorListener.java +++ b/altoslib/AltosIdleMonitorListener.java @@ -17,12 +17,6 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.*; - public interface AltosIdleMonitorListener { public void update(AltosState state); } \ No newline at end of file diff --git a/altoslib/AltosIdleRecordTM.java b/altoslib/AltosIdleRecordTM.java index 112b847e..d48ff7e4 100644 --- a/altoslib/AltosIdleRecordTM.java +++ b/altoslib/AltosIdleRecordTM.java @@ -17,10 +17,6 @@ package org.altusmetrum.AltosLib; -import java.io.*; -import java.util.*; -import java.text.*; -import java.util.prefs.*; import java.util.concurrent.*; class AltosADCTM { diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index 2402331e..8d383f12 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -17,9 +17,7 @@ package org.altusmetrum.AltosLib; -import java.awt.*; import java.util.*; -import java.text.*; import java.io.*; import java.nio.charset.Charset; diff --git a/altoslib/AltosLink.java b/altoslib/AltosLink.java index 415c3c64..6d510563 100644 --- a/altoslib/AltosLink.java +++ b/altoslib/AltosLink.java @@ -17,11 +17,9 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.io.*; import java.util.concurrent.*; import java.util.*; -import java.text.*; public abstract class AltosLink implements Runnable { diff --git a/altoslib/AltosLog.java b/altoslib/AltosLog.java index 55a25bb4..3c124700 100644 --- a/altoslib/AltosLog.java +++ b/altoslib/AltosLog.java @@ -18,8 +18,6 @@ package org.altusmetrum.AltosLib; import java.io.*; -import java.lang.*; -import java.util.*; import java.text.ParseException; import java.util.concurrent.LinkedBlockingQueue; diff --git a/altoslib/AltosParse.java b/altoslib/AltosParse.java index 7d832f1a..e938a177 100644 --- a/altoslib/AltosParse.java +++ b/altoslib/AltosParse.java @@ -18,7 +18,6 @@ package org.altusmetrum.AltosLib; import java.text.*; -import java.lang.*; public class AltosParse { public static boolean isdigit(char c) { diff --git a/altoslib/AltosPreferences.java b/altoslib/AltosPreferences.java index 9ab80cf5..13fee46d 100644 --- a/altoslib/AltosPreferences.java +++ b/altoslib/AltosPreferences.java @@ -19,11 +19,7 @@ package org.altusmetrum.AltosLib; import java.io.*; import java.util.*; -import java.text.*; import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; -import java.awt.Component; -import javax.swing.*; import javax.swing.filechooser.FileSystemView; public class AltosPreferences { diff --git a/altoslib/AltosRecord.java b/altoslib/AltosRecord.java index 8722bc05..dd741716 100644 --- a/altoslib/AltosRecord.java +++ b/altoslib/AltosRecord.java @@ -17,11 +17,6 @@ package org.altusmetrum.AltosLib; -import java.lang.*; -import java.text.*; -import java.util.HashMap; -import java.io.*; - public class AltosRecord implements Comparable , Cloneable { public static final int seen_flight = 1; diff --git a/altoslib/AltosReplayReader.java b/altoslib/AltosReplayReader.java index 1585f9eb..50bef07a 100644 --- a/altoslib/AltosReplayReader.java +++ b/altoslib/AltosReplayReader.java @@ -19,9 +19,6 @@ package org.altusmetrum.AltosLib; import java.io.*; import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; /* * Open an existing telemetry file and replay it in realtime diff --git a/altoslib/AltosTelemetry.java b/altoslib/AltosTelemetry.java index ee244824..15534158 100644 --- a/altoslib/AltosTelemetry.java +++ b/altoslib/AltosTelemetry.java @@ -17,9 +17,7 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.text.*; -import java.util.HashMap; /* * Telemetry data contents diff --git a/altoslib/AltosTelemetryMap.java b/altoslib/AltosTelemetryMap.java index 003cb6a9..bc1486d8 100644 --- a/altoslib/AltosTelemetryMap.java +++ b/altoslib/AltosTelemetryMap.java @@ -16,7 +16,6 @@ */ package org.altusmetrum.AltosLib; -import java.lang.*; import java.text.*; import java.util.HashMap; diff --git a/altoslib/AltosTelemetryReader.java b/altoslib/AltosTelemetryReader.java index bdb44eef..94fa560b 100644 --- a/altoslib/AltosTelemetryReader.java +++ b/altoslib/AltosTelemetryReader.java @@ -17,7 +17,6 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.text.*; import java.io.*; import java.util.concurrent.*; diff --git a/altoslib/AltosTelemetryRecordGeneral.java b/altoslib/AltosTelemetryRecordGeneral.java index 5e157a54..a53280cf 100644 --- a/altoslib/AltosTelemetryRecordGeneral.java +++ b/altoslib/AltosTelemetryRecordGeneral.java @@ -17,9 +17,7 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.text.*; -import java.util.HashMap; public class AltosTelemetryRecordGeneral { diff --git a/altoslib/AltosTelemetryRecordLegacy.java b/altoslib/AltosTelemetryRecordLegacy.java index 3976a07a..b11fed58 100644 --- a/altoslib/AltosTelemetryRecordLegacy.java +++ b/altoslib/AltosTelemetryRecordLegacy.java @@ -17,9 +17,7 @@ package org.altusmetrum.AltosLib; -import java.lang.*; import java.text.*; -import java.util.HashMap; /* * Telemetry data contents diff --git a/altoslib/AltosTelemetryRecordRaw.java b/altoslib/AltosTelemetryRecordRaw.java index dc1b8947..fbb373d5 100644 --- a/altoslib/AltosTelemetryRecordRaw.java +++ b/altoslib/AltosTelemetryRecordRaw.java @@ -17,10 +17,6 @@ package org.altusmetrum.AltosLib; -import java.lang.*; -import java.text.*; -import java.util.HashMap; - public class AltosTelemetryRecordRaw extends AltosTelemetryRecord { int[] bytes; int serial; -- cgit v1.2.3 From 66a1e07efcac9324d33a1eca0dfb58a2724b667a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 10 Sep 2012 09:14:03 -0700 Subject: altoslib: Add imperial units conversion support "Redneck" mode support Signed-off-by: Keith Packard --- altoslib/AltosAccel.java | 43 +++++++++++++++++++++++++++++++ altoslib/AltosConvert.java | 28 +++++++++++++++++++++ altoslib/AltosDistance.java | 49 ++++++++++++++++++++++++++++++++++++ altoslib/AltosHeight.java | 43 +++++++++++++++++++++++++++++++ altoslib/AltosPreferences.java | 17 +++++++++++++ altoslib/AltosSpeed.java | 43 +++++++++++++++++++++++++++++++ altoslib/AltosUnits.java | 57 ++++++++++++++++++++++++++++++++++++++++++ altoslib/Makefile.am | 7 +++++- 8 files changed, 286 insertions(+), 1 deletion(-) create mode 100644 altoslib/AltosAccel.java create mode 100644 altoslib/AltosDistance.java create mode 100644 altoslib/AltosHeight.java create mode 100644 altoslib/AltosSpeed.java create mode 100644 altoslib/AltosUnits.java (limited to 'altoslib/AltosPreferences.java') diff --git a/altoslib/AltosAccel.java b/altoslib/AltosAccel.java new file mode 100644 index 00000000..d14764a2 --- /dev/null +++ b/altoslib/AltosAccel.java @@ -0,0 +1,43 @@ +/* + * Copyright © 2012 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.AltosLib; + +public class AltosAccel extends AltosUnits { + + public double value(double v) { + if (AltosConvert.imperial_units) + return AltosConvert.meters_to_feet(v); + return v; + } + + public String show_units() { + if (AltosConvert.imperial_units) + return "ft/s²"; + return "m/s²"; + } + + public String say_units() { + if (AltosConvert.imperial_units) + return "feet per second squared"; + return "meters per second squared"; + } + + int show_fraction(int width) { + return width / 9; + } +} \ No newline at end of file diff --git a/altoslib/AltosConvert.java b/altoslib/AltosConvert.java index 3527b575..acd6c5f4 100644 --- a/altoslib/AltosConvert.java +++ b/altoslib/AltosConvert.java @@ -242,6 +242,14 @@ public class AltosConvert { return meters * (100 / (2.54 * 12)); } + public static double meters_to_miles(double meters) { + return meters_to_feet(meters) / 5280; + } + + public static double meters_to_mph(double mps) { + return meters_to_miles(mps) * 3600; + } + public static double meters_to_mach(double meters) { return meters / 343; /* something close to mach at usual rocket sites */ } @@ -250,6 +258,26 @@ public class AltosConvert { return meters / 9.80665; } + public static boolean imperial_units = false; + + public static AltosDistance distance = new AltosDistance(); + + public static AltosHeight height = new AltosHeight(); + + public static AltosSpeed speed = new AltosSpeed(); + + public static AltosAccel accel = new AltosAccel(); + + public static String show_gs(String format, double a) { + a = meters_to_g(a); + format = format.concat(" g"); + return String.format(format, a); + } + + public static String say_gs(double a) { + return String.format("%6.0 gees", meters_to_g(a)); + } + public static int checksum(int[] data, int start, int length) { int csum = 0x5a; for (int i = 0; i < length; i++) diff --git a/altoslib/AltosDistance.java b/altoslib/AltosDistance.java new file mode 100644 index 00000000..a5e7331c --- /dev/null +++ b/altoslib/AltosDistance.java @@ -0,0 +1,49 @@ +/* + * Copyright © 2012 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.AltosLib; + +public class AltosDistance extends AltosUnits { + + public double value(double v) { + if (AltosConvert.imperial_units) + return AltosConvert.meters_to_miles(v); + return v; + } + + public String show_units() { + if (AltosConvert.imperial_units) + return "miles"; + return "m"; + } + + public String say_units() { + if (AltosConvert.imperial_units) + return "miles"; + return "meters"; + } + + int show_fraction(int width) { + if (AltosConvert.imperial_units) + return width / 3; + return width / 9; + } + + int say_fraction() { + return 1; + } +} \ No newline at end of file diff --git a/altoslib/AltosHeight.java b/altoslib/AltosHeight.java new file mode 100644 index 00000000..da7ffdae --- /dev/null +++ b/altoslib/AltosHeight.java @@ -0,0 +1,43 @@ +/* + * Copyright © 2012 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.AltosLib; + +public class AltosHeight extends AltosUnits { + + public double value(double v) { + if (AltosConvert.imperial_units) + return AltosConvert.meters_to_feet(v); + return v; + } + + public String show_units() { + if (AltosConvert.imperial_units) + return "ft"; + return "m"; + } + + public String say_units() { + if (AltosConvert.imperial_units) + return "feet"; + return "meters"; + } + + int show_fraction(int width) { + return width / 9; + } +} \ No newline at end of file diff --git a/altoslib/AltosPreferences.java b/altoslib/AltosPreferences.java index 13fee46d..065b6e99 100644 --- a/altoslib/AltosPreferences.java +++ b/altoslib/AltosPreferences.java @@ -93,6 +93,10 @@ public class AltosPreferences { public final static String frequency_format = "FREQUENCY-%d"; public final static String description_format = "DESCRIPTION-%d"; + /* Units preference */ + + public final static String unitsPreference = "IMPERIAL-UNITS"; + public static AltosFrequency[] load_common_frequencies() { AltosFrequency[] frequencies = null; boolean existing = false; @@ -176,6 +180,7 @@ public class AltosPreferences { common_frequencies = load_common_frequencies(); + AltosConvert.imperial_units = preferences.getBoolean(unitsPreference, false); } static { init(); } @@ -356,4 +361,16 @@ public class AltosPreferences { new_frequencies[i+1] = common_frequencies[i]; set_common_frequencies(new_frequencies); } + + public static boolean imperial_units() { + return AltosConvert.imperial_units; + } + + public static void set_imperial_units(boolean imperial_units) { + AltosConvert.imperial_units = imperial_units; + synchronized (preferences) { + preferences.putBoolean(unitsPreference, imperial_units); + flush_preferences(); + } + } } diff --git a/altoslib/AltosSpeed.java b/altoslib/AltosSpeed.java new file mode 100644 index 00000000..4e2daf5a --- /dev/null +++ b/altoslib/AltosSpeed.java @@ -0,0 +1,43 @@ +/* + * Copyright © 2012 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.AltosLib; + +public class AltosSpeed extends AltosUnits { + + public double value(double v) { + if (AltosConvert.imperial_units) + return AltosConvert.meters_to_mph(v); + return v; + } + + public String show_units() { + if (AltosConvert.imperial_units) + return "mph"; + return "m/s"; + } + + public String say_units() { + if (AltosConvert.imperial_units) + return "miles per hour"; + return "meters per second"; + } + + int show_fraction(int width) { + return width / 9; + } +} \ No newline at end of file diff --git a/altoslib/AltosUnits.java b/altoslib/AltosUnits.java new file mode 100644 index 00000000..47540c61 --- /dev/null +++ b/altoslib/AltosUnits.java @@ -0,0 +1,57 @@ +/* + * Copyright © 2012 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.AltosLib; + +public abstract class AltosUnits { + + public abstract double value(double v); + + public abstract String show_units(); + + public abstract String say_units(); + + abstract int show_fraction(int width); + + int say_fraction() { + return 0; + } + + private String show_format(int width) { + return String.format("%%%d.%df %s", width, show_fraction(width), show_units()); + } + + private String say_format() { + return String.format("%%1.%df", say_fraction()); + } + + private String say_units_format() { + return String.format("%%1.%df %s", say_fraction(), say_units()); + } + + public String show(int width, double v) { + return String.format(show_format(width), value(v)); + } + + public String say(double v) { + return String.format(say_format(), value(v)); + } + + public String say_units(double v) { + return String.format(say_units_format(), value(v)); + } +} \ No newline at end of file diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index 39b43f3d..a9f810f9 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -68,7 +68,12 @@ AltosLib_JAVA = \ $(SRC)/AltosTelemetryRecordMegaData.java \ $(SRC)/AltosMs5607.java \ $(SRC)/AltosIMU.java \ - $(SRC)/AltosMag.java + $(SRC)/AltosMag.java \ + $(SRC)/AltosUnits.java \ + $(SRC)/AltosDistance.java \ + $(SRC)/AltosHeight.java \ + $(SRC)/AltosSpeed.java \ + $(SRC)/AltosAccel.java JAR=AltosLib.jar -- cgit v1.2.3