Implementing Usb Mouse


jokeman

Still Fresh
Joined
Feb 4, 2006
Messages
101
Location
Austria
Website
Visit site
hi!

i've a working USB host port... now i want to write a program using a USB mouse...

i downloaded the usb modules from http://www.artaylor.co.uk/~richard/gp2x/

i load the following modules:
usbcore.o
input.o
hid.o
keybdev.o
mousedev.o
mmsp2_usbh.o
usb-ohci.o
usb-ohci-mmsp2.o

i don't have much linux experience so i don't know, if all these modules are nessesary

when i connect a mouse i get
Code:
hub.c: new USB device <NULL>-1, assigned address 4
input: USB HID v1.11 Mouse [Logitech USB Receiver] on usb1:4.0

i tried cat /dev/input/mice like described in the linux USB guide and i got "bizarre looking characters" as i moved the mouse

then i modified SDLTest by Guyfawkes to catch mouse events:

Code:
void TestInput()
{
	bool endtest = false;
	char g_string[255];
	strcpy(g_string," ");

	while (!endtest)
	{
		SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0,0,0));
		drawText(screen, "Input Test", 0, 0, 255, 255, 255);
		drawText(screen, g_string, 0, 30, 255, 255, 255);
		drawText(screen, "Press START to exit", 0, 215, 255, 0, 0);
		SDL_Flip(screen);

		SDL_Event event;

		while( SDL_PollEvent( &event ) )
		{
			if(event.type == SDL_MOUSEBUTTONDOWN)
				strcpy(g_string,"Mouse is down.");

			if(event.type == SDL_MOUSEBUTTONUP)
				strcpy(g_string,"Mouse is up.");

			if(event.type == SDL_MOUSEMOTION)
				strcpy(g_string,"Mouse is being moved.");

			if(event.type == SDL_JOYBUTTONDOWN)
				if(event.jbutton.button == GP2X_BUTTON_START)
				{
					endtest=true;
				}
		}
	}
}


but it doesn't work....
i also tried to connect a keyboard and also get no SDL_KEY events
instead, the letters i type are displayed along the screen

any idea, how to use the mouse?
i don't think, the code is wrong... i think it's a driver (kernel?) thing and i havn't enough linux experience to figure it out :(

thanks for any help
 

paeryn

Reclusive maniac
Joined
Nov 28, 2005
Messages
432
Age
50
Location
Sheffield, England
Website
paeryn.myby.co.uk
I'll look into how Linux gets mouse information and add support in SDL as soon as I can. I'll buy the usbhost thingy soon (when I can afford it) so I can test it.
Same goes for the keyboard, though I've just had a quick look and I can't see where SDL's geting either from. I'll delve into it and try and have something basic by the weekend.
 

paeryn

Reclusive maniac
Joined
Nov 28, 2005
Messages
432
Age
50
Location
Sheffield, England
Website
paeryn.myby.co.uk
Vimacs posted on Apr 13 2006 at 12:39 AM said:
paeryn, just add a paypal adress to your sig, you will have the money in no time.
Cheers for the advice, I'm not really interested in making any money out of this, but the hardware doesn't buy itself :rolleyes:
 
Last edited by a moderator:

jokeman

Still Fresh
Joined
Feb 4, 2006
Messages
101
Location
Austria
Website
Visit site
paeryn, sounds great... that would help me very much
i'll test it when you are ready, if you want

would it also be possible to use two mice at the same time and get the x and y values from each mouse?
 

jokeman

Still Fresh
Joined
Feb 4, 2006
Messages
101
Location
Austria
Website
Visit site
hmm... good idea
i could read /dev/input/mouse0 and /dev/input/mouse1 to get data from both mice

is the data provided by the file like described here?

and how do i read the file? can i read it like a simple file? how do i know when the mouse sends new data?
 

paeryn

Reclusive maniac
Joined
Nov 28, 2005
Messages
432
Age
50
Location
Sheffield, England
Website
paeryn.myby.co.uk
I've looked into SDL's mouse code, everything seems to be there for fbcon so I'll copy that into my driver and make the changes to the input handler. Should be ready for testing on Saturday.
 

paeryn

Reclusive maniac
Joined
Nov 28, 2005
Messages
432
Age
50
Location
Sheffield, England
Website
paeryn.myby.co.uk
Sorry for the delay, I've got most of it done. I've had to take a few days off programming 'cause it hurts to type, but I'll try and get at least this done tonight for you.
 

paeryn

Reclusive maniac
Joined
Nov 28, 2005
Messages
432
Age
50
Location
Sheffield, England
Website
paeryn.myby.co.uk
I've updated the code on sourceforge, you can get the precompiled test version from here
The debug output should at least tell you it's looking for a mouse, it expects to find it at /dev/input/mouse/0
Proper keyboard support will be there soon, but GPH added stuff (for a serial keyboard I think), I'll cut that out and see what I can do. Don't know how it'll handle different keymaps yet.
 

jokeman

Still Fresh
Joined
Feb 4, 2006
Messages
101
Location
Austria
Website
Visit site
cool... the mouse is working! :)
great work!

is there also a way to use 2 mice? so that i get coordinates of 2 mouse pointer at the same time?
or do i have to do it the way theoddbot suggested?
 

paeryn

Reclusive maniac
Joined
Nov 28, 2005
Messages
432
Age
50
Location
Sheffield, England
Website
paeryn.myby.co.uk
The way it's set up at the moment is for just one mouse.
I've just had a quick look, it'll require a bit of hacking as SDL's not designed to cope with more than one.
Can you confirm whether the cursor responds properly to mouse movements, and if so whether it still does after SDL_WarpMouse() or SDL_MoveCursor()? I'm not totally sure whether SDL handles the mouse movements in those two functions or whether I have to.
There's only one cursor too (both in hardware and SDL), so you'll only ever be able to get events from the second, but that's not much of a loss.
I've got a few other things to add that I'm giving priority to over adding a 2nd mouse, but give me a week or so and I'll sort it out for you.
 

jokeman

Still Fresh
Joined
Feb 4, 2006
Messages
101
Location
Austria
Website
Visit site
the mouse movement is working fine...
after SDL_WarpMouse() the cursor shows up at the right coordinates
but when i move the mouse again, the cursor jumps back to its old position
 

paeryn

Reclusive maniac
Joined
Nov 28, 2005
Messages
432
Age
50
Location
Sheffield, England
Website
paeryn.myby.co.uk
Cheers, I thought that might be the case. I'll update that part tomorrow.
As I said, it'll be a few days before I start tackling getting the 2nd mouse in, but I'll try and give you an idea of how I'll be exposing the events beforehand.
Thanks for testing ;)
 

Epicenter

Very Active Member
Joined
Oct 9, 2005
Messages
2,068
Age
38
Location
USA
Website
www.epicgaming.us or http
Paeryn-- what is the status of compatibility of your hardware-accelerated SDL Library with USB *joysticks*? I'd very much enjoy using a USB gamepad to run the game I am developing .. at least until I install a D-Pad.
 

paeryn

Reclusive maniac
Joined
Nov 28, 2005
Messages
432
Age
50
Location
Sheffield, England
Website
paeryn.myby.co.uk
Epicenter posted on May 5 2006 at 05:31 PM said:
Paeryn-- what is the status of compatibility of your hardware-accelerated SDL Library with USB *joysticks*? I'd very much enjoy using a USB gamepad to run the game I am developing .. at least until I install a D-Pad.
I've not had much chance to do much, but I need to address the vsnyc issue with the latest firmware so I'll get it all done asap. If you've not heard owt from me in the next 2-3 days send me a virtual kick-up-the-backside.
I've not finished the joystick stuff, but I think I've fixed the vsync polarity, my test prog now runs at normal speed under FW2.0, if anyone can test if it still works under 1.4 (or earlier) I'd appreciate it. pre-compiled Source will be available when I finish adding USB joysticks.
Delay... I managed to lock linux up the other day whilst burning a DVD, unfortunately it corrupted some gconf data and I've not been able to restore it.
It has forced me into updating to Fedora Core 5, but it's going to be a few days before I get everything setup properly.
 
Last edited by a moderator:
Top