Custom scripts system?

Hi there I started working on a handheld system. Right now I have retropie installed, and although it works fine I see no easy way of adding my own functionality to it. What I really need is a way to run my own python scripts (for example) whenever a game is launched, to activate LEDs and stuff like that. I mean, the more flexible the better! But if this single thing is possible in Lakka in a slightly easier way I’m switching to it right now. Both are open source, which is great but the winner is whoever allows me to do that without going down that rabbit hole :smiley:

I don’t think Lakka’s going to be any more useful in that sense than retropie. RetroArch doesn’t currently have any hooks to allow launching outside processes (though we’ve discussed the possibility before).

Oh, that’s retroarch’s fault? Damn you, retroarch! Oh well. Do you have any suggestions? I’ll ponder for a while whether it’s worth making my own frontend or giving up on doing fun things with my project.

Emulation Station, which I think is the frontend that comes with retropie, can probably run arbitrary scripts if you just add them to your launch commands.

That’s my best lead so far. I managed to run a little py script whenever you launch a game by manipulating a runcommand.sh file I found that’s being called by emulationstation. This is as far as I got following this trail though. I still don’t know how to get a different script (or parameters to that same script) depending on the system. I don’t know if it’s possible yet.

Actually, RetroPie’s runcommand-onstart.sh and runcommand-onend.sh could solve your problem. They also get parameters before being run like the name of the system and of the ROM being launched.

However, hello everyone! :slight_smile: I was facing the same problems. I’d like to have some functions launched before a game starts and after a game execution ends, so I was looking for the same information. I managed to solve my problem in RetroPie, but actually I’d prefer to stick with Lakka - I definitely like it better. Bad news that RetroArch doesn’t have any hooks.

So… could you maybe discuss the possibility again? :slight_smile: Or maybe someone could point me to the section of the code where a game is launched/suspended so that I could try to hack into the code a bit?

As other people already have, I built myself a customized controller (using and Arduino Mega) whose buttons configuration is modifyable on-the-fly, so with RetroPie I could send it a configuration enabling or disabling some buttons (and their LEDs) and I’d love to do the same with Lakka! :slight_smile:

Thanks to anyone who could help me in this.

I would suggest that you take a look at this github Issue as a starting point: https://github.com/libretro/Lakka/issues/611

Please also be aware that this link relates to the ‘old’ Lakka github repository so new development is focused on this repository: https://github.com/lakkatv/Lakka-LibreELEC

Hello Mark, thanks for your response! I took the time to read the topic you suggested me; did some little tests this weekend and now I grasped a little more of the “big picture”. Sorry, I am just a beginner with Lakka and OpenELEC! From what I saw, Lakka is based on OpenELEC (and will switch to LibreELEC very soon), that is a “Just-enough-OS” system, whose core is stored in a read-only system mounted on top of the physical SYSTEM file, created by squashfs, and this system will mount in read-write mode the /storage partition only. Ok. From the other topic I see that you don’t want to add other tools (python, perl, etc) to Lakka, and that is perfectly OK with me as the only tools I need are the echo command (working) and the stty command (but busybox is present so it’s ok, too). The only other thing I’d need is to launch a script before and after retroarch; as “sh” is present too, I’d have everything I need. So, I tried to do the following:

  • copy SYSTEM to another machine.
  • mount SYSTEM with -t squashfs -o loop in order to see what’s in there.
  • copy everything from there to another directory
  • ln -s busybox stty (not actually needed, I know I can call “busybox stty args”)
  • [the experimental part:] mv retroarch retroarch.bin, create a /bin/sh file named retroarch, mkdir /storage/scripts, wrote a couple of scripts there, and from retroarch that now is a shell script call the /storage/scripts/onstart.sh, then retroarch.bin, then /storage/scripts/onend.sh.
  • built a new SYSTEM file using squashfs tools and the modified directory, and copied the new SYSTEM file with its md5sum in /storage/.update I saw that Lakka took quite some time before starting, so I thought it could have taken the new SYSTEM, but actually it didn’t. Well, definitely it found the new SYSTEM as it’s no longer in the .update directory, but I don’t know what its fate was :slight_smile:

Well, I was wondering if my guess on how to proceed could be correct, or I made any mistake. Or maybe you would suggest to wait until the switch to LibreELEC is complete. I also made a virtual machine on top of my Windows laptop with VirtualBox, on which I mounted a Debian distro, to try to recompile Lakka from scratch, so that maybe I could try to mess with the SYSTEM creation part directly from there.

Any comment/help? Maybe I should write on the other topic too?

It seems like you have been making some good progress! Let me mention first of all that I am not a Lakka developer. I have contributed a little bit of code but mainly I keep an eye on the Lakka forum and github issue tracker and I contribute documentation. I’m interested in helping people how to figure out how to accomplish their projects :slight_smile:

I hope that you may eventually attract the attention of Kivutar or gouchi who are the two main Lakka developers. You might also want to attract the attention of @Ashura (CoalaJoe) who shares your interest in Lakka scripting. Either of them may be able to help you get to the next step of your project to modify SYSTEM, but I’m personally not sure how to advise you on that point.

I think that in general if you can get a build environment set up to compile Lakka that will open up easier routes to altering SYSTEM than the one you’re currently using, but either approach seems like it could achieve your goal.

Depending on whether you choose to focus your efforts on the OpenElec version of Lakka or the LibreElec version, I do think you may want to post in the appropriate github Issue tracker to get some additional help since this is a fairly technical project.

OpenElec vs LibreElec Lakka Development on the OpenElec Lakka has now pretty much ended, and there may not be another release. However the LibreElec Lakka is not entirely stable yet. If you can accept some instability with with LibreElec version in the short term that would be my recommendation. If you are looking for Lakka that is already stable now and you don’t mind potentially reworking your scripts in the future, you should stick with the OpenElec version.

Hey there. @markwkidd Thanks for mentioning me. I know this is an old topic, but I had the same problem. Eventough, I’d love to see a scripting API for Lakka, I don’t think this will be something that is going to happen soon :frowning:.
RetroPie has those start and stop scripts which you can specify. But I still chose Lakka(somewhat) over RetroPie. Lakka is basically a simple OS that runs RetroArch, so you can make your own Lakka. Install a minimalist Linux and try get it running after your machine has booted. Then develop a script that checks your processes. I didn’t develop that myself yet, but I’d look how/what processes/when start and end and then trigger something in a script.

If you have any questions, feel free to ask me questions.

i’m interested too in some scripting, mainly my interest is to “trigger” some script when actions occur, example: trigger a script when a joypad is connected/disconnected trigger a script when retroarch is stopped/running trigger a script when wifi estabilished a connection mainly to turn on/off a gpio pin for front panel leds of my lakka box :slight_smile:

Hi @markwkidd, @Ashura! Thanks for your reply, some time passed because I had other things to do (basically, life, and I was in the process of printing the stickers for my cabinet and soldering a circuit to pilot an electronic-locked coin mechanism and some LEDS via an Arduino Mega I’ll use as a double USB joystick).

My bad, I must admit anyway I was completely wrong. I found that, while in RetroPie the RetroArch executable is called every time a ROM is launched, if I understood correctly in Lakka it’s always running in menu mode (except when the ROM is running of course). So, while in RetroPie using their scripts is fair simple, in RetroArch itself it is not :slight_smile: I may be wrong, but if no hooks are provided, I think the only way to accomplish what both @Yurif74 and I would like, is to get our hands dirty in the main loop of RetroArch. Did I guess correctly this time?

1 Like

Yes you are right. RetroPie has a good method for hooking in. RetroArch does not provide something like this at this point.