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_altitude(void)
92 __pdata int16_t agl = ao_max_height;
93 __xdata uint8_t digits[10];
94 __pdata uint8_t ndigits, i;
100 digits[ndigits++] = agl % 10;
106 ao_report_digit(digits[--i]);
110 #if HAS_IGNITE_REPORT
112 ao_report_igniter_ready(enum ao_igniter igniter)
114 return ao_igniter_status(igniter) == ao_igniter_ready ? 1 : 0;
118 ao_report_igniter(void)
120 return (ao_report_igniter_ready(ao_igniter_drogue) |
121 (ao_report_igniter_ready(ao_igniter_main) << 1));
125 ao_report_continuity(void) __reentrant
130 if (!ao_igniter_present)
133 c = ao_report_igniter();
136 high(AO_MS_TO_TICKS(25));
137 pause(AO_MS_TO_TICKS(100));
142 high(AO_MS_TO_TICKS(20));
143 low(AO_MS_TO_TICKS(20));
148 pause(AO_MS_TO_TICKS(100));
151 low(AO_MS_TO_TICKS(100));
152 mid(AO_MS_TO_TICKS(100));
153 high(AO_MS_TO_TICKS(100));
154 mid(AO_MS_TO_TICKS(100));
164 ao_report_state = ao_flight_state;
167 if (ao_flight_state == ao_flight_landed) {
168 ao_report_altitude();
170 ao_delay(AO_SEC_TO_TICKS(5));
174 #if HAS_IGNITE_REPORT
175 if (ao_flight_state == ao_flight_idle)
176 ao_report_continuity();
177 while (ao_flight_state == ao_flight_pad) {
179 ao_report_continuity();
181 while (c-- && ao_flight_state == ao_flight_pad)
182 pause(AO_MS_TO_TICKS(100));
186 while (ao_report_state == ao_flight_state)
187 ao_sleep(DATA_TO_XDATA(&ao_flight_state));
188 ao_report_state = ao_flight_state;
192 static __xdata struct ao_task ao_report_task;
197 ao_add_task(&ao_report_task, ao_report, "report");