]> git.gag.com Git - fw/altos/blob - altosui/AltosPad.java
Bump altosdroid version to 20, always build release apk
[fw/altos] / altosui / AltosPad.java
1 /*
2  * Copyright © 2010 Keith Packard <keithp@keithp.com>
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 altosui;
20
21 import java.util.*;
22 import org.altusmetrum.altoslib_13.*;
23 import org.altusmetrum.altosuilib_13.*;
24
25 public class AltosPad extends AltosUIFlightTab {
26
27         class Battery extends AltosUIVoltageIndicator {
28                 public double voltage(AltosState state) { return state.battery_voltage; }
29                 public double good() { return AltosLib.ao_battery_good; }
30                 public Battery (AltosUIFlightTab container, int y) { super(container, y, "Battery Voltage", 2); }
31         }
32
33         class Apogee extends AltosUIVoltageIndicator {
34                 public boolean hide(double v) { return v == AltosLib.MISSING; }
35                 public double voltage(AltosState state) { return state.apogee_voltage; }
36                 public double good() { return AltosLib.ao_igniter_good; }
37                 public Apogee (AltosUIFlightTab container, int y) { super(container, y, "Apogee Igniter Voltage", 2); }
38         }
39
40         class Main extends AltosUIVoltageIndicator {
41                 public boolean hide(double v) { return v == AltosLib.MISSING; }
42                 public double voltage(AltosState state) { return state.main_voltage; }
43                 public double good() { return AltosLib.ao_igniter_good; }
44                 public Main (AltosUIFlightTab container, int y) { super(container, y, "Main Igniter Voltage", 2); }
45         }
46
47         class LoggingReady extends AltosUIIndicator {
48                 public void show (AltosState state, AltosListenerState listener_state) {
49                         AltosCalData    cal_data = state.cal_data();
50                         if (state == null || cal_data.flight == AltosLib.MISSING) {
51                                 hide();
52                         } else {
53                                 if (cal_data.flight != 0) {
54                                         if (state.state() <= Altos.ao_flight_pad)
55                                                 show("Ready to record");
56                                         else if (state.state() < Altos.ao_flight_landed ||
57                                                  state.state() == AltosLib.ao_flight_stateless)
58                                                 show("Recording data");
59                                         else
60                                                 show("Recorded data");
61                                 } else
62                                         show("Storage full");
63                                 set_lights(cal_data.flight != 0);
64                         }
65                 }
66                 public LoggingReady (AltosUIFlightTab container, int y) {
67                         super(container, y, "On-board Data Logging", 1, true, 2);
68                 }
69         }
70
71         class GPSLocked extends AltosUIIndicator {
72                 public void show (AltosState state, AltosListenerState listener_state) {
73                         if (state == null || state.gps == null)
74                                 hide();
75                         else {
76                                 int     sol = state.gps.nsat;
77                                 int     sat = state.gps.cc_gps_sat == null ? 0 : state.gps.cc_gps_sat.length;
78                                 show("%d in solution", sol, "%d in view", sat);
79                                 set_lights(state.gps.locked && sol >= 4);
80                         }
81                 }
82                 public GPSLocked (AltosUIFlightTab container, int y) {
83                         super (container, y, "GPS Locked", 2, true, 1);
84                 }
85         }
86
87         class GPSReady extends AltosUIIndicator {
88                 public void show (AltosState state, AltosListenerState listener_state) {
89                         if (state == null || state.gps == null)
90                                 hide();
91                         else {
92                                 if (state.gps_ready)
93                                         show("Ready");
94                                 else
95                                         show("Waiting %d", state.gps_waiting);
96                                 set_lights(state.gps_ready);
97                         }
98                 }
99                 public GPSReady (AltosUIFlightTab container, int y) {
100                         super (container, y, "GPS Ready", 1, true, 2);
101                 }
102         }
103
104         class ReceiverBattery extends AltosUIVoltageIndicator {
105
106                 double  last_voltage = AltosLib.MISSING;
107
108                 public double voltage(AltosState state) {
109                         return last_voltage;
110                 }
111
112                 public double good() { return AltosLib.ao_battery_good; }
113
114                 public boolean hide(AltosState state, AltosListenerState listener_state, int i) {
115                         return value(state, listener_state, i) == AltosLib.MISSING;
116                 }
117
118                 public double value(AltosState state, AltosListenerState listener_state, int i) {
119                         if (listener_state == null)
120                                 last_voltage = AltosLib.MISSING;
121                         else
122                                 last_voltage = listener_state.battery;
123                         return last_voltage;
124                 }
125
126                 public ReceiverBattery (AltosUIFlightTab container, int y) {
127                         super(container, y, "Receiver Battery", 2);
128                 }
129         }
130
131         boolean report_pad(AltosState state) {
132                 if (state.state() == AltosLib.ao_flight_stateless ||
133                     state.state() < AltosLib.ao_flight_pad)
134                 {
135                         return false;
136                 }
137                 return true;
138         }
139
140         class PadLat extends AltosUIIndicator {
141
142                 double  last_lat = AltosLib.MISSING - 1;
143
144                 public void show (AltosState state, AltosListenerState listener_state) {
145                         double lat = AltosLib.MISSING;
146                         String label = null;
147
148                         if (state != null) {
149                                 if (report_pad(state)) {
150                                         lat = state.pad_lat;
151                                         label = "Pad Latitude";
152                                 } else if (state.gps != null) {
153                                         lat = state.gps.lat;
154                                         label = "Latitude";
155                                 }
156                         }
157                         if (lat != last_lat) {
158                                 if (lat != AltosLib.MISSING) {
159                                         show(AltosConvert.latitude.show(10, lat));
160                                         set_label(label);
161                                 } else
162                                         hide();
163                                 last_lat = lat;
164                         }
165                 }
166
167                 public void reset() {
168                         super.reset();
169                         last_lat = AltosLib.MISSING - 1;
170                 }
171
172                 public PadLat (AltosUIFlightTab container, int y) {
173                         super (container, y, "Pad Latitude", 1, false, 2);
174                 }
175         }
176
177         class PadLon extends AltosUIIndicator {
178
179                 double last_lon = AltosLib.MISSING - 1;
180
181                 public void show (AltosState state, AltosListenerState listener_state) {
182                         double lon = AltosLib.MISSING;
183                         String label = null;
184
185                         if (state != null) {
186                                 if (report_pad(state)) {
187                                         lon = state.pad_lon;
188                                         label = "Pad Longitude";
189                                 } else if (state.gps != null) {
190                                         lon = state.gps.lon;
191                                         label = "Longitude";
192                                 }
193                         }
194                         if (lon != last_lon) {
195                                 if (lon != AltosLib.MISSING) {
196                                         show(AltosConvert.longitude.show(10, lon));
197                                         set_label(label);
198                                 } else
199                                         hide();
200                                 last_lon = lon;
201                         }
202                 }
203
204                 public void reset() {
205                         super.reset();
206                         last_lon = AltosLib.MISSING - 1;
207                 }
208
209                 public PadLon (AltosUIFlightTab container, int y) {
210                         super (container, y, "Pad Longitude", 1, false, 2);
211                 }
212         }
213
214         class PadAlt extends AltosUIUnitsIndicator {
215
216                 public double value(AltosState state, int i) {
217                         if (report_pad(state))
218                                 return state.pad_alt;
219                         else if (state.gps != null)
220                                 return state.gps.alt;
221                         else
222                                 return state.altitude();
223                 }
224
225                 public void show (AltosState state, AltosListenerState listener_state) {
226                         String label = "Altitude";
227
228                         if (state != null && report_pad(state))
229                                 label = "Pad Altitude";
230                         set_label(label);
231                         super.show(state, listener_state);
232                 }
233
234                 public PadAlt (AltosUIFlightTab container, int y) {
235                         super (container, y, AltosConvert.height, "Pad Altitude", 1, false, 2);
236                 }
237         }
238         public String getName() { return "Pad"; }
239
240         public AltosPad() {
241                 int y = 0;
242                 add(new Battery(this, y++));
243                 add(new ReceiverBattery(this, y++));
244                 add(new Apogee(this, y++));
245                 add(new Main(this, y++));
246                 add(new LoggingReady(this, y++));
247                 add(new GPSLocked(this, y++));
248                 add(new GPSReady(this, y++));
249                 add(new PadLat(this, y++));
250                 add(new PadLon(this, y++));
251                 add(new PadAlt(this, y++));
252         }
253 }