altoslib,altosuilib: Bump library version numbers
[fw/altos] / altoslib / AltosSensorEMini.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; 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_12;
20
21 import java.util.concurrent.TimeoutException;
22
23 public class AltosSensorEMini {
24         public int      tick;
25         public int      apogee;
26         public int      main;
27         public int      batt;
28
29         static public void provide_data(AltosDataListener listener, AltosLink link, AltosCalData cal_data, int version) throws InterruptedException {
30                 try {
31                         AltosSensorEMini        sensor_emini = new AltosSensorEMini(link);
32
33                         if (sensor_emini == null)
34                                 return;
35                         switch (version) {
36                         case 1:
37                                 listener.set_battery_voltage(AltosConvert.easy_mini_1_voltage(sensor_emini.batt, cal_data.serial));
38                                 listener.set_apogee_voltage(AltosConvert.easy_mini_1_voltage(sensor_emini.apogee, cal_data.serial));
39                                 listener.set_main_voltage(AltosConvert.easy_mini_1_voltage(sensor_emini.main, cal_data.serial));
40                                 break;
41                         case 2:
42                                 listener.set_battery_voltage(AltosConvert.easy_mini_2_voltage(sensor_emini.batt));
43                                 listener.set_apogee_voltage(AltosConvert.easy_mini_2_voltage(sensor_emini.apogee));
44                                 listener.set_main_voltage(AltosConvert.easy_mini_2_voltage(sensor_emini.main));
45                                 break;
46                         }
47
48                 } catch (TimeoutException te) {
49                 }
50         }
51
52         public AltosSensorEMini(AltosLink link) throws InterruptedException, TimeoutException {
53                 String[] items = link.adc();
54                 for (int i = 0; i < items.length;) {
55                         if (items[i].equals("tick:")) {
56                                 tick = Integer.parseInt(items[i+1]);
57                                 i += 2;
58                                 continue;
59                         }
60                         if (items[i].equals("apogee:")) {
61                                 apogee = Integer.parseInt(items[i+1]);
62                                 i += 2;
63                                 continue;
64                         }
65                         if (items[i].equals("main:")) {
66                                 main = Integer.parseInt(items[i+1]);
67                                 i += 2;
68                                 continue;
69                         }
70                         if (items[i].equals("batt:")) {
71                                 batt = Integer.parseInt(items[i+1]);
72                                 i += 2;
73                                 continue;
74                         }
75                         i++;
76                 }
77         }
78 }
79