109af1ed05050f31f2af72bdc3d590587c1f7a1b
[fw/altos] / src / micropeak / ao_report_tiny.c
1 /*
2  * Copyright © 2012 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 #define mid(time)       ao_led_for(AO_LED_REPORT, time)
21 #define pause(time)     ao_delay(time)
22
23 static void
24 ao_report_digit(uint8_t digit) __reentrant
25 {
26         if (!digit) {
27                 mid(AO_MS_TO_TICKS(600));
28                 pause(AO_MS_TO_TICKS(300));
29         } else {
30                 while (digit--) {
31                         mid(AO_MS_TO_TICKS(300));
32                         pause(AO_MS_TO_TICKS(300));
33                 }
34         }
35         pause(AO_MS_TO_TICKS(600));
36 }
37
38 void
39 ao_report_altitude(void)
40 {
41         __pdata int16_t agl = ao_max_height;
42         __xdata uint8_t digits[10];
43         __pdata uint8_t ndigits, i;
44
45         if (agl < 0)
46                 agl = 0;
47         ndigits = 0;
48         do {
49                 digits[ndigits++] = agl % 10;
50                 agl /= 10;
51         } while (agl);
52
53         i = ndigits;
54         do
55                 ao_report_digit(digits[--i]);
56         while (i != 0);
57 }