2 * Copyright © 2013 Mike Beattie <mike@ethernal.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.AltosDroid;
21 import org.altusmetrum.altoslib_14.*;
23 import android.os.Bundle;
24 import android.view.*;
25 import android.widget.*;
26 import android.location.Location;
28 public class TabFlight extends AltosDroidTab {
29 private TextView speed_view;
30 private TextView height_view;
31 private TextView altitude_view;
32 private View tilt_view;
33 private TextView tilt_value;
34 private TextView max_speed_view;
35 private TextView max_height_view;
36 private TextView max_altitude_view;
37 private TextView elevation_view;
38 private TextView range_view;
39 private TextView bearing_view;
40 private TextView compass_view;
41 private TextView distance_view;
42 private TextView latitude_view;
43 private TextView longitude_view;
44 private View apogee_view;
45 private TextView apogee_voltage_view;
46 private TextView apogee_voltage_label;
47 private GoNoGoLights apogee_lights;
48 private View main_view;
49 private TextView main_voltage_view;
50 private TextView main_voltage_label;
51 private GoNoGoLights main_lights;
54 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
55 View v = inflater.inflate(R.layout.tab_flight, container, false);
57 speed_view = (TextView) v.findViewById(R.id.speed_value);
58 height_view = (TextView) v.findViewById(R.id.height_value);
59 altitude_view = (TextView) v.findViewById(R.id.altitude_value);
60 tilt_view = (View) v.findViewById(R.id.tilt_view);
61 tilt_value = (TextView) v.findViewById(R.id.tilt_value);
62 max_speed_view = (TextView) v.findViewById(R.id.max_speed_value);
63 max_height_view = (TextView) v.findViewById(R.id.max_height_value);
64 max_altitude_view= (TextView) v.findViewById(R.id.max_altitude_value);
65 elevation_view = (TextView) v.findViewById(R.id.elevation_value);
66 range_view = (TextView) v.findViewById(R.id.range_value);
67 bearing_view = (TextView) v.findViewById(R.id.bearing_value);
68 compass_view = (TextView) v.findViewById(R.id.compass_value);
69 distance_view = (TextView) v.findViewById(R.id.distance_value);
70 latitude_view = (TextView) v.findViewById(R.id.lat_value);
71 longitude_view = (TextView) v.findViewById(R.id.lon_value);
73 apogee_view = v.findViewById(R.id.apogee_view);
74 apogee_voltage_view = (TextView) v.findViewById(R.id.apogee_voltage_value);
75 apogee_lights = new GoNoGoLights((ImageView) v.findViewById(R.id.apogee_redled),
76 (ImageView) v.findViewById(R.id.apogee_greenled),
78 apogee_voltage_label = (TextView) v.findViewById(R.id.apogee_voltage_label);
80 main_view = v.findViewById(R.id.main_view);
81 main_voltage_view = (TextView) v.findViewById(R.id.main_voltage_value);
82 main_lights = new GoNoGoLights((ImageView) v.findViewById(R.id.main_redled),
83 (ImageView) v.findViewById(R.id.main_greenled),
85 main_voltage_label = (TextView) v.findViewById(R.id.main_voltage_label);
90 public String tab_name() { return AltosDroid.tab_flight_name; }
92 public void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver) {
94 set_value(speed_view, AltosConvert.speed, 1, state.speed());
95 set_value(height_view, AltosConvert.height, 1, state.height());
96 set_value(altitude_view, AltosConvert.height, 1, state.altitude());
97 double orient = state.orient();
98 if (orient == AltosLib.MISSING) {
99 tilt_view.setVisibility(View.GONE);
101 tilt_value.setText(AltosDroid.number("%1.0f°", orient));
102 tilt_view.setVisibility(View.VISIBLE);
104 set_value(max_speed_view, AltosConvert.speed, 1, state.max_speed());
105 set_value(max_height_view, AltosConvert.height, 1, state.max_height());
106 set_value(max_altitude_view, AltosConvert.height, 1, state.max_altitude());
107 if (from_receiver != null) {
108 elevation_view.setText(AltosDroid.number("%1.0f°", from_receiver.elevation));
109 set_value(range_view, AltosConvert.distance, 1, from_receiver.range);
110 bearing_view.setText(AltosDroid.number("%1.0f°", from_receiver.bearing));
111 compass_view.setText(from_receiver.bearing_words(AltosGreatCircle.BEARING_LONG));
112 set_value(distance_view, AltosConvert.distance, 1, from_receiver.distance);
114 elevation_view.setText("<unknown>");
115 range_view.setText("<unknown>");
116 bearing_view.setText("<unknown>");
117 compass_view.setText("<unknown>");
118 distance_view.setText("<unknown>");
120 if (state.gps != null) {
121 latitude_view.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
122 longitude_view.setText(AltosDroid.pos(state.gps.lon, "E", "W"));
125 if (state.apogee_voltage == AltosLib.MISSING) {
126 apogee_view.setVisibility(View.GONE);
128 apogee_voltage_view.setText(AltosDroid.number("%1.2f V", state.apogee_voltage));
129 apogee_lights.set(state.apogee_voltage > 3.2, state.apogee_voltage == AltosLib.MISSING);
130 apogee_view.setVisibility(View.VISIBLE);
133 if (state.main_voltage == AltosLib.MISSING) {
134 main_view.setVisibility(View.GONE);
136 main_voltage_view.setText(AltosDroid.number("%1.2f V", state.main_voltage));
137 main_lights.set(state.main_voltage > 3.2, state.main_voltage == AltosLib.MISSING);
138 main_view.setVisibility(View.VISIBLE);