new toolchain for STM32L is in /usr/bin, not /opt/cortex/bin
[fw/altos] / src / micropeak / ao_micropeak.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 #include <ao_micropeak.h>
20 #include <ao_ms5607.h>
21 #include <ao_log_micro.h>
22 #include <ao_async.h>
23
24 static struct ao_ms5607_sample  sample;
25 static struct ao_ms5607_value   value;
26
27 alt_t           ground_alt, max_alt;
28 alt_t           ao_max_height;
29
30 void
31 ao_pa_get(void)
32 {
33         ao_ms5607_sample(&sample);
34         ao_ms5607_convert(&sample, &value);
35         pa = value.pres;
36 }
37
38 static void
39 ao_compute_height(void)
40 {
41         ground_alt = ao_pa_to_altitude(pa_ground);
42         max_alt = ao_pa_to_altitude(pa_min);
43         ao_max_height = max_alt - ground_alt;
44 }
45
46 static void
47 ao_pips(void)
48 {
49         uint8_t i;
50         for (i = 0; i < 10; i++) {
51                 ao_led_toggle(AO_LED_REPORT);
52                 ao_delay(AO_MS_TO_TICKS(80));
53         }
54         ao_delay(AO_MS_TO_TICKS(200));
55 }
56
57 int
58 main(void)
59 {
60         ao_led_init(LEDS_AVAILABLE);
61         ao_timer_init();
62
63         /* Init external hardware */
64         ao_spi_init();
65         ao_ms5607_init();
66         ao_ms5607_setup();
67
68         /* Give the person a second to get their finger out of the way */
69         ao_delay(AO_MS_TO_TICKS(1000));
70
71         ao_log_micro_restore();
72         ao_compute_height();
73         ao_report_altitude();
74         ao_pips();
75         ao_log_micro_dump();
76         
77         ao_delay(BOOST_DELAY);
78
79         ao_microflight();
80
81         ao_log_micro_save();
82         ao_compute_height();
83         ao_report_altitude();
84         for (;;) {
85                 cli();
86                 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
87                 sleep_mode();
88         }
89 }