Make stm-demo display a scrolling message
[fw/altos] / src / stm-demo / ao_demo.c
1 /*
2  * Copyright © 2011 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 struct ao_task demo_task;
21
22 static inline int min(int a, int b) { return a < b ? a : b; }
23
24 void
25 ao_demo(void)
26 {
27         char    message[] = "Hello, Mike & Bdale --- ";
28         char    part[7];
29         int     i = 0;
30         int     len = sizeof(message) - 1;
31         int     first, second;
32
33         part[6] = '\0';
34         for (;;) {
35                 ao_delay(AO_MS_TO_TICKS(150));
36                 first = min(6, len - i);
37                 second = 6 - first;
38                 memcpy(part, message + i, first);
39                 memcpy(part + first, message, second);
40                 ao_lcd_font_string(part);
41                 if (++i >= len)
42                         i = 0;
43         }
44 }
45
46 void _close() { }
47 void _sbrk() { }
48 void _isatty() { }
49 void _lseek() { }
50 void _exit () { }
51 void _read () { }
52 void _fstat() { }
53 int
54 main(void)
55 {
56         ao_clock_init();
57         
58         ao_serial_init();
59         ao_timer_init();
60         ao_cmd_init();
61         ao_lcd_stm_init();
62         ao_lcd_font_init();
63         ao_add_task(&demo_task, ao_demo, "demo");
64         
65         ao_start_scheduler();
66         return 0;
67 }