Use ao_ee_flush_internal while holding mutex
[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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #include "ao.h"
20
21 static const char * __xdata flight_reports[] = {
22         "...",          /* startup, 'S' */
23         "..",           /* idle 'I' */
24         ".--.",         /* launchpad 'P' */
25         "-...",         /* boost 'B' */
26         "-.-.",         /* coast 'C' */
27         ".-",           /* apogee 'A' */
28         "-..",          /* drogue 'D' */
29         "--",           /* main 'M' */
30         ".-..",         /* landed 'L' */
31         ".-.-.-",       /* invalid */
32 };
33
34 #if 1
35 #define signal(time)    ao_beep_for(AO_BEEP_MID, time)
36 #else
37 #define signal(time)    ao_led_for(AO_LED_RED, time)
38 #endif
39 #define pause(time)     ao_delay(time)
40
41 static void
42 ao_report_state(void)
43 {
44         char *r = flight_reports[ao_flight_state];
45         char c;
46
47         if (!r)
48                 return;
49         while (c = *r++) {
50                 if (c == '.')
51                         signal(AO_MS_TO_TICKS(200));
52                 else
53                         signal(AO_MS_TO_TICKS(600));
54                 pause(AO_MS_TO_TICKS(200));
55         }
56 }
57
58 static __xdata ao_report_wait;
59
60 void
61 ao_report_notify(void)
62 {
63         ao_wakeup(&ao_report_wait);
64 }
65
66 void
67 ao_report(void)
68 {
69         for(;;) {
70                 ao_report_state();
71                 ao_sleep(&ao_report_wait);
72         }
73 }
74
75 static __xdata struct ao_task ao_report_task;
76
77 void
78 ao_report_init(void)
79 {
80         ao_add_task(&ao_report_task, ao_report);
81 }