8230757c2b4237c12680cd83627f7f81b6ca1bde
[fw/altos] / altosdroid / app / src / main / java / org / altusmetrum / AltosDroid / TabFlight.java
1 /*
2  * Copyright © 2013 Mike Beattie <mike@ethernal.org>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 package org.altusmetrum.AltosDroid;
20
21 import org.altusmetrum.altoslib_14.*;
22
23 import android.os.Bundle;
24 import android.view.*;
25 import android.widget.*;
26 import android.location.Location;
27
28 public class TabFlight extends AltosDroidTab {
29         private TextView speed_view;
30         private TextView height_view;
31         private TextView altitude_view;
32         private TextView max_speed_view;
33         private TextView max_height_view;
34         private TextView max_altitude_view;
35         private TextView elevation_view;
36         private TextView range_view;
37         private TextView bearing_view;
38         private TextView compass_view;
39         private TextView distance_view;
40         private TextView latitude_view;
41         private TextView longitude_view;
42         private View apogee_view;
43         private TextView apogee_voltage_view;
44         private TextView apogee_voltage_label;
45         private GoNoGoLights apogee_lights;
46         private View main_view;
47         private TextView main_voltage_view;
48         private TextView main_voltage_label;
49         private GoNoGoLights main_lights;
50
51         @Override
52         public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
53                 View v = inflater.inflate(R.layout.tab_flight, container, false);
54
55                 speed_view     = (TextView) v.findViewById(R.id.speed_value);
56                 height_view    = (TextView) v.findViewById(R.id.height_value);
57                 altitude_view    = (TextView) v.findViewById(R.id.altitude_value);
58                 max_speed_view = (TextView) v.findViewById(R.id.max_speed_value);
59                 max_height_view= (TextView) v.findViewById(R.id.max_height_value);
60                 max_altitude_view= (TextView) v.findViewById(R.id.max_altitude_value);
61                 elevation_view = (TextView) v.findViewById(R.id.elevation_value);
62                 range_view     = (TextView) v.findViewById(R.id.range_value);
63                 bearing_view   = (TextView) v.findViewById(R.id.bearing_value);
64                 compass_view   = (TextView) v.findViewById(R.id.compass_value);
65                 distance_view  = (TextView) v.findViewById(R.id.distance_value);
66                 latitude_view  = (TextView) v.findViewById(R.id.lat_value);
67                 longitude_view = (TextView) v.findViewById(R.id.lon_value);
68
69                 apogee_view = v.findViewById(R.id.apogee_view);
70                 apogee_voltage_view = (TextView) v.findViewById(R.id.apogee_voltage_value);
71                 apogee_lights = new GoNoGoLights((ImageView) v.findViewById(R.id.apogee_redled),
72                                                  (ImageView) v.findViewById(R.id.apogee_greenled),
73                                                  getResources());
74                 apogee_voltage_label = (TextView) v.findViewById(R.id.apogee_voltage_label);
75
76                 main_view = v.findViewById(R.id.main_view);
77                 main_voltage_view = (TextView) v.findViewById(R.id.main_voltage_value);
78                 main_lights = new GoNoGoLights((ImageView) v.findViewById(R.id.main_redled),
79                                                (ImageView) v.findViewById(R.id.main_greenled),
80                                                getResources());
81                 main_voltage_label = (TextView) v.findViewById(R.id.main_voltage_label);
82
83                 return v;
84         }
85
86         public String tab_name() { return AltosDroid.tab_flight_name; }
87
88         public void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver) {
89                 if (state != null) {
90                         set_value(speed_view, AltosConvert.speed, 1, state.speed());
91                         set_value(height_view, AltosConvert.height, 1, state.height());
92                         set_value(altitude_view, AltosConvert.height, 1, state.altitude());
93                         set_value(max_speed_view, AltosConvert.speed, 1, state.max_speed());
94                         set_value(max_height_view, AltosConvert.height, 1, state.max_height());
95                         set_value(max_altitude_view, AltosConvert.height, 1, state.max_altitude());
96                         if (from_receiver != null) {
97                                 elevation_view.setText(AltosDroid.number("%1.0f°", from_receiver.elevation));
98                                 set_value(range_view, AltosConvert.distance, 1, from_receiver.range);
99                                 bearing_view.setText(AltosDroid.number("%1.0f°", from_receiver.bearing));
100                                 compass_view.setText(from_receiver.bearing_words(AltosGreatCircle.BEARING_LONG));
101                                 set_value(distance_view, AltosConvert.distance, 1, from_receiver.distance);
102                         } else { 
103                                 elevation_view.setText("<unknown>");
104                                 range_view.setText("<unknown>");
105                                 bearing_view.setText("<unknown>");
106                                 compass_view.setText("<unknown>");
107                                 distance_view.setText("<unknown>");
108                         }
109                         if (state.gps != null) {
110                                 latitude_view.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
111                                 longitude_view.setText(AltosDroid.pos(state.gps.lon, "E", "W"));
112                         }
113
114                         if (state.apogee_voltage == AltosLib.MISSING) {
115                                 apogee_view.setVisibility(View.GONE);
116                         } else {
117                                 apogee_voltage_view.setText(AltosDroid.number("%1.2f V", state.apogee_voltage));
118                                 apogee_lights.set(state.apogee_voltage > 3.2, state.apogee_voltage == AltosLib.MISSING);
119                                 apogee_view.setVisibility(View.VISIBLE);
120                         }
121
122                         if (state.main_voltage == AltosLib.MISSING) {
123                                 main_view.setVisibility(View.GONE);
124                         } else {
125                                 main_voltage_view.setText(AltosDroid.number("%1.2f V", state.main_voltage));
126                                 main_lights.set(state.main_voltage > 3.2, state.main_voltage == AltosLib.MISSING);
127                                 main_view.setVisibility(View.VISIBLE);
128                         }
129                 }
130         }
131
132 }