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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.AltosDroid;
20 import org.altusmetrum.altoslib_11.*;
22 import android.app.Activity;
23 import android.os.Bundle;
24 import android.support.v4.app.Fragment;
25 import android.view.*;
26 import android.widget.*;
27 import android.location.Location;
29 public class TabFlight extends AltosDroidTab {
30 private TextView speed_view;
31 private TextView height_view;
32 private TextView max_speed_view;
33 private TextView max_height_view;
34 private TextView elevation_view;
35 private TextView range_view;
36 private TextView bearing_view;
37 private TextView compass_view;
38 private TextView distance_view;
39 private TextView latitude_view;
40 private TextView longitude_view;
41 private View apogee_view;
42 private TextView apogee_voltage_view;
43 private TextView apogee_voltage_label;
44 private GoNoGoLights apogee_lights;
45 private View main_view;
46 private TextView main_voltage_view;
47 private TextView main_voltage_label;
48 private GoNoGoLights main_lights;
51 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
52 View v = inflater.inflate(R.layout.tab_flight, container, false);
54 speed_view = (TextView) v.findViewById(R.id.speed_value);
55 height_view = (TextView) v.findViewById(R.id.height_value);
56 max_speed_view = (TextView) v.findViewById(R.id.max_speed_value);
57 max_height_view= (TextView) v.findViewById(R.id.max_height_value);
58 elevation_view = (TextView) v.findViewById(R.id.elevation_value);
59 range_view = (TextView) v.findViewById(R.id.range_value);
60 bearing_view = (TextView) v.findViewById(R.id.bearing_value);
61 compass_view = (TextView) v.findViewById(R.id.compass_value);
62 distance_view = (TextView) v.findViewById(R.id.distance_value);
63 latitude_view = (TextView) v.findViewById(R.id.lat_value);
64 longitude_view = (TextView) v.findViewById(R.id.lon_value);
66 apogee_view = v.findViewById(R.id.apogee_view);
67 apogee_voltage_view = (TextView) v.findViewById(R.id.apogee_voltage_value);
68 apogee_lights = new GoNoGoLights((ImageView) v.findViewById(R.id.apogee_redled),
69 (ImageView) v.findViewById(R.id.apogee_greenled),
71 apogee_voltage_label = (TextView) v.findViewById(R.id.apogee_voltage_label);
73 main_view = v.findViewById(R.id.main_view);
74 main_voltage_view = (TextView) v.findViewById(R.id.main_voltage_value);
75 main_lights = new GoNoGoLights((ImageView) v.findViewById(R.id.main_redled),
76 (ImageView) v.findViewById(R.id.main_greenled),
78 main_voltage_label = (TextView) v.findViewById(R.id.main_voltage_label);
83 public String tab_name() { return AltosDroid.tab_flight_name; }
85 public void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver) {
87 set_value(speed_view, AltosConvert.speed, 6, state.speed());
88 set_value(height_view, AltosConvert.height, 6, state.height());
89 set_value(max_speed_view, AltosConvert.speed, 6, state.max_speed());
90 set_value(max_height_view, AltosConvert.height, 6, state.max_height());
91 if (from_receiver != null) {
92 elevation_view.setText(AltosDroid.number("%3.0f°", from_receiver.elevation));
93 set_value(range_view, AltosConvert.distance, 6, from_receiver.range);
94 bearing_view.setText(AltosDroid.number("%3.0f°", from_receiver.bearing));
95 compass_view.setText(from_receiver.bearing_words(AltosGreatCircle.BEARING_LONG));
96 set_value(distance_view, AltosConvert.distance, 6, from_receiver.distance);
98 elevation_view.setText("<unknown>");
99 range_view.setText("<unknown>");
100 bearing_view.setText("<unknown>");
101 compass_view.setText("<unknown>");
102 distance_view.setText("<unknown>");
104 if (state.gps != null) {
105 latitude_view.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
106 longitude_view.setText(AltosDroid.pos(state.gps.lon, "E", "W"));
109 if (state.apogee_voltage == AltosLib.MISSING) {
110 apogee_view.setVisibility(View.GONE);
112 apogee_voltage_view.setText(AltosDroid.number("%4.2f V", state.apogee_voltage));
113 apogee_lights.set(state.apogee_voltage > 3.2, state.apogee_voltage == AltosLib.MISSING);
114 apogee_view.setVisibility(View.VISIBLE);
117 if (state.main_voltage == AltosLib.MISSING) {
118 main_view.setVisibility(View.GONE);
120 main_voltage_view.setText(AltosDroid.number("%4.2f V", state.main_voltage));
121 main_lights.set(state.main_voltage > 3.2, state.main_voltage == AltosLib.MISSING);
122 main_view.setVisibility(View.VISIBLE);