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