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

    How to run games programmatically?

    Scheduled Pinned Locked Moved Help and Support
    runcommandscriptingprogrammingcommand linedaemon
    4 Posts 2 Posters 1.5k 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.
    • coderkevinC
      coderkevin
      last edited by coderkevin

      Hello, I'm trying to get a system daemon to be able to start/stop games and emulationstation. What's the recommended way to do this?

      UPDATE
      I solved this problem with a script. You can use it too: https://github.com/coderkevin/mini-nes/tree/master/screen

      The inspiration I've found for making this work is DaftMike's NESPi, but his script is pretty brute force. (https://github.com/imdaftmike/NESPi/blob/master/nespi.py) It seeks out and kills any and all emulator processes and emulationstation processes, and then uses openvt to run runcommand.sh on console 1 as root. However, I'm even having problems getting this to work right (joystick support not working for me).

      I'm thinking there's got to be a better way to transition the system to start an emulator or restart ES. If there's not code to support it, I don't mind putting in some effort, just need a good push in the right direction.

      (Here's the repo I've started to work with this, if anyone wants to see where I'm at or track progress: https://github.com/coderkevin/mini-nes)

      Thanks!

      dankcushionsD 1 Reply Last reply Reply Quote 0
      • dankcushionsD
        dankcushions Global Moderator @coderkevin
        last edited by

        @coderkevin i'm not sure about starting a game within ES.

        ...but, this might be a way to exit a game remotely: https://github.com/libretro/RetroArch/wiki/Network-Commands

        this would only work for lr- emulators, though (which is most of them). retroarch may have a better way of doing this directly. i think RA might trap SIGTERM (rather than SIGKILL) cleanly, which might be a better way as it would save .SRM etc. i've not tested...

        1 Reply Last reply Reply Quote 0
        • coderkevinC
          coderkevin
          last edited by

          I'm dreaming up a better way to do this right now.

          I'm thinking of replacing the autostart call to emulationstation, and calling a python script instead. And having that python script use subprocess.Popen to manage subprocesses to emulationstation and/or runcommand, then being able to send signals to those subprocesses without having to rely on console ps and kill calls.

          For the actual switching of tasks, I'm thinking about watching a file under /dev/shm that could be edited by any other process with permissions to do so. This way, any external process could update that config to point to a rom file, then this python script would see the change and act accordingly.

          Example:
          Autostart runs script
          Script by default start emulationstation
          Script starts watching /dev/shm file.

          Other process receives an event (GPIO button press, NFC tag, whatever)
          Other process overwrites /dev/shm file to point to rom file.

          Script detects that the /dev/shm file has changed and reads it.
          Script reads rom in config file, sends signal to terminate current subprocess (emulationstation) and start new subprocess (runcommand)

          I think something like this could be really useful for projects other than mine. If you're reading this and would file it helpful, let me know here. Whatever changes I do make will be available on my mini-nes github repo (or another repo that it references, I suppose)

          1 Reply Last reply Reply Quote 0
          • coderkevinC
            coderkevin
            last edited by

            Okay folks, I've written up a script to handle this exactly the way I described before.

            It runs from the autostart.sh and watches /dev/shm/screen_manager.cfg for updates.
            That way any other system process can create/modify that file and this script will respond by either starting the rom, or starting the dashboard.

            Cheers!

            https://github.com/coderkevin/mini-nes/tree/master/screen

            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.