2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
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.
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.
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.
19 #include <ao_flight.h>
20 #include <ao_sample.h>
22 #define BIT(i,x) ((x) ? (1 << (i)) : 0)
23 #define MORSE1(a) (1 | BIT(3,a))
24 #define MORSE2(a,b) (2 | BIT(3,a) | BIT(4,b))
25 #define MORSE3(a,b,c) (3 | BIT(3,a) | BIT(4,b) | BIT(5,c))
26 #define MORSE4(a,b,c,d) (4 | BIT(3,a) | BIT(4,b) | BIT(5,c) | BIT(6,d))
27 #define MORSE5(a,b,c,d,e) (5 | BIT(3,a) | BIT(4,b) | BIT(5,c) | BIT(6,d) | BIT(7,e))
29 static const uint8_t flight_reports[] = {
30 MORSE3(0,0,0), /* startup, 'S' */
31 MORSE2(0,0), /* idle 'I' */
32 MORSE4(0,1,1,0), /* pad 'P' */
33 MORSE4(1,0,0,0), /* boost 'B' */
34 MORSE4(0,0,1,0), /* fast 'F' */
35 MORSE4(1,0,1,0), /* coast 'C' */
36 MORSE3(1,0,0), /* drogue 'D' */
37 MORSE2(1,1), /* main 'M' */
38 MORSE4(0,1,0,0), /* landed 'L' */
39 MORSE4(1,0,0,1), /* invalid 'X' */
43 #define low(time) ao_beep_for(AO_BEEP_LOW, time)
44 #define mid(time) ao_beep_for(AO_BEEP_MID, time)
45 #define high(time) ao_beep_for(AO_BEEP_HIGH, time)
47 #define low(time) ao_led_for(AO_LED_GREEN, time)
48 #define mid(time) ao_led_for(AO_LED_RED, time)
49 #define high(time) ao_led_for(AO_LED_GREEN|AO_LED_RED, time)
51 #define pause(time) ao_delay(time)
53 static __pdata enum ao_flight_state ao_report_state;
56 ao_report_beep(void) __reentrant
58 uint8_t r = flight_reports[ao_flight_state];
65 mid(AO_MS_TO_TICKS(600));
67 mid(AO_MS_TO_TICKS(200));
68 pause(AO_MS_TO_TICKS(200));
71 pause(AO_MS_TO_TICKS(400));
75 ao_report_digit(uint8_t digit) __reentrant
78 mid(AO_MS_TO_TICKS(500));
79 pause(AO_MS_TO_TICKS(200));
82 mid(AO_MS_TO_TICKS(200));
83 pause(AO_MS_TO_TICKS(200));
86 pause(AO_MS_TO_TICKS(300));
90 ao_report_number(int16_t n)
92 __xdata uint8_t digits[10];
93 __pdata uint8_t ndigits, i;
99 digits[ndigits++] = n % 10;
105 ao_report_digit(digits[--i]);
110 ao_report_altitude(void)
112 ao_report_number(ao_max_height);
115 #if HAS_BATTERY_REPORT
117 ao_report_battery(void)
119 __xdata struct ao_data packet;
121 ao_data_get(&packet);
122 if (packet.adc.v_batt != 0)
124 ao_sleep(DATA_TO_XDATA(&ao_sample_data));
126 ao_report_number(ao_battery_decivolt(packet.adc.v_batt));
130 #if HAS_IGNITE_REPORT
132 ao_report_igniter_ready(enum ao_igniter igniter)
134 return ao_igniter_status(igniter) == ao_igniter_ready ? 1 : 0;
138 ao_report_igniter(void)
140 return (ao_report_igniter_ready(ao_igniter_drogue) |
141 (ao_report_igniter_ready(ao_igniter_main) << 1));
145 ao_report_continuity(void) __reentrant
150 if (!ao_igniter_present)
153 c = ao_report_igniter();
156 high(AO_MS_TO_TICKS(25));
157 pause(AO_MS_TO_TICKS(100));
162 high(AO_MS_TO_TICKS(20));
163 low(AO_MS_TO_TICKS(20));
168 pause(AO_MS_TO_TICKS(100));
171 low(AO_MS_TO_TICKS(100));
172 mid(AO_MS_TO_TICKS(100));
173 high(AO_MS_TO_TICKS(100));
174 mid(AO_MS_TO_TICKS(100));
184 ao_report_state = ao_flight_state;
186 #if HAS_BATTERY_REPORT
187 if (ao_flight_state == ao_flight_startup)
192 if (ao_flight_state == ao_flight_landed) {
193 ao_report_altitude();
195 ao_delay(AO_SEC_TO_TICKS(5));
199 #if HAS_IGNITE_REPORT
200 if (ao_flight_state == ao_flight_idle)
201 ao_report_continuity();
202 while (ao_flight_state == ao_flight_pad) {
204 ao_report_continuity();
206 while (c-- && ao_flight_state == ao_flight_pad)
207 pause(AO_MS_TO_TICKS(100));
211 while (ao_report_state == ao_flight_state)
212 ao_sleep(DATA_TO_XDATA(&ao_flight_state));
213 ao_report_state = ao_flight_state;
217 static __xdata struct ao_task ao_report_task;
222 ao_add_task(&ao_report_task, ao_report, "report");