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' */
23 ".--.", /* launchpad 'P' */
24 "-...", /* boost 'B' */
25 "-.-.", /* coast 'C' */
26 ".-", /* apogee 'A' */
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));
103 ao_report_state = ao_flight_state;
105 if (ao_flight_state == ao_flight_landed)
106 ao_report_altitude();
109 while (ao_report_state == ao_flight_state)
110 ao_sleep(DATA_TO_XDATA(&ao_flight_state));
111 ao_report_state = ao_flight_state;
116 static __xdata struct ao_task ao_report_task;
121 ao_add_task(&ao_report_task, ao_report, "report");