Ryan's IMPS/2 mouse fix
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%4060
This commit is contained in:
parent
254c4d997c
commit
24b54aa981
1 changed files with 59 additions and 15 deletions
|
@ -397,21 +397,64 @@ static int gpm_available(void)
|
||||||
return available;
|
return available;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* rcg06112001 Set up IMPS/2 mode, if possible. This gives
|
||||||
|
* us access to the mousewheel, etc. Returns zero if
|
||||||
|
* writes to device failed, but you still need to query the
|
||||||
|
* device to see which mode it's actually in.
|
||||||
|
*/
|
||||||
|
static int set_imps2_mode(int fd)
|
||||||
|
{
|
||||||
|
/* If you wanted to control the mouse mode (and we do :) ) ...
|
||||||
|
Set IMPS/2 protocol:
|
||||||
|
{0xf3,200,0xf3,100,0xf3,80}
|
||||||
|
Reset mouse device:
|
||||||
|
{0xFF}
|
||||||
|
*/
|
||||||
|
Uint8 set_imps2[] = {0xf3, 200, 0xf3, 100, 0xf3, 80};
|
||||||
|
Uint8 reset = 0xff;
|
||||||
|
fd_set fdset;
|
||||||
|
struct timeval tv;
|
||||||
|
int retval = 0;
|
||||||
|
|
||||||
|
if ( write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2) ) {
|
||||||
|
if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) {
|
||||||
|
retval = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get rid of any chatter from the above */
|
||||||
|
FD_ZERO(&fdset);
|
||||||
|
FD_SET(fd, &fdset);
|
||||||
|
tv.tv_sec = 0;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) {
|
||||||
|
char temp[32];
|
||||||
|
read(fd, temp, sizeof(temp));
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Returns true if the mouse uses the IMPS/2 protocol */
|
/* Returns true if the mouse uses the IMPS/2 protocol */
|
||||||
static int detect_imps2(int fd)
|
static int detect_imps2(int fd)
|
||||||
{
|
{
|
||||||
int imps2;
|
int imps2;
|
||||||
|
|
||||||
imps2 = 0;
|
imps2 = 0;
|
||||||
|
|
||||||
|
/* rcg06112001 Attempt to set IMPS/2 mode first, even with envr var... */
|
||||||
|
set_imps2_mode(fd);
|
||||||
|
|
||||||
if ( getenv("SDL_MOUSEDEV_IMPS2") ) {
|
if ( getenv("SDL_MOUSEDEV_IMPS2") ) {
|
||||||
imps2 = 1;
|
imps2 = 1;
|
||||||
}
|
}
|
||||||
if ( ! imps2 ) {
|
if ( ! imps2 ) {
|
||||||
unsigned char query_ps2 = 0xF2;
|
Uint8 query_ps2 = 0xF2;
|
||||||
fd_set fdset;
|
fd_set fdset;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
|
|
||||||
/* Get rid of any mouse motion noise */
|
/* Get rid of any mouse motion noise */
|
||||||
FD_ZERO(&fdset);
|
FD_ZERO(&fdset);
|
||||||
FD_SET(fd, &fdset);
|
FD_SET(fd, &fdset);
|
||||||
|
@ -422,16 +465,10 @@ static int detect_imps2(int fd)
|
||||||
read(fd, temp, sizeof(temp));
|
read(fd, temp, sizeof(temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Query for the type of mouse protocol */
|
/* Query for the type of mouse protocol */
|
||||||
if ( write(fd, &query_ps2, 1) == 1 ) {
|
if ( write(fd, &query_ps2, sizeof (query_ps2)) == sizeof (query_ps2)) {
|
||||||
unsigned char ch = 0;
|
Uint8 ch = 0;
|
||||||
|
|
||||||
/* If you wanted to control the mouse mode:
|
|
||||||
Set IMPS/2 protocol:
|
|
||||||
{0xf3,200,0xf3,100,0xf3,80}
|
|
||||||
Reset mouse device:
|
|
||||||
{0xFF}
|
|
||||||
*/
|
|
||||||
/* Get the mouse protocol response */
|
/* Get the mouse protocol response */
|
||||||
do {
|
do {
|
||||||
FD_ZERO(&fdset);
|
FD_ZERO(&fdset);
|
||||||
|
@ -441,7 +478,7 @@ static int detect_imps2(int fd)
|
||||||
if ( select(fd+1, &fdset, 0, 0, &tv) < 1 ) {
|
if ( select(fd+1, &fdset, 0, 0, &tv) < 1 ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while ( (read(fd, &ch, 1) == 1) &&
|
} while ( (read(fd, &ch, sizeof (ch)) == sizeof (ch)) &&
|
||||||
((ch == 0xFA) || (ch == 0xAA)) );
|
((ch == 0xFA) || (ch == 0xAA)) );
|
||||||
|
|
||||||
/* Experimental values (Logitech wheelmouse) */
|
/* Experimental values (Logitech wheelmouse) */
|
||||||
|
@ -502,9 +539,16 @@ fprintf(stderr, "Using GPM mouse\n");
|
||||||
}
|
}
|
||||||
/* Now try to use the new HID unified mouse device */
|
/* Now try to use the new HID unified mouse device */
|
||||||
if ( mouse_fd < 0 ) {
|
if ( mouse_fd < 0 ) {
|
||||||
mouse_fd = open("/dev/input/mice", O_RDONLY, 0);
|
mouse_fd = open("/dev/input/mice", O_RDWR, 0);
|
||||||
if ( mouse_fd >= 0 ) {
|
if (mouse_fd < 0) {
|
||||||
mouse_drv = MOUSE_IMPS2;
|
mouse_fd = open("/dev/input/mice", O_RDONLY, 0);
|
||||||
|
}
|
||||||
|
if (mouse_fd >= 0) {
|
||||||
|
if (detect_imps2(mouse_fd)) {
|
||||||
|
mouse_drv = MOUSE_IMPS2;
|
||||||
|
} else {
|
||||||
|
mouse_drv = MOUSE_PS2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Now try to use a modern PS/2 port mouse */
|
/* Now try to use a modern PS/2 port mouse */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue