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.
20 static const char * __xdata flight_reports[] = {
21 "...", /* startup, 'S' */
24 "-...", /* boost 'B' */
25 "..-.", /* fast 'F' */
26 "-.-.", /* coast 'C' */
27 "-..", /* drogue 'D' */
29 ".-..", /* landed 'L' */
30 ".-.-.-", /* invalid */
34 #define signal(time) ao_beep_for(AO_BEEP_MID, time)
36 #define signal(time) ao_led_for(AO_LED_RED, time)
38 #define pause(time) ao_delay(time)
40 static __xdata enum ao_flight_state ao_report_state;
43 ao_report_beep(void) __reentrant
45 char *r = flight_reports[ao_flight_state];
52 signal(AO_MS_TO_TICKS(200));
54 signal(AO_MS_TO_TICKS(600));
55 pause(AO_MS_TO_TICKS(200));
57 pause(AO_MS_TO_TICKS(400));
61 ao_report_digit(uint8_t digit) __reentrant
64 signal(AO_MS_TO_TICKS(500));
65 pause(AO_MS_TO_TICKS(200));
68 signal(AO_MS_TO_TICKS(200));
69 pause(AO_MS_TO_TICKS(200));
72 pause(AO_MS_TO_TICKS(300));
76 ao_report_altitude(void)
78 __xdata int16_t agl = ao_pres_to_altitude(ao_min_pres) - ao_pres_to_altitude(ao_ground_pres);
79 __xdata uint8_t digits[10];
80 __xdata uint8_t ndigits, i;
86 digits[ndigits++] = agl % 10;
94 ao_report_digit(digits[--i]);
96 pause(AO_SEC_TO_TICKS(5));
101 ao_report_igniter_ready(enum ao_igniter igniter)
103 return ao_igniter_status(igniter) == ao_igniter_ready ? 1 : 0;
107 ao_report_continuity(void) __reentrant
109 uint8_t c = (ao_report_igniter_ready(ao_igniter_drogue) |
110 (ao_report_igniter_ready(ao_igniter_main) << 1));
113 ao_beep_for(AO_BEEP_HIGH, AO_MS_TO_TICKS(25));
114 pause(AO_MS_TO_TICKS(100));
119 ao_beep_for(AO_BEEP_HIGH, AO_MS_TO_TICKS(20));
120 ao_beep_for(AO_BEEP_LOW, AO_MS_TO_TICKS(20));
124 while (c-- && ao_flight_state == ao_flight_pad)
125 pause(AO_MS_TO_TICKS(100));
131 ao_report_state = ao_flight_state;
133 if (ao_flight_state == ao_flight_landed)
134 ao_report_altitude();
136 if (ao_flight_state == ao_flight_idle)
137 ao_report_continuity();
138 while (ao_flight_state == ao_flight_pad)
139 ao_report_continuity();
141 while (ao_report_state == ao_flight_state)
142 ao_sleep(DATA_TO_XDATA(&ao_flight_state));
143 ao_report_state = ao_flight_state;
148 static __xdata struct ao_task ao_report_task;
153 ao_add_task(&ao_report_task, ao_report, "report");