@cyperghost said in My second project--another Nespi case build:
Can you post the script here please?
Would like to use it as I up to now use the bash script....
Here is the python script I am using to watch both buttons. This script is effectively my Mausberry script and my RESET script:
#!/usr/bin/env python
# Import the RPi.GPIO and OS
import RPi.GPIO as GPIO
import os
import time
# Define which GPIO pins u're using for the Mausberry IN, OUT
# (which are reversed in the script because mbOut comes to pi as input),
# and reset buttons (change this to whatever pin you use)
mbIn = 24
mbOut = 23
resetBtn = 25
# GPIO port setup
GPIO.setmode(GPIO.BCM) # Set pin numbering to BROADCOM GPIO numbering
GPIO.setup(mbOut, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set up pin as an input, pulled down
GPIO.setup(mbIn, GPIO.OUT)
GPIO.output(mbIn, 1) # Set pin value to 1. Mausberry watches for this to change to zero
GPIO.setup(resetBtn, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set up pin as an input, pulled UP since shorting to GND
# Define a function which will be called when Mausberry switch is triggered
def interrupt_mbShutdown(channel):
# Print indication to console
print "You pressed the power button!"
# Code for shutdown would go here
os.system('sudo shutdown -h now')
# Define a function which will be called when Mausberry switch is triggered
def interrupt_resetBtn(channel):
# Print indication to console
print "You pressed the reset button!"
# Code for reset would go here
os.system('/home/pi/bin/exitemu.sh')
# Enable shutdown switch interrupt to trigger on a raising edge (i.e. low-to-high transition)
GPIO.add_event_detect(mbOut, GPIO.RISING, callback = interrupt_mbShutdown, bouncetime=1000)
# Enable RESET button interrupt to trigger on a raising edge (i.e. low-to-high transition)
GPIO.add_event_detect(resetBtn, GPIO.FALLING, callback = interrupt_resetBtn, bouncetime=1000)
# --------------------------------------------------------------------
# Now just wait forever for the user to press a button
# The sleep time doesn't really matter, make it long enough so it isn't wasting cpu cycles
while 1:
time.sleep(5)
This gets called from my /etc/rc.local
It also relies on the exitemu.sh which is a bash script that leverages insights from all of the previous work to kill the PID for whatever emulator might be running (returns you back to ES). I am just using the same script @lostless posted a while back. You could also just issue a sudo reboot. In any case, the second part I need to add is meleu's shutdown service to completely exit stuff when doing the full shutdown.
So, I am not doing anything with soft shutdown requiring a diode/transistor. I have not gone that far yet because I am still using a sticky pushbutton instead of a momentary.