Joystick Nubs


JerryBlade

Member
Joined
Oct 3, 2008
Messages
148
I just updated to SuperZaxxon Final (love it!), and everything checks out on my Apple ][ emulator except the nubs... they no longer function as joysticks! Does the following shell script still work or do I need to investigate how to access joystick nubs in the new Angstrom kernel?



Code:
NUB0MODE=`cat /proc/pandora/nub0/mode`

NUB1MODE=`cat /proc/pandora/nub1/mode`

echo absolute > /proc/pandora/nub0/mode

echo absolute > /proc/pandora/nub1/mode

./linapple

echo $NUB0MODE > /proc/pandora/nub0/mode

echo $NUB1MODE > /proc/pandora/nub1/mode


Any suggestions on where to start?


Thanks!


-Jerry
 
I bet you're hardcoding the nub to be joystick 1 and 2 in SDL ?


That's not the case anymore. Read the joystick name and search for nub0 and nub1 :)
 
Read the joystick name and search for nub0 and nub1

I am not 100% sure what you mean... :blink:


Yes - I was hardcoding them before, assuming that the left nub was Joy1 and right nub was Joy2, provided they were set to "absolute" by the shell script... Do you mean I now need to start using "SDL_NumJoysticks" to get the number of actual Joysticks and then use "SDL_JoystickName" to figure out which nubs are actual joysticks?


Thanks :)
 
Last edited by a moderator:
You have to do this because input device enumeration order is not guaranteed on Linux. For example, you could switch the nubs to mouse mode, plug in USB joystick, then switch nubs to absolute again (which will cause reenumeration) and nubs will be ordered after USB joy even on old firmware.
 
I updated the emulator today for the way joysticks/nubs are handled in the lastest firmware.



Code:
For OpenPandora linapple version 1.5.0.0:

Fixed Joystick SDL routines - Removed hardcoding of JOY1/JOY2 for SuperZaxxon Firmware Compatibility. Nubs are filled as joysticks on first

available basis (i.e. nub0 is mapped if available as a joystick before nub1 is mapped)


You can find it here


Thanks for all of the help!


-Jerry
 
I am actually having a strange issue with the nubs and the emulator now... and I am not sure what the cause is. If anyone can help, I would greatly appreciate it!


The first time you load the app, after a reboot, everything works as it should. The emulator finds 2 SDL joysticks - nub0 & nub1 (which is also shown in the .out file). The second and any subsequent times you run the app, SDL_NumJoysticks returns 0, and the nubs no longer act as joysticks in the emulator. However, if you manually put them into joystick mode, at any point, they work fine. This behavior leads me to believe there is something happening at the OS level and not in the app since you can "manually override" the nubs as joysticks issue. If something wasn't exiting nicely or not being released properly, I don't think I would be able to get the nubs to work on subsequent runs by manually putting them in joystick mode. Also, one other weird behavior... sometimes when exiting the app, the right nub doesn't act as mouse buttons anymore... even though it shows up in the nub configurator as mouse buttons. Flipping it to something else then back to mouse buttons and saving it in the nub configurator, fixes that problem... Here is the shell script I am using... If anyone has any ideas, I am all ears!



Code:
NUB0MODE=`cat /proc/pandora/nub0/mode`

NUB1MODE=`cat /proc/pandora/nub1/mode`

echo absolute > /proc/pandora/nub0/mode

echo absolute > /proc/pandora/nub1/mode

./linapple

echo $NUB0MODE > /proc/pandora/nub0/mode

echo $NUB1MODE > /proc/pandora/nub1/mode


Thanks!


-Jerry
 
It's a race condition between your emu and the OS, when you do



Code:
echo absolute > /proc/pandora/nub0/mode

it does not have effect instantly, it may take several seconds to enumerate the joysticks.

To solve this, you can call a helper script in the OS



Code:
/usr/pandora/scripts/op_nubchange.sh absolute absolute

or add a sleep after echo, but it's not clear how much sleep is enough, because it may take longer when system is busy. op_nubchange.sh is not available on HF6 or earlier though, you could perhaps do:



Code:
if [ -e /usr/pandora/scripts/op_nubchange.sh ]; then

  /usr/pandora/scripts/op_nubchange.sh absolute absolute

else

  echo absolute > /proc/pandora/nub0/mode

  echo absolute > /proc/pandora/nub1/mode

fi
 
Last edited by a moderator:
I'll update the shell script and report back - thanks Notaz!


Is this how everyone else is doing it? Is there a better way to do this (like from inside the emulator?)?


Thanks!


-Jerry
 
I updated the shell script to take advantage of the new nub script in SuperZaxxon (Thanks Notaz!!!). So, I should not need to manually set the nubs in joystick mode anymore if people are running the latest firmware!



Code:
For OpenPandora linapple version 1.5.1.0:

Updated shell script loader to use new SuperZaxxon nub script when available



Here is the new linapple.sh:





Code:
NUB0MODE=`cat /proc/pandora/nub0/mode`

NUB1MODE=`cat /proc/pandora/nub1/mode`

if [ -e /usr/pandora/scripts/op_nubchange.sh ]; then

  /usr/pandora/scripts/op_nubchange.sh absolute absolute

else

  echo absolute > /proc/pandora/nub0/mode

  echo absolute > /proc/pandora/nub1/mode

fi

./linapple

echo $NUB0MODE > /proc/pandora/nub0/mode

echo $NUB1MODE > /proc/pandora/nub1/mode


Thanks again Notaz!


-Jerry
 
Last edited by a moderator:
Dirty trick:


If you always want to have left nub as Joy0, do the following:



Code:
NUB0MODE=`cat /proc/pandora/nub0/mode`

NUB1MODE=`cat /proc/pandora/nub1/mode`

if [ -e /usr/pandora/scripts/op_nubchange.sh ]; then

  /usr/pandora/scripts/op_nubchange.sh mouse mouse

else

  echo mouse > /proc/pandora/nub0/mode

  echo mouse > /proc/pandora/nub1/mode

fi

if [ -e /usr/pandora/scripts/op_nubchange.sh ]; then

  /usr/pandora/scripts/op_nubchange.sh absolute absolute

else

  echo absolute > /proc/pandora/nub0/mode

  echo absolute > /proc/pandora/nub1/mode

fi

./linapple

echo $NUB0MODE > /proc/pandora/nub0/mode

echo $NUB1MODE > /proc/pandora/nub1/mode
 
How does putting them in mouse-mode then absolute-mode accomplish that? Also, how do I force a "nub reset" when it exits the emulator? Sometimes, it loses its auto-config when it exits (i.e. the nub wont go left or up), so I think a forced reset would be a nice addition.


Thanks!


-Jerry
 
Well, if the right joystick already is in joystickmode and the left one isn't when you start the emulator, the right nub is joy0 and the left one will get joy1. When you first set them not to be joysticks, the value is first written to the left, then to the right nub, making the first(left) joy0 and the right one joy1.


If this is not correct, please stone me and delete my posts ;)
 
Dirty trick:


If you always want to have left nub as Joy0, do the following:



Code:
NUB0MODE=`cat /proc/pandora/nub0/mode`

NUB1MODE=`cat /proc/pandora/nub1/mode`

if [ -e /usr/pandora/scripts/op_nubchange.sh ]; then

/usr/pandora/scripts/op_nubchange.sh mouse mouse

else

echo mouse > /proc/pandora/nub0/mode

echo mouse > /proc/pandora/nub1/mode

fi

if [ -e /usr/pandora/scripts/op_nubchange.sh ]; then

/usr/pandora/scripts/op_nubchange.sh absolute absolute

else

echo absolute > /proc/pandora/nub0/mode

echo absolute > /proc/pandora/nub1/mode

fi

./linapple

echo $NUB0MODE > /proc/pandora/nub0/mode

echo $NUB1MODE > /proc/pandora/nub1/mode
That's just awful, don't do this!

Well, if the right joystick already is in joystickmode and the left one isn't when you start the emulator, the right nub is joy0 and the left one will get joy1. When you first set them not to be joysticks, the value is first written to the left, then to the right nub, making the first(left) joy0 and the right one joy1.
If you are talking about /dev/input/jsX or SDL_JoystickOpen() order, you must not rely on it, see post #5 above. You need to look at their names, which are nub0 for the left nub and nub1 for the right one, they always stay constant.
 
Last edited by a moderator:
Ok, it seemed to work for me, but yes, should be actually easier to get the names and open the joystickdevices accordingly.
 
Ok good Notaz - In theory, that's exactly what I am doing now :)



Code:
if(joy1) SDL_JoystickClose(joy1);

if(joy2) SDL_JoystickClose(joy2);

int number_of_joysticks = SDL_NumJoysticks();

int applejoy1 = -1;

if (joyinfo[joytype[0]].device == DEVICE_JOYSTICK)

{

// JOYCAPS caps;

  if (number_of_joysticks > 0)

  {

    for (int i=0; i<number_of_joysticks;i++)

    {

	  if (strncmp (SDL_JoystickName(i),"nub0",4) == 0)

	  {

	    joy1 = SDL_JoystickOpen(i); // open joystick and get its information into SDL_Joystick struct

	    applejoy1 = i;

	  }

    }

    if (!joy1)

    {

	  for (int i=0; i<number_of_joysticks;i++)

	  {

	  if (strncmp (SDL_JoystickName(i),"nub1",4) == 0)

	  {

	    joy1 = SDL_JoystickOpen(i); // open joystick and get its information into SDL_Joystick struct

	    applejoy1 = i;

	  }

    }

  }

}

if (joyinfo[joytype[1]].device == DEVICE_JOYSTICK)

{

// JOYCAPS caps;

  if (number_of_joysticks > 0)

  {

    for (int i=0; i<number_of_joysticks;i++)

    {

	  if (strncmp (SDL_JoystickName(i),"nub0",4) == 0)

	  {

	    if (applejoy1 != i)

	    {

		  joy2 = SDL_JoystickOpen(i); // open joystick and get its information into SDL_Joystick struct

	    }

	  }

    }

    if (!joy2)

    {

	  for (int i=0; i<number_of_joysticks;i++)

	  {

	  if (strncmp (SDL_JoystickName(i),"nub1",4) == 0)

	  {

	    if (applejoy1 != i)

	    {

		  joy2 = SDL_JoystickOpen(i); // open joystick and get its information into SDL_Joystick struct

	    }

	  }

    }

  }

}


Thanks!


-Jerry
 
Last edited by a moderator:
Back
Top