Skip to contentSkip to conversation

TurboMouse fix

DISCUSSION Tom Harrington 3 participants 9 messages Dec 22, 1998 – Dec 23, 1998

lore
Share & tools
lore
#0 lore raw

I've updated Mark Abene's "mousehack" fix for the Kensington Turbo Mouse to work with newer kernels. The source code is below.

It should compile straight away-- "cc mousehack.c". Then run the program, abd your TurboMouse should work as a 3-button mouse. If it works for you, put it somewhere convenient (like /sbin) and call it from /etc/rc.d/rc.local.

This has only been tested on a G3 desktop, running 2.1.125, with a version 5.0 TurboMouse. I'd appreciate feedback on how it works (or fails to work) with other setups.

See notes in the comments about tracking speed and button arrangement.

Tom Harrington

--- cut here ---
/* mousehack.c
*
* A program for linux-pmac by jonh Tue Feb 18 00:46:10 EST 1997
* hacked mercilessly by [email protected]: don't blame jonh for my bugs! *
* Now does magic for the Kensington turbo mouse trackball ([email protected])
* 8/30/98
*
* Minor update to make it work with 2.1.125 ([email protected]) 12/21/1998
* - If tracking is too fast, use "xset" to fix it.
* - If button arrangement seems weird, use "xmodmap". The default is:
* lower left = 1, lower right = 2, upper left = 3, upper left = off.
* xmodmap -e "pointer = 1 3 2" works for me.
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <asm/adb_mouse.h>
#include <asm/cuda.h>

int fd;

void
send(unsigned char *y, int len)

{
    int n;
#ifdef DEBUG
    printf("send: ");
    for (n=0; n < len; n++)
	printf("0x%02x ",y[n]);
    printf("\n");

#endif

    n = write(fd, y, (size_t) len);
    if (n < len) {
	perror("writing /dev/adb");
	close(fd);
	exit (EXIT_FAILURE);
    }
}

void
listen(unsigned char *y)

{
    int n;
    
    n = read(fd, y, 80);
#ifdef DEBUG
    printf("%d: ",n);
    if (n > 0) {
	int i;
	for (i=0; i < n; i++)
	    printf("0x%02x ",y[i]);
    }
    printf("\n");

#endif

    if (n < 0) {
	perror("reading /dev/adb");
	close(fd);
	exit(EXIT_FAILURE);
    }
}

void
sethandler(int addr, int handler)

{
    unsigned char y[15];

    y[0] = ADB_PACKET;
    /* mouse (0x30) listen (0x08) reg 3 (0x03) */
    y[1] = ADB_WRITEREG(addr, 3);
    /* service request enable (0x20), device addr 3 (0x03) */
    y[2] = 0x20 + addr;
    y[3]= handler;

    send(y, 4);
    listen(y);
}

void
moveadb(int src, int dst)

{
	unsigned char y[15];
	
	y[0] = ADB_PACKET;
	y[1] = ADB_WRITEREG(src, 3);
	y[2] = 0x20 + dst;
	y[3] = 0xfe;

	send(y, 4);
	listen(y);
}

void
initreg2()

{
	unsigned char x[15];
	unsigned char y[] = { ADB_PACKET, ADB_WRITEREG(3, 2), 0xe7, 0x8c, 0, 0, 0, 0xff, 0xff, 0x94 };
	send(y, 10);
	listen(x);

	x[0] = ADB_PACKET;
	x[1] = 0x31;	/* flush device 3 */
	send(x, 2);
	listen(x);
}

void
setreg2()

{
	unsigned char y[] = { ADB_PACKET, ADB_WRITEREG(3, 2), 0xa5, 0x14, 0, 0, 0x69, 0xff, 0xff, 0x27 };
	send(y, 10);
	listen(y);
}

int
main(int argc, char **argv)

{
	fd = open("/dev/adb", O_RDWR);
	if (fd <= 0) {
		perror("opening /dev/adb");
		exit(EXIT_FAILURE);
	}
  
    	sethandler(15, -1);	/* tph */
	sethandler(3, 4);
	moveadb(3, 15);
	initreg2();
	setreg2();

	close(fd);
	return 0;
}

--- cut here ---

[[ This message was sent via the linuxppc-dev mailing list. Replies are ]] [[ not forced back to the list, so be sure to Cc linuxppc-dev if your ]] [[ reply is of general interest. To unsubscribe from linuxppc-dev, send ]] [[ the message 'unsubscribe' to [email protected] ]]

#1 lore raw
Quoted 3 lines

I've updated Mark Abene's "mousehack" fix for the Kensington Turbo Mouse to work with newer kernels. The source code is below.

<snip>

Quoted 3 lines

This has only been tested on a G3 desktop, running 2.1.125, with a version 5.0 TurboMouse. I'd appreciate feedback on how it works (or fails to work) with other setups.

system: 7500 chasis with 166 MHz 604 card, 2.1.127 kernel. Kensington TurboMouse 4.0 (the 2 button kind), window maker 0.20.3

(do you need to know anything else? sorry, I'm still a wet behind the ears...)

exported mail to ~, trimmed file in pico, then cc mousehack.c.

gives :
/tmp/cca082751.o: In function `sethandler':
/tmp/cca082751.o(.text+0x148): undefined reference to ADB-WRITEREG' (same error repeated at (.text+0x1dc) in function moveadb'

                        (.text+0x26c) in function `initreg2'
                        (.text+0x364) in function `setreg2'

collect2: ld returned 1 exit status

ack! what now? I'm drooling at the thought of a functional 2 button mouse, and if it only ends up working with v5.0 TurboMice, Santa might have to make a late delivery...

john.
[email protected]
www.treefort.org/~jacobs/ <--- LinuxPPC notes'n'stuff...

[[ This message was sent via the linuxppc-dev mailing list. Replies are ]] [[ not forced back to the list, so be sure to Cc linuxppc-dev if your ]] [[ reply is of general interest. To unsubscribe from linuxppc-dev, send ]] [[ the message 'unsubscribe' to [email protected] ]]

#2 lore raw
Quoted 13 lines

system: 7500 chasis with 166 MHz 604 card, 2.1.127 kernel. Kensington TurboMouse 4.0 (the 2 button kind), window maker 0.20.3

(do you need to know anything else? sorry, I'm still a wet behind the ears...)

exported mail to ~, trimmed file in pico, then cc mousehack.c.

gives :
/tmp/cca082751.o: In function `sethandler':
/tmp/cca082751.o(.text+0x148): undefined reference to ADB-WRITEREG' (same error repeated at (.text+0x1dc) in function moveadb'

Quoted 7 lines
                        (.text+0x26c) in function `initreg2'
                        (.text+0x364) in function `setreg2'

collect2: ld returned 1 exit status

ack! what now? I'm drooling at the thought of a functional 2 button mouse, and if it only ends up working with v5.0 TurboMice, Santa might have to make a late delivery...

Hmm, maybe something in your header files? ADB_WRITEREG is defined (on my system) in /usr/include/asm/adb_mouse.h. Look for this file and see what's there.

I'm surprised it complains about "ADB-WRITEREG" when the code uses "ADB_WRITEREG". You didn't happen to "fix" this while trimming the file in pico, did you?

I really don't know if mousehack is useful (or even necessary) with a v4.0 TurboMouse. I assume you've tried the "mousemode" command?

Tom

[[ This message was sent via the linuxppc-dev mailing list. Replies are ]] [[ not forced back to the list, so be sure to Cc linuxppc-dev if your ]] [[ reply is of general interest. To unsubscribe from linuxppc-dev, send ]] [[ the message 'unsubscribe' to [email protected] ]]

#3 lore raw
Quoted 4 lines

Hmm, maybe something in your header files? ADB_WRITEREG is defined (on my system) in /usr/include/asm/adb_mouse.h. Look for this file and see what's there.

OMM, the /usr/include/asm dir is a symlink to asm-ppc in the kernel source, which is 2.1.131. That file contains a struct def for mouse_status, and that's all. The ADB_WRITEREG, etc. #defines are in adb.h.

Quoted 3 lines

I'm surprised it complains about "ADB-WRITEREG" when the code uses "ADB_WRITEREG". You didn't happen to "fix" this while trimming the file in pico, did you?

No, I screwed up while re-typing the error messages into my email. Nothing in between the --cut here-- and --cut here-- (or whatever you had delimiting the code) was changed.

(Is it just me, or is everybody assuming I'm way more stupid than is necessary? I followed instructions, and when that didn't work, I provided the requested feedback, and so far I've got two condescending emails to show for it.)

Quoted 2 lines

I really don't know if mousehack is useful (or even necessary) with a v4.0 TurboMouse. I assume you've tried the "mousemode" command?

Well, Mark Abene(sp?) has said in this thread that mousehack doesn't work with the 4.0 balls. I've tried mousemode; the mouse just switches back.

Maybe it's time to start shopping for one of the 5.0 turbo mice -- too bad, the design and construction seems a lot more solid on the 4.0 models.

john.
[email protected]
www.treefort.org/~jacobs

[[ This message was sent via the linuxppc-dev mailing list. Replies are ]] [[ not forced back to the list, so be sure to Cc linuxppc-dev if your ]] [[ reply is of general interest. To unsubscribe from linuxppc-dev, send ]] [[ the message 'unsubscribe' to [email protected] ]]

#4 lore raw
Quoted 9 lines
Quoted 4 lines

Hmm, maybe something in your header files? ADB_WRITEREG is defined (on my system) in /usr/include/asm/adb_mouse.h. Look for this file and see what's there.

OMM, the /usr/include/asm dir is a symlink to asm-ppc in the kernel source, which is 2.1.131. That file contains a struct def for mouse_status, and that's all. The ADB_WRITEREG, etc. #defines are in adb.h.

Err... hmm. I can't quite account for that. I did make a mistake in that the macro is defined in cuda.h, not adb_mouse.h, on my system. But I'm running a pretty basic R4 install, upgraded to 2.1.125. Maybe you chose different install options than I did? IIRC I told it to give me every programming-related option available.

If you see the definition in adb.h on your box, then adding "#include asm/adb.h", and deleting either adb_mouse.h or cuda.h, (whichever gcc doesn't like) should get it compiling.

Can anyone else account for the header file discrepancy?

Quoted 4 lines
Quoted 3 lines

I'm surprised it complains about "ADB-WRITEREG" when the code uses "ADB_WRITEREG". You didn't happen to "fix" this while trimming the file in pico, did you?

Quoted 8 lines

No, I screwed up while re-typing the error messages into my email. Nothing in between the --cut here-- and --cut here-- (or whatever you had delimiting the code) was changed.

(Is it just me, or is everybody assuming I'm way more stupid than is necessary? I followed instructions, and when that didn't work, I provided the requested feedback, and so far I've got two condescending emails to show for it.)

Two of the most painful lessons of programming are:
1. Everyone makes the stupidest mistakes, all the time.
2. If you don't understand #1, you will still make stupid mistakes, but it will take you FOREVER to find them.

Yes, I suggested that you might have made a stupid mistake. That doesn't mean I was suggesting that _you_ are stupid. If you do understand #1, you learn to look for stupid mistakes right from the start (I _still_ use "=" for "==" sometimes, but now I know to expect it).

Quoted 5 lines
Quoted 2 lines

I really don't know if mousehack is useful (or even necessary) with a v4.0 TurboMouse. I assume you've tried the "mousemode" command?

Well, Mark Abene(sp?) has said in this thread that mousehack doesn't work with the 4.0 balls. I've tried mousemode; the mouse just switches back.

Yeah, it sounds like the 4.0 TurboMouse is pretty weird in this regard. They could have just used the extended mouse protocol, after all.

Tom

[[ This message was sent via the linuxppc-dev mailing list. Replies are ]] [[ not forced back to the list, so be sure to Cc linuxppc-dev if your ]] [[ reply is of general interest. To unsubscribe from linuxppc-dev, send ]] [[ the message 'unsubscribe' to [email protected] ]]

#5 lore raw
Quoted 9 lines · Tom Harrington
Quoted 8 lines
Quoted 3 lines

Hmm, maybe something in your header files? ADB_WRITEREG is defined (on my system) in /usr/include/asm/adb_mouse.h. Look for this file and see what's there.

OMM, the /usr/include/asm dir is a symlink to asm-ppc in the kernel source, which is 2.1.131. That file contains a struct def for mouse_status, and that's all. The ADB_WRITEREG, etc. #defines are in adb.h.

Quoted 5 lines

Err... hmm. I can't quite account for that. I did make a mistake in that the macro is defined in cuda.h, not adb_mouse.h, on my system. But I'm running a pretty basic R4 install, upgraded to 2.1.125. Maybe you chose different install options than I did? IIRC I told it to give me every programming-related option available.

That's also what I did, IIRC. Keep in mind that while I'm booting off the 2.1.127 kernal, using BootX, all my kernel sources are 2.1.131. Am I wrong to think that things might have moved around?

Quoted 4 lines

If you see the definition in adb.h on your box, then adding "#include asm/adb.h", and deleting either adb_mouse.h or cuda.h, (whichever gcc doesn't like) should get it compiling.

Actually, it's not necessary to remove anything; just adding

	#include <asm/adb.h>

below the last #include results in happy source, which complies into a.out. Woo hoo! Running the code _does_ have an effect -- two to be exact. Before running the code, left button was mouse1 and right button either did nothing or produced seriously wacky results in a non-intuitive way. After running the code, right button maps to mouse2! A step in the right direction. However, left button is now mapped to some funky click-lock like mode, where one click causes it to act like a depress-and-hold. You have to double-click to get a single click effect, 4Xclick to 2Xclick.

Any ideas why that's happening?

Quoted 4 lines

Two of the most painful lessons of programming are:
1. Everyone makes the stupidest mistakes, all the time.
2. If you don't understand #1, you will still make stupid mistakes, but it will take you FOREVER to find them.

For me, 1. expresess itself via using numeric comparison operators in Perl when I should use string comparison operators (I can't get it thru my head that (==) != (eq) )

Quoted 5 lines

Yes, I suggested that you might have made a stupid mistake. That doesn't mean I was suggesting that _you_ are stupid. If you do understand #1, you learn to look for stupid mistakes right from the start (I _still_ use "=" for "==" sometimes, but now I know to expect it).

Sorry -- I may over over-read your original reply. I'm touchy this time of year -- all that Xmas cheer stuff.

Quoted 1 line

They could have just used the extended mouse protocol, after all.

Prrotocols? We don't need no steekin' protocols!

john.
[email protected]
www.treefort.org/~jacobs

[[ This message was sent via the linuxppc-dev mailing list. Replies are ]] [[ not forced back to the list, so be sure to Cc linuxppc-dev if your ]] [[ reply is of general interest. To unsubscribe from linuxppc-dev, send ]] [[ the message 'unsubscribe' to [email protected] ]]

#6 lore raw
In reply to john s jacobs anderson

Three things:

1) mousehack is **ONLY** for TurboMouse 5.0 trackballs! Not two button 4.0's. I had written a hack last year for my 4.0, but abandoned it when I got a 5.0. The 4.0 would actually require kernel mods to the ADB code since the two buttons send left and right arrow-key keycodes, and the kernel would have to recognize that they were coming from a different ADB address in order to properly treat them as mouse-button events. Otherwise, the kernel just thinks you have two keyboards. At least in kernel 2.1.24, the adb code treats anything with dev-handler 2 as a keyboard, which in this case is faulty logic.

2) You should NEVER edit source code with pico, since it breaks wrapped lines which turns source code into useless mulch.

3) Did you type in your error messages by hand? The macro used in my program is ADB_WRITEREG, with an underscore, not a hyphen. It's no shock that the hyphenated version is undefined, as it don't exist.

-Mark

Quoted 19 lines · john s jacobs anderson

<snip>

system: 7500 chasis with 166 MHz 604 card, 2.1.127 kernel. Kensington TurboMouse 4.0 (the 2 button kind), window maker 0.20.3

(do you need to know anything else? sorry, I'm still a wet behind the ears...)

exported mail to ~, trimmed file in pico, then cc mousehack.c.

gives :
/tmp/cca082751.o: In function `sethandler':
/tmp/cca082751.o(.text+0x148): undefined reference to ADB-WRITEREG' (same error repeated at (.text+0x1dc) in function moveadb'

                        (.text+0x26c) in function `initreg2'
                        (.text+0x364) in function `setreg2'

collect2: ld returned 1 exit status

Quoted 8 lines

ack! what now? I'm drooling at the thought of a functional 2 button mouse, and if it only ends up working with v5.0 TurboMice, Santa might have to make a late delivery...

john.
[email protected]
www.treefort.org/~jacobs/ <--- LinuxPPC notes'n'stuff...

...

[[ This message was sent via the linuxppc-dev mailing list. Replies are ]] [[ not forced back to the list, so be sure to Cc linuxppc-dev if your ]] [[ reply is of general interest. To unsubscribe from linuxppc-dev, send ]] [[ the message 'unsubscribe' to [email protected] ]]

#7 lore raw

Bad morning, Mark?

Quoted 8 lines

1) mousehack is **ONLY** for TurboMouse 5.0 trackballs! Not two button 4.0's. I had written a hack last year for my 4.0, but abandoned it when I got a 5.0. The 4.0 would actually require kernel mods to the ADB code since the two buttons send left and right arrow-key keycodes, and the kernel would have to recognize that they were coming from a different ADB address in order to properly treat them as mouse-button events. Otherwise, the kernel just thinks you have two keyboards. At least in kernel 2.1.24, the adb code treats anything with dev-handler 2 as a keyboard, which in this case is faulty logic.

ok.

Quoted 2 lines

2) You should NEVER edit source code with pico, since it breaks wrapped lines which turns source code into useless mulch.

did you look at the source? none of the lines were that long; I didn't have emacs open, and vi(m) still gives me headaches. But thanks for the heads up.

Quoted 3 lines

3) Did you type in your error messages by hand? The macro used in my program is ADB_WRITEREG, with an underscore, not a hyphen. It's no shock that the hyphenated version is undefined, as it don't exist.

yes, I did, and yes, my finger apparently slipped off the shift key for the duration of the - keystroke. Mea maxima culpa, eh?

john.

[[ This message was sent via the linuxppc-dev mailing list. Replies are ]] [[ not forced back to the list, so be sure to Cc linuxppc-dev if your ]] [[ reply is of general interest. To unsubscribe from linuxppc-dev, send ]] [[ the message 'unsubscribe' to [email protected] ]]

#8 lore raw

FD_SET/FD_ZERO, vi clone compiling

In reply to Tom Harrington

Forgive the FAQ, but it's not in the FAQ-O-Matic, and I know I've seen it answered on this list before (that email is saved on the Mac side, and I'm running a monster Perl script, so I can't reboot right at the moment).

I keep getting errors that refer to undefined references to __FD_SET and __FD_ZERO when I'm compiling stuff. How do I fix this?

On a different note, has anyone successfully compiled the late-ish versions of any of the vi clones (vim, elvis, vile) under LinuxPPC? That's where I'm getting those errors...

Thanks,
john.
[email protected]
www.treefort.org/~jacobs <-- LinuxPPC stuff...

[[ This message was sent via the linuxppc-dev mailing list. Replies are ]] [[ not forced back to the list, so be sure to Cc linuxppc-dev if your ]] [[ reply is of general interest. To unsubscribe from linuxppc-dev, send ]] [[ the message 'unsubscribe' to [email protected] ]]