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 7.2k 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.
    • hansolo77H
      hansolo77
      last edited by

      Ah.. you think blocking rw access will "disable" the device? I did some searching and came up with a 3rd party tool "hud-ctrl" but it didn't work. I will try modifying the access to the device on my next day off. It would be a chmod thing right?

      Who's Scruffy Looking?

      mituM 1 Reply Last reply Reply Quote 0
      • mituM
        mitu Global Moderator @hansolo77
        last edited by mitu

        @hansolo77 said in Disable devices?:

        It would be a chmod thing right?

        Yes, something chmod g-rw /dev/input/jsX to disable read/write access and then chmod g+rw /dev/input/jsX to restore it afterwards. Make sure you use sudo chmod ... to run the commands.

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

          @mitu Yes that seems to be the hard way but is a route. But how can be assured which controller is related to which device-tree-number?

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

            (Just turning gears in my head here, can't test the theory right now)....

            Can you chmod through /dev/input/by-id or /dev/input/by-path rather than /dev/input/jsX? I seem to recall having difficulties with the Joystick Selection tool because the js# would change on random during boot up.

            Who's Scruffy Looking?

            mituM 1 Reply Last reply Reply Quote 0
            • mituM
              mitu Global Moderator @hansolo77
              last edited by

              @hansolo77 No, symlinks have their own permissions. However, you can use realpath to get the target of the symlink.

              # by id
              pi@retropie:~ $ ls -l /dev/input/by-id/usb-0583_USB_2-axis_8-button_gamepad-joystick
              lrwxrwxrwx 1 root root 6 Jul 19 02:46 /dev/input/by-id/usb-0583_USB_2-axis_8-button_gamepad-joystick -> ../js0
              pi@retropie:~ $ realpath /dev/input/by-id/usb-0583_USB_2-axis_8-button_gamepad-joystick
              /dev/input/js0
              
              # by path
              pi@retropie:~ $ ls -l /dev/input/by-path/platform-3f980000.usb-usb-0\:1.4\:1.0-joystick
              lrwxrwxrwx 1 root root 6 Jul 19 02:46 /dev/input/by-path/platform-3f980000.usb-usb-0:1.4:1.0-joystick -> ../js0
              pi@retropie:~ $ realpath /dev/input/by-path/platform-3f980000.usb-usb-0\:1.4\:1.0-joystick
              /dev/input/js0
              
              1 Reply Last reply Reply Quote 0
              • hansolo77H
                hansolo77
                last edited by

                Something to experiment with at least..

                Who's Scruffy Looking?

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

                  Ok, got home and did a test..

                  pi@retropie:~ $ ls -l /dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick
                  lrwxrwxrwx 1 root root 6 Jul 23 00:34 /dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick -> ../js3
                  

                  Then I did a sudo reboot and ran it again:

                  pi@retropie:~ $ ls -l /dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick
                  lrwxrwxrwx 1 root root 6 Jul 23 22:26 /dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick -> ../js0
                  

                  If it stayed the same, I could try and use that command to temporary disable js3, but after reboot it's now js0. This is my problem I'm always having. The Pi doesn't enumerate the devices according to their plugged in location. I thought I had it figured out at one point, even official Raspberry Pi documentation said it should go "top left, bottom left, top right, bottom right". But this clearly isn't the case. It might be because the Xbox dongle hasn't fully "booted up" yet, as the little light blinks a good while before it's fully up and ready. The Raphnet is probably faster, so it takes over. But this doesn't happen all the time, which is what is so frustrating.

                  Is there a way to maybe have a script or something that can detect which port it's running in and THEN disable it? Something like

                  Execute "ls -l /dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick"
                  Export results to "Variable"
                  Execute chmod to disable "Variable"
                  -----
                  Then on return from game - Execute chmod to enable "Variable"
                  

                  Probably no way to do that huh? Have it intelligently identify the jsX variable by executing that command before hand.

                  Who's Scruffy Looking?

                  mituM 1 Reply Last reply Reply Quote 1
                  • mituM
                    mitu Global Moderator @hansolo77
                    last edited by

                    @hansolo77 Since the ID is the same, you'll get the jsX device by executing

                    realpath /dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick
                    

                    Your variable can be something like

                    raphnetJS=$(realpath /dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick)
                    chmod g-rw /dev/input/$raphnetJS
                    
                    1 Reply Last reply Reply Quote 2
                    • cyperghostC
                      cyperghost
                      last edited by

                      @mitu Wow that is a nice solution. But I think you have to strip the /dev/input because realpath is /dev/input/js# to change filestate sudo command is needed.

                      I think that will work ... so to disable that device chmod g-rw to enable chmod g+rw

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

                        I just tested this combination:

                        pi@retropie:~ $ ls -l /dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick
                        lrwxrwxrwx 1 root root 6 Jul 23 22:54 /dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick -> ../js0
                        
                        pi@retropie:~ $ sudo chmod g-rw /dev/input/js0
                        

                        The result is that the controller is still active (I plugged it in to test). Just for "fun" I ran this with that same result:

                        pi@retropie:~ $ ls -l /dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick
                        lrwxrwxrwx 1 root root 6 Jul 23 22:54 /dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick -> ../js0
                        

                        Did I format my chmod wrong?


                        EDIT Another quick find:

                        pi@retropie:~ $ ls -l /dev/input
                        total 0
                        drwxr-xr-x 2 root root     280 Jul 24 21:02 by-id
                        drwxr-xr-x 2 root root     280 Jul 24 21:02 by-path
                        crw-rw---- 1 root input 13, 64 Jul 23 22:54 event0
                        crw-rw---- 1 root input 13, 65 Jul 23 22:54 event1
                        crw-rw---- 1 root input 13, 66 Jul 23 22:54 event2
                        crw-rw---- 1 root input 13, 67 Jul 23 22:54 event3
                        crw-rw---- 1 root input 13, 68 Jul 23 22:54 event4
                        crw-rw---- 1 root input 13, 69 Jul 23 22:54 event5
                        crw-rw---- 1 root input 13, 70 Jul 23 22:54 event6
                        crw-rw---- 1 root input 13, 71 Jul 24 21:02 event7
                        crw------- 1 root input 13,  0 Jul 23 22:54 js0
                        crw-rw---- 1 root input 13,  1 Jul 23 22:54 js1
                        crw-rw---- 1 root input 13,  2 Jul 23 22:54 js2
                        crw-rw---- 1 root input 13,  3 Jul 23 22:54 js3
                        crw-rw---- 1 root input 13,  4 Jul 24 21:02 js4
                        crw-rw---- 1 root input 13, 63 Jul 23 22:54 mice
                        crw-rw---- 1 root input 13, 32 Jul 23 22:54 mouse0
                        

                        So it DID set the -rw.. but the device is still reading input from the controller... :(


                        EDIT 2
                        I give up for tonight. Did a bunch of googling, came up with a potential option from here:
                        https://github.com/AntiMicro/antimicro/wiki/Methods-for-Disabling-Joystick-Reading-in-Linux#permission-change
                        Essentially, using chmod 000 rather than chmod g-rw. Unfortunately, it didn't work either. I tried doing it on the jsX, event, and the by-id path. Nothing I tried worked. The controller was still responsive even though I confirmed through ls -l that the device was no longer readable or writable. Bummer there.. Any other ideas?

                        Who's Scruffy Looking?

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

                          I think I might have found a solution. Something I remember coming across before.. If the "raphnet" adapter is identified as js0, I can do a sudo mv to change it's ID. SO...

                          I run a test.

                          pi@retropie:~ $ ls -l /dev/input/by-id
                          total 0
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-Mayflash_Ltd_Mayflash_MD_USB_Adapter-event-joystick -> ../event6
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-Mayflash_Ltd_Mayflash_MD_USB_Adapter-if01-event-joystick -> ../event7
                          lrwxrwxrwx 1 root root 6 Jul 26 23:55 usb-Mayflash_Ltd_Mayflash_MD_USB_Adapter-if01-joystick -> ../js4
                          lrwxrwxrwx 1 root root 6 Jul 26 23:55 usb-Mayflash_Ltd_Mayflash_MD_USB_Adapter-joystick -> ../js3
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-Microsoft_Microsoft®_2.4GHz_Transceiver_v8.0-event-kbd -> ../event3
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-Microsoft_Microsoft®_2.4GHz_Transceiver_v8.0-if01-event-mouse -> ../event4
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-Microsoft_Microsoft®_2.4GHz_Transceiver_v8.0-if01-mouse -> ../mouse0
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-Microsoft_Microsoft®_2.4GHz_Transceiver_v8.0-if02-event-kbd -> ../event5
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-©Microsoft_Xbox_360_Wireless_Receiver_for_Windows_E1594E70-event-joystick -> ../event2
                          lrwxrwxrwx 1 root root 6 Jul 26 23:55 usb-©Microsoft_Xbox_360_Wireless_Receiver_for_Windows_E1594E70-joystick -> ../js2
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-raphnet.net_nes2usb_1228-event-joystick -> ../event1
                          lrwxrwxrwx 1 root root 6 Jul 26 23:55 usb-raphnet.net_nes2usb_1228-joystick -> ../js1
                          

                          The "raphnet" is located on js1. Everything should work like it should. Test running OpenBOR, and YUP! The Xbox controller works just fine. Reboot and test again:

                          pi@retropie:~ $ ls -l /dev/input/by-id
                          total 0
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-Mayflash_Ltd_Mayflash_MD_USB_Adapter-event-joystick -> ../event6
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-Mayflash_Ltd_Mayflash_MD_USB_Adapter-if01-event-joystick -> ../event7
                          lrwxrwxrwx 1 root root 6 Jul 26 23:55 usb-Mayflash_Ltd_Mayflash_MD_USB_Adapter-if01-joystick -> ../js4
                          lrwxrwxrwx 1 root root 6 Jul 26 23:55 usb-Mayflash_Ltd_Mayflash_MD_USB_Adapter-joystick -> ../js3
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-Microsoft_Microsoft®_2.4GHz_Transceiver_v8.0-event-kbd -> ../event3
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-Microsoft_Microsoft®_2.4GHz_Transceiver_v8.0-if01-event-mouse -> ../event4
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-Microsoft_Microsoft®_2.4GHz_Transceiver_v8.0-if01-mouse -> ../mouse0
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-Microsoft_Microsoft®_2.4GHz_Transceiver_v8.0-if02-event-kbd -> ../event5
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-©Microsoft_Xbox_360_Wireless_Receiver_for_Windows_E1594E70-event-joystick -> ../event2
                          lrwxrwxrwx 1 root root 6 Jul 26 23:55 usb-©Microsoft_Xbox_360_Wireless_Receiver_for_Windows_E1594E70-joystick -> ../js2
                          lrwxrwxrwx 1 root root 9 Jul 26 23:55 usb-raphnet.net_nes2usb_1228-event-joystick -> ../event1
                          lrwxrwxrwx 1 root root 6 Jul 26 23:55 usb-raphnet.net_nes2usb_1228-joystick -> ../js0
                          

                          (ok so I just copied the same block and changed it but...)
                          Now the "Raphnet" is located on js0. Test it in OpenBOR and the result is the Xbox controller doesn't work. So let's try this... Reboot, confirm "raphnet" is located on js0. It is, so I execute this:

                          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
                          

                          Then I try and run OpenBOR. The game is working with the Xbox controller like it should again! The trick here is to move the controller's ID to something beyond all the other controller ID's. The game appears to then be loading up the next "first" controller Linux has set up (in this case, the Xbox). The hard part it took me a while to figure out is that I have to do this BEFORE launching an OpenBOR game. If not, the configs are out of sync or something and don't work even if I remember to move them and re-load the game. It only works if I move the ID before the first time I load an OpenBOR game. But it works!

                          So now I just need a way to add this to my runcommand-onstart script. I tried creating an IF/THEN for the $1 system of "openbor" but it didn't work. I also tried to flat out add the commands to very top of the script without any IF/THEN, but that didn't work either.

                          Any thoughts?

                          Who's Scruffy Looking?

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

                            Ok, got a working runcommand-onstartscript going, but it's not pretty. Had some complications but it's all figured out now.

                            if [ "$1" = "openbor" ]
                            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
                            

                            The "not pretty" part is that this is a suicide modification. I don't know how to store the original ID's as variables to be recalled in the runcommand-onend script to put things back to normal. Going this route solves the problem for OpenBOR, but kills any other games that would use that device. What I need is a script that will do this:

                            if [ "$1" = "openbor" ] && [ "/dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick" = "js0" ]
                            then
                            # store variable for /dev/input/by-id/usb-raphnet.net_nes2usb_1228-event-joystick as this changes randomly too and ties with the 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
                            

                            and runcommand-onend:

                            if [ "$1" = "openbor" ] && [ "/dev/input/by-id/usb-raphnet.net_nes2usb_1228-joystick" = "js99" ]
                            then
                            # recall stored variable for eventX
                            sudo mv /dev/input/js99 /dev/input/js0
                            sudo mv /dev/input/event99 /dev/input/eventX #variable
                            fi
                            

                            Does this sound possible? I know my &&'s and ='s are probably wrong, this is coming from a google search lol. Does the runcommand-onend remember the $1 variable when a game is exiting?

                            Who's Scruffy Looking?

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

                              Anybody have any experience with this care to offer some helpful advice? :) Sorry I gotta ask. Once I get this figured out and working, I promise to leave you guys alone for a month or so before I try and do something else lol.

                              Who's Scruffy Looking?

                              mediamogulM 1 Reply Last reply Reply Quote 0
                              • 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
                                            • 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.