Rev 1363 | Rev 1399 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1347 | giacomo | 1 | |
2 | /* |
||
3 | * Project: S.Ha.R.K. |
||
4 | * |
||
5 | * Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * |
||
7 | * Authors : Mauro Marinoni <mauro.marinoni@unipv.it> |
||
8 | * (see authors.txt for full list of hartik's authors) |
||
9 | * |
||
10 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
11 | * |
||
12 | * http://www.sssup.it |
||
13 | * http://retis.sssup.it |
||
14 | * http://shark.sssup.it |
||
15 | */ |
||
16 | |||
17 | /* |
||
18 | * This program is free software; you can redistribute it and/or modify |
||
19 | * it under the terms of the GNU General Public License as published by |
||
20 | * the Free Software Foundation; either version 2 of the License, or |
||
21 | * (at your option) any later version. |
||
22 | * |
||
23 | * This program is distributed in the hope that it will be useful, |
||
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
26 | * GNU General Public License for more details. |
||
27 | * |
||
28 | * You should have received a copy of the GNU General Public License |
||
29 | * along with this program; if not, write to the Free Software |
||
30 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
31 | */ |
||
32 | |||
33 | #include <kernel/kern.h> |
||
34 | #include <kernel/func.h> |
||
35 | #include <stdlib.h> |
||
36 | #include <string.h> |
||
37 | |||
1363 | mauro | 38 | #include <drivers/shark_fb26.h> |
39 | |||
1347 | giacomo | 40 | #include <drivers/shark_mouse26.h> |
41 | #include <drivers/shark_keyb26.h> |
||
42 | #include <drivers/shark_spk26.h> |
||
1363 | mauro | 43 | #include <drivers/shark_joy26.h> |
1347 | giacomo | 44 | |
1363 | mauro | 45 | #define RGB_BLACK rgb16( 0, 0, 0) |
46 | #define RGB_GRAY rgb16(127,127,127) |
||
47 | #define RGB_WHITE rgb16(255,255,255) |
||
48 | #define RGB_RED rgb16(255, 0, 0) |
||
49 | #define RGB_GREEN rgb16( 0,255, 0) |
||
50 | #define RGB_BLUE rgb16( 0, 0,255) |
||
51 | #define RGB_YELLOW rgb16(255,255, 0) |
||
52 | #define RGB_MAGENTA rgb16(255, 0,255) |
||
53 | #define RGB_CYAN rgb16( 0,255,255) |
||
54 | #define RGB_D_RED rgb16(127, 0, 0) |
||
55 | #define RGB_D_GREEN rgb16( 0,127, 0) |
||
56 | #define RGB_D_BLUE rgb16( 0, 0,127) |
||
57 | #define RGB_D_YELLOW rgb16(127,127, 0) |
||
58 | #define RGB_D_MAGENTA rgb16(127, 0,127) |
||
59 | #define RGB_D_CYAN rgb16( 0,127,127) |
||
60 | |||
1389 | mauro | 61 | void my_sysend(KEY_EVT *e) |
1347 | giacomo | 62 | { |
1389 | mauro | 63 | sys_end(); |
64 | } |
||
1363 | mauro | 65 | |
1389 | mauro | 66 | void no_note(KEY_EVT *e) |
67 | { |
||
68 | speaker_sound(0, 0); |
||
69 | } |
||
1363 | mauro | 70 | |
1389 | mauro | 71 | void my_note(KEY_EVT *e) |
72 | { |
||
73 | switch (e->scan) { |
||
74 | case KEY_Q: |
||
75 | speaker_sound(262, 0); /* DO */ |
||
76 | break; |
||
77 | case KEY_W: |
||
78 | speaker_sound(277, 0); /* DO# */ |
||
79 | break; |
||
80 | case KEY_E: |
||
81 | speaker_sound(294, 0); /* RE */ |
||
82 | break; |
||
83 | case KEY_R: |
||
84 | speaker_sound(311, 0); /* RE# */ |
||
85 | break; |
||
86 | case KEY_T: |
||
87 | speaker_sound(330, 0); /* MI */ |
||
88 | break; |
||
89 | case KEY_Y: |
||
90 | speaker_sound(349, 0); /* FA */ |
||
91 | break; |
||
92 | case KEY_U: |
||
93 | speaker_sound(370, 0); /* FA# */ |
||
94 | break; |
||
95 | case KEY_I: |
||
96 | speaker_sound(392, 0); /* SOL */ |
||
97 | break; |
||
98 | case KEY_O: |
||
99 | speaker_sound(415, 0); /* SOL# */ |
||
100 | break; |
||
101 | case KEY_P: |
||
102 | speaker_sound(440, 0); /* LA */ |
||
103 | break; |
||
104 | case KEY_BRL: |
||
105 | speaker_sound(466, 0); /* LA# */ |
||
106 | break; |
||
107 | case KEY_BRR: |
||
108 | speaker_sound(494, 0); /* SI */ |
||
109 | break; |
||
110 | } |
||
1347 | giacomo | 111 | } |
112 | |||
1389 | mauro | 113 | TASK my_getjoy(void *arg) |
114 | { |
||
1363 | mauro | 115 | int a0, a1, a2, a3, btn; |
116 | char st[20]; |
||
117 | |||
118 | while (1) { |
||
119 | joy_getstatus(&a0, &a1, &a2, &a3, &btn); |
||
120 | |||
121 | sprintf(st, "X Axis : %6d ", a0); |
||
122 | grx_text(st, 100, 64, RGB_CYAN, RGB_BLACK); |
||
123 | sprintf(st, "Y Axis : %6d ", a1); |
||
124 | grx_text(st, 100, 114, RGB_CYAN, RGB_BLACK); |
||
125 | sprintf(st, "Buttons: %2x ", btn); |
||
126 | grx_text(st, 100, 164, RGB_CYAN, RGB_BLACK); |
||
127 | |||
128 | task_endcycle(); |
||
129 | if (btn == 0xF) |
||
1389 | mauro | 130 | my_sysend(NULL); |
1363 | mauro | 131 | } |
132 | } |
||
133 | |||
1389 | mauro | 134 | TASK my_getch(void *arg) |
135 | { |
||
136 | #define MYNCHAR 25 |
||
1363 | mauro | 137 | |
138 | BYTE ch; |
||
139 | int i = 0; |
||
140 | char st[20]; |
||
141 | |||
142 | while (1) { |
||
143 | ch = keyb_getch(NON_BLOCK); |
||
144 | if (ch) { |
||
1389 | mauro | 145 | if (ch == BACKSPACE) { //backspace |
146 | i--; |
||
147 | //ch = 0x20; |
||
148 | } |
||
149 | if (ch == ENTER) { //enter |
||
150 | i = ((i / MYNCHAR) + 1) * MYNCHAR - 1; |
||
151 | ch = 0x20; |
||
152 | } |
||
1363 | mauro | 153 | sprintf(st, "%c", ch); |
1389 | mauro | 154 | grx_text(st, 340 + 10 * (i%MYNCHAR), 25 + 20 * (i/MYNCHAR), RGB_BLUE, RGB_BLACK); |
1363 | mauro | 155 | |
1389 | mauro | 156 | if (ch == BACKSPACE) //backspace |
157 | i--; |
||
158 | if (++i >= MYNCHAR * 9) { |
||
1363 | mauro | 159 | i = 0; |
1389 | mauro | 160 | grx_box(315, 15, 623, 223, RGB_BLACK); |
161 | } |
||
1363 | mauro | 162 | } |
163 | |||
164 | task_endcycle(); |
||
165 | } |
||
166 | } |
||
167 | |||
1389 | mauro | 168 | void my_mouse(MOUSE_EVT *e) |
169 | { |
||
170 | char st[20]; |
||
171 | char pressed = 0; |
||
172 | |||
173 | sprintf(st, "X Axis : %3d (%4d)", e->x, e->dx); |
||
174 | grx_text(st, 100, 280, RGB_YELLOW, RGB_BLACK); |
||
175 | sprintf(st, "Y Axis : %3d (%4d)", e->y, e->dy); |
||
176 | grx_text(st, 100, 320, RGB_YELLOW, RGB_BLACK); |
||
177 | sprintf(st, "Z Axis : %3d (%4d)", e->z, e->dz); |
||
178 | grx_text(st, 100, 360, RGB_YELLOW, RGB_BLACK); |
||
179 | sprintf(st, "Buttons: %6x ", (int)e->buttons); |
||
180 | grx_text(st, 100, 400, RGB_YELLOW, RGB_BLACK); |
||
181 | |||
182 | if ((e->x > 377) && (e->x < 401) && (e->y > 300) && (e->y < 360) && (e->buttons == MOUSE_LBUTTON)){ |
||
183 | if (!pressed) { |
||
184 | speaker_sound(277, 0); /* DO# */ |
||
185 | pressed = 1; |
||
186 | } |
||
187 | return; |
||
188 | } |
||
189 | if ((e->x > 407) && (e->x < 431) && (e->y > 300) && (e->y < 360) && (e->buttons == MOUSE_LBUTTON)){ |
||
190 | if (!pressed) { |
||
191 | speaker_sound(311, 0); /* RE# */ |
||
192 | pressed = 1; |
||
193 | } |
||
194 | return; |
||
195 | } |
||
196 | if ((e->x > 467) && (e->x < 491) && (e->y > 300) && (e->y < 360) && (e->buttons == MOUSE_LBUTTON)){ |
||
197 | if (!pressed) { |
||
198 | speaker_sound(370, 0); /* FA# */ |
||
199 | pressed = 1; |
||
200 | } |
||
201 | return; |
||
202 | } |
||
203 | if ((e->x > 497) && (e->x < 521) && (e->y > 300) && (e->y < 360) && (e->buttons == MOUSE_LBUTTON)){ |
||
204 | if (!pressed) { |
||
205 | speaker_sound(415, 0); /* SOL# */ |
||
206 | pressed = 1; |
||
207 | } |
||
208 | return; |
||
209 | } |
||
210 | if ((e->x > 527) && (e->x < 551) && (e->y > 300) && (e->y < 360) && (e->buttons == MOUSE_LBUTTON)){ |
||
211 | if (!pressed) { |
||
212 | speaker_sound(466, 0); /* LA# */ |
||
213 | pressed = 1; |
||
214 | } |
||
215 | return; |
||
216 | } |
||
217 | |||
218 | if ((e->x > 360) && (e->x < 388) && (e->y > 300) && (e->y < 400) && (e->buttons == MOUSE_LBUTTON)){ |
||
219 | if (!pressed) { |
||
220 | speaker_sound(262, 0); /* DO */ |
||
221 | pressed = 1; |
||
222 | } |
||
223 | return; |
||
224 | } |
||
225 | if ((e->x > 390) && (e->x < 418) && (e->y > 300) && (e->y < 400) && (e->buttons == MOUSE_LBUTTON)) { |
||
226 | if (!pressed) { |
||
227 | speaker_sound(294, 0); /* RE */ |
||
228 | pressed = 1; |
||
229 | } |
||
230 | return; |
||
231 | } |
||
232 | if ((e->x > 420) && (e->x < 448) && (e->y > 300) && (e->y < 400) && (e->buttons == MOUSE_LBUTTON)) { |
||
233 | if (!pressed) { |
||
234 | speaker_sound(330, 0); /* MI */ |
||
235 | pressed = 1; |
||
236 | } |
||
237 | return; |
||
238 | } |
||
239 | if ((e->x > 450) && (e->x < 478) && (e->y > 300) && (e->y < 400) && (e->buttons == MOUSE_LBUTTON)) { |
||
240 | if (!pressed) { |
||
241 | speaker_sound(349, 0); /* FA */ |
||
242 | pressed = 1; |
||
243 | } |
||
244 | return; |
||
245 | } |
||
246 | if ((e->x > 480) && (e->x < 508) && (e->y > 300) && (e->y < 400) && (e->buttons == MOUSE_LBUTTON)) { |
||
247 | if (!pressed) { |
||
248 | speaker_sound(392, 0); /* SOL */ |
||
249 | pressed = 1; |
||
250 | } |
||
251 | return; |
||
252 | } |
||
253 | if ((e->x > 510) && (e->x < 538) && (e->y > 300) && (e->y < 400) && (e->buttons == MOUSE_LBUTTON)) { |
||
254 | if (!pressed) { |
||
255 | speaker_sound(440, 0); /* LA */ |
||
256 | pressed = 1; |
||
257 | } |
||
258 | return; |
||
259 | } |
||
260 | if ((e->x > 540) && (e->x < 568) && (e->y > 300) && (e->y < 400) && (e->buttons == MOUSE_LBUTTON)) { |
||
261 | if (!pressed) { |
||
262 | speaker_sound(494, 0); /* SI */ |
||
263 | pressed = 1; |
||
264 | } |
||
265 | return; |
||
266 | } |
||
267 | |||
268 | speaker_sound(0, 0); |
||
269 | pressed = 0; |
||
270 | } |
||
271 | |||
1363 | mauro | 272 | void graph_init(void) |
273 | { |
||
274 | grx_rect( 4, 4, 634, 474, RGB_WHITE); |
||
1389 | mauro | 275 | grx_rect( 14, 14, 304, 224, RGB_YELLOW); |
276 | grx_rect(314, 14, 624, 224, RGB_RED); |
||
277 | grx_rect( 14, 234, 304, 464, RGB_GREEN); |
||
278 | grx_rect(314, 234, 624, 464, RGB_BLUE); |
||
279 | |||
280 | /* Draw Teyboard */ |
||
281 | grx_box(360, 300, 388, 400, RGB_WHITE); /* DO */ |
||
282 | grx_box(390, 300, 418, 400, RGB_WHITE); /* RE */ |
||
283 | grx_box(420, 300, 448, 400, RGB_WHITE); /* MI */ |
||
284 | grx_box(450, 300, 478, 400, RGB_WHITE); /* FA */ |
||
285 | grx_box(480, 300, 508, 400, RGB_WHITE); /* SOL */ |
||
286 | grx_box(510, 300, 538, 400, RGB_WHITE); /* LA */ |
||
287 | grx_box(540, 300, 568, 400, RGB_WHITE); /* SI */ |
||
288 | |||
289 | grx_box(377, 301, 401, 360, RGB_BLACK); /* DO# */ |
||
290 | grx_box(407, 301, 431, 360, RGB_BLACK); /* RE# */ |
||
291 | grx_box(467, 301, 491, 360, RGB_BLACK); /* FA# */ |
||
292 | grx_box(497, 301, 521, 360, RGB_BLACK); /* SOL# */ |
||
293 | grx_box(527, 301, 551, 360, RGB_BLACK); /* LA# */ |
||
1363 | mauro | 294 | } |
295 | |||
1389 | mauro | 296 | void start_sound(void) |
297 | { |
||
298 | KEY_EVT ev; |
||
299 | |||
300 | speaker_sound(440, 400); |
||
301 | while ( (sys_gettime(NULL)/1000) < 1000); |
||
302 | |||
303 | ev.ascii = 'q'; |
||
304 | ev.scan = KEY_Q; |
||
305 | ev.flag = 0; |
||
306 | ev.status = KEY_PRESSED; |
||
307 | keyb_hook(ev, my_note, FALSE); |
||
308 | ev.status = KEY_RELEASED; |
||
309 | keyb_hook(ev, no_note, FALSE); |
||
310 | |||
311 | ev.ascii = 'w'; |
||
312 | ev.scan = KEY_W; |
||
313 | ev.flag = 0; |
||
314 | ev.status = KEY_PRESSED; |
||
315 | keyb_hook(ev, my_note, FALSE); |
||
316 | ev.status = KEY_RELEASED; |
||
317 | keyb_hook(ev, no_note, FALSE); |
||
318 | |||
319 | ev.ascii = 'e'; |
||
320 | ev.scan = KEY_E; |
||
321 | ev.flag = 0; |
||
322 | ev.status = KEY_PRESSED; |
||
323 | keyb_hook(ev, my_note, FALSE); |
||
324 | ev.status = KEY_RELEASED; |
||
325 | keyb_hook(ev, no_note, FALSE); |
||
326 | |||
327 | ev.ascii = 'r'; |
||
328 | ev.scan = KEY_R; |
||
329 | ev.flag = 0; |
||
330 | ev.status = KEY_PRESSED; |
||
331 | keyb_hook(ev, my_note, FALSE); |
||
332 | ev.status = KEY_RELEASED; |
||
333 | keyb_hook(ev, no_note, FALSE); |
||
334 | |||
335 | ev.ascii = 't'; |
||
336 | ev.scan = KEY_T; |
||
337 | ev.flag = 0; |
||
338 | ev.status = KEY_PRESSED; |
||
339 | keyb_hook(ev, my_note, FALSE); |
||
340 | ev.status = KEY_RELEASED; |
||
341 | keyb_hook(ev, no_note, FALSE); |
||
342 | |||
343 | ev.ascii = 'y'; |
||
344 | ev.scan = KEY_Y; |
||
345 | ev.flag = 0; |
||
346 | ev.status = KEY_PRESSED; |
||
347 | keyb_hook(ev, my_note, FALSE); |
||
348 | ev.status = KEY_RELEASED; |
||
349 | keyb_hook(ev, no_note, FALSE); |
||
350 | |||
351 | ev.ascii = 'u'; |
||
352 | ev.scan = KEY_U; |
||
353 | ev.flag = 0; |
||
354 | ev.status = KEY_PRESSED; |
||
355 | keyb_hook(ev, my_note, FALSE); |
||
356 | ev.status = KEY_RELEASED; |
||
357 | keyb_hook(ev, no_note, FALSE); |
||
358 | |||
359 | ev.ascii = 'i'; |
||
360 | ev.scan = KEY_I; |
||
361 | ev.flag = 0; |
||
362 | ev.status = KEY_PRESSED; |
||
363 | keyb_hook(ev, my_note, FALSE); |
||
364 | ev.status = KEY_RELEASED; |
||
365 | keyb_hook(ev, no_note, FALSE); |
||
366 | |||
367 | ev.ascii = 'o'; |
||
368 | ev.scan = KEY_O; |
||
369 | ev.flag = 0; |
||
370 | ev.status = KEY_PRESSED; |
||
371 | keyb_hook(ev, my_note, FALSE); |
||
372 | ev.status = KEY_RELEASED; |
||
373 | keyb_hook(ev, no_note, FALSE); |
||
374 | |||
375 | ev.ascii = 'p'; |
||
376 | ev.scan = KEY_P; |
||
377 | ev.flag = 0; |
||
378 | ev.status = KEY_PRESSED; |
||
379 | keyb_hook(ev, my_note, FALSE); |
||
380 | ev.status = KEY_RELEASED; |
||
381 | keyb_hook(ev, no_note, FALSE); |
||
382 | |||
383 | ev.ascii = '['; |
||
384 | ev.scan = KEY_BRL; |
||
385 | ev.flag = 0; |
||
386 | ev.status = KEY_PRESSED; |
||
387 | keyb_hook(ev, my_note, FALSE); |
||
388 | ev.status = KEY_RELEASED; |
||
389 | keyb_hook(ev, no_note, FALSE); |
||
390 | |||
391 | ev.ascii = ']'; |
||
392 | ev.scan = KEY_BRR; |
||
393 | ev.flag = 0; |
||
394 | ev.status = KEY_PRESSED; |
||
395 | keyb_hook(ev, my_note, FALSE); |
||
396 | ev.status = KEY_RELEASED; |
||
397 | keyb_hook(ev, no_note, FALSE); |
||
398 | } |
||
399 | |||
1347 | giacomo | 400 | int main(int argc, char **argv) |
401 | { |
||
1363 | mauro | 402 | SOFT_TASK_MODEL mp; |
403 | PID pid; |
||
404 | |||
1347 | giacomo | 405 | KEY_EVT ev; |
406 | |||
407 | ev.ascii = 'c'; |
||
408 | ev.scan = KEY_C; |
||
409 | ev.status = KEY_PRESSED; |
||
410 | ev.flag = CNTL_BIT; |
||
1389 | mauro | 411 | keyb_hook(ev, my_sysend, FALSE); |
1347 | giacomo | 412 | ev.flag = CNTR_BIT; |
1389 | mauro | 413 | keyb_hook(ev, my_sysend, FALSE); |
1347 | giacomo | 414 | |
1363 | mauro | 415 | graph_init(); |
416 | |||
417 | mouse_grxlimits(639, 479); |
||
418 | mouse_setposition(319, 239, 0); |
||
1389 | mauro | 419 | mouse_hook(my_mouse); |
1363 | mauro | 420 | mouse_grxcursor(ENABLE, 2); |
421 | |||
422 | soft_task_default_model(mp); |
||
423 | soft_task_def_level(mp,2); |
||
424 | soft_task_def_ctrl_jet(mp); |
||
425 | soft_task_def_met(mp,700); |
||
426 | soft_task_def_period(mp,10000); |
||
427 | soft_task_def_usemath(mp); |
||
428 | pid = task_create("Key_Print", my_getch, &mp, NULL); |
||
429 | if (pid == NIL) { |
||
430 | perror("Could not create task <Key_Print>"); |
||
431 | sys_end(); |
||
432 | } else |
||
433 | task_activate(pid); |
||
434 | |||
1389 | mauro | 435 | if (JOY26_installed()) { |
436 | soft_task_default_model(mp); |
||
437 | soft_task_def_level(mp,2); |
||
438 | soft_task_def_ctrl_jet(mp); |
||
439 | soft_task_def_met(mp,700); |
||
440 | soft_task_def_period(mp,10000); |
||
441 | soft_task_def_usemath(mp); |
||
442 | pid = task_create("Joy_Print", my_getjoy, &mp, NULL); |
||
443 | if (pid == NIL) { |
||
444 | perror("Could not create task <Joy_Print>"); |
||
445 | sys_end(); |
||
446 | } else |
||
447 | task_activate(pid); |
||
448 | } |
||
449 | |||
450 | start_sound(); |
||
1347 | giacomo | 451 | return 0; |
452 | } |