--- /dev/null
+/*
+ * Copyright © 2012 Keith Packard <keithp@keithp.com>
+ *
+ * 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
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 */
}
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++)
--- /dev/null
+/*
+ * Copyright © 2012 Keith Packard <keithp@keithp.com>
+ *
+ * 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
--- /dev/null
+/*
+ * Copyright © 2012 Keith Packard <keithp@keithp.com>
+ *
+ * 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
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;
common_frequencies = load_common_frequencies();
+ AltosConvert.imperial_units = preferences.getBoolean(unitsPreference, false);
}
static { init(); }
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();
+ }
+ }
}
--- /dev/null
+/*
+ * Copyright © 2012 Keith Packard <keithp@keithp.com>
+ *
+ * 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
--- /dev/null
+/*
+ * Copyright © 2012 Keith Packard <keithp@keithp.com>
+ *
+ * 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
$(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