2 Apr 2018, 20:16

Hello everyone I am new here in the forum and I have some doubts here, someone could help to solve this code below I picked it from the retropie used to turn off the system and respibarry in a safe way with a Power button. I've seen some topics but they usually use circuit boards different from the ones I have. see the script.

mkdir -p /bin/button

nano /bin/button/nespi.py

#!/bin/python

import RPi.GPIO as GPIO
import os, time


GPIO.setmode(GPIO.BCM)
GPIO.setup( 2, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Reset switch
GPIO.setup( 3, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Power switch
GPIO.setup( 5, GPIO.OUT) #ON control
GPIO.output( 5, GPIO.HIGH)

while True :
	if (GPIO.input( 3 )):
		time.sleep( 0.25 )
	else:
		encho ( "Shutting down...")
		os.system( "shutdown -h now")
	break

	if (GPIO.input( 2 )):
		time.sleep( 0.25 )
	else:
		encho ( "Resetting...")
		os.system( "reboot now")
	break

nano /etc/rc.local

	python /bin/button/nespi.py &

chmod u+x /etc/rc.local

shutdown -h now

#!/bin/bash

# Check if EmulationStation is running. Finish the script if doesn't.
	espid="$(pgrep -f "/opt/recalbox/supplementary/.*/emulationstation([^.]|$)")" || exit 0

# the "sed" command below isn't a crypted message :), it's just a trick to
# make $emucall regex-safe to use in the "pgrep -f" below.
	emucall="$(sed '4!d; s/\([\\"]\|[[:alnum:]_]\+=[^ ]* \)//g; s/[][(){}^$*.|+? ]/\\&/g' /dev/shm/runcommand.info)"

# If there's an emulator running, we need to kill it and go back to ES
if [[ -n "$emucall" ]]; then
		emupid="$(pgrep -f "$emucall" | tr '\n' ' ')"
		pkill -P "$(echo $emupid | tr ' ' ',')"
		kill "$emupid"
		wait "$emupid"
		sleep 5 # maybe it can be lesser
fi

kill "$espid"
wait "$espid"
sleep 5 # maybe it can be lesser

/etc/killes.sh

chmod a+x /etc/killes.sh

/etc/systemd/system/killes.service

[Unit]
Description=Kill EmulationStation
After=autologin@tty1.service

[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/etc/killes.sh

[Install]
WantedBy=multi-user.target

systemctl enable killes

thank you so much