Shutdown with keypress
-
Is it possible to issue a shutdown command from only a keypress? I have a project very near completion and this is one of the final touches before I post the tutorial. I need to be able to press a keyboard key(any key, doesn't matter which one) and issue either one of the following commands:
sudo shutdown -h now
or
sudo poweroffThis would need to work both in EmulationStation and within games. I searched through retroarch.cfg and saw nothing related to powering down. I know that it has the ability, because I can hit start and go to shutdown and the system shuts off.
Any ideas?
-
You should find some helpful info here...
https://unix.stackexchange.com/questions/107818/how-can-you-run-a-script-triggered-by-a-joystick-input -
If you can work with some simple electronics, google "raspberry power switch". Should give you plenty of ideas.
Top of my to do list :)
-
@mediamogul said in Shutdown with keypress:
You should find some helpful info here...
https://unix.stackexchange.com/questions/107818/how-can-you-run-a-script-triggered-by-a-joystick-inputI never thought of that, I made an arcade controller a while back... there is an unused button. I was thinking of how I'm going to utilise that extra button, now seem to find a really good candidate :)
-
@whsiung Check out this link."https://www.element14.com/community/docs/DOC-78055/l/adding-a-shutdown-button-to-the-raspberry-pi-b" It should be all you need.
-
@whsiung said in Shutdown with keypress:
I'm going to utilise that extra button
It's a great trick. Since I'm using a controller without a dedicated button for this function, I modified it a bit to have a combination of presses shut down the pi. I've been very pleased with the results. Of course nothing beats a hardwired power switch when it comes to turning it back on.
-
That's not exactly what I was hoping for, but it might work for me. My goal was to limit the amount of addons and software running in the background. I'm already running Retrogame to convert GPIO buttons to keyboard keys, and that uses a small amount of CPU power. I'm attempting to make this as lean as possible to limit CPU overhead and the possibility of software glitches. My hope was that this ability was built into the RetroPie suite.
Do you know whether the script uses much CPU power to run in the background?
I'm about 95% complete with a Pi Zero handheld console project that I'm sure everyone will love, and I am very anxious to complete it and show it off.
Also, I'll give a little background on why I need this button. I've made a dual-mosfet power circuit that draws no power from the batteries when the Pi is off, and power is turned on with a momentary pushbutton. When the Pi is shut down (by going to shutdown system in the start options) the power to the Pi/LCD/Audio is completely killed after the OS shutdown completes. It can then be powered on again by pushing the button again. I want to be able to push the button while the OS is running and have the Poweroff command run (the wiring is already done, and it is software I need). I also have a warning light set to come on when the battery is low, and this same circuit can ground out the same GPIO pin that's wired to the power switch and cause Retrogame to issue a keypress, which will shut down the console safely before the battery dies.
-
@adamspc said in Shutdown with keypress:
Do you know whether the script uses much CPU power to run in the background?
Any software solution to something like this is going to take the tiniest amount off the CPU, but it's negligible. I tend to doubt there would be a game that even saw a drop in frame rate here, but I guess there's always that possibility. For your purposes, a hardware solution may be the best answer.
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.