Clean up task list formatting
[fw/altos] / ao_report.c
1 /*
2  * Copyright © 2009 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; version 2 of the License.
7  *
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.
12  *
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.
16  */
17
18 #include "ao.h"
19
20 static const char * __xdata flight_reports[] = {
21         "...",          /* startup, 'S' */
22         "..",           /* idle 'I' */
23         ".--.",         /* launchpad 'P' */
24         "-...",         /* boost 'B' */
25         "-.-.",         /* coast 'C' */
26         ".-",           /* apogee 'A' */
27         "-..",          /* drogue 'D' */
28         "--",           /* main 'M' */
29         ".-..",         /* landed 'L' */
30         ".-.-.-",       /* invalid */
31 };
32
33 #if 1
34 #define signal(time)    ao_beep_for(AO_BEEP_MID, time)
35 #else
36 #define signal(time)    ao_led_for(AO_LED_RED, time)
37 #endif
38 #define pause(time)     ao_delay(time)
39
40 static __xdata enum ao_flight_state ao_report_state;
41
42 static void
43 ao_report_beep(void)
44 {
45         char *r = flight_reports[ao_report_state];
46         char c;
47
48         if (!r)
49                 return;
50         while (c = *r++) {
51                 if (c == '.')
52                         signal(AO_MS_TO_TICKS(200));
53                 else
54                         signal(AO_MS_TO_TICKS(600));
55                 pause(AO_MS_TO_TICKS(200));
56         }
57         pause(AO_MS_TO_TICKS(400));
58 }
59
60 void
61 ao_report(void)
62 {
63         ao_report_state = ao_flight_state;
64         for(;;) {
65                 ao_report_beep();
66                 __critical {
67                         while (ao_report_state == ao_flight_state)
68                                 ao_sleep(DATA_TO_XDATA(&ao_flight_state));
69                         ao_report_state = ao_flight_state;
70                 }
71         }
72 }
73
74 static __xdata struct ao_task ao_report_task;
75
76 void
77 ao_report_init(void)
78 {
79         ao_add_task(&ao_report_task, ao_report, "report");
80 }