Hi,
I'm planning to add Momentary Tact Push Button Switch to my RPi3. Will the below work? This site I found was kind of old but was wonder if the code and kodi setup is the same for LibreElec. The author used OpenElec, HowTo: Raspberry Pi OpenElec Power Wake and Shutdown Button using GPIO – barryhubbard.com
Code
mkdir /storage/scripts
nano /storage/scripts/shutdown.py
Add this line:
#!/usr/bin/python
import sys
sys.path.append('/storage/.kodi/addons/python.RPi.GPIO/lib')
import RPi.GPIO as GPIO
import time
import subprocess
# we will use the pin numbering to match the pins on the Pi, instead of the
# GPIO pin outs (makes it easier to keep track of things)
GPIO.setmode(GPIO.BOARD)
# use the same pin that is used for the reset button (one button to rule them all!)
GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)
oldButtonState1 = True
while True:
#grab the current button state
buttonState1 = GPIO.input(5)
# check to see if button has been pushed
if buttonState1 != oldButtonState1 and buttonState1 == False:
subprocess.call("shutdown -h now", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
oldButtonState1 = buttonState1
time.sleep(.1)
Display More