pidesktop
pidesktop copied to clipboard
Change python code to gpio zero?
gpiozero might provide cleaner code in the long run. Note the nice pin numbering explaination.
I was able to start the mcu poweroff timer but I wan unable to read the button presses. Here's my current code:
#!/usr/bin/env python
#
# pd-powerkey.py - monitor GPIO to detect power key press from Power MCU (PCU)
#
import time,os,sys
sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib') # Import gpiozero in LibreELEC
from gpiozero import Button,LED
print("pidesktop: power button service initializing")
pwrBtn = Button(13) # PCU to Pi - detect power key pressed
pcu = LED(6) # Pi to PCU - start/stop shutdown timer
pcu.off() # tell PCU we are alive
pcu.on() # cause blink by starting shutdown timer
time.sleep(0.5)
pcu.off() # clear timer we really are alive
# callback function
def powerkey_pressed(channels):
print("pidesktop: power button press detected, initiating shutdown")
os.system("sync")
os.system("shutdown -h now")
sys.exit()
# wait for power key press
pwrBtn.when_pressed = powerkey_pressed
print("pidesktop: power button monitor enabled")
# idle - TODO: use wait
while True:
time.sleep(10)
The button reports high both pressed and released so I don't know where to go from here.
I made it work. I'll publish it soon.