Homepage Forums RetroPie Project Everything else related to the RetroPie Project Change RetroPie GPIO button coding to 1 press

Viewing 28 posts - 1 through 28 (of 28 total)
  • Author
    Posts
  • #3372
    bradj074
    Participant

    I have a Retropie GPIO added into my pi (rev 2) that i put in a SNES. I wired the button on the GPIO to my reset button on the SNES but it isn’t functioning quite like i would prefer. I simply would like for the switch to press the escape key after one press (not 3) and nothing more (no 1 press for “r” or shutdown on 5).

    I cannot find where\which file of SNESDev-Pi needs to be modified to accomplish this. Which file should i change and how should i change it to adjust to this result?

    #3374
    petrockblog
    Keymaster

    Currently, you would have to modify the lines around https://github.com/petrockblog/SNESDev-RPi/blob/master/src/SNESDev.c#L287 and recompile/reinstall SNESDev.

    I plan to make this configurable when I find some time.

    #3375
    bradj074
    Participant

    Awesome, thanks for the help. I’ve got it edited the way i need to.

    Now for my dumb question, how do i recompile and reinstall SNESDEV?

    #3409
    supersirlink
    Participant

    Would like to know how to do this as well… :)

    #3411
    petrockblog
    Keymaster

    With the recent version of SNESDev, you need to run ./build from within the directory /home/pi/RetroPie/supplementary/SNESDev-Rpi/. After the compilation has finished, you need to copy the new executable to /usr/local/bin via

    sudo cp "/home/pi/RetroPie/supplementary/SNESDev-Rpi/SNESDev" /usr/local/bin/

    and restart SNESDev via

    sudo service SNESDev restart

    I know that this should be easier – in the best case the button behavior could also be configured via the config file. But I did not find the time to implement that feature yet.

    #3422
    supersirlink
    Participant

    That’s not bad at all! I changed the single press from R to H to reset the ROM and kept 3 and 5 press as is for now… I got the GPIO board the other day and plan to wire it up this weekend! I also got a shutdown switch from Mausberry Circuits that I will be wiring up to power/shutdown… Thanks!

    #3423
    bradj074
    Participant

    i modified the SNESDev.c lines in the coding in several different ways and am not having any luck getting it to register correctly. I have confirmed the button itself functions with the original code so it is in my editing.

    I have pasted the modified code i tried that is the same method supersirlink said he had written in the interest of helping out both of us (i used the escape key instead of h). I left the shutdown command in and that will function if it gets those 5 key presses but for some reason it will not register any of the esc keys.

    Can you have a look at the coding and tell me how it should be properly coded?

    case BTN_STATE_PRESSED:
    if (button.pressedCtr == 1 && button.duration >= 1) {
    uinput_kbd_write(&uinp_kbd, KEY_ESC, 1, EV_KEY);
    }
    break;
    case BTN_STATE_RELEASED:
    if (button.pressedCtr == 1 && button.duration >= 1) {
    uinput_kbd_write(&uinp_kbd, KEY_ESC, 0, EV_KEY);
    } else if (button.pressedCtr == 3 && button.duration >= 1) {
    // Sending ESC
    uinput_kbd_write(&uinp_kbd, KEY_ESC, 1, EV_KEY);
    usleep(50000);
    uinput_kbd_write(&uinp_kbd, KEY_ESC, 0, EV_KEY);
    } else if (button.pressedCtr == 5 && button.duration >= 1) {
    uinput_kbd_write(&uinp_kbd, KEY_ESC, 1, EV_KEY);
    usleep(50000);
    uinput_kbd_write(&uinp_kbd, KEY_ESC, 0, EV_KEY);
    // shutting down
    system(“shutdown -t 3 -h now”);

    #3491
    supersirlink
    Participant

    Do you have this line defined in one of your retroarch.cfg files:
    input_enable_hotkey_btn = 6

    I found when I set that, I have to use the hotkey to send ANY commands, even from the keyboard. My momentary switch works when I hold down the hotkey button then press the switch…

    #3492
    supersirlink
    Participant

    If all you want is ESC, try this:

    if (confres.button_enabled) {
                            btn_read(&button);
    
                            switch (button.state) {
                            case BTN_STATE_IDLE:
                                    break;
                            case BTN_STATE_PRESSED:
                                    if (button.pressedCtr == 1 && button.duration >= 1) {
                                            uinput_kbd_write(&uinp_kbd, KEY_ESC, 1, EV_KEY);
                                    }
                                    break;
                            case BTN_STATE_RELEASED:
                                            if (button.pressedCtr == 1 && button.duration >= 1) {
                                                    uinput_kbd_write(&uinp_kbd, KEY_ESC, 0, EV_KEY);
                                            }
                                    break;
                            }
                    }
    
                    /* wait for some time to keep the CPU load low */
    
    #3493
    supersirlink
    Participant

    Florian, can we put a key combination in the code, like say KEY_ALT+ESC, or KEY_ALT+H?

    #3507
    brooksyx
    Participant

    [quote=3492]If all you want is ESC, try this:

    [/quote]

    Thanks for this. I went ahead and forked the main repo. Will try to rebuild from my own tonight.

    Also I trying to wire this up to the reset button on the snes. Does anyone know which pins I need to short out? I would imagine it would be the 2 larger ones on the bottom.

    #3512
    supersirlink
    Participant

    Chances are 2 pins are for the circuit and the other(s) are support. Test for continuity across all the points, with the switch depressed and open.

    If you do this on the switch provided with the GPIO board, you will see the outer 2 are isolated from the inner 2. And the corresponding holes on the board are also isolated. (Sometimes can be ground, but I didn’t see that. )

    So for mine, I used a NES reset switch, I picked up the middle two points.

    I actually soldered a connector there for easy removal.

    #3513
    brooksyx
    Participant

    [quote=3512]Chances are 2 pins are for the circuit and the other(s) are support. Test for continuity across all the points, with the switch depressed and open.

    If you do this on the switch provided with the GPIO board, you will see the outer 2 are isolated from the inner 2. And the corresponding holes on the board are also isolated. (Sometimes can be ground, but I didn’t see that. )

    So for mine, I used a NES reset switch, I picked up the middle two points.

    I actually soldered a connector there for easy removal.
    [/quote]

    Thanks, makes sense. However I am not sure I know what you mean when you say the middle 2, as there are only 4, one on each corner. I assume you mean the two larger holes on the bottom. I did check to see if the resistance changed when the button was pressed with a multiometer and did not notice a change.

    edit:

    Do I need short the red points or the blue points?

    1

    #3519
    supersirlink
    Participant

    It’s the red ones… You don’t want to check for resistance, but continuity… Should make a sound and show a value when the probes are touched…

    #3520
    supersirlink
    Participant

    I haven’t managed to find if you can send a key sequence with the script… Anyone know if that is possible?

    #3521
    brooksyx
    Participant

    Thanks much! Gonna wire it up later tonight.

    #3523
    brooksyx
    Participant

    [quote=3411]With the recent version of SNESDev, you need to run ./build from within the directory /home/pi/RetroPie/supplementary/SNESDev-Rpi/. After the compilation has finished, you need to copy the new executable to /usr/local/bin via

    sudo cp "/home/pi/RetroPie/supplementary/SNESDev-Rpi/SNESDev" /usr/local/bin/

    and restart SNESDev via

    sudo service SNESDev restart

    I know that this should be easier – in the best case the button behavior could also be configured via the config file. But I did not find the time to implement that feature yet.
    [/quote]

    I can’t build from /home/pi/RetroPie/supplementary/SNESDev-Rpi as there is no build.sh there. I tried building from /home/pi/SNESDev-RPi/ and copying that to /usr/local/bin/ but I get a /etc/snesdev.cfg not found when I do that.

    Any tips on how to fix this or way to completely remove SNESDev and re-install it?

    Thanks!

    #3524
    petrockblog
    Keymaster

    If you start with the RetroPie SD-card image, first you need to install SNESDev from sources (e.g., via the RetroPie-Setup Script, source-baseed installation, select only SNESDev). The file build.sh is available afterwards.

    #3525
    petrockblog
    Keymaster

    [quote=3493]Florian, can we put a key combination in the code, like say KEY_ALT+ESC, or KEY_ALT+H?[/quote]
    I have not tried this myself, but I would guess that something like

                            case BTN_STATE_PRESSED:
                                    if (button.pressedCtr == 1 && button.duration >= 1) {
                                            uinput_kbd_write(&uinp_kbd, KEY_LEFTALT,  1, EV_KEY);
                                            uinput_kbd_write(&uinp_kbd, KEY_H, 1, EV_KEY);
                                    }
                                    break;
                            case BTN_STATE_RELEASED:
                                            if (button.pressedCtr == 1 && button.duration >= 1) {
                                                    uinput_kbd_write(&uinp_kbd, KEY_LEFTALT, 0, EV_KEY);
                                                    uinput_kbd_write(&uinp_kbd, KEY_H, 0, EV_KEY);
                                            }
                                    break;

    could work.

    See, e.g., http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/include/linux/input.h?v=2.6.11.8#L164 for a complete list of key codes.

    #3527
    brooksyx
    Participant

    [quote=3524]If you start with the RetroPie SD-card image, first you need to install SNESDev from sources (e.g., via the RetroPie-Setup Script, source-baseed installation, select only SNESDev). The file build.sh is available afterwards.[/quote]

    I did use the sd card image but I installed SNESDev via github and not via retropie_setup.sh. If thats what you are saying. I have SNESDev at /home/pi/SNESDev-RPi/ , can I install it from this location or do I need to run the retropie_setup.sh to add the additional files to /home/pi/RetroPie/supplements/SNESDev-Rpi/ ?

    #3528
    bradj074
    Participant

    I tried Petrockblog’s most recent idea of entering two commands for key pressed to be able to use hotkeys and confirmed it does not work. I can get the GPIO button to function while holding down my function key on the gamepad but mapping two button commands to one command did not provide any results. Let me know if anyone else has any ideas so we can get this all figured out!

    #3529
    brooksyx
    Participant

    Now I am really confused. I just did a fresh install and added SNESDev from my own forked repo which is set to exit back to emulation station after one press. However it is still 3 presses. What did I do wrong? I am positive I added my own correct repo. git clone git://github.com/brooksyx/SNESDev-RPi.git

    #3534
    petrockblog
    Keymaster

    [quote=3529]Now I am really confused. I just did a fresh install and added SNESDev from my own forked repo which is set to exit back to emulation station after one press. However it is still 3 presses. What did I do wrong? I am positive I added my own correct repo. git clone git://github.com/brooksyx/SNESDev-RPi.git[/quote]
    If you are running SNESDev as a service, you need to copy the new binary to /usr/local/bin/, see https://github.com/retropie/RetroPie-Setup/blob/master/scriptmodules/supplementary.shinc#L210.

    #3539
    brooksyx
    Participant

    Okay, I gotcha. Looks like it copied over a precompiled version from the retropie setup. Thanks again!

    #3543
    supersirlink
    Participant

    [quote=3528]I tried Petrockblog’s most recent idea of entering two commands for key pressed to be able to use hotkeys and confirmed it does not work. I can get the GPIO button to function while holding down my function key on the gamepad but mapping two button commands to one command did not provide any results. Let me know if anyone else has any ideas so we can get this all figured out![/quote]

    There was an extra space after the comma after leftalt, be sure you only have one space… Also you will need to put the correct key in for the hot key assignment you made… Thats where I put two hot keys in my retroarch.cfg

    I have one hot key defined for my controller and one for the keyboard. That way I can input commands from the controller OR keyboard without having to grab both…

    input_enable_hotkey = alt
    input_enable_hotkey_btn = 6
    case BTN_STATE_PRESSED:
                                    if (button.pressedCtr == 1 && button.duration >= 1) {
    										uinput_kbd_write(&uinp_kbd, KEY_LEFTALT, 1, EV_KEY);
                                            uinput_kbd_write(&uinp_kbd, KEY_R, 1, EV_KEY);
                                    }
                                    break;
                            case BTN_STATE_RELEASED:
                                            if (button.pressedCtr == 1 && button.duration >= 1) {
    												uinput_kbd_write(&uinp_kbd, KEY_LEFTALT, 0, EV_KEY);
                                                    uinput_kbd_write(&uinp_kbd, KEY_R, 0, EV_KEY);
    

    And just to confirm this worked for me… I push the momentary switch and with the assignments above, the rom resets (without having to touch the controller or keyboard)…

    Thanks Florian!

    #3550
    brooksyx
    Participant

    [quote=3534]

    <div class=”d4p-bbt-quote-title”>brooksyx wrote:</div>
    Now I am really confused. I just did a fresh install and added SNESDev from my own forked repo which is set to exit back to emulation station after one press. However it is still 3 presses. What did I do wrong? I am positive I added my own correct repo. git clone git://github.com/brooksyx/SNESDev-RPi.git

    If you are running SNESDev as a service, you need to copy the new binary to /usr/local/bin/, see https://github.com/retropie/RetroPie-Setup/blob/master/scriptmodules/supplementary.shinc#L210.
    [/quote]

    I don’t seem to be having any luck compiling my own version of SNESDev and overwriting the prebuilt one. I backed up SNESDev in /usr/local/bin/ as SNESDev and overwrote with the one I compiled but it says its needs /etc/snesdev.cfg. So I copied the file in /home/pi/SNESDev-RPi/scipts/SNESDev over to etc as snesdev.cfg and it gives an error. Is that snesdev.cfg file from my build in a different location in SNESDev-RPi?

    #3555
    petrockblog
    Keymaster

    The cfg file is located in /home/pi/RetroPie/supplementary/SNESDev-Rpi/supplementary/.

    #3556
    brooksyx
    Participant

    I don’t remember off of the top of my head but I don’t believe I saw it in there. Is it a hidden file? (Maybe that’s what you mean by “/.”?)

    edit: Well either way I just downloaded it from the repo. So even if I can’t find it I will just write this one. I would imagine it would work just fine.

    https://github.com/petrockblog/SNESDev-RPi/tree/master/supplementary

    edit: That fixed it. Working great with one button reboot now! Thanks x10

Viewing 28 posts - 1 through 28 (of 28 total)
  • The forum ‘Everything else related to the RetroPie Project’ is closed to new topics and replies.