Changeset 58a369e in mainline
- Timestamp:
- 2012-08-13T15:00:03Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e0cd9042
- Parents:
- 91ecaa10
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/wacomdump/wacomdump.c
r91ecaa10 r58a369e 32 32 #include <loc.h> 33 33 #include <stdio.h> 34 #include <macros.h> 34 35 35 36 #define BUF_SIZE 64 … … 37 38 #define START_OF_PACKET 128 38 39 #define CONTROL_PACKET 64 40 #define TOUCH_EVENT 16 39 41 #define FINGER1 1 40 42 #define FINGER2 2 … … 70 72 bool stylus_in_proximity; 71 73 bool stylus_is_eraser; 72 bool button1_pressed; 73 bool button2_pressed; 74 bool tip_pressed; /* Reported as stylus button 1 */ 75 bool button1_pressed; /* Reported as stylus button 2 */ 76 bool button2_pressed; /* Reported as stylus button 3 */ 77 bool finger1_pressed; /* Reported as touch button 1 */ 74 78 75 79 /* Session to the serial device */ … … 186 190 isdv4_event_init(&event); 187 191 188 /* size_t dbg_ctr;*/189 /* printf("Packet: ");*/190 /* for (dbg_ctr = 0; dbg_ctr < size; dbg_ctr++) {*/191 /* printf("%02hhx ", packet[dbg_ctr]);*/192 /* }*/193 /* printf("\n");*/194 192 195 193 if (size == 5 || size == 7) { … … 199 197 event.y = ((packet[3] & 127) << 7) | (packet[4] & 127); 200 198 event.source = TOUCH; 201 printf("TOUCH finger finger1=%d x=%u y=%u\n", finger1, event.x, event.y);202 199 203 200 if (!state->stylus_in_proximity) { 204 if (!finger1 && state-> button1_pressed) {205 state-> button1_pressed = false;201 if (!finger1 && state->finger1_pressed) { 202 state->finger1_pressed = false; 206 203 207 204 event.type = RELEASE; … … 209 206 state->emit_event_fn(&event); 210 207 } 211 else if (finger1 && !state-> button1_pressed) {212 state-> button1_pressed = true;208 else if (finger1 && !state->finger1_pressed) { 209 state->finger1_pressed = true; 213 210 214 211 event.type = PRESS; … … 233 230 event.pressure = (packet[5] & 127) | ((packet[6] & 7) << 7); 234 231 235 bool eraser = !tip && button2;236 printf("STYLUS tip=%d button1=%d button2=%d proximity=%d x=%u y=%u p=%u\n",237 tip, button1, button2, proximity, event.x, event.y, event.pressure);238 239 232 if (proximity && !state->stylus_in_proximity) { 240 233 /* Stylus came into proximity */ 241 234 state->stylus_in_proximity = true; 242 state->stylus_is_eraser = eraser;235 state->stylus_is_eraser = !tip && button2; 243 236 event.source = (state->stylus_is_eraser ? STYLUS_ERASER : STYLUS_TIP); 244 237 event.type = PROXIMITY_IN; … … 254 247 else { 255 248 /* Proximity state didn't change, but we need to check if it is still eraser */ 256 if ( eraser != state->stylus_is_eraser) {249 if (state->stylus_is_eraser && !button2) { 257 250 event.type = PROXIMITY_OUT; 258 event.source = eraser ? STYLUS_TIP :STYLUS_ERASER;251 event.source = STYLUS_ERASER; 259 252 state->emit_event_fn(&event); 260 253 event.type = PROXIMITY_IN; 261 event.source = eraser ? STYLUS_ERASER : STYLUS_TIP; 262 state->emit_event_fn(&event); 263 state->stylus_is_eraser = eraser; 254 event.source = STYLUS_TIP; 255 state->emit_event_fn(&event); 256 state->stylus_is_eraser = false; 257 } 258 else if (!state->stylus_is_eraser && !tip && button2) { 259 event.type = PROXIMITY_OUT; 260 event.source = STYLUS_TIP; 261 state->emit_event_fn(&event); 262 event.type = PROXIMITY_IN; 263 event.source = STYLUS_ERASER; 264 state->emit_event_fn(&event); 265 state->stylus_is_eraser = true; 264 266 } 265 267 } 266 268 267 269 if (!state->stylus_is_eraser) { 270 if (tip && !state->tip_pressed) { 271 state->tip_pressed = true; 272 event.type = PRESS; 273 event.source = STYLUS_TIP; 274 event.button = 1; 275 state->emit_event_fn(&event); 276 } 277 else if (!tip && state->tip_pressed) { 278 state->tip_pressed = false; 279 event.type = RELEASE; 280 event.source = STYLUS_TIP; 281 event.button = 1; 282 state->emit_event_fn(&event); 283 } 268 284 if (button1 && !state->button1_pressed) { 269 285 state->button1_pressed = true; 270 286 event.type = PRESS; 271 287 event.source = STYLUS_TIP; 272 event.button = 1;288 event.button = 2; 273 289 state->emit_event_fn(&event); 274 290 } … … 277 293 event.type = RELEASE; 278 294 event.source = STYLUS_TIP; 279 event.button = 1;295 event.button = 2; 280 296 state->emit_event_fn(&event); 281 297 } … … 284 300 event.type = PRESS; 285 301 event.source = STYLUS_TIP; 286 event.button = 2;302 event.button = 3; 287 303 state->emit_event_fn(&event); 288 304 } … … 291 307 event.type = RELEASE; 292 308 event.source = STYLUS_TIP; 293 event.button = 2;309 event.button = 3; 294 310 state->emit_event_fn(&event); 295 311 } 296 312 event.type = MOVE; 297 313 event.source = STYLUS_TIP; 298 event.button = ( button1 ? 1 : 0) | (button2 ? 2: 0);314 event.button = (tip ? 1: 0) | (button1 ? 2 : 0) | (button2 ? 4 : 0); 299 315 state->emit_event_fn(&event); 300 316 } 301 317 else { 302 if ( button1 && !state->button1_pressed) {303 state-> button1_pressed = true;318 if (tip && !state->tip_pressed) { 319 state->tip_pressed = true; 304 320 event.type = PRESS; 305 321 event.source = STYLUS_ERASER; … … 307 323 state->emit_event_fn(&event); 308 324 } 309 else if (! button1 && state->button1_pressed) {310 state-> button1_pressed = false;325 else if (!tip && state->tip_pressed) { 326 state->tip_pressed = false; 311 327 event.type = RELEASE; 312 328 event.source = STYLUS_ERASER; … … 316 332 event.type = MOVE; 317 333 event.source = STYLUS_ERASER; 318 event.button = ( button1? 1 : 0);334 event.button = (tip ? 1 : 0); 319 335 state->emit_event_fn(&event); 320 336 } 321 //int xtilt = (packet[8] & 127);322 //int ytilt = (packet[7] & 127);323 337 } 324 338 … … 414 428 { 415 429 bool reading = true; 416 bool silence = true;430 size_t packet_remaining = 1; 417 431 while (reading) { 432 if (packet_remaining == 0) packet_remaining = 1; 418 433 ssize_t read = char_dev_read(state->sess, state->buf + state->buf_end, 419 434 state->buf_size - state->buf_end); … … 424 439 state->buf_end += read; 425 440 426 if (!silence && read == 0) {427 silence = true;428 usleep(100000); /* 100 ms */429 continue;430 }431 else if (read > 0) {432 silence = false;433 }434 435 441 size_t i = 0; 436 442 … … 444 450 /* Process packets one by one */ 445 451 while (reading && i < state->buf_end) { 446 /* Find a start of next packet */ 452 /* Determine the packet length */ 453 if (state->buf[i] & CONTROL_PACKET) { 454 packet_remaining = 11; 455 } 456 else if (state->buf[i] & TOUCH_EVENT) { 457 packet_remaining = 5; 458 } 459 else { 460 packet_remaining = 9; 461 } 462 463 /* Find the end of the packet */ 447 464 i++; /* We need to skip the first byte with START_OF_PACKET set */ 448 while (i < state->buf_end && (state->buf[i] & START_OF_PACKET) == 0) i++; 465 packet_remaining--; 466 while (packet_remaining > 0 && i < state->buf_end && 467 (state->buf[i] & START_OF_PACKET) == 0) { 468 i++; 469 packet_remaining--; 470 } 449 471 end = i; 450 472 451 473 /* If we have whole packet, process it */ 452 if (end > start && (end != state->buf_end || read == 0)) {474 if (end > start && packet_remaining == 0) { 453 475 reading = consumer(state->buf + start, end - start, state); 454 476 start = end; … … 487 509 write_command(state->sess, CMD_STOP); 488 510 usleep(250000); /* 250 ms */ 489 while (char_dev_read(state->sess, state->buf, state->buf_size) > 0);511 // FIXME: Read all possible garbage before sending commands 490 512 write_command(state->sess, CMD_QUERY_STYLUS); 491 513 read_packets(state, parse_response_stylus);
Note:
See TracChangeset
for help on using the changeset viewer.