]> git.gag.com Git - fw/altos/blob - altoslib/AltosSensorMetrum.java
builds, loads, runs, not very useful yet
[fw/altos] / altoslib / AltosSensorMetrum.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; 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.altoslib_11;
20
21 import java.util.concurrent.TimeoutException;
22
23 class AltosSensorMetrum {
24         int             tick;
25         int             sense_a;
26         int             sense_m;
27         int             v_batt;
28
29         public AltosSensorMetrum(AltosLink link) throws InterruptedException, TimeoutException {
30                 String[] items = link.adc();
31                 for (int i = 0; i < items.length;) {
32                         if (items[i].equals("tick:")) {
33                                 tick = Integer.parseInt(items[i+1]);
34                                 i += 2;
35                                 continue;
36                         }
37                         if (items[i].equals("drogue:")) {
38                                 sense_a = Integer.parseInt(items[i+1]);
39                                 i += 2;
40                                 continue;
41                         }
42                         if (items[i].equals("main:")) {
43                                 sense_m = Integer.parseInt(items[i+1]);
44                                 i += 2;
45                                 continue;
46                         }
47                         if (items[i].equals("batt:")) {
48                                 v_batt = Integer.parseInt(items[i+1]);
49                                 i += 2;
50                                 continue;
51                         }
52                         i++;
53                 }
54         }
55
56         static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException {
57                 try {
58                         AltosSensorMetrum       sensor_metrum = new AltosSensorMetrum(link);
59                         state.set_battery_voltage(AltosConvert.mega_battery_voltage(sensor_metrum.v_batt));
60                         state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sensor_metrum.sense_a));
61                         state.set_main_voltage(AltosConvert.mega_pyro_voltage(sensor_metrum.sense_m));
62                 } catch (TimeoutException te) {
63                 }
64         }
65 }
66