+ void update_ui(AltosState state) {
+ mCallsignView.setText(state.data.callsign);
+ mRSSIView.setText(String.format("%d", state.data.rssi));
+ mSerialView.setText(String.format("%d", state.data.serial));
+ mFlightView.setText(String.format("%d", state.data.flight));
+ mStateView.setText(state.data.state());
+ double speed = state.speed;
+ if (!state.ascent)
+ speed = state.baro_speed;
+ mSpeedView.setText(String.format("%6.0f m/s", speed));
+ mAccelView.setText(String.format("%6.0f m/s²", state.acceleration));
+ mRangeView.setText(String.format("%6.0f m", state.range));
+ mHeightView.setText(String.format("%6.0f m", state.height));
+ mElevationView.setText(String.format("%3.0f°", state.elevation));
+ if (state.from_pad != null)
+ mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
+ mLatitudeView.setText(pos(state.gps.lat, "N", "S"));
+ mLongitudeView.setText(pos(state.gps.lon, "W", "E"));
+
+ mAltosVoice.tell(state);
+ }
+
+ String pos(double p, String pos, String neg) {
+ String h = pos;
+ if (p < 0) {
+ h = neg;
+ p = -p;
+ }
+ int deg = (int) Math.floor(p);
+ double min = (p - Math.floor(p)) * 60.0;
+ return String.format("%d° %9.6f\" %s", deg, min, h);
+ }