ff5e4c3d6fe520000cd30162bb2e0be3fc3c2a7c
[fw/altos] / altoslib / AltosFlightListener.java
1 /*
2  * Copyright © 2017 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
15 package org.altusmetrum.altoslib_11;
16
17 public abstract class AltosFlightListener {
18
19         int flight;
20
21         public int tick;
22         int boost_tick;
23
24         AltosGPS temp_gps;
25         int temp_gps_sat_tick;
26
27         /* AltosEepromRecord */
28         public void set_boost_tick(int boost_tick) {
29                 if (boost_tick != AltosLib.MISSING)
30                         this.boost_tick = boost_tick;
31         }
32
33         public void set_tick(int tick) {
34                 if (tick != AltosLib.MISSING)
35                         this.tick = tick;
36         }
37
38         public double time() {
39                 if (tick == AltosLib.MISSING)
40                         return AltosLib.MISSING;
41                 return tick / 100.0;
42         }
43
44         public double boost_time() {
45                 if (boost_tick == AltosLib.MISSING)
46                         return AltosLib.MISSING;
47                 return boost_tick / 100.0;
48         }
49
50         /* AltosEepromRecordFull */
51
52         public abstract void set_state(int state);
53         public abstract void set_ground_accel(double ground_accel);
54         public void set_flight(int flight) {
55                 if (flight != AltosLib.MISSING)
56                         this.flight = flight;
57         }
58         public int flight() {
59                 return flight;
60         }
61
62         public abstract void set_accel(double accel);
63         public abstract void set_accel_g(double accel_plus_g, double accel_minus_g);
64         public abstract void set_pressure(double pa);
65
66         public abstract void set_temperature(double deg_c);
67         public abstract void set_battery_voltage(double volts);
68
69         public abstract void set_apogee_voltage(double volts);
70         public abstract void set_main_voltage(double volts);
71
72         public void set_temp_gps() {
73                 temp_gps = null;
74         }
75
76         public boolean gps_pending() {
77                 return temp_gps != null;
78         }
79
80         public AltosGPS make_temp_gps(boolean sats) {
81                 if (temp_gps == null) {
82                         temp_gps = new AltosGPS();
83                 }
84                 if (sats) {
85                         if (tick != temp_gps_sat_tick)
86                                 temp_gps.cc_gps_sat = null;
87                         temp_gps_sat_tick = tick;
88                 }
89                 return temp_gps;
90         }
91
92         public abstract void set_ground_pressure(double ground_pressure);
93         public abstract void set_accel_ground(double along, double across, double through);
94         public abstract void set_gyro_zero(double roll, double pitch, double yaw);
95         public abstract void set_ms5607(int pres_val, int temp_val);
96         public abstract void check_imu_wrap(AltosIMU imu);
97         public abstract void set_imu(AltosIMU imu);
98         public abstract void set_mag(AltosMag mag);
99         public abstract void set_pyro_voltage(double volts);
100         public abstract void set_ignitor_voltage(double[] voltage);
101         public abstract void set_pyro_fired(int pyro_mask);
102
103         public void copy(AltosFlightListener old) {
104                 flight = old.flight;
105                 tick = old.tick;
106                 boost_tick = old.boost_tick;
107                 temp_gps = old.temp_gps;
108                 temp_gps_sat_tick = old.temp_gps_sat_tick;
109         }
110
111         public void init() {
112                 flight = AltosLib.MISSING;
113                 tick = AltosLib.MISSING;
114                 boost_tick = AltosLib.MISSING;
115                 temp_gps_sat_tick = AltosLib.MISSING;
116         }
117 }