Advanced Safe Shutdown Idea
-
Hello,
I would like to begin this post by introducing myself, i am korn16ftl3 and am a hobbyist of many many things video games and electronics related. i enjoy console modding as well as the occasional tinkering with arduino kits (notice i said kits i have yet to really go out and do anything on my own yet). i have set up things like home servers with linux as well as used a bit of kali, needless to say im always game to try something interesting and new which is what brought me to the raspberry pi 3 and retropie.I have signed up here today because i am curently making my own retropie build (first one actually) for my kids to enjoy. i have purchased the pie as well as the necessary hardware and even a retroflag nespi case. The whole idea im about to propose all came to mind when i decided i did not like the way the power and reset system worked on the nespi case as it simply was a hard power off and momentary switch temporarily cutting power to the hard wires switch. this posed a couple of problems as it bypasses the built in circuit protection from the pi micro usb port as well as improperly shuts down the pi by directly killing power to it and as those that are familiar with computers at all well know this is never a good idea. After a bit of reading and research i stumbled across a kit for a safe shutdown and reset hack/mod this was exactly what i was looking for as it provides both a alternate circuit protection as well as a way to safely reset or shut down the pi using the power and reset buttons. Alternatively there is another script that allows you to quit back to the retropie screen if the reset button is hit. so now i have a choice between 2 options/scripts which brings me to my overall idea.
I would like to use both options as i feel the ability to have both a reset option as well as quitting back to the main screen would be great options together rather than having to choose one or the other. the problem presented is the fact there is only 1 reset button and i have 2 different scripts i would like to use i obviously can not just use the scripts as is and i would have to have some kind of timing to seperate the functions as well, for example if the reset button is pressed for anything less than 4 seconds it quits back to the retropie screen if the reset button is pushed longer than 4 seconds it resets the whole pi. this is where I end up coming to the community because i have somewhat of an idea how to get here but as I have stated for one I have never coded ANYTHING in my life so i will need help with that, for two im not certain how to get these functions from one momentary button or how to select the correct hardware. I have kinda guessed some sort of micro-controller would work awesome for this task (again I have no coding skills at all) but im not exactly what or how to select a candidate for this sort of task all tho im thinking along the lines of one of the following: Arduino Pro Mini, Arduino Uno, Arduino Pro Micro, ATtiny85, ATtiny45, ATtiny25. Those are all used in the PSnee project and a couple of them are also rather smalww like the AT IC's.
Now from looking at the scripts ( looking at this guide here: https://drive.google.com/file/d/0B9AzTQWe_cTFem1JS01HVU1GMDg/view ) both options (the quit to ES screen and the soft reset options) are set to use GPIO pin #'s 23, 24, & 25 the pinout reads that these pins are as follows: 23 = SPI_CLK , 24= SPI_CEO_N, 25= Ground. At this point im lost as im not certain if there are other GPIO pins that have or can have the equivalent functions not do i know what these abbreviations or function mean/are.
My initial thought would be to use one script as is and set for its original pinout and to modify the second script whichever it may be to work with an alternate set of pins.
Idealy as I proposed the micro controller will track the amount of time that the reset button is pressed then decide what GPIO pin(s) need to receive the signal to carry out the desired action and script (either soft reset or quit back to the ES screen).
so the things I need to sort out would probably be as follows:
- Is this idea plausible?
-What micro-controller should I use for this task? OR how do I select a proper micro-controller for this (or any) task
-learn or at least understand the functions of the code for the micro-controller - Select appropriate (if any) substitute GPIO pins for the second script
-Make appropriate changes to the python script as needed for desired function
-figure out the needed wiring if anything Im failing to see needs to be performed aside from powering the micro-controller - is there anything I am missing up here?
I hope to learn how to learn from this community to accomplish what im after and understand what is going on as best as I can as well as make this probably my first time coding anything from scratch as I have only really used previously made sketches,scripts, and programs.
Thanks for your time and for hearing my idea out Im looking forward to everyone's feedback as well as working on this project with the group.
- Is this idea plausible?
-
@korn16ftl3 Welcome to this forum.
Lots of people did here did a modding a NESPi case.@Yahmez Wrote the guide you are refering and made a own build here
@cyperghost (me) made also a build but with massive modifications by recreating a new PCB and using a Mausberry
@caver01 did also build a NESPi and to be honest I would take this route, tooRead cavers text, here I found out how to modify the latching/sliding power button to use it as a momentary push button!
Oh... and last but not least!
Use this service script to not loose metadata during poweroff by button press!A own MC development isn't needed for this task. Other guys did that already and with the Raspberry you've a "controller" with a whole OS behind.
-
@cyperghost said in Advanced Safe Shutdown Idea:
@korn16ftl3 Welcome to this forum.
Lots of people did here did a modding a NESPi case.@Yahmez Wrote the guide you are refering and made a own build here
@cyperghost (me) made also a build but with massive modifications by recreating a new PCB and using a Mausberry
@caver01 did also build a NESPi and to be honest I would take this route, tooRead cavers text, here I found out how to modify the latching/sliding power button to use it as a momentary push button!
Oh... and last but not least!
Use this service script to not loose metadata during poweroff by button press!A own MC development isn't needed for this task. Other guys did that already and with the Raspberry you've a "controller" with a whole OS behind.
so has someone has already done what im wanting to do?
power = soft power down and power on
reset long press = reset pi/OS
reset short press = exits emulator back to the retropie main screenthe original mod for the safe reset kit (as noted above here: https://drive.google.com/file/d/0B9AzTQWe_cTFem1JS01HVU1GMDg/view ) says i can choose between 2 scripts that will do the following:
script 1: resets the pi/os
script 2: exits the emulator back to the retropie main screeni would like to figure out how to do both options determined by the length of time that the reset (a momentary switch on its own) is pressed in
-
@korn16ftl3 said in Advanced Safe Shutdown Idea:
power = soft power down and power on
reset long press = reset pi/OS
reset short press = exits emulator back to the retropie main screenI can only speak for myself.
Soft power down and power on - Yes
reset short button > if emulator is running it return to ES, if ES is running it restarts ESBut also the long/short press.... is made up here even if I don't understand why long holding reset should reboot the whole mashine :) - it's unnecessary.
But the script posted in the tutorial seems to do it's job, too. Even if the PID detection is a bit bare but it should work in most cases.
-
@cyperghost said in Advanced Safe Shutdown Idea:
@korn16ftl3 said in Advanced Safe Shutdown Idea:
power = soft power down and power on
reset long press = reset pi/OS
reset short press = exits emulator back to the retropie main screenI can only speak for myself.
Soft power down and power on - Yes
reset short button > if emulator is running it return to ES, if ES is running it restarts ESthat is how the original script works?
the way you described it above would work just fine with the exit ti ES then if in ES it reboots -
@korn16ftl3 I never used the python scripts only mine
and there the function call
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
should be changed to
restart_es) [[ -n $emupid ]] && kill $emupid && es_wait $emupid && es_wait $rcpid [[ -z $emupid ]] && touch /tmp/es-sysrestart && chown pi:pi /tmp/es-sysrestart && kill $espid && sleep 2
That would return to ES if an emulator is currently running and if you are in ES main screen you will perform a reboot.
-
But as I said.... it's better to use a python script for edge detection than a bash script like this. All you want is doable ... but needs a bit of software knowledge. I would rather step into @caver01 solution than in mine and learn a bit of python.
-
So its looking like I want to do the mausberry varient if these power mods, which varient are people using mostly to get what I'm after tho?
https://mausberry-circuits.myshopify.com/products/shutdown-circuit-use-your-own-switchdirect-plug micro-USB, 2-pin spring terminal header, or the versions with a USB female plug?
I'm still not 100% certain how this works but it looks like the switch only controls either the reset or power switch? If that's the case does the power switch still power everything directly?
What I'm thinking is this correct me if I'm wrong?
Power switch = hard on off power (no script for safe shut down)
Reset switch = mausberry switch with script that if in emulator and pressed quits the emulator and if not in emulator and is pressed runs script for safe reset?
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.