Opened 13 years ago

Closed 13 years ago

#7429 closed enhancement (fixed)

BJoystick and usb_joy patch

Reported by: caz_haiku Owned by: mmlr
Priority: normal Milestone: R1
Component: Kits/Device Kit Version: R1/Development
Keywords: Cc: mdisreali@…
Blocked By: Blocking:
Platform: All

Description

Patch for BJoystick, i have tested it with different applications and can use a joystick normally in these apps. This BJoystick patch does not yet parse joystick configuration files etc, not sure this is even needed anymore because most people will use usb. But this could be completed as most of the work has been done already by various people in JoystickTweaker if backward compatibility is critical.

Also a patch for the usb_joy driver, it works with this BJoystick. There was a problem with the usb_joy driver causing a crash, this has been fixed. The bug was to do with realloc in driver.c. Now whether you want to enable the usb_joy driver for haiku is another matter. But at least for now people can use some of the supported gamepads etc that usb_joy supports.

Attachments (4)

joystick_usbjoy.diff (14.0 KB ) - added by caz_haiku 13 years ago.
BJoystick and usb_joy patch
listusb_rumblepad.txt (16.0 KB ) - added by Disreali 13 years ago.
usbjoy_v2.patch (14.0 KB ) - added by Disreali 13 years ago.
BeSnesx_controler_setup.png (147.9 KB ) - added by Disreali 13 years ago.

Download all attachments as: .zip

Change History (17)

by caz_haiku, 13 years ago

Attachment: joystick_usbjoy.diff added

BJoystick and usb_joy patch

comment:1 by caz_haiku, 13 years ago

patch: 01

comment:2 by Disreali, 13 years ago

Cc: mdisreali@… added

Thanks Caz.

I'm really excited about this. Will test when I have access to my Haiku systems later this week.

comment:3 by Disreali, 13 years ago

Version: R1/alpha2R1/Development

I attempted to apply the patch to hrev41190, but there were a couple lines about which jam complained. Attaching an updated patch. I found no difference in how my Logitech USB RumblePad2 behaved in BeSnes9x_1.41.

I also ran the testjoy cmd that you attached to here, but after nothing happened, I had to CTRL-C to get back to the Terminal. Output below:

hdev/haiku/joystick_gamepad_testing/joystick_test_code> testjoy /dev/bus/usb/3/1
ioctl - 0
ioctl - 0

Standard mode test: press both buttons to quit
axes 0 =      0
axes 1 =      0
button 0 = off
button 1 = off

I'm curious if the it is because my controller is wireless that I have no luck.

by Disreali, 13 years ago

Attachment: listusb_rumblepad.txt added

by Disreali, 13 years ago

Attachment: usbjoy_v2.patch added

comment:4 by caz_haiku, 13 years ago

Hey Disraeli,

Thanks for trying the patch, and correcting it.

The testjoy app should be run as testjoy /dev/joystick/usb_haiku/0 for example. Also make sure the driver is installed properly in /boot/home/config/addons/kernel/drivers/bin/ and a symbolic link to this file in /boot/home/config/addons/kernel/drivers/dev/ Also the new libdevice.so must be built and can be installed in the lib folder of the app you are testing or copied to haiku's library folder. It is possible after doing this that your gamepad won't be compatible with the usb_joy driver. The usb_joy driver is not built by default for haiku as you probably know. Caz

comment:5 by caz_haiku, 13 years ago

Here is a ready to use package for testing http://www.cemist.f2s.com/usbjoyhaiku.zip

in reply to:  4 comment:6 by Disreali, 13 years ago

Replying to caz_haiku:

The testjoy app should be run as testjoy /dev/joystick/usb_haiku/0 for example.

I do not have a /dev/joystick/... device listed in my systems dev tree. I used the device address from listusb as can be seen here

Also make sure the driver is installed properly in /boot/home/config/addons/kernel/drivers/bin/ and a symbolic link to this file in /boot/home/config/addons/kernel/drivers/dev/ Also the new libdevice.so must be built and can be installed in the lib folder of the app you are testing or copied to haiku's library folder. It is possible after doing this that your gamepad won't be compatible with the usb_joy driver. The usb_joy driver is not built by default for haiku as you probably know. Caz

I was not aware of these requirements. I'll try again with your most resent version.

comment:7 by Disreali, 13 years ago

I copied the usb_joy file to where you directed, made a link to it in .../drivers/dev, and suddenly there was a /dev/joystick listing. After re-booting, I re-ran the testjoy cmd and got the following uptput:

Welcome to the Haiku shell.
/hdev/haiku/patches/joystick/joystick_test_code> testjoy /dev/joystick/usb_haiku/0
ioctl - 0
ioctl - 12

Standard mode test: press both buttons to quit
axes 0 =      0
axes 1 =      0
button 0 = off
button 1 = off

I still had to use CTRL-C to get back to the prompt.

I also created a lib dir under the BeSnes dir to which I copied the libdevice.so, tried setting BeSnes to use the gamepad, but got nothing.

At least testjoy did something this time.

comment:8 by Disreali, 13 years ago

Out of curiosity, I ran the testjoy cmd included in the xbox360_driver_0.2.zip and got different results. The button 0 and button 1 would turn on and off as I press the corresponding buttons on the controller. Also, I did not need to use CTRL-C to quit testjoy. Pressing both buttons ended the test. (Output below)

I noticed that the xbox360_driver_0.2 has lib/libdevice.so, while joystick_test_code has lib/libdevicetest.so. That may account for my previous test not working. I ran both testjoy cmds as is after unzipping the archives.

StickIt also worked when run from the xbox360_driver dir. It is very cool to see the controller actually do something.

Since I had such luck with the stuff in the xbox360_driver dir, I copied the xbox360 driver to /boot/home/config/add-ons/kernel/drivers/bin/ and made the appropriate symlink in /dev. I tested beSnesx_1.41 again, but it still would not work with my Logitech Rumblepad. Attempting to set Controller2 resulted in all being set to |(0)B(4). It may not have worked, but it was a different result. In my previous attempt, i would get no change when trying to set buttons.

Also, I see that you include the source and project files. Are you building these on BeOS?

testjoy output:

/hdev/haiku/patches/joystick/xbox360_driver-0.2> testjoy /dev/joystick/usb_haiku/0

Standard mode test: press both buttons to quit
axes 0 =      0
axes 1 =   -256
button 0 = ON 
button 1 = ON 

Enhanced mode test: press first two buttons to quit
Device: Joystick
Module: Module

Axis 0:      0
Axis 1:   -256
Axis 2:   -256
Axis 3:      0
Button 0: ON 
Button 1: ON 
Button 2: off
Button 3: off
Button 4: off
Button 5: off
Button 6: off
Button 7: off
Button 8: off
Button 9: off
Button 10: off
Button 11: off
/hdev/haiku/patches/joystick/xbox360_driver-0.2> 

by Disreali, 13 years ago

Attachment: BeSnesx_controler_setup.png added

comment:9 by caz_haiku, 13 years ago

Ok, it looks like the usb_joy driver works but hopefully the reason it does not work in BeS9x is because of different libraries being used, i admit it's a bit confusing. If stickit works then BeS9x should also. I've uploaded a libdevice.so here http://www.cemist.f2s.com/lib.zip which should be placed in the BeS9x directory and it should work. It's the same code as my patch. The xbox360 driver only works with xbox360 controllers. I'm building the code on haiku using BeIDE. Thanks for the feedback.

comment:10 by caz_haiku, 13 years ago

Sorry for going missing for a while, i had to work in the evenings last month and over the next few months and won't be able to contribute properly, i do still want to contribute though. I saw some action on haiku development mailing list about joysticks and i think i know why BeSnes9x doesn't work properly with usb_joy. The reason is because the usb_hid driver detects gamepads as a mouse it intereferes with usb_joy, both drivers are accessing the hardware at the same time. I've reproduced what you have noticed disraeli that the joystick configuration window just populates all or some of the boxes with the same buttons etc.

I had fixed this problem with a temporary kludge on my haiku and it wasn't happening, for usb_joy to work properly you will have to stop usb_hid detecting your gamepad, joystick etc as a mouse. Here is the kludge i used in the file src/add-ons/kernel/drivers/input/usb_hid. Because my mouse has a wheel and a gamepad doesn't then this stops usb_hid from detecting a gamepad and then usb_joy works.

ProtocolHandler *
MouseDevice::AddHandler(HIDDevice *device, HIDReport *report)
{
	// try to find at least an x and y axis
	HIDReportItem *xAxis = report->FindItem(B_HID_USAGE_PAGE_GENERIC_DESKTOP,
		B_HID_UID_GD_X);
	if (xAxis == NULL)
		return NULL;

	HIDReportItem *yAxis = report->FindItem(B_HID_USAGE_PAGE_GENERIC_DESKTOP,
		B_HID_UID_GD_Y);
	if (yAxis == NULL)
		return NULL;

	HIDReportItem *wheel = report->FindItem(B_HID_USAGE_PAGE_GENERIC_DESKTOP,
		B_HID_UID_GD_WHEEL);
	if(wheel == NULL)
		return NULL;

	return new(std::nothrow) MouseDevice(report, xAxis, yAxis);
}

Now i'm not saying that usb_joy should be enabled in Haiku src tree, but the driver works 100% here with a few gamepads i have and could at least be used temporarily if users were willing to build their own.

Carwyn

comment:11 by mmlr, 13 years ago

See #7354. I'll add joystick/gamepad support to usb_hid as part of/right after the restructuring. I'll see about applying the relevant BJoystick patch parts (after a style cleanup) as well.

comment:12 by mmlr, 13 years ago

Owner: changed from nobody to mmlr
Status: newin-progress

comment:13 by mmlr, 13 years ago

Resolution: fixed
Status: in-progressclosed

Reworked parts of BJoystick in hrev41849, in part based on the patch attached here. JoystickProtocolHandler implemented in hrev41851. So joysticks, gamepads and multiaxis controllers should now be enumerable and usable through BJoystick (and therefore by applications using that interface). I'm closing this ticket, please add reports for bugs in said implementation as new tickets.

Note: See TracTickets for help on using tickets.