Mercurial > sdl-ios-xcode
comparison touchTest/touchSimp.c @ 4640:f068a6dfc858
Added SDL_touch.c/SDL_touch_c.h as slightly modifeind SDL_mouse*. Made reads in touchSimp non-blocking.
author | Jim Grandpre <jim.tla@gmail.com> |
---|---|
date | Tue, 25 May 2010 23:23:23 -0400 |
parents | f5cd4b6231ba |
children | 057e8762d2a1 |
comparison
equal
deleted
inserted
replaced
4639:f5cd4b6231ba | 4640:f068a6dfc858 |
---|---|
15 #define MAX_FINGERS 2 | 15 #define MAX_FINGERS 2 |
16 | 16 |
17 int mousx,mousy; | 17 int mousx,mousy; |
18 int keystat[512]; | 18 int keystat[512]; |
19 int bstatus; | 19 int bstatus; |
20 | |
20 | 21 |
21 | 22 |
22 | 23 |
23 typedef struct { | 24 typedef struct { |
24 int x,y; | 25 int x,y; |
118 | 119 |
119 if (argc > 1) | 120 if (argc > 1) |
120 device = argv[1]; | 121 device = argv[1]; |
121 | 122 |
122 //Open Device | 123 //Open Device |
123 if ((fd = open (device, O_RDONLY)) == -1) | 124 if ((fd = open (device, O_RDONLY | O_NONBLOCK)) == -1) |
124 printf ("%s is not a vaild device.\n", device); | 125 printf ("%s is not a vaild device.\n", device); |
125 | 126 |
126 //Print Device Name | 127 //Print Device Name |
127 ioctl (fd, EVIOCGNAME (sizeof (name)), name); | 128 ioctl (fd, EVIOCGNAME (sizeof (name)), name); |
128 printf ("Reading From : %s (%s)\n", device, name); | 129 printf ("Reading From : %s (%s)\n", device, name); |
187 break; | 188 break; |
188 } | 189 } |
189 } | 190 } |
190 | 191 |
191 //poll for Touch <- Goal: make this a case: | 192 //poll for Touch <- Goal: make this a case: |
192 if ((rd = read (fd, ev, size * 64)) < size) | 193 |
193 perror_exit ("read()"); | 194 |
195 /*if ((rd = read (fd, ev, size * 64)) < size) | |
196 perror_exit ("read()"); */ | |
194 //printf("time: %i\n type: %X\n code: %X\n value: %i\n ", | 197 //printf("time: %i\n type: %X\n code: %X\n value: %i\n ", |
195 // ev->time,ev->type,ev->code,ev->value); | 198 // ev->time,ev->type,ev->code,ev->value); |
196 for (i = 0; i < rd / sizeof(struct input_event); i++) | 199 if((rd = read (fd, ev, size * 64)) >= size) |
197 switch (ev[i].type) | 200 for (i = 0; i < rd / sizeof(struct input_event); i++) |
198 { | 201 switch (ev[i].type) |
199 case EV_ABS: | 202 { |
200 if(ev[i].code == ABS_X) | 203 case EV_ABS: |
201 tx = ev[i].value; | 204 if(ev[i].code == ABS_X) |
202 else if (ev[i].code == ABS_Y) | 205 tx = ev[i].value; |
203 ty = ev[i].value; | 206 else if (ev[i].code == ABS_Y) |
204 else if (ev[i].code == ABS_MISC) | 207 ty = ev[i].value; |
205 { | 208 else if (ev[i].code == ABS_MISC) |
206 //printf("Misc:type: %X\n code: %X\n value: %i\n ", | 209 { |
207 // ev[i].type,ev[i].code,ev[i].value); | 210 //printf("Misc:type: %X\n code: %X\n value: %i\n ", |
208 } | 211 // ev[i].type,ev[i].code,ev[i].value); |
209 break; | 212 } |
210 case EV_MSC: | 213 break; |
211 if(ev[i].code == MSC_SERIAL) | 214 case EV_MSC: |
212 curf = ev[i].value; | 215 if(ev[i].code == MSC_SERIAL) |
213 break; | 216 curf = ev[i].value; |
214 case EV_SYN: | 217 break; |
215 curf -= 1; | 218 case EV_SYN: |
216 if(tx >= 0) | 219 curf -= 1; |
217 finger[curf].x = tx; | 220 if(tx >= 0) |
218 if(ty >= 0) | 221 finger[curf].x = tx; |
219 finger[curf].y = ty; | 222 if(ty >= 0) |
220 | 223 finger[curf].y = ty; |
221 //printf("Synched: %i tx: %i, ty: %i\n",curf,finger[curf].x,finger[curf].y); | 224 |
222 tx = -1; | 225 //printf("Synched: %i tx: %i, ty: %i\n",curf,finger[curf].x,finger[curf].y); |
223 ty = -1; | 226 tx = -1; |
224 break; | 227 ty = -1; |
225 | 228 break; |
226 } | 229 |
227 //And draw | 230 } |
228 DrawScreen(screen,h); | 231 //And draw |
229 /* | 232 DrawScreen(screen,h); |
230 for(i=0;i<512;i++) | 233 /* |
231 if(keystat[i]) printf("%i\n",i); | 234 for(i=0;i<512;i++) |
232 printf("Buttons:%i\n",bstatus); | 235 if(keystat[i]) printf("%i\n",i); |
233 */ | 236 printf("Buttons:%i\n",bstatus); |
234 } | 237 */ |
235 SDL_Quit(); | 238 } |
236 | 239 SDL_Quit(); |
240 | |
237 return 0; | 241 return 0; |
238 } | 242 } |