Build Your Own Arcade Controls Forum

Main => Software Forum => Linux => Topic started by: migraineman on November 03, 2011, 08:15:01 pm

Title: GP-Wiz40 with linux?
Post by: migraineman on November 03, 2011, 08:15:01 pm
I'm trying to get my recently acquired GP-Wiz40 to work with MAME under linux.  The GP-Wiz is identified properly, shows up in lsusb, and works great with jstest.  However, linux MAME doesn't seem to accept input from it, in spite of identifying it and mapping Physical id 0 to Logical id 0.  I can run jstest in a terminal window, and invoke MAME from another terminal using "mame -v -w" so it runs verbose in a window.  I can see jstest identify the button inputs from the GP-Wiz40, but MAME doesn't respond.

I even went so far as to install the windows port of MAME in a VM on the same machine (linux as the host system.)  The windows version accepted input from the GP-Wiz40 just fine.

I've tried to get this working on both a FC15 and Ubuntu 11.10 distro, and neither seems to like my GP-Wiz40.  Am I missing something?  Anybody have one working under linux?  Oh, MAME is 0.143 in all cases.
Title: Re: GP-Wiz40 with linux?
Post by: Quinny on November 04, 2011, 02:06:58 pm
Is there a setting in mame.ini to turn on joysticks or mouses or something?

Sorry just going from a vague memory.
Title: Re: GP-Wiz40 with linux?
Post by: migraineman on November 04, 2011, 02:30:53 pm
Yep.  The "joystick" option is turned on.  It works fine when I plug in a Logitech gamepad. 

While doing a comparison between the Logitech gamepad and the GP-Wiz40 using jstest, I noticed that the GP-Wiz axis control values range from 127 to -127, where the Logitech values were 32767 to -32767.  I'm wondering if I have an 8-bit versus 16-bit parameter issue.  I poked around in the MAME source code, and the MAX_VALUE declaration for the analog joystick input is 65536, and the MIN_VALUE is -65536.  There is a deadzone and saturation scale factor in the mame.ini file which defaults to 0.3 and 0.85 of full scale, respectively.  I suspected that my teeny 8-bit values might be stuck in the deadzone, but I changed the deadzone to 0.0 and didn't appear to make a difference.  I also set the saturation value to 0.0015 which should cause an input of 127 to be considered "full scale," but that didn't change anything either.   

I'll continue digging through the source.  I haven't found the place where they actually take a control input and convert that to a command for the emulator.  Gotta make sure I can build MAME from source, too.  If I can do both of these, I can make a butchered version that prints the joystick values at the point where they're converted to commands, and maybe I'll be able to figure out what the heck is going on here.  Note - software engineer, I am not.
Title: Re: GP-Wiz40 with linux?
Post by: Quinny on November 05, 2011, 10:47:50 am
Good luck! I haven't had any issues with MAME not detecting any hardware controls that Linux knows about.

What module is the GP-Wiz using compared to the gamepad? Maybe the wrong module is being used for the GP-Wiz.
Title: Re: GP-Wiz40 with linux?
Post by: migraineman on March 02, 2012, 09:47:03 am
I did some more digging, and I need to correct my previous post.  The GP-Wiz40 is properly recognized by the Linux system, and is mounted using the joydev module.  However, the reported joystick values are 0, 127, and 255 (the previous -127 to 127 is just plain wrong.  Sorry about that.)  So in addition to being small compared to the Logitech gamepad values, there's a fixed offset.  I also built a better test fixture, and confirmed that Button1 and Button2 for Player 1 respond properly.   So at least part of the GP-Wiz40 is being handled properly.

I was hoping I could manually edit the code in the GP-Wiz40, but the Cypress CY7C63513 low-speed USB microcontroller doesn't appear to be in-circuit programmable.  I could have handled a Microchip or Atmel device.  Dang.

So I've been bashing away at the MAME and SDL sources.  I've been able to build both from source (which ain't an easy task.)  I've added diagnostic print messages to try to figure out where the MAME code decides what kind of joystick is present, how it scales and limits the input values, and then hands that data off to the emulator core.  Honestly, I'm an embedded guy, and the C++++ infinite-layers-of-abstraction are making my head asplode.

From the Linux command line, I can run jscal and properly calibrate the joystick.  Once calibrated, jstest reports values of -32767, 0, and 32767.  That's encouraging, but MAME doesn't seem to be using the calibrated joystick values.  I've read about SDL ignoring the /dev/input/js0 device in favor of the event interface (which can't be calibrated.)  I poked at the libSDL package and re-built it from source, commenting out the event driver path.  Didn't make a difference, though at this point I'm not convinced that what I changed was comprehensive enough to do what I want.

SDL calibration issues are referenced here:
http://superuser.com/questions/17959/linux-joystick-seems-mis-calibrated-in-an-sdl-game-freespace-2-open (http://superuser.com/questions/17959/linux-joystick-seems-mis-calibrated-in-an-sdl-game-freespace-2-open)
Title: Re: GP-Wiz40 with linux?
Post by: migraineman on May 23, 2012, 10:25:43 am
SUCCESS!  After several weeks of beating my head against the SDL wall, I decided to approach from a different angle.  I added the environment variable "SDL_JOYSTICK_DEVICE=/dev/input/js0" to /etc/environment.  After a reboot, the variable appeared in the env list (it wouldn't stay persistent when manually added.)  I calibrated the GPWiz40 using "jscal -c /dev/input/js0".  MAME now uses the calibrated joystck values through SDL. 

I'm not out of the woods yet, but I'm past a major tech hurdle.  I need to cal four joysticks, make sure the calibrations are persistent, and make sure the usb device assignments are consistent through power cycling. 
Title: Re: GP-Wiz40 with linux?
Post by: drventure on May 23, 2012, 11:05:23 am
I'd love to hear what you find out about the device assignments being persistent through a reboot.

Also, do they stay consistent as you add and remove devices?

Windows is notorious about not handling that situation very well. That's why I wrote ControllerRemap. I'm just curious if Linux handles things better.