public void failed() {
}
+
+ public void error(String reason) {
+ stop_idle_monitor();
+ }
}
}
+ public boolean mma655x_inverted() throws AltosUnknownProduct {
+ if (product.startsWith("EasyMega-v1"))
+ return false;
+ if (product.startsWith("TeleMetrum-v2"))
+ return true;
+ if (product.startsWith("TeleMega-v2"))
+ return false;
+ if (product.startsWith("TeleMega-v1"))
+ return false;
+ throw new AltosUnknownProduct(product);
+ }
+
public void get_values(AltosConfigValues source) throws AltosConfigDataException {
/* HAS_FLIGHT */
static final int idle_sensor_tmini = 14;
static final int idle_sensor_tgps = 15;
- public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException {
+ public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException, AltosUnknownProduct {
for (int idler : idlers) {
AltosIdle idle = null;
switch (idler) {
double frequency;
String callsign;
- public void update_state(AltosState state) throws InterruptedException {
+ public void update_state(AltosState state) throws InterruptedException, AltosUnknownProduct {
try {
+ boolean matched = false;
/* Fetch config data from remote */
AltosConfigData config_data = new AltosConfigData(link);
state.set_state(AltosLib.ao_flight_stateless);
for (AltosIdler idler : idlers) {
if (idler.matches(config_data)) {
idler.update_state(state, link, config_data);
+ matched = true;
break;
}
}
+ if (!matched)
+ throw new AltosUnknownProduct(config_data.product);
state.set_received_time(System.currentTimeMillis());
} catch (TimeoutException te) {
}
return link.reply_abort;
}
- boolean update_state(AltosState state) throws InterruptedException, TimeoutException {
+ boolean update_state(AltosState state) throws InterruptedException, TimeoutException, AltosUnknownProduct {
boolean worked = false;
boolean aborted = false;
update_state(state);
listener.update(state, listener_state);
} catch (TimeoutException te) {
+ } catch (AltosUnknownProduct ae) {
+ listener.error(String.format("Unknown product \"%s\"", ae.product));
}
if (link.has_error || link.reply_abort) {
listener.failed();
public interface AltosIdleMonitorListener {
public void update(AltosState state, AltosListenerState listener_state);
+ public void error(String reason);
public void failed();
}
public class AltosMma655x implements Cloneable {
- int accel;
+ private int accel;
public boolean parse_line(String line) throws NumberFormatException {
if (line.startsWith("MMA655X value")) {
return n;
}
- static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException {
+ static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException, AltosUnknownProduct {
try {
AltosMma655x mma655x = new AltosMma655x(link);
- if (mma655x != null)
- state.set_accel(mma655x.accel);
+ if (mma655x != null) {
+ int accel = mma655x.accel;
+ if (config_data.mma655x_inverted())
+ accel = 4095 - accel;
+ if (config_data.pad_orientation == 1)
+ accel = 4095 - accel;
+ state.set_accel(accel);
+ }
} catch (TimeoutException te) {
} catch (NumberFormatException ne) {
}
package org.altusmetrum.altoslib_10;
public interface AltosStateUpdate {
- public void update_state(AltosState state) throws InterruptedException;
-}
\ No newline at end of file
+ public void update_state(AltosState state) throws InterruptedException, AltosUnknownProduct;
+}
--- /dev/null
+/*
+ * Copyright © 2010 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_10;
+
+public class AltosUnknownProduct extends Exception {
+ public String product;
+
+ public AltosUnknownProduct (String in_product) {
+ product = in_product;
+ }
+}
AltosTelemetrySatellite.java \
AltosTelemetryStandard.java \
AltosUnitsListener.java \
+ AltosUnknownProduct.java \
AltosMs5607.java \
AltosIMU.java \
AltosMag.java \
SwingUtilities.invokeLater(r);
}
+ public void error(final String reason) {
+ Runnable r = new Runnable() {
+ public void run() {
+ disconnect();
+ JOptionPane.showMessageDialog(AltosIdleMonitorUI.this,
+ reason,
+ "Error fetching data",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ };
+ SwingUtilities.invokeLater(r);
+ }
+
Container bag;
AltosUIFreqList frequencies;
JTextField callsign_value;