hoopsurfer / pidesktop

Collected files, drivers and documentation for the pidesktop case
MIT License
27 stars 19 forks source link

Change python code to gpio zero? #27

Open hoopsurfer opened 5 years ago

hoopsurfer commented 5 years ago

gpiozero might provide cleaner code in the long run. Note the nice pin numbering explaination.

gpiozero pinout

jiriks74 commented 2 months ago

I was able to start the mcu poweroff timer but I wan unable to read the button presses. Here's my current code:

Code ```python3 #!/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.

jiriks74 commented 2 months ago

I made it work. I'll publish it soon.