ini
[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 int myparam=0;
34
35 void f(void * data)
36 {
37         printf("POUET\n");
38 }
39
40 struct menu my_menu[] = {
41     MENU_ROOT("racine"),
42       MENU_FCT("a", f, &myparam),
43       MENU_START("sub1"),
44         MENU_FCT("b", f, &myparam),
45         MENU_FCT("c", f, &myparam),
46         MENU_FCT("d", f, &myparam),
47       MENU_END(),
48       MENU_START("sub2"),
49         MENU_FCT("e", f, &myparam),
50       MENU_END(),
51       MENU_FCT("f", f, &myparam),
52     MENU_END(),
53 };
54
55
56
57 int main(void)
58 {
59     struct menu *m = my_menu;
60     char c;
61
62 #ifndef HOST_VERSION
63     uart_init();  
64     fdevopen(uart0_dev_send, uart0_dev_recv);
65     sei();
66 #endif
67
68     /* tests */
69     printf("Root is %s\n", menu_get_name(m));
70     m = menu_down(m);
71     printf("1st son of root is %s\n", menu_get_name(m));
72     m = menu_right(m);
73     printf("The submenu is %s\n", menu_get_name(m));
74
75     
76     m = menu_get_first_son(m);
77     printf("1st son is %s\n", menu_get_name(m));
78     m = menu_right(m);
79     printf("2nd son is %s\n", menu_get_name(m));
80     m = menu_right(m);
81     printf("3rd son is %s\n", menu_get_name(m));
82     m = menu_right(m);
83     printf("return to 1st son : %s\n", menu_get_name(m));
84
85     m = menu_left(m);
86     printf("3rd son is %s\n", menu_get_name(m));
87     m = menu_left(m);
88     printf("2nd son is %s\n", menu_get_name(m));
89     m = menu_left(m);
90     printf("1st son is %s\n", menu_get_name(m));
91     m = menu_left(m);
92     
93     
94     wait_ms(1000);
95
96     //    exit(0);
97
98
99     m = my_menu;
100     while (1) {
101         menu_default_display(m);
102 #ifdef HOST_VERSION        
103         scanf("%c",&c);
104 #else
105         c=uart0_recv();
106 #endif
107         m=menu_default_update(m, c);
108     }
109
110     return 0;
111 }