jefflunt / glint-box

(retired) This was fun - but seriously, try Lakka instead (http://www.lakka.tv/)
MIT License
21 stars 5 forks source link

Create udev rules for NES controllers #22

Closed brandtdaniels closed 11 years ago

brandtdaniels commented 11 years ago

The udev rules will update the ES and RetroArch config files based on the known controller. At this point we have definitions for Jeff's USB controller and Brandt's Retro-Bit USB adapter.

brandtdaniels commented 11 years ago

es_input.cfg:

JOYNAME USB Gamepad BUTTON 1 5 BUTTON 2 6 BUTTON 8 8 BUTTON 9 7 AXISPOS 0 4 AXISPOS 1 2 AXISNEG 0 3 AXISNEG 1 1

or

JOYNAME INNEX NES Controller USB BUTTON 0 5 BUTTON 1 6 BUTTON 2 8 BUTTON 3 7 AXISPOS 0 4 AXISPOS 1 2 AXISNEG 0 3 AXISNEG 1 1

AND

retroarch.cfg

input_player1_joypad_index = "0" input_player1_a_btn = "1" input_player1_b_btn = "2" input_player1_select_btn = "8" input_player1_start_btn = "9" input_player1_left_axis = "-0" input_player1_right_axis = "+0" input_player1_up_axis = "-1" input_player1_down_axis = "+1"

brandtdaniels commented 11 years ago

What is the command to tell glint-es and retroarch to re-read their config files?

jefflunt commented 11 years ago

Sent an email to Aloshi to ask about OS signal responses for EmulationStation - I don't see any jumping out in the code.

Not sure about RetroArch.

jefflunt commented 11 years ago

I confirmed with Aloshi that there is no such command currently for EmulationStation - still not sure about RetroArch. I'll have to add a handler for this to glint-es, thinking maybe something that responds to an OS signal (what do you think)?

The only alternative that is currently available that I'm aware of is to do a killall glint-es and restart it, making sure to start it as the same user that started it before.

brandtdaniels commented 11 years ago

Unfortunately when being restarted by a udev script there is no user set in the environment and all I see is the dot on the screen. I can try setting $HOME in code.

-Brandt

Sent from my iPhone

On Dec 26, 2012, at 9:10 AM, Jeff Lunt notifications@github.com wrote:

I confirmed with Aloshi that there is no such command currently for EmulationStation - still not sure about RetroArch. I'll have to add a handler for this to glint-es, thinking maybe something that responds to an OS signal (what do you think)?

The only alternative that is currently available that I'm aware of is to do a killall glint-es and restart it, making sure to start it as the same user that started it before.

— Reply to this email directly or view it on GitHub.

brandtdaniels commented 11 years ago

adding the line:

export HOME="/home/pi"

to my script that restarts glint-es works

Another question,

can ES only configure the controller for player 1? meaning player 2 can't control the menu?

jefflunt commented 11 years ago

Right now, yes. Out of the box it's only built for one player. On Dec 26, 2012 10:43 PM, "Brandt Daniels" notifications@github.com wrote:

adding the line:

export HOME="/home/pi"

to my script that restarts glint-es works

Another question,

can ES only configure the controller for player 1? meaning player 2 can't control the menu?

— Reply to this email directly or view it on GitHubhttps://github.com/normalocity/glint-nes/issues/22#issuecomment-11701032.

brandtdaniels commented 11 years ago

scripted udev rule:

echo -e 'SUBSYSTEM=="input", ACTION=="add", KERNEL=="js[0-1]", RUN+="/usr/local/bin/inputconfig.sh $number \047$attr{name}\047"' >> /etc/udev/rules.d/99-input.rules
/etc/init.d/udev restart

script (/usr/local/bin/inputconfig.sh):

!/bin/bash

export HOME="/home/pi" ESCONFIG="/home/pi/.glint-es/es_input.cfg" RACONFIG="/home/pi/.retroarch/retroarch.cfg" SYSLOG="/var/log/syslog"

PLAYERINDEX=$1 PLAYER=expr $PLAYERINDEX + 1 #zero-indexed CONTROLLER=$2

echo "\ $0 - Joystick Index: $PLAYERINDEX *" >> $SYSLOG echo "*** $0 - Controller Name: $CONTROLLER " >> $SYSLOG

declare -A buttons

if [ "$CONTROLLER" == "INNEX NES Controller USB" ]; then

Brandt

buttons=( ["a"]="0" ["b"]="1" ["select"]="2" ["start"]="3" ["left"]="0" ["right"]="0" ["up"]="1" ["down"]="1" ) elif [ "$CONTROLLER" == "USB Gamepad" ]; then

Jeff

buttons=( ["a"]="1" ["b"]="2" ["select"]="8" ["start"]="9" ["left"]="0" ["right"]="0" ["up"]="1" ["down"]="1" ) fi

if [ "$PLAYERINDEX" == "0" ]; then echo "\ $0 - $ESCONFIG written **" >> $SYSLOG cat < EOF >> $ESCONFIG JOYNAME ${CONTROLLER} BUTTON ${buttons["a"]} 5 BUTTON ${buttons["b"]} 6 BUTTON ${buttons["select"]} 8 BUTTON ${buttons["start"]} 7 AXISPOS ${buttons["left"]} 4 AXISPOS ${buttons["right"]} 2 AXISNEG ${buttons["up"]} 3 AXISNEG ${buttons["down"]} 1 EOF

echo "\ $0 - Restarting ES **" >> $SYSLOG killall glint-es && /home/pi/glint-es/glint-es &

else echo "\ $0 - $ESCONFIG NOT written for player $PLAYER **" >> $SYSLOG fi

echo "** $0 - $RACONFIG updated for player: $PLAYER using controller: $PLAYERINDEX *_" >> $SYSLOG if grep -q "input_player${PLAYER}" $RACONFIG; then sed -ie "s/input_player${PLAYER}_joypadindex./input_player${PLAYER}_joypad_index = \"${PLAYERINDEX}\"/g" $RACONFIG sed -ie "s/input_player${PLAYER}_abtn./input_player${PLAYER}_a_btn = \"${buttons["a"]}\"/g" $RACONFIG sed -ie "s/input_player${PLAYER}_bbtn./input_player${PLAYER}_b_btn = \"${buttons["b"]}\"/g" $RACONFIG sed -ie "s/input_player${PLAYER}_selectbtn./input_player${PLAYER}_select_btn = \"${buttons["select"]}\"/g" $RACONFIG sed -ie "s/input_player${PLAYER}_startbtn./input_player${PLAYER}_start_btn = \"${buttons["start"]}\"/g" $RACONFIG sed -ie "s/input_player${PLAYER}_leftaxis./input_player${PLAYER}_left_axis = \"-${buttons["left"]}\"/g" $RACONFIG sed -ie "s/input_player${PLAYER}_rightaxis./input_player${PLAYER}_right_axis = \"+${buttons["right"]}\"/g" $RACONFIG sed -ie "s/input_player${PLAYER}_upaxis./input_player${PLAYER}_up_axis = \"-${buttons["up"]}\"/g" $RACONFIG sed -ie "s/input_player${PLAYER}_downaxis./input_player${PLAYER}_down_axis = \"+${buttons["down"]}\"/g" $RACONFIG

echo "\ $0 - Restarting RetroArch **" >> $SYSLOG

killall retroarch

else echo "** $0 - Player $PLAYER not configured in $RACONFIG...Configuring now *_" >> $SYSLOG cat << EOF >> $RACONFIG input_player${PLAYER}_joypad_index = "${PLAYERINDEX}" input_player${PLAYER}_a_btn = "${buttons["a"]}" input_player${PLAYER}_b_btn = "${buttons["b"]}" input_player${PLAYER}_select_btn = "${buttons["select"]}" input_player${PLAYER}_start_btn = "${buttons["start"]}" input_player${PLAYER}_left_axis = "-${buttons["left"]}" input_player${PLAYER}_right_axis = "+${buttons["right"]}" input_player${PLAYER}_up_axis = "-${buttons["up"]}" input_player${PLAYER}_down_axis = "+${buttons["down"]}" EOF

echo "_* $0 - Restarting RetroArch **" >> $SYSLOG

killall retroarch

fi

exit 0

brandtdaniels commented 11 years ago

Trying to remember the logic behind controllers on the original NES...I don't want to kill retroarch when someone plugs in a controller..

NES console had two sockets, labeled player 1 and player 2 ??

What happens if a game is started with no controllers plugged in??

What happens if a game is in progress and player 1 plugs in???

What happens if player 2 plugs in during player 1's game??

what happens if a controller is unplugged during a game?

Maybe you can help me remember these things.

jefflunt commented 11 years ago

It's a direct hardware connection that was polled directly, I believe. You can plug/unplug controllers on the fly. The Xbox (maybe the 360) was the first console I know of that automatically paused the game when a controller in use became disconnected.

brandtdaniels commented 11 years ago

On-the-fly would work with this if the controllers are already configured in retroarch and/or ES. If they are not configured than what we do? should we update the config and then next time retroarch starts it will see it? or what?

On Dec 27, 2012, at 7:19 AM, Jeff Lunt notifications@github.com wrote:

It's a direct hardware connection that was polled directly, I believe. You can plug/unplug controllers on the fly. The Xbox (maybe the 360) was the first console I know of that automatically paused the game when a controller in use became disconnected.

— Reply to this email directly or view it on GitHub.

brandtdaniels commented 11 years ago

Please test this implementation, and if you have no issues then please include in the december milestone

jefflunt commented 11 years ago

The player 2 stuff is going to get bumped to the next release, I'm afraid. :(

brandtdaniels commented 11 years ago

The player 2 stuff isn't an issue with the script above. The player 2 stuff is retroarch related. I was hoping this script would have been included in this latest release.

jefflunt commented 11 years ago

I don't think this script is going to get included at all, because it's too specific to the controllers that you and I are using.

Over the last month the #1 support issue has been people wanting to use their on controllers, and the script above (which sets button mappings for two specific controllers) is an infeasible approach to supporting everyone that has been interested in the project.

The only workable strategy has proven to be asking users to configure their controllers on first use, and to considate the controls between glint-es and glint-nes so that you configure your controllers once, and have the config pushed to both components.

jefflunt commented 11 years ago

Blog post on the official project blog: http://karmanebula.com/glint/2013/2/10/you-must-configure-your-own-joystick

jefflunt commented 11 years ago

I did wind up using to to set the controls from glint-es, which should be included whenever the next release gets done.