altos/lpc: Add bits for building flash loaders
[fw/altos] / altoslib / AltosRecordMini.java
1 /*
2  * Copyright © 2012 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 org.altusmetrum.altoslib_1;
19
20 public class AltosRecordMini extends AltosRecord {
21
22         /* Sensor values */
23         public int      pres;
24         public int      temp;
25         
26         public int      sense_a;
27         public int      sense_m;
28         public int      v_batt;
29
30         public int      ground_pres;
31
32         public int      flight_accel;
33         public int      flight_vel;
34         public int      flight_pres;
35
36         static double adc(int raw) {
37                 return raw / 4095.0;
38         }
39
40         public double pressure() {
41                 if (pres != MISSING)
42                         return pres;
43                 return MISSING;
44         }
45
46         public double temperature() {
47                 if (temp != MISSING)
48                         return temp;
49                 return MISSING;
50         }
51
52         public double ground_pressure() {
53                 if (ground_pres != MISSING)
54                         return ground_pres;
55                 return MISSING;
56         }
57
58         public double battery_voltage() {
59                 if (v_batt != MISSING)
60                         return 3.3 * adc(v_batt) * (15.0 + 27.0) / 27.0;
61                 return MISSING;
62         }
63
64         static double pyro(int raw) {
65                 if (raw != MISSING)
66                         return 3.3 * adc(raw) * (100.0 + 27.0) / 27.0;
67                 return MISSING;
68         }
69
70         public double main_voltage() {
71                 return pyro(sense_m);
72         }
73
74         public double apogee_voltage() {
75                 return pyro(sense_a);
76         }
77
78         public void copy (AltosRecordMini old) {
79                 super.copy(old);
80
81                 pres = old.pres;
82                 temp = old.temp;
83
84                 sense_a = old.sense_a;
85                 sense_m = old.sense_m;
86                 v_batt = old.v_batt;
87
88                 ground_pres = old.ground_pres;
89                 
90                 flight_accel = old.flight_accel;
91                 flight_vel = old.flight_vel;
92                 flight_pres = old.flight_pres;
93         }
94
95
96
97         public AltosRecordMini clone() {
98                 return new AltosRecordMini(this);
99         }
100
101         void make_missing() {
102
103                 pres = MISSING;
104
105                 sense_a = MISSING;
106                 sense_m = MISSING;
107                 v_batt = MISSING;
108
109                 ground_pres = MISSING;
110
111                 flight_accel = 0;
112                 flight_vel = 0;
113                 flight_pres = 0;
114         }
115
116         public AltosRecordMini(AltosRecord old) {
117                 super.copy(old);
118                 make_missing();
119         }
120
121         public AltosRecordMini(AltosRecordMini old) {
122                 copy(old);
123         }
124
125         public AltosRecordMini() {
126                 super();
127                 make_missing();
128         }
129 }