diff options
author | Keith Packard <keithp@keithp.com> | 2017-05-27 00:27:04 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2017-05-27 00:27:04 -0700 |
commit | b6b5c64f93fa56bcb22ea1c4279e4f754e6e6f1c (patch) | |
tree | 6ec6ecb767be291c8712030e0097fae051652637 /altosdroid/src | |
parent | 8b4dcca73c65e87462d5f8d08dbc025aa8cf08a6 (diff) |
altosdroid: Deal with AltosState changes
cal data split out from altos state.
altos state needed to have no-arguments constructor for JSON code.
Also messed with voice to make it stay quiet during app startup.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosdroid/src')
7 files changed, 101 insertions, 45 deletions
diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java index 30a949d5..36ba0308 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java @@ -54,6 +54,29 @@ import android.graphics.drawable.*; import org.altusmetrum.altoslib_11.*; +class SavedState { + long received_time; + int state; + boolean locked; + String callsign; + int serial; + int flight; + int rssi; + + SavedState(AltosState state) { + received_time = state.received_time; + this.state = state.state(); + if (state.gps != null) + locked = state.gps.locked; + else + locked = false; + callsign = state.cal_data.callsign; + serial = state.cal_data.serial; + flight = state.cal_data.flight; + rssi = state.rssi; + } +} + public class AltosDroid extends FragmentActivity implements AltosUnitsListener, LocationListener { // Actions sent to the telemetry server at startup time @@ -114,6 +137,9 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, public Location location = null; + private AltosState state; + private SavedState saved_state; + // Tabs TabHost mTabHost; AltosViewPager mViewPager; @@ -123,7 +149,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, // Timer and Saved flight state for Age calculation private Timer timer; - AltosState saved_state; + TelemetryState telemetry_state; Integer[] serials; @@ -307,7 +333,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, if (telemetry_state.states.containsKey(current_serial)) { state = telemetry_state.states.get(current_serial); - int age = state_age(state); + int age = state_age(state.received_time); if (age < 20) aged = false; if (current_serial == selected_serial) @@ -322,7 +348,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, for (int serial : telemetry_state.states.keySet()) { AltosState existing = telemetry_state.states.get(serial); - int existing_age = state_age(existing); + int existing_age = state_age(existing.received_time); if (newest_state == null || existing_age < newest_age) { newest_state = existing; @@ -334,7 +360,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, state = newest_state; } - update_ui(telemetry_state, state); + update_ui(telemetry_state, state, telemetry_state.quiet); start_timer(); } @@ -362,8 +388,8 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, blend_component(a, b, r, 24, 0xff)); } - int state_age(AltosState state) { - return (int) ((System.currentTimeMillis() - state.received_time + 500) / 1000); + int state_age(long received_time) { + return (int) ((System.currentTimeMillis() - received_time + 500) / 1000); } void set_screen_on(int age) { @@ -375,7 +401,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, void update_age() { if (saved_state != null) { - int age = state_age(saved_state); + int age = state_age(saved_state.received_time); double age_scale = age / 100.0; @@ -399,17 +425,19 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, } } - void update_ui(TelemetryState telem_state, AltosState state) { + void update_ui(TelemetryState telem_state, AltosState state, boolean quiet) { + + this.state = state; int prev_state = AltosLib.ao_flight_invalid; AltosGreatCircle from_receiver = null; if (saved_state != null) - prev_state = saved_state.state(); + prev_state = saved_state.state; if (state != null) { - set_screen_on(state_age(state)); + set_screen_on(state_age(state.received_time)); if (state.state() == AltosLib.ao_flight_stateless) { boolean prev_locked = false; @@ -417,8 +445,8 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, if(state.gps != null) locked = state.gps.locked; - if (saved_state != null && saved_state.gps != null) - prev_locked = saved_state.gps.locked; + if (saved_state != null) + prev_locked = saved_state.locked; if (prev_locked != locked) { String currentTab = mTabHost.getCurrentTabTag(); if (locked) { @@ -456,22 +484,22 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, state.gps.alt); } - if (saved_state == null || !same_string(saved_state.callsign, state.callsign)) { - mCallsignView.setText(state.callsign); + if (saved_state == null || !same_string(saved_state.callsign, state.cal_data.callsign)) { + mCallsignView.setText(state.cal_data.callsign); } - if (saved_state == null || state.serial != saved_state.serial) { - if (state.serial == AltosLib.MISSING) + if (saved_state == null || state.cal_data.serial != saved_state.serial) { + if (state.cal_data.serial == AltosLib.MISSING) mSerialView.setText(""); else - mSerialView.setText(String.format("%d", state.serial)); + mSerialView.setText(String.format("%d", state.cal_data.serial)); } - if (saved_state == null || state.flight != saved_state.flight) { - if (state.flight == AltosLib.MISSING) + if (saved_state == null || state.cal_data.flight != saved_state.flight) { + if (state.cal_data.flight == AltosLib.MISSING) mFlightView.setText(""); else - mFlightView.setText(String.format("%d", state.flight)); + mFlightView.setText(String.format("%d", state.cal_data.flight)); } - if (saved_state == null || state.state() != saved_state.state()) { + if (saved_state == null || state.state() != saved_state.state) { if (state.state() == AltosLib.ao_flight_stateless) { mStateLayout.setVisibility(View.GONE); } else { @@ -485,15 +513,16 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, else mRSSIView.setText(String.format("%d", state.rssi)); } + saved_state = new SavedState(state); } for (AltosDroidTab mTab : mTabs) mTab.update_ui(telem_state, state, from_receiver, location, mTab == mTabsAdapter.currentItem()); + AltosDebug.debug("quiet %b\n", quiet); if (mAltosVoice != null) - mAltosVoice.tell(telem_state, state, from_receiver, location, (AltosDroidTab) mTabsAdapter.currentItem()); + mAltosVoice.tell(telem_state, state, from_receiver, location, (AltosDroidTab) mTabsAdapter.currentItem(), quiet); - saved_state = state; } private void onTimerTick() { @@ -567,8 +596,9 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, // Display the Version mVersion = (TextView) findViewById(R.id.version); mVersion.setText("Version: " + BuildInfo.version + - " Built: " + BuildInfo.builddate + " " + BuildInfo.buildtime + " " + BuildInfo.buildtz + - " (" + BuildInfo.branch + "-" + BuildInfo.commitnum + "-" + BuildInfo.commithash + ")"); + (AltosVersion.has_google_maps_api_key() ? " maps" : "") + + " Built: " + BuildInfo.builddate + " " + BuildInfo.buildtime + " " + BuildInfo.buildtz + + " (" + BuildInfo.branch + "-" + BuildInfo.commitnum + "-" + BuildInfo.commithash + ")"); mCallsignView = (TextView) findViewById(R.id.callsign_value); mRSSIView = (TextView) findViewById(R.id.rssi_value); @@ -703,7 +733,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, location.getLatitude(), location.getLongitude()); - update_ui(telemetry_state, saved_state); + update_ui(telemetry_state, state, true); } @Override @@ -1094,7 +1124,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, AltosDebug.debug("Location changed to %f,%f", location.getLatitude(), location.getLongitude()); - update_ui(telemetry_state, saved_state); + update_ui(telemetry_state, state, false); } public void onStatusChanged(String provider, int status, Bundle extras) { diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferencesBackend.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferencesBackend.java index 2e6ccb34..2fceb535 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferencesBackend.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferencesBackend.java @@ -77,7 +77,17 @@ public class AltosDroidPreferencesBackend extends AltosPreferencesBackend { } public String getString(String key, String def) { - return prefs.getString(key, def); + String ret; + ret = prefs.getString(key, def); +// AltosDebug.debug("AltosDroidPreferencesBackend get string %s:\n", key); +// if (ret == null) +// AltosDebug.debug(" (null)\n"); +// else { +// String[] lines = ret.split("\n"); +// for (String l : lines) +// AltosDebug.debug(" %s\n", l); +// } + return ret; } public byte[] getBytes(String key, byte[] def) { @@ -103,6 +113,10 @@ public class AltosDroidPreferencesBackend extends AltosPreferencesBackend { } public void putString(String key, String value) { +// AltosDebug.debug("AltosDroidPreferencesBackend put string %s:\n", key); +// String[] lines = value.split("\n"); +// for (String l : lines) +// AltosDebug.debug(" %s\n", l); editor.putString(key, value); } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOffline.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOffline.java index 76771adc..3f74bbba 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOffline.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOffline.java @@ -164,6 +164,7 @@ public class AltosMapOffline extends View implements ScaleGestureDetector.OnScal break; case AltosMapTile.forbidden: message = "Too many requests, try later"; + AltosDebug.debug("Forbidden map response %d\n", AltosMapStore.forbidden_response); break; } if (message != null) { @@ -476,11 +477,11 @@ public class AltosMapOffline extends View implements ScaleGestureDetector.OnScal if (t_state.gps != null) { AltosLatLon latlon = new AltosLatLon(t_state.gps.lat, t_state.gps.lon); rocket.set_position(latlon, t_state.received_time); - if (state.serial == serial) + if (state.cal_data.serial == serial) there = latlon; } if (state != null) - rocket.set_active(state.serial == serial); + rocket.set_active(state.cal_data.serial == serial); } } if (receiver != null) { diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosVoice.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosVoice.java index 811b0367..308c50e7 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosVoice.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosVoice.java @@ -49,6 +49,7 @@ public class AltosVoice { private Location last_receiver; private long last_speak_time; private int last_flight_tell = TELL_FLIGHT_NONE; + private boolean quiet = false; private long now() { return System.currentTimeMillis(); @@ -80,7 +81,8 @@ public class AltosVoice { public synchronized void speak(String s) { if (!tts_enabled) return; last_speak_time = now(); - tts.speak(s, TextToSpeech.QUEUE_ADD, null); + if (!quiet) + tts.speak(s, TextToSpeech.QUEUE_ADD, null); } public synchronized long time_since_speak() { @@ -121,6 +123,8 @@ public class AltosVoice { if (state == null) return false; + AltosDebug.debug("tell_pad lag %b ltm %d\n", last_apogee_good, last_tell_mode); + if (state.apogee_voltage != AltosLib.MISSING) last_apogee_good = tell_gonogo("apogee", state.apogee_voltage >= AltosLib.ao_igniter_good, @@ -277,7 +281,9 @@ public class AltosVoice { public void tell(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver, - AltosDroidTab tab) { + AltosDroidTab tab, boolean quiet) { + + this.quiet = quiet; boolean spoken = false; @@ -288,7 +294,7 @@ public class AltosVoice { int tell_serial = last_tell_serial; if (state != null) - tell_serial = state.serial; + tell_serial = state.cal_data.serial; if (tell_serial != last_tell_serial) reset_last(); diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java index 492f7f5f..37e2df18 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java @@ -178,10 +178,10 @@ public class TabPad extends AltosDroidTab { } main_lights.set(state.main_voltage >= AltosLib.ao_igniter_good, state.main_voltage == AltosLib.MISSING); - int num_igniter = state.ignitor_voltage == null ? 0 : state.ignitor_voltage.length; + int num_igniter = state.igniter_voltage == null ? 0 : state.igniter_voltage.length; for (int i = 0; i < 4; i++) { - double voltage = i >= num_igniter ? AltosLib.MISSING : state.ignitor_voltage[i]; + double voltage = i >= num_igniter ? AltosLib.MISSING : state.igniter_voltage[i]; if (voltage == AltosLib.MISSING) { ignite_row[i].setVisibility(View.GONE); } else { @@ -191,7 +191,7 @@ public class TabPad extends AltosDroidTab { ignite_lights[i].set(voltage >= AltosLib.ao_igniter_good, voltage == AltosLib.MISSING); } - if (state.flight != 0) { + if (state.cal_data.flight != 0) { if (state.state() <= AltosLib.ao_flight_pad) data_logging_view.setText("Ready to record"); else if (state.state() < AltosLib.ao_flight_landed) @@ -201,7 +201,7 @@ public class TabPad extends AltosDroidTab { } else { data_logging_view.setText("Storage full"); } - data_logging_lights.set(state.flight != 0, state.flight == AltosLib.MISSING); + data_logging_lights.set(state.cal_data.flight != 0, state.cal_data.flight == AltosLib.MISSING); if (state.gps != null) { int soln = state.gps.nsat; diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java index 34c86ce5..45bb4732 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java @@ -259,14 +259,15 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene private void telemetry(AltosTelemetry telem) { AltosState state; - if (telemetry_state.states.containsKey(telem.serial)) - state = telemetry_state.states.get(telem.serial).clone(); + if (telemetry_state.states.containsKey(telem.serial())) + state = telemetry_state.states.get(telem.serial()); else - state = new AltosState(); - telem.update_state(state); - telemetry_state.states.put(telem.serial, state); + state = new AltosState(new AltosCalData()); + telem.provide_data(state, state.cal_data); + telemetry_state.states.put(telem.serial(), state); + telemetry_state.quiet = false; if (state != null) { - AltosPreferences.set_state(state); + AltosPreferences.set_state(state,telem.serial()); } send_to_clients(); } @@ -615,6 +616,8 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene telemetry_state.latest_serial = AltosPreferences.latest_state(); + telemetry_state.quiet = true; + AltosDebug.debug("latest serial %d\n", telemetry_state.latest_serial); for (int serial : serials) { @@ -625,7 +628,7 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene AltosDebug.debug("recovered old state serial %d flight %d", serial, - saved_state.flight); + saved_state.cal_data.flight); if (saved_state.gps != null) AltosDebug.debug("\tposition %f,%f", saved_state.gps.lat, @@ -699,7 +702,7 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene /* AltosIdleMonitorListener */ public void update(AltosState state, AltosListenerState listener_state) { - telemetry_state.states.put(state.serial, state); + telemetry_state.states.put(state.cal_data.serial, state); telemetry_state.receiver_battery = listener_state.battery; send_to_clients(); } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryState.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryState.java index 32ba1254..46b4027a 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryState.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryState.java @@ -36,6 +36,8 @@ public class TelemetryState { double frequency; int telemetry_rate; + boolean quiet; + HashMap<Integer,AltosState> states; int latest_serial; |