altosui: Mark TeleMega additional pyro ignitor fired points in graphs
[fw/altos] / altosui / AltosGraphDataPoint.java
1 /*
2  * Copyright © 2013 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; version 2 of the License.
7  *
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.
12  *
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.
16  */
17
18 package altosui;
19
20 import org.altusmetrum.altosuilib_1.*;
21 import org.altusmetrum.altoslib_3.*;
22
23 public class AltosGraphDataPoint implements AltosUIDataPoint {
24
25         AltosState      state;
26
27         public static final int data_height = 0;
28         public static final int data_speed = 1;
29         public static final int data_accel = 2;
30         public static final int data_temp = 3;
31         public static final int data_battery_voltage = 4;
32         public static final int data_drogue_voltage = 5;
33         public static final int data_main_voltage = 6;
34         public static final int data_rssi = 7;
35         public static final int data_state = 8;
36         public static final int data_gps_height = 9;
37         public static final int data_gps_nsat_solution = 10;
38         public static final int data_gps_nsat_view = 11;
39         public static final int data_temperature = 12;
40         public static final int data_range = 13;
41         public static final int data_distance = 14;
42         public static final int data_pressure = 15;
43         public static final int data_accel_x = 16;
44         public static final int data_accel_y = 17;
45         public static final int data_accel_z = 18;
46         public static final int data_gyro_x = 19;
47         public static final int data_gyro_y = 20;
48         public static final int data_gyro_z = 21;
49         public static final int data_mag_x = 22;
50         public static final int data_mag_y = 23;
51         public static final int data_mag_z = 24;
52         public static final int data_orient = 25;
53         public static final int data_ignitor_0 = 26;
54         public static final int data_ignitor_num = 32;
55         public static final int data_ignitor_max = data_ignitor_0 + data_ignitor_num - 1;
56         public static final int data_ignitor_fired_0 = data_ignitor_0 + data_ignitor_num;
57         public static final int data_ignitor_fired_max = data_ignitor_fired_0 + data_ignitor_num - 1;
58
59         public double x() throws AltosUIDataMissing {
60                 double  time = state.time_since_boost();
61                 if (time < -2)
62                         throw new AltosUIDataMissing(-1);
63                 return time;
64         }
65
66         public double y(int index) throws AltosUIDataMissing {
67                 double y = AltosLib.MISSING;
68                 switch (index) {
69                 case data_height:
70                         y = state.height();
71                         break;
72                 case data_speed:
73                         y = state.speed();
74                         break;
75                 case data_accel:
76                         y = state.acceleration();
77                         break;
78                 case data_temp:
79                         y = state.temperature;
80                         break;
81                 case data_battery_voltage:
82                         y = state.battery_voltage;
83                         break;
84                 case data_drogue_voltage:
85                         y = state.apogee_voltage;
86                         break;
87                 case data_main_voltage:
88                         y = state.main_voltage;
89                         break;
90                 case data_rssi:
91                         y = state.rssi;
92                         break;
93                 case data_gps_height:
94                         y = state.gps_height;
95                         break;
96                 case data_gps_nsat_solution:
97                         if (state.gps != null)
98                                 y = state.gps.nsat;
99                         break;
100                 case data_gps_nsat_view:
101                         if (state.gps != null && state.gps.cc_gps_sat != null)
102                                 y = state.gps.cc_gps_sat.length;
103                         break;
104                 case data_temperature:
105                         y = state.temperature;
106                         break;
107                 case data_range:
108                         y = state.range;
109                         break;
110                 case data_distance:
111                         if (state.from_pad != null)
112                                 y = state.from_pad.distance;
113                         break;
114                 case data_pressure:
115                         y = state.pressure();
116                         break;
117
118                 case data_accel_x:
119                 case data_accel_y:
120                 case data_accel_z:
121                 case data_gyro_x:
122                 case data_gyro_y:
123                 case data_gyro_z:
124                         AltosIMU        imu = state.imu;
125                         if (imu == null)
126                                 break;
127                         switch (index) {
128                         case data_accel_x:
129                                 y = imu.accel_x;
130                                 break;
131                         case data_accel_y:
132                                 y = imu.accel_y;
133                                 break;
134                         case data_accel_z:
135                                 y = imu.accel_z;
136                                 break;
137                         case data_gyro_x:
138                                 y = imu.gyro_x;
139                                 break;
140                         case data_gyro_y:
141                                 y = imu.gyro_y;
142                                 break;
143                         case data_gyro_z:
144                                 y = imu.gyro_z;
145                                 break;
146                         }
147                         break;
148                 case data_mag_x:
149                 case data_mag_y:
150                 case data_mag_z:
151                         AltosMag        mag = state.mag;
152                         if (mag == null)
153                                 break;
154                         switch (index) {
155                         case data_mag_x:
156                                 y = mag.x;
157                                 break;
158                         case data_mag_y:
159                                 y = mag.y;
160                                 break;
161                         case data_mag_z:
162                                 y = mag.z;
163                                 break;
164                         }
165                         break;
166                 case data_orient:
167                         y = state.orient();
168                         break;
169                 default:
170                         if (data_ignitor_0 <= index && index <= data_ignitor_max) {
171                                 int ignitor = index - data_ignitor_0;
172                                 if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length)
173                                         y = state.ignitor_voltage[ignitor];
174                         } else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) {
175                                 int ignitor = index - data_ignitor_fired_0;
176                                 if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) {
177                                         if ((state.pyro_fired & (1 << ignitor)) != 0)
178                                                 y = 1;
179                                         else
180                                                 y = 0;
181                                 }
182                         }
183                         break;
184                 }
185                 if (y == AltosLib.MISSING)
186                         throw new AltosUIDataMissing(index);
187                 return y;
188         }
189
190         public int id(int index) {
191                 if (index == data_state) {
192                         int s = state.state;
193                         if (s < Altos.ao_flight_boost || s > Altos.ao_flight_landed)
194                                 return -1;
195                         return s;
196                 } else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) {
197                         int ignitor = index - data_ignitor_fired_0;
198                         if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) {
199                                 if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) {
200                                         if ((state.pyro_fired & (1 << ignitor)) != 0)
201                                                 return 1;
202                                 }
203                         }
204                 }
205                 return 0;
206         }
207
208         public String id_name(int index) {
209                 if (index == data_state) {
210                         return state.state_name();
211                 } else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) {
212                         int ignitor = index - data_ignitor_fired_0;
213                         if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length)
214                                 return AltosIgnitor.ignitor_name(ignitor);
215                 }
216                 return "";
217         }
218
219         public AltosGraphDataPoint (AltosState state) {
220                 this.state = state;
221         }
222 }