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 max_speed_view;
32 private TextView max_height_view;
33 private TextView elevation_view;
34 private TextView range_view;
35 private TextView bearing_view;
36 private TextView compass_view;
37 private TextView distance_view;
38 private TextView latitude_view;
39 private TextView longitude_view;
40 private View apogee_view;
41 private TextView apogee_voltage_view;
42 private TextView apogee_voltage_label;
43 private GoNoGoLights apogee_lights;
44 private View main_view;
45 private TextView main_voltage_view;
46 private TextView main_voltage_label;
47 private GoNoGoLights main_lights;
50 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
51 View v = inflater.inflate(R.layout.tab_flight, container, false);
53 speed_view = (TextView) v.findViewById(R.id.speed_value);
54 height_view = (TextView) v.findViewById(R.id.height_value);
55 max_speed_view = (TextView) v.findViewById(R.id.max_speed_value);
56 max_height_view= (TextView) v.findViewById(R.id.max_height_value);
57 elevation_view = (TextView) v.findViewById(R.id.elevation_value);
58 range_view = (TextView) v.findViewById(R.id.range_value);
59 bearing_view = (TextView) v.findViewById(R.id.bearing_value);
60 compass_view = (TextView) v.findViewById(R.id.compass_value);
61 distance_view = (TextView) v.findViewById(R.id.distance_value);
62 latitude_view = (TextView) v.findViewById(R.id.lat_value);
63 longitude_view = (TextView) v.findViewById(R.id.lon_value);
65 apogee_view = v.findViewById(R.id.apogee_view);
66 apogee_voltage_view = (TextView) v.findViewById(R.id.apogee_voltage_value);
67 apogee_lights = new GoNoGoLights((ImageView) v.findViewById(R.id.apogee_redled),
68 (ImageView) v.findViewById(R.id.apogee_greenled),
70 apogee_voltage_label = (TextView) v.findViewById(R.id.apogee_voltage_label);
72 main_view = v.findViewById(R.id.main_view);
73 main_voltage_view = (TextView) v.findViewById(R.id.main_voltage_value);
74 main_lights = new GoNoGoLights((ImageView) v.findViewById(R.id.main_redled),
75 (ImageView) v.findViewById(R.id.main_greenled),
77 main_voltage_label = (TextView) v.findViewById(R.id.main_voltage_label);
82 public String tab_name() { return AltosDroid.tab_flight_name; }
84 public void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver) {
86 set_value(speed_view, AltosConvert.speed, 1, state.speed());
87 set_value(height_view, AltosConvert.height, 1, state.height());
88 set_value(max_speed_view, AltosConvert.speed, 1, state.max_speed());
89 set_value(max_height_view, AltosConvert.height, 1, state.max_height());
90 if (from_receiver != null) {
91 elevation_view.setText(AltosDroid.number("%1.0f°", from_receiver.elevation));
92 set_value(range_view, AltosConvert.distance, 1, from_receiver.range);
93 bearing_view.setText(AltosDroid.number("%1.0f°", from_receiver.bearing));
94 compass_view.setText(from_receiver.bearing_words(AltosGreatCircle.BEARING_LONG));
95 set_value(distance_view, AltosConvert.distance, 1, from_receiver.distance);
97 elevation_view.setText("<unknown>");
98 range_view.setText("<unknown>");
99 bearing_view.setText("<unknown>");
100 compass_view.setText("<unknown>");
101 distance_view.setText("<unknown>");
103 if (state.gps != null) {
104 latitude_view.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
105 longitude_view.setText(AltosDroid.pos(state.gps.lon, "E", "W"));
108 if (state.apogee_voltage == AltosLib.MISSING) {
109 apogee_view.setVisibility(View.GONE);
111 apogee_voltage_view.setText(AltosDroid.number("%1.2f V", state.apogee_voltage));
112 apogee_lights.set(state.apogee_voltage > 3.2, state.apogee_voltage == AltosLib.MISSING);
113 apogee_view.setVisibility(View.VISIBLE);
116 if (state.main_voltage == AltosLib.MISSING) {
117 main_view.setVisibility(View.GONE);
119 main_voltage_view.setText(AltosDroid.number("%1.2f V", state.main_voltage));
120 main_lights.set(state.main_voltage > 3.2, state.main_voltage == AltosLib.MISSING);
121 main_view.setVisibility(View.VISIBLE);