strat db + avoid
[aversive.git] / projects / kbd_uart_test / main.c
1 #include <stdio.h>\r
2 #include <string.h>\r
3 \r
4 #include <base/fifo/fifo.h>\r
5 #include <comm/uart/uart.h>\r
6 #include <other/kbd/kbd.h>\r
7 #include <base/wait/wait.h>\r
8 #include <time/scheduler/scheduler.h>\r
9 #include <time/hour/hour.h>\r
10 //#include <other/menu/menu.h>\r
11 #include <other/lcd/lcd.h>\r
12 \r
13 uint8_t global=16;\r
14 FILE * lcd;\r
15 \r
16 \r
17 \r
18 void process(uint8_t c)\r
19 {\r
20   char tab[16];\r
21   uint16_t nb;\r
22   int add;\r
23 \r
24   tab[0] = 0;\r
25 \r
26   uart0_send(c);\r
27 \r
28   if(c=='\r')\r
29     {\r
30       nb=scanf("%s %d",tab,&add);\r
31 \r
32       if( !strcmp(tab,"set"))\r
33         {\r
34           time_set(add,0);\r
35           printf("\r\n>> time set to %d\r\n",add);\r
36         }\r
37       else if (!strcmp(tab,"get"))\r
38         printf("\r\n>> %d secondes\r\n",time_get_s());\r
39       else if (!strcmp(tab,"show"))\r
40         printf("\r\n>> Value at 0x%X : %d\r\n",add,*(uint8_t *)add); \r
41       else\r
42         printf("\r\n>> command not found\r\n");\r
43     }\r
44 }\r
45 \r
46 \r
47 \r
48 \r
49 /* void menu_print(void) */\r
50 /* { */\r
51 /*   int8_t tmp=menu_current(); */\r
52 \r
53 /*   menu_init_brother_list(); */\r
54 \r
55 /*   lcd_clrscr(); */\r
56 /*   while(tmp != 0) */\r
57 /*     { */\r
58 /*       fprintf(lcd,"|"); */\r
59 /*       tmp=menu_up(tmp); */\r
60 /*     } */\r
61 /*   fprintf(lcd,"%s%s",(menu_is_leaf(menu_current())?"* ":"> "),menu_txt(menu_current())); */\r
62 \r
63 /* } */\r
64 \r
65 \r
66 \r
67 /* void menu_control(uint8_t c) */\r
68 /* { */\r
69 /*   if(c == '0') */\r
70 /*     menu_set(menu_left(menu_current())); */\r
71 /*   else if(c=='8') */\r
72 /*     menu_set(menu_right(menu_current())); */\r
73 /*   else if(c=='*') */\r
74 /*     { */\r
75 /*       if(menu_action_is_allowed()) */\r
76 /*      menu_action_disallow(); */\r
77 /*       else */\r
78 /*      menu_set(menu_up(menu_current()));       */\r
79 /*     } */\r
80 /*   else if(c=='#') */\r
81 /*     { */\r
82 /*       if(menu_is_leaf(menu_current())) */\r
83 /*      menu_action_allow(); */\r
84 /*       else */\r
85 /*      menu_set(menu_down(menu_current())); */\r
86 /*     } */\r
87 \r
88 /*   menu_print(); */\r
89 /* } */\r
90 \r
91 FIFO_DECLARE_TYPE(g_read_fifo, uint8_t, 16);\r
92 FIFO_DEFINE(g_read_fifo);\r
93 FIFO_DEFINE_FUNCTIONS(uint8_t);\r
94 \r
95 int kbd_get_next(void)\r
96 {\r
97   uint8_t c;\r
98   \r
99   if(FIFO_IS_FULL(g_read_fifo))\r
100     return -1;\r
101 \r
102   FIFO_DEL_ELT(&c, g_read_fifo);  \r
103 \r
104   return c;\r
105 }\r
106 \r
107 \r
108 /* void menu_add_char(uint8_t c) */\r
109 /* { */\r
110 /*   int val; */\r
111 \r
112 /*   // exit */\r
113 /*   if(c=='*') */\r
114 /*     { */\r
115 /*       FIFO_ADD_ELT(' ', g_read_fifo, uint8_t); */\r
116 /*       menu_action_disallow(); */\r
117 /*       kbd_register_event(menu_control); */\r
118 /*       fscanf(lcd,"%d",&val); */\r
119 /*       time_set(val,0); */\r
120 /*       printf("\r\nLCD: time set to %d\r\n",val); */\r
121 /*       menu_print(); */\r
122 /*       return; */\r
123 /*     } */\r
124 \r
125 /*   lcd_putc(c); */\r
126 /*   FIFO_ADD_ELT(c, g_read_fifo, uint8_t); */\r
127 /* } */\r
128 \r
129 \r
130 \r
131 \r
132 // PE1 PE3 PB3 PB4\r
133 void leds(void)\r
134 {\r
135   static uint8_t a=0;\r
136 \r
137   PORTB=a++;\r
138 }\r
139 \r
140 int main(void)\r
141 {\r
142   /* LEDS */\r
143   DDRB=0x18;\r
144 \r
145   uart_init();  \r
146   //  kbd_init();\r
147   scheduler_init();\r
148   //  lcd_init(LCD_DISP_ON);\r
149   //  menu_init();\r
150 \r
151   FIFO_INIT(g_read_fifo, uint8_t, 16);\r
152 \r
153   //  scheduler_add_periodical_event(leds, 20000l/SCHEDULER_UNIT);\r
154   /* ajoute la scrutation du clavier */\r
155   //  scheduler_add_periodical_event(kbd_manage, 100);\r
156   \r
157   /* envoie les caracteres du clavier vers le LCD */\r
158   //  kbd_register_event(menu_control);\r
159 \r
160   /* appele la fonction process a chaque reception de caractere */\r
161   //  uart0_register_rx_event(process);\r
162 \r
163   /* creation du device uart */\r
164   fdevopen(uart0_dev_send,uart0_dev_recv);\r
165 \r
166   /* creation du device lcd */\r
167   //  lcd=fdevopen(lcd_dev_putc,kbd_dev_get_next);\r
168 \r
169   sei();\r
170 \r
171   time_init();\r
172   //  menu_print();\r
173   time_set(10,0);\r
174 /*   printf_P(PSTR("\r\nWelcome to this demo\r\n")); */\r
175 /*   printf_P(PSTR("\r\n")); */\r
176 /*   printf_P(PSTR("                                                          \r\n")); */\r
177 /*   printf_P(PSTR("                      .__,.      ___.                     \r\n")); */\r
178 /*   printf_P(PSTR("                   _%i~`            -'i;_                 \r\n")); */\r
179 /*   printf_P(PSTR("                 _=Xr~                '{a__               \r\n")); */\r
180 /*   printf_P(PSTR("               <ln2                    :|2S=;             \r\n")); */\r
181 /*   printf_P(PSTR("              _xnxn                    :=oox>.            \r\n")); */\r
182 /*   printf_P(PSTR("             .nnvno      ..______..    :=oonss            \r\n")); */\r
183 /*   printf_P(PSTR("             .onvnn_. __s>ss%xixaii_,_ =Invv1n            \r\n")); */\r
184 /*   printf_P(PSTR("             :vnnnnns_+''^~-` ---^^'(;sxvnnnn1            \r\n")); */\r
185 /*   printf_P(PSTR("           .__onvnvnxn_,.          __svvvnnnnv_,          \r\n")); */\r
186 /*   printf_P(PSTR("       _i%vnn2nvnnvnvn2n2nss;.;<aIvo2nxxnnvnx1nnnas_.     \r\n")); */\r
187 /*   printf_P(PSTR("      i)nnvnnnnxnvnnnnvnnnn1(-=]SIvnnvnnvnnnnnnnnnnx>_    \r\n")); */\r
188 /*   printf_P(PSTR("    =innonn|=;::+<innnvvvvv    .:o2vvo2oo===;==)vnvvn2:.  \r\n")); */\r
189 /*   printf_P(PSTR("   _Jn!^~`    <xs;. -^11oc+      **v}!-` i<a;.   --'{lu(  \r\n")); */\r
190 /*   printf_P(PSTR("   Xc|        Ixoc|       .:   .:        vvn(.        nc| \r\n")); */\r
191 /*   printf_P(PSTR(" ..v;         ~)n1x     .)n21vvnoIl    ._XuI'         ~<i \r\n")); */\r
192 /*   printf_P(PSTR("  .i;          =ix2v;    =innnnnn=+   :)onv.           =i \r\n")); */\r
193 /*   printf_P(PSTR("   i;            -'o1v_,.=vnvnvxo+| =snxI~~            -+ \r\n")); */\r
194 /*   printf_P(PSTR("   +:              -)ol=;)nnvvnnvvv:)n+;              .   \r\n")); */\r
195 /*   printf_P(PSTR("                      .<xxnvnvv1nnn<,                .    \r\n")); */\r
196 /*   printf_P(PSTR("      ===.          :iooonnnnno2ovvn1l             |;     \r\n")); */\r
197 /*   printf_P(PSTR("        --'=<__s_asxuonx1}|^`---'**nnnnnaii_s__/+^^       \r\n")); */\r
198 /*   printf_P(PSTR("              ==+==;=;               .=;;::=..           \r\n")); */\r
199 /*   printf_P(PSTR("\r\n")); */\r
200 /*   printf_P(PSTR("                                      Microb Technology\r\n")); */\r
201 /*   printf_P(PSTR("\r\n")); */\r
202 //  printf("\r\n>> Time set to %d seconds\r\n",time_get_s());\r
203   \r
204   while(1)\r
205     {\r
206       \r
207 /*       wait_ms(1); */\r
208 /*       uart0_send(0x00); */\r
209 /*       wait_ms(1); */\r
210 /*       uart0_send(0x03); */\r
211 /*       wait_ms(1); */\r
212 /*       uart0_send(0xAA); */\r
213 /*       wait_ms(1); */\r
214 /*       uart0_send(0x55); */\r
215 /*       wait_ms(1); */\r
216 /*       uart0_send(0xFF); */\r
217 /*       wait_ms(1); */\r
218 /*       wait_ms(1); */\r
219       printf("\r\n>> Time set to %d seconds\r\n",time_get_s());\r
220       //      menu_action();\r
221     }\r
222   return 0;\r
223 }\r
224 \r
225 \r