]> git.gag.com Git - fw/altos/blob - altoslib/AltosEepromRecordTiny.java
doc: add documentation on how to re-flash a TeleMini v3 over USB
[fw/altos] / altoslib / AltosEepromRecordTiny.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_14;
16
17 public class AltosEepromRecordTiny extends AltosEepromRecord implements AltosDataProvider {
18         public static final int record_length = 2;
19
20         private int value() {
21                 return eeprom.data16(start);
22         }
23
24         public boolean valid(int s) {
25                 return eeprom.data16(s) != 0xffff;
26         }
27
28         public int cmd() {
29                 if (start == 0)
30                         return AltosLib.AO_LOG_FLIGHT;
31                 if ((value() & 0x8000) != 0)
32                         return AltosLib.AO_LOG_STATE;
33                 return AltosLib.AO_LOG_SENSOR;
34         }
35
36         public int tick() {
37                 int     tick = 0;
38                 int     step = 10;
39                 for (int i = 2; i < start; i += 2)
40                 {
41                         int v = eeprom.data16(i);
42
43                         if ((v & 0x8000) != 0) {
44                                 if ((v & 0x7fff) >= AltosLib.ao_flight_drogue)
45                                         step = 100;
46                         } else {
47                                 tick += step;
48                         }
49                 }
50                 return tick;
51         }
52
53         public void provide_data(AltosDataListener listener) {
54                 int value = data16(-header_length);
55
56                 listener.set_tick(tick());
57                 switch (cmd()) {
58                 case AltosLib.AO_LOG_FLIGHT:
59                         listener.set_state(AltosLib.ao_flight_pad);
60                         listener.cal_data().set_flight(value);
61                         listener.cal_data().set_boost_tick();
62                         break;
63                 case AltosLib.AO_LOG_STATE:
64                         listener.set_state(value & 0x7fff);
65                         break;
66                 case AltosLib.AO_LOG_SENSOR:
67                         listener.set_pressure(AltosConvert.barometer_to_pressure(value));
68                         break;
69                 }
70         }
71
72         public AltosEepromRecord next() {
73                 int     s = next_start();
74                 if (s < 0)
75                         return null;
76                 return new AltosEepromRecordTiny(eeprom, s);
77         }
78
79         public AltosEepromRecordTiny(AltosEeprom eeprom, int start) {
80                 super(eeprom, start, record_length);
81         }
82
83         public AltosEepromRecordTiny(AltosEeprom eeprom) {
84                 this(eeprom, 0);
85         }
86 }