1 | /* |
---|
2 | * RTEMS for Nintendo DS input parser. |
---|
3 | * |
---|
4 | * Copyright (c) 2008 by Matthieu Bucchianeri <mbucchia@gmail.com> |
---|
5 | * |
---|
6 | * The license and distribution terms for this file may be |
---|
7 | * found in the file LICENSE in this distribution or at |
---|
8 | * |
---|
9 | * http://www.rtems.org/license/LICENSE |
---|
10 | */ |
---|
11 | |
---|
12 | #include <stdio.h> |
---|
13 | #include <stdlib.h> |
---|
14 | #include <rtems.h> |
---|
15 | |
---|
16 | #include <nds.h> |
---|
17 | |
---|
18 | #include <rtems/mw_uid.h> |
---|
19 | |
---|
20 | /* |
---|
21 | * from console/console.c |
---|
22 | */ |
---|
23 | |
---|
24 | extern void console_push (char c); |
---|
25 | |
---|
26 | /* |
---|
27 | * from reco.c |
---|
28 | */ |
---|
29 | |
---|
30 | extern char PA_CheckLetter (int down, int x, int y); |
---|
31 | |
---|
32 | /* |
---|
33 | * message queue for touchscreen and graffiti events. |
---|
34 | */ |
---|
35 | |
---|
36 | static rtems_id mou_queue_id = 0; |
---|
37 | static rtems_id kbd_queue_id = 0; |
---|
38 | |
---|
39 | /* |
---|
40 | * old position. |
---|
41 | */ |
---|
42 | |
---|
43 | static int old_x = 0; |
---|
44 | static int old_y = 0; |
---|
45 | static int old_btns = 0; |
---|
46 | |
---|
47 | /* |
---|
48 | * hand mode. |
---|
49 | */ |
---|
50 | |
---|
51 | static int hand = 0; |
---|
52 | |
---|
53 | /* |
---|
54 | * update touchscreen position. |
---|
55 | */ |
---|
56 | |
---|
57 | void |
---|
58 | update_touchscreen (void) |
---|
59 | { |
---|
60 | static int graffiti = 0; |
---|
61 | struct MW_UID_MESSAGE m; |
---|
62 | int x, y, k, kh, btns = 0; |
---|
63 | touchPosition pos; |
---|
64 | char c; |
---|
65 | |
---|
66 | /* update keypad & touchscreen */ |
---|
67 | scanKeys (); |
---|
68 | pos = touchReadXY (); |
---|
69 | x = pos.px; |
---|
70 | y = pos.py; |
---|
71 | k = keysDown (); |
---|
72 | kh = keysHeld (); |
---|
73 | |
---|
74 | /* check for character recognition */ |
---|
75 | if ((kh & KEY_L) || (kh & KEY_R)) { |
---|
76 | graffiti = 1; |
---|
77 | c = PA_CheckLetter ((kh & KEY_TOUCH ? 1 : 0), x, y); |
---|
78 | if (c) { |
---|
79 | /* signal the console driver */ |
---|
80 | console_push (c); |
---|
81 | if (kbd_queue_id != 0) { |
---|
82 | /* send the read character */ |
---|
83 | m.type = MV_UID_KBD; |
---|
84 | m.m.kbd.code = c; |
---|
85 | m.m.kbd.modifiers = 0; |
---|
86 | m.m.kbd.mode = MV_KEY_MODE_ASCII; |
---|
87 | rtems_message_queue_send (kbd_queue_id, (void *) &m, |
---|
88 | sizeof (struct MW_UID_MESSAGE)); |
---|
89 | } |
---|
90 | } |
---|
91 | } else { |
---|
92 | if (graffiti == 1) { |
---|
93 | x = old_x; |
---|
94 | y = old_y; |
---|
95 | } |
---|
96 | graffiti = 0; |
---|
97 | } |
---|
98 | |
---|
99 | if (mou_queue_id == 0) |
---|
100 | return; |
---|
101 | |
---|
102 | if (hand == 1) { |
---|
103 | if (k & KEY_LEFT) { |
---|
104 | btns = MV_BUTTON_LEFT; |
---|
105 | } |
---|
106 | if (k & KEY_RIGHT) { |
---|
107 | btns = MV_BUTTON_RIGHT; |
---|
108 | } |
---|
109 | } else { |
---|
110 | if (k & KEY_A) { |
---|
111 | btns = MV_BUTTON_LEFT; |
---|
112 | } |
---|
113 | if (k & KEY_B) { |
---|
114 | btns = MV_BUTTON_RIGHT; |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | if (!((kh & KEY_L) || (kh & KEY_R)) && (kh & KEY_TOUCH) |
---|
119 | && (x != old_x || y != old_y || btns)) { |
---|
120 | /* send the read position */ |
---|
121 | m.type = MV_UID_ABS_POS; |
---|
122 | old_btns = m.m.pos.btns = btns; |
---|
123 | old_x = m.m.pos.x = x; |
---|
124 | old_y = m.m.pos.y = y; |
---|
125 | m.m.pos.z = 0; |
---|
126 | rtems_message_queue_send (mou_queue_id, (void *) &m, |
---|
127 | sizeof (struct MW_UID_MESSAGE)); |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | /* |
---|
132 | * register a message queue for touchscreen events. |
---|
133 | */ |
---|
134 | |
---|
135 | void |
---|
136 | register_mou_msg_queue (char *q_name) |
---|
137 | { |
---|
138 | rtems_name queue_name; |
---|
139 | rtems_status_code status; |
---|
140 | |
---|
141 | queue_name = rtems_build_name (q_name[0], q_name[1], q_name[2], q_name[3]); |
---|
142 | status = rtems_message_queue_ident (queue_name, RTEMS_LOCAL, &mou_queue_id); |
---|
143 | if (status != RTEMS_SUCCESSFUL) { |
---|
144 | printk ("[!] cannot create queue %d\n", status); |
---|
145 | return; |
---|
146 | } |
---|
147 | |
---|
148 | update_touchscreen (); |
---|
149 | } |
---|
150 | |
---|
151 | /* |
---|
152 | * unregister the message queue. |
---|
153 | */ |
---|
154 | |
---|
155 | void |
---|
156 | unregister_mou_msg_queue (void) |
---|
157 | { |
---|
158 | /* nothing here */ |
---|
159 | } |
---|
160 | |
---|
161 | /* |
---|
162 | * register a message queue for graffiti events. |
---|
163 | */ |
---|
164 | |
---|
165 | void |
---|
166 | register_kbd_msg_queue (char *q_name) |
---|
167 | { |
---|
168 | rtems_name queue_name; |
---|
169 | rtems_status_code status; |
---|
170 | |
---|
171 | queue_name = rtems_build_name (q_name[0], q_name[1], q_name[2], q_name[3]); |
---|
172 | status = rtems_message_queue_ident (queue_name, RTEMS_LOCAL, &kbd_queue_id); |
---|
173 | if (status != RTEMS_SUCCESSFUL) { |
---|
174 | printk ("[!] cannot create queue %d\n", status); |
---|
175 | return; |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
179 | /* |
---|
180 | * unregister the message queue. |
---|
181 | */ |
---|
182 | |
---|
183 | void |
---|
184 | unregister_kbd_msg_queue (void) |
---|
185 | { |
---|
186 | /* nothing here */ |
---|
187 | } |
---|
188 | |
---|
189 | /* |
---|
190 | * set hand mode. |
---|
191 | */ |
---|
192 | |
---|
193 | void |
---|
194 | touchscreen_sethand (int h) |
---|
195 | { |
---|
196 | hand = h; |
---|
197 | } |
---|