To Mention: This is version based on Batocera 5.20, so RetroFlag script is not available here
I will update the script as Batocera 5.21 is released
Okay... tested the script it works best and seems fail safe.
# https://shop.pimoroni.com/products/onoff-shim/
onoffshim_start()
{
#Check if dtooverlay is setted in boot/config
#This is needed to do proper restarts/shutdowns
if ! grep -q "^dtoverlay=gpio-poweroff,gpiopin=$2,active_low=1,input=1" "/boot/config.txt"; then
mount -o remount, rw /boot
echo "dtoverlay=gpio-poweroff,gpiopin=$2,active_low=1,input=1" >> "/boot/config.txt"
fi
# This is Button command (GPIO17 default)
echo $1 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio$1/direction
power=$(cat /sys/class/gpio/gpio$1/value)
[ $power -eq 0 ] && switchtype=1 #Sliding Switch
[ $power -eq 1 ] && switchtype=0 #Momentary push button
until [ $power -eq $switchtype ]; do
power=$(cat /sys/class/gpio/gpio$1/value)
sleep 1
done
# Switch off
if [ "$?" = "0" ]; then
touch "/tmp/poweroff.please"
poweroff
fi
}
onoffshim_stop()
{
# Cleanup GPIO init
for i in $*; do
echo "$i" > /sys/class/gpio/unexport
done
}
Script call is onoffshim_$1 17 4
GPIO 17 is button
GPIO 4 is powerctrl
full script can be downloaded here
edit file powerswitch with nano /recalbox/scripts/powerswitch.sh
or install with cd /recalbox/scripts; wget -N https://raw.githubusercontent.com/crcerror/SomeOtherScript/master/Batocera/powerswitch.sh; chmod +x powerswitch.sh; ./recalbox-save-overlay.sh