• 2 Votes
    26 Posts
    24k Views
    cnotoC

    @cyperghost got it. I am attempting to change my setup from a nespi case to an onoffshim with a non momentary switch. I used your instructions, to setup the onoffshim, but the system cuts power as soon as i press the button to initiate the shutdown script. (No 3 blinks, just off).

    Could the original install of the raspi-gpio for the nespi case impacting things?

  • 6 Votes
    57 Posts
    18k Views
    cyperghostC
    How to perform a software shutdown with the Mausberry and the diode/transistor hack?

    NOTE: This does only work on momentary switches!

    1. Prerequisites
    You need to solder a diode (1N400x type 1N4001 or 1N4002) or a transistor (NPN-Type, 2N3904, BC547 or BC337) to the Mausberry on/off switch.
    For the diode: Connect it between a GPIO and the mausberry button ground.
    The transistors needs to soldered between ground and positive to the switch and the base line is connected to the GPIO (maybe you need a resistor to control current flow)

    Therefore I strongly recommand the DIODE hack!

    Don't be afraid the Raspberry is in both ways protected against current backdraws! Use the diode or the right direction as shown in the box above....

    GPIO MAUSBERRY from Pie DIODE switch ground O---------------->|----------------O 1N4002

    More to read here

    2. Software part

    Create gpio-shutoff with sudo nano /lib/systemd/system-shutdown/gpio-shutoff Enter code from box below Make the script executable with sudo chmod +x /lib/systemd/system-shutdown/gpio-shutoff

    GPIO16 (or PIN 36 ) is just an example here and is my real setup

    #!/bin/sh # Perform Software Shutdown with Mausberry switch # cyperghost for retropie.org.uk # This is the GPIO pinconnected to the diode or transistor GPIOpinDIODE=16 if [ "$1" = "poweroff" ]; then echo $GPIOpinDIODE > /sys/class/gpio/export echo out > /sys/class/gpio/gpio$GPIOpinDIODE/direction echo 1 > /sys/class/gpio/gpio$GPIOpinDIODE/value sleep 0.5 echo 0 > /sys/class/gpio/gpio$GPIOpinDIODE/value sleep 0.5 fi

    3. Software script with proper Reset and Shutdown
    This is the full working bash script
    Installation:

    add it to /etc/rc.local/ add it to /opt/retropie/configs/all/autostart.sh` whatever case you select make the script executable with chmod +x scriptname.shand add sudo yourscript.sh & to choosen autostart

    This script adds:

    Working Reset button
    1.1 if an emulator is running it will end this
    1.2 if ES is running (without emulator) a restart of ES will be made Working shutdown button #!/bin/bash # Mausberry shutdown script v3 # # extended by cyperghost for # Yet annother NESPi case # Tested version 15/01/18 es_action() { case $1 in check) [[ -f "/dev/shm/runcommand.info" ]] && \ emu="$(sed '4!d; s/\([\\"]\|[[:alnum:]_]\+=[^ ]* \)//g; s/[][(){}^$*.|+? ]/\\&/g' /dev/shm/runcommand.info)" && \ [[ -n "$emu" ]] && emupid="$(pgrep -f "$emu")" && \ rcpid="$(pgrep -f -o runcommand.sh)" espid="$(pgrep -f "/opt/retropie/supplementary/.*/emulationstation([^.]|$)")" ;;#" restart_es) touch /tmp/es-restart && chown pi:pi /tmp/es-restart [[ -n $emupid ]] && kill $emupid && es_wait $emupid && es_wait $rcpid [[ -z $emupid ]] && kill $espid && sleep 5 ;; shutdown_es) touch /tmp/es-shutdown && chown pi:pi /tmp/es-shutdown ;; esac } es_wait() #Wait function for finishing running emulators { while [ -e /proc/$1 ] do sleep 0.15 done } #this is the GPIO pin connected to the duoLed RED GPIOpinLED=21 #this is the GPIO pin connected to NESPi RESET siwtch GPIOpinRESET=20 #this is the GPIO pin connected to the lead on switch labeled OUT GPIOpin1=19 #this is the GPIO pin connected to the lead on switch labeled IN GPIOpin2=26 #SWITCH LED ON echo "$GPIOpinLED" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio$GPIOpinLED/direction echo "1" > /sys/class/gpio/gpio$GPIOpinLED/value #Initiate RESET echo "$GPIOpinRESET" > /sys/class/gpio/export echo "in" > /sys/class/gpio/gpio$GPIOpinRESET/direction #Initiate MAUSBERRY SWITCH echo "$GPIOpin1" > /sys/class/gpio/export echo "in" > /sys/class/gpio/gpio$GPIOpin1/direction echo "$GPIOpin2" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio$GPIOpin2/direction echo "1" > /sys/class/gpio/gpio$GPIOpin2/value power=$(cat /sys/class/gpio/gpio$GPIOpin1/value) reset=$(cat /sys/class/gpio/gpio$GPIOpinRESET/value) until [ $power = 1 ]; do power=$(cat /sys/class/gpio/gpio$GPIOpin1/value) reset=$(cat /sys/class/gpio/gpio$GPIOpinRESET/value) [ $reset = 0 ] && es_action check && es_action restart_es sleep 1 done # Power button pressed? if [ $power = 1 ]; then es_action check [[ -n $emupid ]] && kill $emupid && es_wait $emupid && es_wait $rcpid es_action shutdown_es kill $espid && es_wait $espid exit #Give back maincontrol to emulationstation.sh fi poweroff

    4. Why are you doing this?
    The Mausberry gots a little design issue. If you performing a software shutdown (maybe via ES > Shutdown system or via SSH sudo poweroff) the PI will shut down but the Mausberry will stay active (LED is on). Furthermore it won't respond to a power button press anymore - it's stuck! So you have to switch it off completly by removing your wall plug or by resetting the Mausberry.

    The diode or transistor just simulates a button press and the Mausberry will properly shutdown ;)

    5. Closing words
    It would be better to use @meleu's nice shutdown service in addition with the gpio-shutdown in section 1 and 2. The great benefit of this is you don't need to modify any scripts that are part of ES or to edit any script in meleus package.

    The button-script is intended to give an example how to perform faster shutdowns (by bypassing sleep timers) and to show the difference between a while-loop with enclousured if-clause in it and a better choosen until-loop with external if-clause ;) - I recommand a script that is python powered ;)

    Link to meleus shutdown service is here

  • 3 Votes
    10 Posts
    3k Views
    cyperghostC

    This goes hand in hand with @meleu s cheevos scraper!

    So the possibility to get games marked that have achievements let us easier select them to collections ;)

  • 0 Votes
    26 Posts
    6k Views
    cyperghostC

    @meleu We just trim CR ;)
    No need for getting mad ... But well we live in WINDOWS world ;)

    Sorry mate - I'm currently hard working :(
    So no time for asking bash ;)

  • 0 Votes
    4 Posts
    2k Views
    cyperghostC

    @pjft I refer to the output result ;) Really no idea?
    If I want to launch CAPCOM/TESTFILE.test then the output is

    /home/pi/RetroPie/roms/123456/CAPCOM/TESTFILE.test segacd /opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-picodrive/picodrive_libretro.so --config /opt/retropie/configs/segacd/retroarch.cfg "/home/pi/RetroPie/roms/123456/CAPCOM/TESTFILE.test" Line is ROMname+it's path as in Gamelist... Is Emulatorcall is command call via runcommand.sh

    And yes you are totally right... how to find correct emulator call :) But with a bit of investigation it is no problem. But you are totally right that are just cases no user will run in this. But I just want to show what is possible and with the knowledge collected in the last few days it seems absolutly possible to give ES the right push.

    So hold on:

    Consider if you terminate/shorten 123456/ in the string then you may have the full path of the rom ;) and now compare it to es_systems.cfg? We can parse the system out ;) and then ..... voila a launching abilty via folder navigation :)

    In fact I won't use 123456/ give to more a stylish name hidden/, toxxic/or just vvaste/ :D I'm joking but it should work...

  • 2 Votes
    8 Posts
    2k Views
    cyperghostC
    lfl-create is now on github

    Feel free to use https://github.com/crcerror/lfl-create

    May the forks be with you