Homepage › Forums › RetroPie Project › Everything else related to the RetroPie Project › Change RetroPie GPIO button coding to 1 press
- This topic has 27 replies, 4 voices, and was last updated 10 years, 11 months ago by brooksyx.
-
AuthorPosts
-
12/02/2013 at 04:05 #3372bradj074Participant
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?
12/02/2013 at 07:22 #3374petrockblogKeymasterCurrently, 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.
12/02/2013 at 07:32 #3375bradj074ParticipantAwesome, 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?
12/04/2013 at 04:42 #3409supersirlinkParticipantWould like to know how to do this as well… :)
12/04/2013 at 21:23 #3411petrockblogKeymasterWith 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
viasudo 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.
12/05/2013 at 03:29 #3422supersirlinkParticipantThat’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!
12/05/2013 at 03:54 #3423bradj074Participanti 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”);12/08/2013 at 22:45 #3491supersirlinkParticipantDo 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…
12/08/2013 at 23:08 #3492supersirlinkParticipantIf 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 */
12/08/2013 at 23:12 #3493supersirlinkParticipantFlorian, can we put a key combination in the code, like say KEY_ALT+ESC, or KEY_ALT+H?
12/09/2013 at 20:20 #3507brooksyxParticipant[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.
12/09/2013 at 21:55 #3512supersirlinkParticipantChances 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.
12/09/2013 at 22:08 #3513brooksyxParticipant[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?
12/09/2013 at 23:38 #3519supersirlinkParticipantIt’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…
12/09/2013 at 23:41 #3520supersirlinkParticipantI haven’t managed to find if you can send a key sequence with the script… Anyone know if that is possible?
12/09/2013 at 23:50 #3521brooksyxParticipantThanks much! Gonna wire it up later tonight.
12/10/2013 at 05:36 #3523brooksyxParticipant[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
viasudo 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!
12/10/2013 at 07:27 #3524petrockblogKeymasterIf 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.12/10/2013 at 07:33 #3525petrockblogKeymaster[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 likecase 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.
12/10/2013 at 08:01 #3527brooksyxParticipant[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/ ?
12/10/2013 at 08:21 #3528bradj074ParticipantI 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!
12/10/2013 at 09:07 #3529brooksyxParticipantNow 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
12/10/2013 at 19:32 #3534petrockblogKeymaster[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.12/10/2013 at 19:52 #3539brooksyxParticipantOkay, I gotcha. Looks like it copied over a precompiled version from the retropie setup. Thanks again!
12/11/2013 at 00:16 #3543supersirlinkParticipant[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!
12/11/2013 at 17:58 #3550brooksyxParticipant[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.gitIf 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?
12/11/2013 at 21:28 #3555petrockblogKeymasterThe cfg file is located in /home/pi/RetroPie/supplementary/SNESDev-Rpi/supplementary/.
12/11/2013 at 21:36 #3556brooksyxParticipantI 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
-
AuthorPosts
- The forum ‘Everything else related to the RetroPie Project’ is closed to new topics and replies.