Mercurial > sdl-ios-xcode
comparison src/video/fbcon/SDL_fbevents.c @ 59:b685c94f8db7
Ryan's IMPS/2 mouse fix
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Mon, 11 Jun 2001 15:48:32 +0000 |
parents | 4f6c5f021323 |
children | e093bbc72ab9 |
comparison
equal
deleted
inserted
replaced
58:bd6b0a910a65 | 59:b685c94f8db7 |
---|---|
395 closedir(proc); | 395 closedir(proc); |
396 } | 396 } |
397 return available; | 397 return available; |
398 } | 398 } |
399 | 399 |
400 | |
401 /* rcg06112001 Set up IMPS/2 mode, if possible. This gives | |
402 * us access to the mousewheel, etc. Returns zero if | |
403 * writes to device failed, but you still need to query the | |
404 * device to see which mode it's actually in. | |
405 */ | |
406 static int set_imps2_mode(int fd) | |
407 { | |
408 /* If you wanted to control the mouse mode (and we do :) ) ... | |
409 Set IMPS/2 protocol: | |
410 {0xf3,200,0xf3,100,0xf3,80} | |
411 Reset mouse device: | |
412 {0xFF} | |
413 */ | |
414 Uint8 set_imps2[] = {0xf3, 200, 0xf3, 100, 0xf3, 80}; | |
415 Uint8 reset = 0xff; | |
416 fd_set fdset; | |
417 struct timeval tv; | |
418 int retval = 0; | |
419 | |
420 if ( write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2) ) { | |
421 if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) { | |
422 retval = 1; | |
423 } | |
424 } | |
425 | |
426 /* Get rid of any chatter from the above */ | |
427 FD_ZERO(&fdset); | |
428 FD_SET(fd, &fdset); | |
429 tv.tv_sec = 0; | |
430 tv.tv_usec = 0; | |
431 while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) { | |
432 char temp[32]; | |
433 read(fd, temp, sizeof(temp)); | |
434 } | |
435 | |
436 return retval; | |
437 } | |
438 | |
439 | |
400 /* Returns true if the mouse uses the IMPS/2 protocol */ | 440 /* Returns true if the mouse uses the IMPS/2 protocol */ |
401 static int detect_imps2(int fd) | 441 static int detect_imps2(int fd) |
402 { | 442 { |
403 int imps2; | 443 int imps2; |
404 | 444 |
405 imps2 = 0; | 445 imps2 = 0; |
446 | |
447 /* rcg06112001 Attempt to set IMPS/2 mode first, even with envr var... */ | |
448 set_imps2_mode(fd); | |
449 | |
406 if ( getenv("SDL_MOUSEDEV_IMPS2") ) { | 450 if ( getenv("SDL_MOUSEDEV_IMPS2") ) { |
407 imps2 = 1; | 451 imps2 = 1; |
408 } | 452 } |
409 if ( ! imps2 ) { | 453 if ( ! imps2 ) { |
410 unsigned char query_ps2 = 0xF2; | 454 Uint8 query_ps2 = 0xF2; |
411 fd_set fdset; | 455 fd_set fdset; |
412 struct timeval tv; | 456 struct timeval tv; |
413 | |
414 | 457 |
415 /* Get rid of any mouse motion noise */ | 458 /* Get rid of any mouse motion noise */ |
416 FD_ZERO(&fdset); | 459 FD_ZERO(&fdset); |
417 FD_SET(fd, &fdset); | 460 FD_SET(fd, &fdset); |
418 tv.tv_sec = 0; | 461 tv.tv_sec = 0; |
420 while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) { | 463 while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) { |
421 char temp[32]; | 464 char temp[32]; |
422 read(fd, temp, sizeof(temp)); | 465 read(fd, temp, sizeof(temp)); |
423 } | 466 } |
424 | 467 |
425 /* Query for the type of mouse protocol */ | 468 /* Query for the type of mouse protocol */ |
426 if ( write(fd, &query_ps2, 1) == 1 ) { | 469 if ( write(fd, &query_ps2, sizeof (query_ps2)) == sizeof (query_ps2)) { |
427 unsigned char ch = 0; | 470 Uint8 ch = 0; |
428 | 471 |
429 /* If you wanted to control the mouse mode: | |
430 Set IMPS/2 protocol: | |
431 {0xf3,200,0xf3,100,0xf3,80} | |
432 Reset mouse device: | |
433 {0xFF} | |
434 */ | |
435 /* Get the mouse protocol response */ | 472 /* Get the mouse protocol response */ |
436 do { | 473 do { |
437 FD_ZERO(&fdset); | 474 FD_ZERO(&fdset); |
438 FD_SET(fd, &fdset); | 475 FD_SET(fd, &fdset); |
439 tv.tv_sec = 1; | 476 tv.tv_sec = 1; |
440 tv.tv_usec = 0; | 477 tv.tv_usec = 0; |
441 if ( select(fd+1, &fdset, 0, 0, &tv) < 1 ) { | 478 if ( select(fd+1, &fdset, 0, 0, &tv) < 1 ) { |
442 break; | 479 break; |
443 } | 480 } |
444 } while ( (read(fd, &ch, 1) == 1) && | 481 } while ( (read(fd, &ch, sizeof (ch)) == sizeof (ch)) && |
445 ((ch == 0xFA) || (ch == 0xAA)) ); | 482 ((ch == 0xFA) || (ch == 0xAA)) ); |
446 | 483 |
447 /* Experimental values (Logitech wheelmouse) */ | 484 /* Experimental values (Logitech wheelmouse) */ |
448 #ifdef DEBUG_MOUSE | 485 #ifdef DEBUG_MOUSE |
449 fprintf(stderr, "Last mouse mode: 0x%x\n", ch); | 486 fprintf(stderr, "Last mouse mode: 0x%x\n", ch); |
500 } | 537 } |
501 } | 538 } |
502 } | 539 } |
503 /* Now try to use the new HID unified mouse device */ | 540 /* Now try to use the new HID unified mouse device */ |
504 if ( mouse_fd < 0 ) { | 541 if ( mouse_fd < 0 ) { |
505 mouse_fd = open("/dev/input/mice", O_RDONLY, 0); | 542 mouse_fd = open("/dev/input/mice", O_RDWR, 0); |
506 if ( mouse_fd >= 0 ) { | 543 if (mouse_fd < 0) { |
507 mouse_drv = MOUSE_IMPS2; | 544 mouse_fd = open("/dev/input/mice", O_RDONLY, 0); |
545 } | |
546 if (mouse_fd >= 0) { | |
547 if (detect_imps2(mouse_fd)) { | |
548 mouse_drv = MOUSE_IMPS2; | |
549 } else { | |
550 mouse_drv = MOUSE_PS2; | |
551 } | |
508 } | 552 } |
509 } | 553 } |
510 /* Now try to use a modern PS/2 port mouse */ | 554 /* Now try to use a modern PS/2 port mouse */ |
511 if ( mouse_fd < 0 ) { | 555 if ( mouse_fd < 0 ) { |
512 mouse_fd = open("/dev/psaux", O_RDWR, 0); | 556 mouse_fd = open("/dev/psaux", O_RDWR, 0); |