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 122.6k 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.
    • AndersHPA
      AndersHP @mitu
      last edited by AndersHP

      @mitu OK thanks, but can I see somehow if everything is working as planned - apart from the obvious thing that Pegasus should quit?

      My "Bubble Bobble" Themed Bartop Arcade
      My Gameboy

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

        @AndersHP The script you posted does nothing more than stopping Pegasus and shutting down, so if comment out the shuttind down part you can check by seeing if the front-end stops.

        1 Reply Last reply Reply Quote 1
        • AndersHPA
          AndersHP
          last edited by

          Did the pidof pegasus-fe trick and pegasus quits to terminal now.
          But the machine doesn't power off now...?

          My "Bubble Bobble" Themed Bartop Arcade
          My Gameboy

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

            @AndersHP your script will just close Pegasus and that's all. you should add a shutdown command to completly shutdown your system.

            your (easy) script would more look like...

            #!/bin/bash
            PEGASUS_BIN="pegasus-fe"
            if [[ -n $(pidof $PEGASUS_BIN) ]] ; then
                killall -w $PEGASUS_BIN
            fi
            sudo poweroff
            

            Much cleaner and more generic than the original one.

            If you want the proper exit of all emulators then use this script...

            #!/bin/bash
            PEGASUS_BIN="pegasus-fe"
            if [[ -n $(pidof $PEGASUS_BIN) ]] ; then
                bash multi_switch.sh --closeemu
                killall -w $PEGASUS_BIN
            fi
            sudo poweroff
            1 Reply Last reply Reply Quote 0
            • AndersHPA
              AndersHP
              last edited by

              But the script literally powered off my Gameboy before I did the ES -> Pegasus change...?

              My "Bubble Bobble" Themed Bartop Arcade
              My Gameboy

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

                @AndersHP But this script does behave like your original one. If you are in terminal and type sudo poweroff does then your mashine power off completly?

                The difference between ES and Pegasus is, that ES uses a "helper" script for shutdown status, therefore the touch-thing.

                I think you should be more specific for your setup, which additional scripts are running, how did you install them.....

                1 Reply Last reply Reply Quote 1
                • AndersHPA
                  AndersHP
                  last edited by

                  I changed to the above mentioned script, and it does quit and then shutdown. Thanks for the help - will try the Multi Switch script next.

                  My "Bubble Bobble" Themed Bartop Arcade
                  My Gameboy

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

                    @AndersHP Don't forget to setup correct path to to script if you call bash multi_switch --closeemu - I know it's sometimes hard to remember doing the things correctly :)

                    1 Reply Last reply Reply Quote 0
                    • quicksilverQ
                      quicksilver
                      last edited by quicksilver

                      @cyperghost Id like to use your multi shotdown script with my new argon one case because their script is much less functional than yours. Their argononed.py script looks like this:

                      import smbus
                      import RPi.GPIO as GPIO
                      import os
                      import time
                      from threading import Thread
                      rev = GPIO.RPI_REVISION
                      if rev == 2 or rev == 3:
                      	bus = smbus.SMBus(1)
                      else:
                      	bus = smbus.SMBus(0)
                      GPIO.setwarnings(False)
                      GPIO.setmode(GPIO.BCM)
                      shutdown_pin=4
                      GPIO.setup(shutdown_pin, GPIO.IN,  pull_up_down=GPIO.PUD_DOWN)
                      def shutdown_check():
                      	while True:
                      		pulsetime = 1
                      		GPIO.wait_for_edge(shutdown_pin, GPIO.RISING)
                      		time.sleep(0.01)
                      		while GPIO.input(shutdown_pin) == GPIO.HIGH:
                      			time.sleep(0.01)
                      			pulsetime += 1
                      		if pulsetime >=2 and pulsetime <=3:
                      			os.system("reboot")
                      		elif pulsetime >=4 and pulsetime <=5:
                      			os.system("shutdown now -h")
                      def get_fanspeed(tempval, configlist):
                      	for curconfig in configlist:
                      		curpair = curconfig.split("=")
                      		tempcfg = float(curpair[0])
                      		fancfg = int(float(curpair[1]))
                      		if tempval >= tempcfg:
                      			return fancfg
                      	return 0
                      def load_config(fname):
                      	newconfig = []
                      	try:
                      		with open(fname, "r") as fp:
                      			for curline in fp:
                      				if not curline:
                      					continue
                      				tmpline = curline.strip()
                      				if not tmpline:
                      					continue
                      				if tmpline[0] == "#":
                      					continue
                      				tmppair = tmpline.split("=")
                      				if len(tmppair) != 2:
                      					continue
                      				tempval = 0
                      				fanval = 0
                      				try:
                      					tempval = float(tmppair[0])
                      					if tempval < 0 or tempval > 100:
                      						continue
                      				except:
                      					continue
                      				try:
                      					fanval = int(float(tmppair[1]))
                      					if fanval < 0 or fanval > 100:
                      						continue
                      				except:
                      					continue
                      				newconfig.append( "{:5.1f}={}".format(tempval,fanval))
                      		if len(newconfig) > 0:
                      			newconfig.sort(reverse=True)
                      	except:
                      		return []
                      	return newconfig
                      def temp_check():
                      	fanconfig = ["65=100", "60=55", "55=10"]
                      	tmpconfig = load_config("/etc/argononed.conf")
                      	if len(tmpconfig) > 0:
                      		fanconfig = tmpconfig
                      	address=0x1a
                      	prevblock=0
                      	while True:
                      		temp = os.popen("vcgencmd measure_temp").readline()
                      		temp = temp.replace("temp=","")
                      		val = float(temp.replace("'C",""))
                      		block = get_fanspeed(val, fanconfig)
                      		if block < prevblock:
                      			time.sleep(30)
                      		prevblock = block
                      		try:
                      			bus.write_byte(address,block)
                      		except IOError:
                      			temp=""
                      		time.sleep(30)
                      try:
                      	t1 = Thread(target = shutdown_check)
                      	t2 = Thread(target = temp_check)
                      	t1.start()
                      	t2.start()
                      except:
                      	t1.stop()
                      	t2.stop()
                      	GPIO.cleanup()
                      

                      I tried changing the os.system to os.system("bash /path/to/multi_switch/multi_switch.sh --es-poweroff")like you suggested an earlier time that you helped me but then the reboot and shutdown dont seem to work anymore (I did use the correct path). Obviously I am missing something. I appreciate any guidance you could provide.

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

                        @quicksilver It should work with the commands you've posted .... but you've to take care about python idents. Is there an error output?

                        if true:
                        print "This won't work"
                        
                        if true:
                            print "This will work"
                        
                        quicksilverQ 1 Reply Last reply Reply Quote 1
                        • quicksilverQ
                          quicksilver @cyperghost
                          last edited by

                          @cyperghost Since you said it should work it made me think of what I might have messed up. Looks like I forgot to give proper permissions to the multi_switch.sh file. Metadata is now saving properly. Thanks for your assistance!

                          cyperghostC 1 Reply Last reply Reply Quote 2
                          • cyperghostC
                            cyperghost @quicksilver
                            last edited by

                            I see no reason for a downvote here.
                            Maybe the the one who downvoted @quicksilver can explain?

                            quicksilverQ 1 Reply Last reply Reply Quote 0
                            • quicksilverQ
                              quicksilver @cyperghost
                              last edited by

                              @cyperghost It's cool, it could have been accidental. And if not, I'm not one who cares much about fake internet points. I'm just happy I got it working. I now have your script setup on 3 different style cases!

                              1 Reply Last reply Reply Quote 0
                              • AndersHPA
                                AndersHP
                                last edited by AndersHP

                                I upvoted the post, so now it's back to 0 ;-)

                                My "Bubble Bobble" Themed Bartop Arcade
                                My Gameboy

                                RionR 1 Reply Last reply Reply Quote 0
                                • RionR
                                  Rion @AndersHP
                                  last edited by

                                  @cyperghost Is it possible to make this work with the Argon One case?

                                  FBNeo rom filtering
                                  Mame2003 Arcade Bezels
                                  Fba Arcade Bezels
                                  Fba NeoGeo Bezels

                                  quicksilverQ 1 Reply Last reply Reply Quote 1
                                  • quicksilverQ
                                    quicksilver @Rion
                                    last edited by quicksilver

                                    @Rion scroll up a few posts ;)

                                    https://retropie.org.uk/forum/topic/17415/multi-switch-shutdown-script/207

                                    1 Reply Last reply Reply Quote 2
                                    • BiZzAr721B
                                      BiZzAr721
                                      last edited by

                                      Hello @cyperghost! Hope all has been well, or as well as it can be with this COVID-19 paranoia. I decided to make a mini arcade using an AdaFruit Arcade Bonnet and a Raspberry Pi 3 B+. I am using a generic momentary pushbutton. I can not get the shutdown script AND the arcade bonnet controls to work at the same time. It seems having raspi-gpio installed blocks the controller inputs (which are mapped to keyboard buttons). Key presses work on a keyboard but not while passing through the arcade bonnet.

                                      The arcade bonnet has breakouts to gpio pins. I tried GPIO 3, which is used by the arcade hat, but I also tried other GPIO pins that are not used by the hat. Here is a link to info and pictures of the board.

                                      During install there is an option to install a gpio-halt utility. I've tried both with and without to no avail. I uploaded the contents of the arcadebonnet.pyand rc.local files. Here is the Adafruit-GPIO-Halt git.
                                      arcadebonnet.py
                                      rc.local

                                      I am wondering if it could be possible to redirect gpio-halt to your shutdown script. I just flashed an SD card with a clean retropie image, so I can start again with a new install.
                                      Thanks, and stay well.

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

                                        @BiZzAr721 Yes ...
                                        https://github.com/adafruit/Adafruit-GPIO-Halt/blob/master/gpio-halt.c#L261
                                        change here the call to script and then compile.

                                        All is well, thank you :)

                                        1 Reply Last reply Reply Quote 1
                                        • BiZzAr721B
                                          BiZzAr721
                                          last edited by

                                          I never did get to learn how to compile like I wanted to. Is there something in a gpio-halt script that can manually edit after it is installed? I'm not even fully understanding how to change the call to script before compiling. Sorry for being a bother.

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

                                            @BiZzAr721 You just change the line

                                            (void)system("shutdown -h now");
                                            

                                            to annother call. I would use annother script.

                                            (void)system("/home/pi/RetroPie/shutdown.sh");
                                            

                                            Then you create annother script /home/pi/RetroPie/shutdown.sh and make it executable with chmod +x /home/pi/RetroPie/shutdown.sh. Then you can nest any command as you like inside this. After this code change you compile as Adafruit descripes. I'm sure you do not need to stick to this specific C-program. The same can be achived in python.

                                            Imho you can use multi_switch.sh --generic powerbtn=21 call to achive same funtion. But I can't test this. Please use sudo apt raspi-gpio before.

                                            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.