Joystick Axis Mapping Bug

Hi, I recently acquired a 4-port Playstation2 => USB adapter, which SDL
identifies as “WiseGroup.,Ltd MP-8800 Quad USB Joypad”.

When I attempt to use this joystick with SDL, the events I receive
aren’t correct. The dpad Y-Axis for player 2 is mapped to the left
analogue X-Axis for player 1.

But when I run jstest /dev/js0, everything is on its own axis. Player
2’s dpad Y-Axis is on axis 19, according to jstest.

So, the problem seems to be in SDL, somewhere.

Is it common practice in SDL to write code for specific joysticks that
misbehave? If so, I’d like to try to write a patch for this. What file
should I modify? (I’m running SDL 1.2.7).
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040622/f1963473/attachment.pgp

To answer my own question, there does seem to be special casing built
into SDL’s joystick handling code. I’ll try adding a special case for my
joystick.

-ChrisOn Tue, 2004-06-22 at 15:49, Chris Nelson wrote:

Hi, I recently acquired a 4-port Playstation2 => USB adapter, which SDL
identifies as “WiseGroup.,Ltd MP-8800 Quad USB Joypad”.

When I attempt to use this joystick with SDL, the events I receive
aren’t correct. The dpad Y-Axis for player 2 is mapped to the left
analogue X-Axis for player 1.

But when I run jstest /dev/js0, everything is on its own axis. Player
2’s dpad Y-Axis is on axis 19, according to jstest.

So, the problem seems to be in SDL, somewhere.

Is it common practice in SDL to write code for specific joysticks that
misbehave? If so, I’d like to try to write a patch for this. What file
should I modify? (I’m running SDL 1.2.7).



SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040622/987d8668/attachment.pgp

— Chris Nelson wrote:

Hi, I recently acquired a 4-port Playstation2 => USB
adapter, which SDL
identifies as “WiseGroup.,Ltd MP-8800 Quad USB
Joypad”.

Cool. How much was it, and where’d you buy it? I have
a Super Joybox 5 I bought at liksang.com for $20. Its
only problem is that it is one HIDs with a Windows
driver that interprets this HIDs and separates it into
4 new HIDs. It would be easy enough to write it for
other platforms though. It sounds like yours is the
same way. (We might even have the same one for all i
know)

When I attempt to use this joystick with SDL, the
events I receive
aren’t correct. The dpad Y-Axis for player 2 is
mapped to the left
analogue X-Axis for player 1.

Are you saying that multiple axes on your controllers
are being represented by the same axis index?

But when I run jstest /dev/js0, everything is on its
own axis. Player
2’s dpad Y-Axis is on axis 19, according to jstest.

So, the problem seems to be in SDL, somewhere.

Could I see your code?

Is it common practice in SDL to write code for
specific joysticks that
misbehave?

No

If so, I’d like to try to write a patch
for this. What file
should I modify? (I’m running SDL 1.2.7).

Maybe you’d be better off buying that adaptor and
having it shipped to Sam. I have the Super Joybox 5
and it was only 20 plus 5 shipping. It works just fine
in OS X for my SDL project, but for some reason Quake3
/ UrT won’t recognize it (or I’m too ignorant to
configure it properly.)

ATTACHMENT part 1.2 application/pgp-signature
name=signature.asc> _______________________________________________
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

Cool. How much was it, and where’d you buy it?

It was $12.50, and I got it from here:

http://www.advancelogicsystem.com/product_info.php?products_id=152

Are you saying that multiple axes on your controllers
are being represented by the same axis index?

Indeed. What was happening was that there actually was a special case
written for this very device, in
src/joysticks/linux/SDL_sysjoystick.c… The author did a very good job
setting up a framework to handle annoying joysticks, but he didn’t quite
grasp just how annoying this particular joystick is.

When you plug in different numbers of joysticks, all the axes are
remapped in completely different ways. Thus, the code he wrote was
likely correct for a certain number of controllers, but failed on every
other number.

Could I see your code?

Quite shortly I’ll be posting a fixed version of
src/joysticks/linux/SDL_sysjoystick.c, that also handles this joystick,
as well as its little brother (which has 2 ports, and the same quirky
behavior). The 4-porter already works just fine, no matter how many
joysticks are plugged in. I just need to get the mappings right for the
2-porter.

Stay tuned…

-Chris

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040623/5b5cc318/attachment.pgp

Are you saying that multiple axes on your controllers
are being represented by the same axis index?

Indeed. What was happening was that there actually was a special case
written for this very device, in
src/joysticks/linux/SDL_sysjoystick.c… The author did a very good job
setting up a framework to handle annoying joysticks,

Thanks :wink:

but he didn’t quite
grasp just how annoying this particular joystick is.

When you plug in different numbers of joysticks, all the axes are
remapped in completely different ways. Thus, the code he wrote was
likely correct for a certain number of controllers, but failed on every
other number.

What I basically did was take a single controller, plugged it into port 1
and wrote down the value for each axis and button, then plugged it
into port 2, 3, and 4, and did the same thing – testing a single
port at a time. The values that I got for each were unique. Then I
tested it with two joysticks, one in port 1 and the other in port 2; I
got the same values. From there I jumped to the (aparently wrong?)
conclusion that the mapping was a linear map from each port to a static
set of buttons/axes/hats.

Is this something specific with the dance pad (I don’t own one so I
can’t test)? I’m supprised that the controller would go to the trouble
of anything other than a linear mapping (though I’ve certainly seen
dumber things).

Could I see your code?

Quite shortly I’ll be posting a fixed version of
src/joysticks/linux/SDL_sysjoystick.c, that also handles this joystick,
as well as its little brother (which has 2 ports, and the same quirky
behavior). The 4-porter already works just fine, no matter how many
joysticks are plugged in. I just need to get the mappings right for the
2-porter.

I’d be happy to test it once you’ve got something working. I need to
feed my zsnes craving anyway.

DaveOn Wed, 23 Jun 2004, Chris Nelson wrote:

Greetings, Mr Author!

What I basically did was take a single controller, plugged it into port 1
and wrote down the value for each axis and button, then plugged it
into port 2, 3, and 4, and did the same thing – testing a single
port at a time. The values that I got for each were unique. Then I
tested it with two joysticks, one in port 1 and the other in port 2; I
got the same values. From there I jumped to the (aparently wrong?)
conclusion that the mapping was a linear map from each port to a static
set of buttons/axes/hats.

Woah, really? Mine’s behaving very very differently than you describe.
When I plug in a controller, it doesn’t matter what port I’m using, the
mapping of the axes / buttons is always the same, as seen by jstest.
This is under linux 2.4.24 and 2.6.7… How does yours behave? Can you
see all 48 possible buttons, even when only a single controller is
plugged in? I can only see 12 buttons per plugged in controller (which I
used to get SDL to correctly report how many logcial joysticks are
available).

Also, on a hunch, could you tell me the results of lsmod | grep joydev?
Mine gives me joydev and input as the two modules. In my experience it
actually matters whether these are modules or not. I can test this
explicitly, if anybody’s curious.

Is this something specific with the dance pad (I don’t own one so I
can’t test)? I’m supprised that the controller would go to the trouble
of anything other than a linear mapping (though I’ve certainly seen
dumber things).

I haven’t tested this with a dance pad, though I begin to wonder how a
dance pad would behave… If up/down are share an axis (which they do,
both according to jstest), then it wouldn’t be possible to press up and
down simultaneously… IIRC, one has to press left, right, and start on
the dance pad to get the adapter into “dance pad mode”. Do you know any
more about this? I have a pair of DDR pads, so I can test this later, at
which point I’ll post my results.

I’d be happy to test it once you’ve got something working. I need to
feed my zsnes craving anyway.

Groovy. It’s available at:

http://cs-people.bu.edu/chrisn1/SDL_sysjoystick.c

Just drop it into the cvs version of SDL (or any other version, I
guess), and let me know how it behaves.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040623/6fcaf54e/attachment.pgp

— Chris Nelson wrote:

Cool. How much was it, and where’d you buy it?

It was $12.50, and I got it from here:

http://www.advancelogicsystem.com/product_info.php?products_id=152

Visually, that really is the exact same product I
have, but mine is not Sony it is Mayflash. Does your
packaging say Sony on it? I can see how someone at
advancelogicsystem.com might have accidentally wrote
Sony because it’s for Sony Playstation 1/2
controllers. Here is mine:

http://www.lik-sang.com/info.php?category=23&products_id=3172

Are you saying that multiple axes on your
controllers
are being represented by the same axis index?

Indeed. What was happening was that there actually
was a special case
written for this very device, in
src/joysticks/linux/SDL_sysjoystick.c… The author
did a very good job
setting up a framework to handle annoying joysticks,
but he didn’t quite
grasp just how annoying this particular joystick is.

When you plug in different numbers of joysticks, all
the axes are
remapped in completely different ways. Thus, the
code he wrote was
likely correct for a certain number of controllers,
but failed on every
other number.

I don’t seem to have this problem on Mac OS X Panther
10.3.3 or 10.3.4. Though maybe we have two
identical-looking but different products. Is it
possible that Mac OS X deals with this on its own?

Could I see your code?

When I wrote this I was considering the possibility
that YOU were doing something wrong, not SDL. A
thousand apologies.

Quite shortly I’ll be posting a fixed version of
src/joysticks/linux/SDL_sysjoystick.c, that also
handles this joystick,
as well as its little brother (which has 2 ports,
and the same quirky
behavior). The 4-porter already works just fine, no
matter how many
joysticks are plugged in. I just need to get the
mappings right for the
2-porter.

Hmm, does this source code also apply to other
platforms (as it’s in the linux sub directory.)
Perhaps Mac OS X already deals with this sort of
problem, because I’ve had no problems with it.

On a side-note, is it really the responsibility of a
product like SDL to handle this sort of thing?
Shouldn’t that really be handled by the joystick
driver? Many joysticks today claim to be "driverless,"
really meaning that they comply to common drivers
found on all modern operating systems. Then the
problem may lie in the actual hardware (which may
certainly be the case here.)

All I can say is that in the driver, or in the
joystick firmware: those seem to be good places for
this sort of fix. While putting individual joystick
solutions into SDL may be convenient, and perhaps even
the only practical way to fix the problem, it doesn’t
seem idealogically appropriate to me.__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail

— David MacCormack wrote:

What I basically did was take a single controller,
plugged it into port 1
and wrote down the value for each axis and button,
then plugged it
into port 2, 3, and 4, and did the same thing –
testing a single
port at a time. The values that I got for each were
unique. Then I
tested it with two joysticks, one in port 1 and the
other in port 2; I
got the same values. From there I jumped to the
(aparently wrong?)
conclusion that the mapping was a linear map from
each port to a static
set of buttons/axes/hats.

Does this particular adapter actually use any hats?
The Super Joybox 5 (visually identical, cannot tell
the difference between the two) that I have does just
what you’re suggesting, but it maps the
directional-pad and analog sticks to axes, and buttons
to buttons (even though it claims to support PS2
controllers, it has no support I see for the PS2’s
pressure sensitive buttons.)

Is this something specific with the dance pad (I
don’t own one so I
can’t test)? I’m supprised that the controller
would go to the trouble
of anything other than a linear mapping (though I’ve
certainly seen
dumber things).

Mine just appears to do linnear mapping, though
admittedly having read Chris’ latest post, I have no
tried more than 2 controllers at a time.

Using a dance pad on the latest versions of the Super
Joybox, one must hold Start, Select, and Up for 3
seconds to go into Dance Pad mode, which mirrors
directional axes onto the action buttons (x, circle,
etc.) and pushes the action buttons indecies onto the
original indecies of the shoulder buttons, which are
not on any dance pad I’ve ever seen.

(In case anyone reading this wants to know, you do the
same thing to get out of dance pad mode, except
instead of DOWN, you hold UP.)__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail

Does your packaging say Sony on it?

Mine says “Super Joybox 5”, now that I look at it, so we’re dealing with
the same device.

I don’t seem to have this problem on Mac OS X Panther
10.3.3 or 10.3.4. Is it possible that Mac OS X deals with
this on its own?

I’m really not certain at this point… Once David reports back with
respect to whether my patch worked for him, or not, we may know more.

It’s possible that somewhere between the adapter and jstest, the linux
HID subsystem is mapping things differently for the two of us. I really
hope this isn’t the case.

Could I see your code?

When I wrote this I was considering the possibility
that YOU were doing something wrong, not SDL. A
thousand apologies.

I still may be doing something wrong, with respect to my kernel
configuration, even though the adapter and it’s 2-port little brother
"work".

Hmm, does this source code also apply to other
platforms (as it’s in the linux sub directory.)

My code only affects the linux port.

On a side-note, is it really the responsibility of a
product like SDL to handle this sort of thing?

I agree with you, that these fixes really should go as close to the
joystick hardware as possible. I doubt that the hardware provides any
interface to modify its firmware, if it even has firmware. The only
alternative would be sticking a fix into the linux kernel. Glancing over
linux/drivers/usb/hid*, I don’t see any device-specific code, however…

Does it belong in SDL? I’m not certain, but a (different) fix for this
very device has already been in cvs for a while. If we decide that this
is the proper role of SDL, we may also want to consider whether it would
be correct to map all Playstation2 controllers to the same axes /
buttons. From a user’s perspective, I would love this, since it means
that any PS2=>USB converter would work equally well, with no extra
configuration on my part.

I’m not advocating this directly, but I thought I’d at least bring it up
for discussion.

-Chris
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040624/bc1e1ef7/attachment.pgp

Woah, really? Mine’s behaving very very differently than you describe.
When I plug in a controller, it doesn’t matter what port I’m using, the
mapping of the axes / buttons is always the same, as seen by jstest.
This is under linux 2.4.24 and 2.6.7… How does yours behave? Can you
see all 48 possible buttons, even when only a single controller is
plugged in?

Heh. Ok, I did some playing around. Try this:

boot without the mp-8800 attached
modprobe any modules as necessary (uhci, hid, joydev, etc…)
unplug all joysticks from the mp-8800
plug the mp-8800 into a usb port
That will give you all available axes, buttons, etc… for all 4 joys.

What I’ve found is that if the mp-8800 has any joysticks plugged into it
when the host controller module is loaded (or, if it’s not a module, when
you boot) then the strange behavior that you’re speaking of occurs.
If I remove all joysticks from the mp-8800 before the host controller
module is loaded and before I plug it into a usb port, then I can plug and
unplug joysticks willy-nilly and things act “normally”.

I used SDL12/test/testjoystick as the test application. Also, I tested
this with vanilla 2.4.25 and 2.4.26 (the uhci host controller driver is
named uhci.o in 2.4.25 and usb-uhci.o in 2.4.26). I have yet to try a
2.6 kernel so I’m not sure about its behavior.

I can only see 12 buttons per plugged in controller (which I
used to get SDL to correctly report how many logcial joysticks are
available).

If you get a chance, try the steps above and see if this is the case. I’m
very curious to see whether or not you get the same result.

Also, on a hunch, could you tell me the results of lsmod | grep joydev?
Mine gives me joydev and input as the two modules. In my experience it
actually matters whether these are modules or not. I can test this
explicitly, if anybody’s curious.

I’m using devfs. I need joydev, otherwise, I don’t get /dev/js0 ;). I
tested both with joydev compiled into the kernel and as a module. The
result was the same in both cases.

Groovy. It’s available at:

http://cs-people.bu.edu/chrisn1/SDL_sysjoystick.c

I’ll give this a shot today or tomorrow and let you know what happens.

Dave

On a side-note, is it really the responsibility of a
product like SDL to handle this sort of thing?
Shouldn’t that really be handled by the joystick
driver? Many joysticks today claim to be "driverless,"
really meaning that they comply to common drivers
found on all modern operating systems. Then the
problem may lie in the actual hardware (which may
certainly be the case here.)

http://twomix.devolution.com/pipermail/sdl/2004-May/062269.html

DaveOn Wed, 23 Jun 2004, Donny Viszneki wrote:

Does this particular adapter actually use any hats?

Yes. To see an example of this, plug in a PS2 controller and hit the
"Analog" button. The two analog pads will now become active; the left
pad will be axis 0 & 1 (replacing the digital pad), the right pad will
be axis 2 & 3, and the digital pad will become hat 0.

This is the behavior of the mp-8800 hardware (e.g. it has nothing to do
with sdl or my changes to it).

DaveOn Wed, 23 Jun 2004, Donny Viszneki wrote:

Heh. Ok, I did some playing around. Try this:

Nice work, I think you’ve figured out what we were doing differently. My
hardware behaves exactly as you describe, when I do this.

Even better, when I plug 4 joysticks into the device, and THEN plug the
device into the USB port, it behaves exactly as it does when the device
is plugged in empty, with joysticks plugged in later.

Groovy. It’s available at:

http://cs-people.bu.edu/chrisn1/SDL_sysjoystick.c

I’ll give this a shot today or tomorrow and let you know what happens.

Cool, do let me know.

As I understand it, the new code should work now independent of when you
plug in the PS2 joysticks. Let me know if you notice any quirks I need
to take care of.

-Chris
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040626/10815acf/attachment.pgp

— David MacCormack wrote:

Does this particular adapter actually use any
hats?

Yes. To see an example of this, plug in a PS2
controller and hit the
"Analog" button. The two analog pads will now
become active; the left
pad will be axis 0 & 1 (replacing the digital pad),
the right pad will
be axis 2 & 3, and the digital pad will become hat
0.

Is this only on a PS2 controller, or also on a PS1
Dual Shock controller?> On Wed, 23 Jun 2004, Donny Viszneki wrote:

This is the behavior of the mp-8800 hardware (e.g.
it has nothing to do
with sdl or my changes to it).

Dave


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail

I’ve been keeping up with this thread, and it seems to
have come to sort of a conclusion (I think.) Am I
correct in saying that no patching is needed? And in
fact you just need to make sure to plug it in with no
joysticks in, and load the proper kernel modules?__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail

Actually, I believe that the patch is still helpful.

Without the patch, the adapter only works if you plug in controllers
after you plug in the adapter to the USB port.

With the patch, the order in which you do this becomes unimportant, but
if you plug in the controllers BEFORE you plug in the adapter to the USB
port, you get the added bonus of SDL reporting the proper number of
logical joysticks, rather than 4 always.

The real person to answer your question, however, is Dave, since he
wrote the original fix, and he’s testing to verify that my fix works as
described.

-Chris
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040627/d8f05c31/attachment.pgpOn Sun, 2004-06-27 at 03:01, Donny Viszneki wrote:

I’ve been keeping up with this thread, and it seems to
have come to sort of a conclusion (I think.) Am I
correct in saying that no patching is needed? And in
fact you just need to make sure to plug it in with no
joysticks in, and load the proper kernel modules?

— Chris Nelson wrote:

I’ve been keeping up with this thread, and it
seems to
have come to sort of a conclusion (I think.) Am I
correct in saying that no patching is needed? And
in
fact you just need to make sure to plug it in with
no
joysticks in, and load the proper kernel modules?

Actually, I believe that the patch is still helpful.

Without the patch, the adapter only works if you
plug in controllers
after you plug in the adapter to the USB port.

With the patch, the order in which you do this
becomes unimportant, but
if you plug in the controllers BEFORE you plug in
the adapter to the USB
port, you get the added bonus of SDL reporting the
proper number of
logical joysticks, rather than 4 always.

That really doesn’t seem like a great feature to me, I
just feel like it’s caused by this particular device,
and its owners should simply be cautioned when using
it. The features your patch provide don’t seem like
they are worth the sacrifice of idealogy (the question
had certainly been made before, as to WHERE this patch
belongs.)

The real person to answer your question, however, is
Dave, since he
wrote the original fix, and he’s testing to verify
that my fix works as
described.

Well I hope he sees my post then.

-Chris

ATTACHMENT part 1.2 application/pgp-signature
name=signature.asc> On Sun, 2004-06-27 at 03:01, Donny Viszneki wrote:


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

What’s the status on this?

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment> On Sun, 2004-06-27 at 03:01, Donny Viszneki wrote:

I’ve been keeping up with this thread, and it seems to
have come to sort of a conclusion (I think.) Am I
correct in saying that no patching is needed? And in
fact you just need to make sure to plug it in with no
joysticks in, and load the proper kernel modules?

Actually, I believe that the patch is still helpful.

Without the patch, the adapter only works if you plug in controllers
after you plug in the adapter to the USB port.

With the patch, the order in which you do this becomes unimportant, but
if you plug in the controllers BEFORE you plug in the adapter to the USB
port, you get the added bonus of SDL reporting the proper number of
logical joysticks, rather than 4 always.

The real person to answer your question, however, is Dave, since he
wrote the original fix, and he’s testing to verify that my fix works as
described.

What’s the status on this?

Nevermind, I’ve applied your patch to CVS. :slight_smile:

Thanks!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Hi Sam. I took the discussion off-list because I couldn’t get that patch
to work and I wanted to work with Chris (the author) to see if he could
he me get it working. For some reason it only detects 1 joystick,
reguardless of how many are plugged in. Chris, have you had a chance to
play with it anymore?

To sum up the situation…

The code before Chris’s patch:

You have two choices.
1) boot w/o any PS joys plugged into the MP8800, and then you
   can swap in & out PS joysticks as you please.

2) rmmod/insmod your usb host-controller module if booted with
   PS joys plugged in and want to change the # of joys

The code after Chris’s patch:

Always detects exactly 1 (of 4 joysticks).

Maybe I’m doing something wrong? I don’t know. Neither Chris nor I have
managed to figure it out. Is there anyone else with this device (and
linux) that can test?

DaveOn Sun, 25 Jul 2004, Sam Lantinga wrote:

What’s the status on this?

Nevermind, I’ve applied your patch to CVS. :slight_smile:

Thanks!
-Sam Lantinga, Software Engineer, Blizzard Entertainment