Rev 1550 | 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 | |||
38 | #include <drivers/shark_keyb26.h> |
||
39 | |||
1572 | mauro | 40 | //#define SHOW_EVT |
41 | |||
1347 | giacomo | 42 | void my_sysclose(KEY_EVT *e) |
43 | { |
||
44 | kern_printf("S.Ha.R.K. closed.\n\n"); |
||
1550 | pj | 45 | exit(0); |
1347 | giacomo | 46 | } |
47 | |||
1572 | mauro | 48 | TASK my_get(void *arg) { |
49 | #ifdef SHOW_EVT |
||
50 | int status; |
||
51 | KEY_EVT ev; |
||
52 | #else |
||
53 | BYTE ch; |
||
54 | #endif |
||
1347 | giacomo | 55 | |
56 | while (1) { |
||
1572 | mauro | 57 | #ifdef SHOW_EVT |
58 | status = keyb_getcode(&ev, NON_BLOCK); |
||
59 | if (status == TRUE) |
||
60 | cprintf("[%c %d %d %d]\n", ev.ascii, ev.scan, ev.status, ev.flag); |
||
61 | #else |
||
1347 | giacomo | 62 | ch = keyb_getch(NON_BLOCK); |
63 | if (ch) |
||
1399 | giacomo | 64 | cprintf("%c", ch); |
1572 | mauro | 65 | #endif |
1347 | giacomo | 66 | task_endcycle(); |
67 | } |
||
68 | } |
||
69 | |||
70 | void my_pause(KEY_EVT *e){ |
||
71 | |||
72 | TIME t; |
||
73 | |||
1399 | giacomo | 74 | cprintf("Start Pause.\n"); |
1347 | giacomo | 75 | keyb_disable(); |
1399 | giacomo | 76 | cprintf("Keyboard Disabled.\n"); |
1347 | giacomo | 77 | t = sys_gettime(NULL); |
78 | while ( ( (sys_gettime(NULL) -t) / 1000) < 5000); |
||
79 | keyb_enable(); |
||
1399 | giacomo | 80 | cprintf("Keyboard Enabled.\n"); |
1347 | giacomo | 81 | } |
82 | |||
1572 | mauro | 83 | void my_test(KEY_EVT *e){ |
84 | cprintf("<test>\n"); |
||
85 | } |
||
86 | |||
87 | void my_arrow(KEY_EVT *e){ |
||
88 | cprintf("<arrow>\n"); |
||
89 | } |
||
90 | |||
1347 | giacomo | 91 | int main(int argc, char **argv) |
92 | { |
||
93 | SOFT_TASK_MODEL mp; |
||
94 | PID pid; |
||
95 | |||
96 | KEY_EVT ev; |
||
97 | |||
98 | ev.ascii = 'p'; |
||
99 | ev.scan = KEY_P; |
||
100 | ev.status = KEY_PRESSED; |
||
101 | ev.flag = CNTR_BIT; |
||
102 | keyb_hook(ev, my_pause, FALSE); |
||
1572 | mauro | 103 | |
104 | set_keyevt(&ev, 'a', KEY_A, 0, KEY_PRESSED|KEY_REPEATED); |
||
105 | keyb_hook(ev, my_test, FALSE); |
||
106 | |||
107 | set_keyevt(&ev, 0, EXT_UP, 0, KEY_PRESSED); |
||
108 | keyb_hook(ev, my_arrow, FALSE); |
||
109 | |||
110 | set_keyevt(&ev, 'b', KEY_B, CNTL_BIT, KEY_PRESSED); |
||
111 | keyb_hook(ev, my_test, TRUE); |
||
112 | |||
1347 | giacomo | 113 | ev.ascii = 'c'; |
114 | ev.scan = KEY_C; |
||
115 | ev.status = KEY_PRESSED; |
||
116 | ev.flag = CNTR_BIT; |
||
117 | keyb_hook(ev, my_sysclose, FALSE); |
||
118 | ev.flag = CNTL_BIT; |
||
119 | keyb_hook(ev, my_sysclose, FALSE); |
||
120 | |||
121 | soft_task_default_model(mp); |
||
122 | soft_task_def_level(mp,2); |
||
123 | soft_task_def_ctrl_jet(mp); |
||
124 | soft_task_def_met(mp,700); |
||
125 | soft_task_def_period(mp,1000); |
||
126 | soft_task_def_usemath(mp); |
||
1572 | mauro | 127 | pid = task_create("Keyb_Print", my_get, &mp, NULL); |
1347 | giacomo | 128 | if (pid == NIL) { |
129 | perror("Could not create task <Keyb_Print>"); |
||
1550 | pj | 130 | exit(1); |
1347 | giacomo | 131 | } else |
132 | task_activate(pid); |
||
133 | |||
134 | return 0; |
||
135 | } |