RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    Multi Switch Shutdown Script!

    Scheduled Pinned Locked Moved Ideas and Development
    shutdown scriptshutdown switchcyperghost
    272 Posts 40 Posters 124.9k 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.
    • caver01C
      caver01 @cyperghost
      last edited by caver01

      @cyperghost are you saying I can just put a bash script into /lib/systemd/system-shutdown/ and it will execute during shutdown? Why do we need meleu's service?

      My 4-player cocktail style cabinet built as a custom "roadcase"

      cyperghostC 1 Reply Last reply Reply Quote 0
      • cyperghostC
        cyperghost @caver01
        last edited by cyperghost

        @caver01 said in Multi Switch Shutdown Script!:

        @cyperghost are you saying I can just put a bash script into /lib/systemd/system-shutdown/ and it will execute during shutdown?

        Yes! The systemd service automatically parses shutdown status to any scripts in this folder. So $1 can be poweroff, halt, reboot and you can initiate actions by this.

        Why do we need meleu's service?

        Well.... I don't know if the service is still useable. Some people report is does not work proper anymore. I tried, too - but also failed for proper shutdown. So the service is sadly out of service. And imho the service is usefull not to push triggers like you (ab)use it ... more to just prober shutdown ES ;)

        BUT if it will work you would never have to modify button scripts. They just initiate a shutdown and the service automatically shuts down emulators and ES. That's the great advantage.

        I modified the original NESPi+ python script for example and added an if/then clause. If butto nis pressed and if ES-PID is active then use multi_switch with es-poweroff switch, else use regular shutdown.
        If the service would work again the python script would be just. If button is pressed then use regular shutdown.

        But imho it's still a flavour what you want to do and how far you understand what you do.

        caver01C 1 Reply Last reply Reply Quote 0
        • caver01C
          caver01 @cyperghost
          last edited by

          @cyperghost I guess we have several options, but I do like your script—one script for several uses. It just makes sense.

          My 4-player cocktail style cabinet built as a custom "roadcase"

          cyperghostC 1 Reply Last reply Reply Quote 0
          • cyperghostC
            cyperghost @caver01
            last edited by

            @caver01 The intention to write this script is a bit more.

            1. It should provide an easy all in one solution for people who use several switch devices (A simple Button connected to GPIO and ground, both NESPi case types, or the Pimonori ONOFF Shim or the Mausberry switch)
            2. It provides a solution if people use several button to make "reset" actions. So the script can be written to just finish any emulators if they are active, or to restart ES, or to reboot the whole system if button is held down for more than 5 seconds. This is all possible if you use the regular switches.
            3. Personally! I'm owner of 4 of the 5 devices the script supports I have a Mausberry in a NESPi case, I've a NESPi+ case, I've a Pimonori Switch and on my old B1 I've a some single push buttons only. And the setup to perform shutdown with this script was never easier to do now. Exactly as you said...
              3.1 Use the script and make calls like multi_switch.sh --es-poweroff from any button script.
              3.2 Personally I use it several time like multi_switch.sh --generic powerbtn=23
              3.3 Sometimes I do some coding on the mashine via SSH and the TV is not powerd on so just a multi_switch.sh --es-poweroff shutdown the system cleanly with proper quitted ES.
              3.4 I setted up a Pimonori Switch on my OwnCloudSystem so there is also just a proper call to multi_switch.sh --onoffshimm

            Nevertheless I hope @meleu reactivates the shutdown service again.

            1 Reply Last reply Reply Quote 0
            • QuackwalksQ
              Quackwalks
              last edited by

              I'd love to see this working for the Kintaro 9000 case. They've been working on the meta data issue for a while now.

              cyperghostC 1 Reply Last reply Reply Quote 0
              • D
                dudumaroja
                last edited by dudumaroja

                hello, i have a question.. i have a nespi case.. but my mod made it have two buttons.. made power button work as intended.. my plan first was to solder the reset button on RUN header to have a hard reset in case of crashes and use power to soft reset..

                i found your script.. and im here to ask if there is any change of using the reset button as generic too?

                tldr: can i use this scrip with two generic buttons?

                edit:

                this solved for me
                /home/pi/RetroPie/scripts/multi_switch.sh --nespicase powerbtn=3 resetbtn=4 &

                1 Reply Last reply Reply Quote 0
                • cyperghostC
                  cyperghost @Quackwalks
                  last edited by

                  @quackwalks Well you modify the python script and integrate the arguments multi_switch.sh offers to get it full working with your kintaro. A way how it can be done I offered here for the NESPi+ case.. You can use the return values of --ES-PID (= ask if EmulationStation is running) and --RC-PID (= ask if there is a emulator running in background) to decide to do actions.

                  As long as I don't have this case I don't do anything to integrate this in the script. It can be done, I know ... but it took several days to get the NESPi+ working ... at last I bought one then the settings were done in less then a few hours.

                  1 Reply Last reply Reply Quote 0
                  • cyperghostC
                    cyperghost
                    last edited by

                    Thx to @fastpop72 he gave positive answer in getting this invoked into python script

                    Tired on bash scripts? Get a functional shutdown for your NESPi+ on python

                    Took a journey on python scripting (really easy, and the script could be improved!) but it works best.... it shows same behaviour as multi_switch as bash call.

                    1. If you press restart if emulator is currently running, then you will be kicked back to ES main menu
                    2. If you press restart in ES main screen, ES will be restartet (no reboot!), good for quick saving metadata or internal saves.
                    3. If you press power-off then Raspberry will shutdown
                    
                    All metadata is always saved
                    Best -> cyperghost
                    

                    You can install the script with
                    wget -O - "https://raw.githubusercontent.com/crcerror/retroflag-picase/master/install.sh" | sudo bash

                    1 Reply Last reply Reply Quote 0
                    • darkniorD
                      darknior
                      last edited by

                      WOAW excellent, i've receved my new NesPi+, i will try it :)
                      Thanks

                      Life is game, just play it !

                      1 Reply Last reply Reply Quote 0
                      • D
                        dudumaroja
                        last edited by dudumaroja

                        Hello.. i have a modification sugestion..

                        maybe you could integrate a save state function to the reset button.. using this!

                        https://github.com/GregorR/RetroArch/wiki/Network-Commands

                        this open doors to.. gracefully quit emulation ( retroarch compatible cores).. and other thinks like.. pressing reset for 5 seconds save state.. quick press load state..

                        you can even set the reset button to reset only the game you are playing.. and other thinks,

                        lostlessL 1 Reply Last reply Reply Quote 0
                        • lostlessL
                          lostless @dudumaroja
                          last edited by

                          @dudumaroja You can do it your self. That's the whole fun of retro pie. If you are willing to do some research and get your hands dirty anything can be done.
                          heres a link to the recalbox help page with instructions on how to set this up.
                          https://github.com/recalbox/recalbox-os/wiki/RetroArch-Network-Commands-(EN)

                          1 Reply Last reply Reply Quote 0
                          • O
                            OrehRuoy
                            last edited by

                            Hello, is there a way to get the source code so that I can add led functionality to the code. I just want it to set a GPIO to high when turned on and to LOW when turned off.

                            Thanks.

                            mituM 1 Reply Last reply Reply Quote 0
                            • mituM
                              mitu Global Moderator @OrehRuoy
                              last edited by

                              @orehruoy The source is on github, link is in the 1st post - https://github.com/crcerror/ES-generic-shutdown.

                              1 Reply Last reply Reply Quote 0
                              • cyperghostC
                                cyperghost
                                last edited by

                                @orehruoy You can modify the code of the script of course. But if you just want to glow a LED for power on/off control then use the UART port. A simple solution and no script needed.

                                Here is a guide of how to do this

                                O 1 Reply Last reply Reply Quote 1
                                • O
                                  OrehRuoy @cyperghost
                                  last edited by

                                  @cyperghost said in Multi Switch Shutdown Script!:

                                  @orehruoy You can modify the code of the script of course. But if you just want to glow a LED for power on/off control then use the UART port. A simple solution and no script needed.

                                  Here is a guide of how to do this

                                  I didn't know how to access your code in the pi. I will try that other method though seems simple. Thanks.

                                  1 Reply Last reply Reply Quote 0
                                  • darkniorD
                                    darknior
                                    last edited by

                                    I finally try your script :)
                                    Correct a problem for me because you install the script in /home/pi/Retropie/Scripts/ and this directory is on my USB drive.
                                    I can't have good right to execute .sh on USB drive with the auto-mount :p
                                    I change to use it in /home/pi/Scripts/ and it's perfect, thanks a lot :)

                                    Only one question, when i want to quit RetroArch to ES i must clic 3 time on my reset button ... Is it normal ?
                                    The power off button working fine every time. Using Reset in ES to restart ES is not working for me.
                                    Your PID detection is impressive, it works with emulators and also OpenBOR :p

                                    Life is game, just play it !

                                    cyperghostC 1 Reply Last reply Reply Quote 0
                                    • cyperghostC
                                      cyperghost @darknior
                                      last edited by

                                      @darknior said in Multi Switch Shutdown Script!:

                                      Only one question, when i want to quit RetroArch to ES i must clic 3 time on my reset button ... Is it normal ?
                                      The power off button working fine every time. Using Reset in ES to restart ES is not working for me.
                                      Your PID detection is impressive, it works with emulators and also OpenBOR :p

                                      Well the detection of button press is just checked every 1 second. So you might press the button for a longer time.

                                      The PID detection is introduced by runcommand script as entry point ;) And from this point I create PID array.

                                      1 Reply Last reply Reply Quote 1
                                      • darkniorD
                                        darknior
                                        last edited by

                                        Ok thanks i understand better now :)

                                        Your PID idea is cool and can maybe be used to improve other scripts?
                                        I use this one, where we must make an array to list all the emulators and homebrews to stop music :(

                                        https://retropie.org.uk/forum/topic/16458/modified-background-music-script-with-added-overlays

                                        I'm sure we can do it with your idea, or maybe just detect when runcommand launch something and mute the music.

                                        Life is game, just play it !

                                        cyperghostC 1 Reply Last reply Reply Quote 0
                                        • cyperghostC
                                          cyperghost @darknior
                                          last edited by

                                          @darknior That's is possible, too.

                                          try the parameter multi_switch.sh --es-emupid
                                          If it returns 0 than there is no emulator called by runcommand.

                                          1 Reply Last reply Reply Quote 0
                                          • M
                                            mrfalk
                                            last edited by

                                            Hi there love this script and community I’m trying to implement this to a 12v relay that turns the pi on and off using NO port so it’s ether open or close depending on if the 12v trigger is on or off

                                            Is it possible with the generic trigger in the script?

                                            cyperghostC 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.