ihm/menu: fix compilation of test with hostsim
[aversive.git] / modules / ihm / menu / test / main.c
1 /*  
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
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,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  *  Revision : $Id: main.c,v 1.3.4.2 2007-05-23 17:18:15 zer0 Exp $
19  *
20  */
21
22 /* Olivier MATZ, Droids-corp 2004 - 2006
23  * Test program for a menu
24  */
25
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 #include <aversive/wait.h>
30 #include <uart.h>
31 #include <menu.h>
32
33 #ifdef HOST_VERSION
34 #include <hostsim.h>
35 #endif
36
37 int myparam=0;
38
39 void f(void * data)
40 {
41         printf("POUET\n");
42 }
43
44 struct menu my_menu[] = {
45     MENU_ROOT("racine"),
46       MENU_FCT("a", f, &myparam),
47       MENU_START("sub1"),
48         MENU_FCT("b", f, &myparam),
49         MENU_FCT("c", f, &myparam),
50         MENU_FCT("d", f, &myparam),
51       MENU_END(),
52       MENU_START("sub2"),
53         MENU_FCT("e", f, &myparam),
54       MENU_END(),
55       MENU_FCT("f", f, &myparam),
56     MENU_END(),
57 };
58
59
60
61 int main(void)
62 {
63     struct menu *m = my_menu;
64     char c;
65
66 #ifndef HOST_VERSION
67     uart_init();  
68     fdevopen(uart0_dev_send, uart0_dev_recv);
69     sei();
70 #endif
71
72     /* tests */
73     printf("Root is %s\n", menu_get_name(m));
74     m = menu_down(m);
75     printf("1st son of root is %s\n", menu_get_name(m));
76     m = menu_right(m);
77     printf("The submenu is %s\n", menu_get_name(m));
78
79     
80     m = menu_get_first_son(m);
81     printf("1st son is %s\n", menu_get_name(m));
82     m = menu_right(m);
83     printf("2nd son is %s\n", menu_get_name(m));
84     m = menu_right(m);
85     printf("3rd son is %s\n", menu_get_name(m));
86     m = menu_right(m);
87     printf("return to 1st son : %s\n", menu_get_name(m));
88
89     m = menu_left(m);
90     printf("3rd son is %s\n", menu_get_name(m));
91     m = menu_left(m);
92     printf("2nd son is %s\n", menu_get_name(m));
93     m = menu_left(m);
94     printf("1st son is %s\n", menu_get_name(m));
95     m = menu_left(m);
96     
97     
98     wait_ms(1000);
99
100     //    exit(0);
101
102
103     m = my_menu;
104     while (1) {
105         menu_default_display(m);
106 #ifdef HOST_VERSION        
107         scanf("%c",&c);
108 #else
109         c=uart_recv(0);
110 #endif
111         m=menu_default_update(m, c);
112     }
113
114     return 0;
115 }