0

PiGrrl 2 TFT button assignment
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

PiGrrl 2 TFT button assignment

by acjgoblu on Mon May 30, 2016 10:00 pm

As a point of reference, my first experience with Linux was going through the tutorial to set up the software on the PiGrrl, so please keep in mind that I have very little knowledge of working within it's command line structure.

I was wondering if someone might be able to help me figure out how to program the PiTFT buttons. Specifically, I'd like to add SAVE, LOAD, VOLUME UP, and VOLUME DOWN as my four buttons. First of all, is that doable? If so, how would I go about it?

I've been able to access retrogame.c, so I know how to get there. Just can't for the life of me find anything to describe what keyboard commands I need to enter to accomplish these goals. I thought I saw somewhere that save and load should map to F2 and F4 respectively, but somewhere else says Alt-F2 and Alt-F4. If it is the latter, is it possible to instruct retrogame.c to do a dual button combination OR can you set up a hotkey/macro function within the program? And I have no idea what the keyboard commands for volume control would be.

This is probably super simple to some, but any help would be appreciated.

Thanks!

acjgoblu
 
Posts: 15
Joined: Mon May 16, 2016 1:33 pm

Re: PiGrrl 2 TFT button assignment

by acjgoblu on Tue May 31, 2016 9:52 pm

Bump...anyone with any thoughts? I'm sure I can't be the only one who would like to use the TFT keys this way.

Please help!

-Andrew

acjgoblu
 
Posts: 15
Joined: Mon May 16, 2016 1:33 pm

Re: PiGrrl 2 TFT button assignment

by Radduran on Wed Jun 29, 2016 12:55 am

For the Love of God BUMP! I have been searching everywhere for this info!

Radduran
 
Posts: 42
Joined: Wed Jun 08, 2016 5:54 am

Re: PiGrrl 2 TFT button assignment

by acjgoblu on Wed Jun 29, 2016 12:06 pm

OK, I was able to figure this out. Not actually that difficult...

Again, I wanted my TFT buttons to control save state, load state, volume up, and volume down. Most of the editing is within the retroarch.cfg file, which can be accessed through the RetroPie menu in EmulationStation ("Edit Retroarch Config" or something to that effect). That'll pull up a new menu, where you'll select "manually configure retroarch.cfg", then at the next menu select the main retroarch.cfg file. Now you're in the file and can edit. It should look like this: https://github.com/libretro/RetroArch/b ... roarch.cfg

Save and Load State is easy, because they are already coded to F2 and F4, respectively. I don't know whether this was necessary (I'm a big time Linux newbie), but I found their code lines (line number 530-533 in the above document, "input Load State and input Save State) and uncommented them. Done.

Volume Up and Volume Down are also in this file (line number 598-601, increase and decrease audio volume). They are currently assigned to kp_plus and kp_minus, but I found I had to change them to other unused regular keyboard keys for this to work. I tried to find a full list of keys that were already pre-assigned in RetroPie, but couldn't find one. I was too lazy to manually find keys that were unused (seems like most are preassigned), so I just ended up reassigning keys that were assigned to functions that I didn't care about. I think I used "r" and "e" and assigned one to "input_volume_up" and one to "input_volume_down", respectively. I then switched the functions that those keys were originally assigned to ("e" was slow motion, lines 585-586; reassigned to "," ; "r" was rewind, lines 556-557, reassigned to "."). I then uncommented all of those lines (all 4 volume up/down lines, and the two lines pertaining to slow motion and rewind that I reassigned - again, not sure if this was required, but it worked!). So now you have volume up and down assigned to normal keys.

Lastly within retroarch.cfg, you need to assign your hotkey button. This is at line 596, "input_enable_hotkey_button" - I set it to "space", as this is preassigned to the select button on a PiGrrl 2. I then uncommented lines 595 and 596. Then save your retroarch.cfg file, and you're done there. All four of those commands are basically hotkeys which then require the select button to be held down to activate; the TFT buttons do nothing if you just press them on their own. But it still works well this way.

Once your retroarch.cfg file is complete, you then have to access the retrogame.c file via an SSH connection to your RasPi. See Adafruit instructions for accessing that here: https://learn.adafruit.com/pigrrl-2/software
Once in that file, scroll down to the ioStandard table, the one with PiTFT buttons at the bottom. You then have to change your button assignments for those four buttons to correlate with the buttons you assigned in retroarch.cfg. Also keep in mind that these buttons are listed in upside down order (ie, GPIO pin 17, which is PiTFT button 1, is actually the lowest button, not the highest). For my file, I did this:
{ 17, KEY_E }, // Volume Down
{ 22, KEY_R }, // Volume Up
{ 23, KEY_F4 }, // Load State
{ 27, KEY_F2 }, // Save State

Which meant that the TFT button closest to the top of the Game Boy was Save State, 2nd from the top was Load State, 3rd was Volume Up, 4th was Volume Down.
Then just save the file as indicated in Adafruit's software guide, reboot, and you should be good!

I don't know if I did this perfectly from a Linux coding perspective, but it has worked well for me so far. I'm not sure if there's a way to do this without the Select button hotkey, but again, I'm not complaining because it works.

Hope this helps!

acjgoblu
 
Posts: 15
Joined: Mon May 16, 2016 1:33 pm

Re: PiGrrl 2 TFT button assignment

by chimomatt on Tue Aug 02, 2016 3:04 pm

are you able to post a complete guide on how to assign those keys I am fairly new to this whole coding thing and I have been trying to figure this out for awhile any help with this would be very appreciated

chimomatt
 
Posts: 5
Joined: Sat Jun 11, 2016 1:26 pm

Re: PiGrrl 2 TFT button assignment

by acjgoblu on Tue Aug 02, 2016 3:17 pm

To be honest, that post is about as step-by-step as I did it. I'm happy to answer any specific questions if I can (I'm pretty new to coding as well), but unfortunately I don't think I have a ton more to add than what I already posted...sorry!

acjgoblu
 
Posts: 15
Joined: Mon May 16, 2016 1:33 pm

Re: PiGrrl 2 TFT button assignment

by chimomatt on Tue Aug 02, 2016 3:26 pm

How do u uncomment something I'm following your steps as we speak

chimomatt
 
Posts: 5
Joined: Sat Jun 11, 2016 1:26 pm

Re: PiGrrl 2 TFT button assignment

by acjgoblu on Tue Aug 02, 2016 3:36 pm

just delete the hashtag symbol in front of the line.

acjgoblu
 
Posts: 15
Joined: Mon May 16, 2016 1:33 pm

Re: PiGrrl 2 TFT button assignment

by chimomatt on Tue Aug 02, 2016 3:39 pm

OK cool thanks and then what do I press to save and exit

chimomatt
 
Posts: 5
Joined: Sat Jun 11, 2016 1:26 pm

Re: PiGrrl 2 TFT button assignment

by acjgoblu on Tue Aug 02, 2016 4:08 pm

Hmmm...that I don't recall. Although I believe it tells you if you scroll to the bottom of the document. Ctrl + something, but I can't recall what that something is.

acjgoblu
 
Posts: 15
Joined: Mon May 16, 2016 1:33 pm

Re: PiGrrl 2 TFT button assignment

by chimomatt on Tue Aug 02, 2016 4:19 pm

unfortunately I can't find it I can change everything but I can figure out how to save afterwards

chimomatt
 
Posts: 5
Joined: Sat Jun 11, 2016 1:26 pm

Re: PiGrrl 2 TFT button assignment

by blackuma on Mon Sep 26, 2016 7:20 pm

I just wanted to add some notes to this thread in case someone seeks the same information in the future as they were things I ran into using acjgoblu's guide.

To save the retroarch.cfg simply tab to "<OK>" it should save on its own when confirmed. Alternatively you can find retroarch.cfg in the terminal within the retropie directory to sudo nano edit the file ctrl+x should ask you if you want to save on exit.

If you want to comment something out using shift+\ should work as a "#".

Last but not least If your looking to add a save/load state button it is to be assumed you wont want to keep overwriting your old saves. Towards the bottom of the config file is an option that reads...

Code: Select all | TOGGLE FULL SIZE
# When saving a savestate, save state index is automatically increased before
# it is saved.
# Also, when loading content, the index will be set to the highest existing index.
# There is no upper bound on the index.
# savestate_auto_index = false

Commenting out the last line and setting it to "True" will do exactly as it says, keeping older save states without over writing them. Good if you plan to move/copy/edit save files or if you just want to go back in time later. Just be weary "There is no upper bound on the index." I'm not sure but this sounds like your save files can really pile up over time depending on your rate of save just keep an eye on that.

blackuma
 
Posts: 3
Joined: Thu Sep 01, 2016 12:18 am

Re: PiGrrl 2 TFT button assignment

by acjgoblu on Mon Sep 26, 2016 8:44 pm

Thanks for the assist! Looks like you have more coding knowledge than me, which is helpful. A lot of what I did was what I could piece together from message boards and such, and when it ended up working, I transcribed it and didn't ask questions!

acjgoblu
 
Posts: 15
Joined: Mon May 16, 2016 1:33 pm

Re: PiGrrl 2 TFT button assignment

by blackuma on Tue Sep 27, 2016 2:34 am

I'm still learning too so your guide was really helpful.

blackuma
 
Posts: 3
Joined: Thu Sep 01, 2016 12:18 am

Re: PiGrrl 2 TFT button assignment

by Sammyk22 on Fri Apr 14, 2017 2:21 am

Where you are entering the {23Key} etc how do I get there? I have made the necessary changes in the .cfg file but I am having a heck of a time getting to where I can edit these keys. I'm using F4 and trying to locate the retrogame.c file there. Am I in the wrong place?

Sammyk22
 
Posts: 11
Joined: Fri Apr 14, 2017 1:39 am

Please be positive and constructive with your questions and comments.


cron