RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Disable devices?

    Scheduled Pinned Locked Moved Help and Support
    disableusb adapter
    31 Posts 5 Posters 6.4k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mediamogulM
      mediamogul Global Moderator @hansolo77
      last edited by mediamogul

      @hansolo77

      I'm not entirely sure I understand the workflow you're aiming for, but if not exactly correct, this may at least serve as inspiration for a better solution.

      In theory, the following should store the two event names as variables, export them and then check to see if they're present to allow the if/then statement to continue.

      runcommand-onstart:

      RNJS="$(find /dev/input/by-id/ -name '*raphnet.net_nes2usb*USB-joystick*')"
      RNEJS="$(find /dev/input/by-id/ -name '*raphnet.net_nes2usb*USB-event-joystick*')"
      
      export RNJS RNEJS
      
      if [ "$1" = "openbor" ] && [ -n "$RNJS" ] && [ -n "$RNEJS" ]; then
        sudo mv /dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick /dev/input/js99
        sudo mv /dev/input/by-id/usb-raphnet.net_nes2usb_1228-event-joystick /dev/input/event99
      fi
      

      With the event name variables exported, the following should put everything back as it was.

      runcommand-onend:

      if [ "$1" = "openbor" ] && [ -n "$RNJS" ] && [ -n "$RNEJS" ]; then
        sudo mv /dev/input/js99 "/dev/input/by-id/""$RNJS"
        sudo mv /dev/input/event99 "/dev/input/by-id/""$RNEJS"
      fi
      

      Does the runcommand-onend remember the $1 variable when a game is exiting?

      It is aware of that variable, yes.

      RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

      hansolo77H 1 Reply Last reply Reply Quote 1
      • hansolo77H
        hansolo77 @mediamogul
        last edited by

        @mediamogul Thanks a lot for this! I will experiment and report back. I wasn't sure how a bash script would work as far as storing variables. My experience in writing a "program" from scratch is limited to my days in high school with TI-BASIC on the TI-85 graphing calculator. LOL! It looks like we name the variable, then the command to locate it. The parts I'm hung up on are the programming commands, like find, -name, and -n. find is pretty self explanatory, as is -name. Reading it across though, are you sure this is correct? I'm not defining $RNJS, just RNJS (missing the preceeding $)... or is that what the export does? Also, I'm still not seeing where the test against the variable is detecting it as js0... It looks like all we're doing is testing for the existence of the $RNJS variable...

        What if we do:

        if [ "$1" = "openbor" ] && [ "/dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick" = "js0" ]; then
          RNJS="$(find /dev/input/by-id/ -name '*raphnet.net_nes2usb*USB-joystick*')"
          RNEJS="$(find /dev/input/by-id/ -name '*raphnet.net_nes2usb*USB-event-joystick*')"  
          export RNJS RNEJS
          sudo mv /dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick /dev/input/js99
          sudo mv /dev/input/by-id/usb-raphnet.net_nes2usb_1228-event-joystick /dev/input/event99
        fi
        

        Or is that just overly complicating things?

        Who's Scruffy Looking?

        mediamogulM 1 Reply Last reply Reply Quote 0
        • mediamogulM
          mediamogul Global Moderator @hansolo77
          last edited by

          @hansolo77 said in Disable devices?:

          It looks like all we're doing is testing for the existence of the $RNJS variable...

          That is all that it's doing. I'm really not sure how you'd correlate an event name to a jsX assignment for the if/then statement. Perhaps you could get there by extracting and manipulating information from:

          cat /proc/bus/input/devices
          

          in some way, but to my knowledge you can't automatically correlate them by just using:

          if  [ "/dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick" = "js0" ]; then
          

          RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

          1 Reply Last reply Reply Quote 0
          • hansolo77H
            hansolo77
            last edited by

            Well I'm getting no where fast. I thought I had the solution, by moving the js assignment. It worked, but now it's not. Even when doing it manually. Now I'm having a problem where the Xbox controller isn't being enumerated as js1. Instead, it's coming up randomly too as js4 sometimes (so OpenBOR's controller mappings need changed and it says "P3 BUTTON 1" etc. Then other times it's coming up as js1 (Player 2), or even a js6 (Player 5) one time. This whole things is ridiculously complicated now. I think I'm going to skip all of it and add another XBOXDRV setting. I really didn't want to do that, because it seems like each new entry takes a little bit longer for the runcommand-onstart to process. But it looks like it's still the best way to go.

            Who's Scruffy Looking?

            mediamogulM 1 Reply Last reply Reply Quote 0
            • mediamogulM
              mediamogul Global Moderator @hansolo77
              last edited by

              @hansolo77

              You never can tell, inspiration usually strikes me just as I've given up. However, xboxdrv will definitely work. One way to keep the script size down is to offload the lengthy xboxdrv launch commands to a separate script, leaving just the if/then statements that call the script in one line. I run a little over 300 xboxdrv maps and my runcommand-onstart file is only 32k.

              RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

              hansolo77H 1 Reply Last reply Reply Quote 1
              • hansolo77H
                hansolo77 @mediamogul
                last edited by

                @mediamogul said in Disable devices?:

                I run a little over 300 xboxdrv maps and my runcommand-onstart file is only 32k.

                And here I am complaining about 7k. :) Maybe it's just in my head.

                Who's Scruffy Looking?

                mediamogulM 1 Reply Last reply Reply Quote 0
                • mediamogulM
                  mediamogul Global Moderator @hansolo77
                  last edited by

                  @hansolo77 said in Disable devices?:

                  Maybe it's just in my head.

                  Maybe not. It could just be some other factor. 7kb shouldn't be slowing you down though. At 32kb, mine loads almost instantly.

                  RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

                  cyperghostC 1 Reply Last reply Reply Quote 0
                  • cyperghostC
                    cyperghost @mediamogul
                    last edited by cyperghost

                    @mediamogul

                    That is all that it's doing. I'm really not sure how you'd correlate an event name to a jsX assignment for the if/then statement. Perhaps you could get there by extracting and manipulating information from ....

                    That's possible, because the events are just symlinks to the jsx-tree. So the idea @mitu introduced works with realpath symlink and gives output dev/input/js[0-99]

                    @hansolo77
                    I think a good approach would be something like this

                    RNJS="$(find /dev/input/by-id/ -name '*raphnet.net_nes2usb*USB-joystick*')"
                    RNEJS="$(find /dev/input/by-id/ -name '*raphnet.net_nes2usb*USB-event-joystick*')"
                    JSX="$(realpath $RNJS)"
                    
                    if [ "$1" = "openbor" ] && [ "${JSX##*/}" = "js0" ]; then
                    export  RNJS RNEJS JSX
                      sudo mv /dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick /dev/input/js99
                      sudo mv /dev/input/by-id/usb-raphnet.net_nes2usb_1228-event-joystick /dev/input/event99
                    fi
                    
                    mediamogulM 1 Reply Last reply Reply Quote 1
                    • mediamogulM
                      mediamogul Global Moderator @cyperghost
                      last edited by

                      @cyperghost

                      I love it when ideas exchange and evolve like this. Thinking on it a little bit, this could be used for a couple of different use cases that I've had in mind and didn't know where to start. I've always disliked how device assignment and handling is out of the user's control.

                      RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

                      1 Reply Last reply Reply Quote 1
                      • hansolo77H
                        hansolo77
                        last edited by

                        It doesn’t solve the problem though. Simply moving the assignment of jsX on the Raphnet didn’t change any of the other assignments. The Xbox controller still wasn’t working because it was assigned to js5. So my Mayflash that was on js2 was picked up as the next controller in OpenBOR. My wireless keyboard was js3 and the mouse was js4. I would have to go through and move the raphnet and the Xbox too. It’s became much more complicated then it should be. XBOXDRV works because you’re removing the kernel driver then creating a new one where you’re assigning the buttons to keyboard keys. It ALWAYS works. But we shouldn’t have to do that. Granted, my particular situation is unique, but the problem is there.

                        Who's Scruffy Looking?

                        mediamogulM 1 Reply Last reply Reply Quote 0
                        • mediamogulM
                          mediamogul Global Moderator @hansolo77
                          last edited by mediamogul

                          @hansolo77 said in Disable devices?:

                          It doesn’t solve the problem though.

                          Why do you always have to be so negative? ;) I do think there's a kernel of a solution here, but I also agree that after you wade through the complexity of what it'd take, it's probably best to seek out a simpler option. This type of issue with controller assignments was actually one of the first things I ever posted about on here. In looking for a solution I ran across xboxdrv and years later it's still a great option for these types of things.

                          RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

                          hansolo77H 1 Reply Last reply Reply Quote 0
                          • hansolo77H
                            hansolo77 @mediamogul
                            last edited by

                            @mediamogul said in Disable devices?:

                            Why do you always have to be so negative? ;)

                            I'm pessimistic.
                            https://www.dictionary.com/browse/pessimistic
                            Comes with my depression, anxiety, low self esteem. The whole belief that nothing positive exists in my life, other than being alive and having a job.

                            Back on topic though, I still think in this particular case, even my initial OP to seek a way to disable a device probably wouldn't have worked either, given that the other devices are also enumerated randomly.

                            Who's Scruffy Looking?

                            mediamogulM 1 Reply Last reply Reply Quote 0
                            • mediamogulM
                              mediamogul Global Moderator @hansolo77
                              last edited by

                              @hansolo77 said in Disable devices?:

                              The whole belief that nothing positive exists in my life, other than being alive and having a job.

                              Don't forget about a kickass retro-gaming console of your own design. That's pretty sweet too.

                              RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

                              1 Reply Last reply Reply Quote 1
                              • ClydeC
                                Clyde @hansolo77
                                last edited by Clyde

                                @hansolo77 said in Disable devices?:

                                Is there a way to disable a device so it's not being detected and identified?

                                USB devices can be disabled via usb authorisation in udev. For example, this udev rule disables my Mayflash Wireless Wii U Adapter:

                                SUBSYSTEM=="usb", ATTRS{idVendor}=="0079", ATTRS{idProduct}=="1800", ATTR{authorized}="0"
                                

                                I got the values for idVendor and idProduct from the output of the lsusb command. Alternatively, you can get them for a specific js* device like this:

                                udevadm info -q all -n /dev/input/js0 | grep 'VENDOR_ID\|MODEL_ID'
                                

                                Just put your vendor and model ids as idVendor and idProduct values in the udev rule and save it in /etc/udev/rules.d/60-disabled_devices.rules (the name between 60- and .rules is arbitrary). That should disable the usb device on the next reboot or after running the command sudo udevadm trigger.

                                edit: The change is not permanent. Just delete the rule or change its value "autorized" to 1 to enable the device again.

                                cyperghostC 1 Reply Last reply Reply Quote 3
                                • cyperghostC
                                  cyperghost @Clyde
                                  last edited by cyperghost

                                  @clyde This looks like a generic solution.
                                  Is it save to execute those commands during a running ES session?

                                  So on runcommand-onstart a driver is disabeld.
                                  On runcommand-onend all drivers are enabled again.

                                  But I think it won't solve the problem, that a specific driver (maybe the XBOX360) will be first row ;)
                                  Any suggetions? I can't test this because all my joypads are simply assigned as js# devices.... there are no events triggered.

                                  ClydeC 1 Reply Last reply Reply Quote 0
                                  • ClydeC
                                    Clyde @cyperghost
                                    last edited by

                                    @cyperghost Alas, I don't now how ES and its emulators will react to this on runtime. I didn't use it myself (yet), but researched it only because of this thread and a general interest for future use.

                                    As for specific drivers, I don't have any experience in that either, but as long as they depend on the devices in /dev/input/, they should react to disabled devices there accordingly, I suppose.

                                    1 Reply Last reply Reply Quote 0
                                    • First post
                                      Last post

                                    Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                    Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.