CommentStreams:Bde16dada61dbb5d25cab17c52c7c11c
@Lisa it does, i found a way to reprogramm "x728-v2.x-plsd-gpiod.py" and save it in "sudo cp -f ./x728-v2.x-plsd-gpiod.py /usr/local/bin/"
- !/usr/bin/env python
import gpiod import time import subprocess
- Define the chip and lines
chipname = "gpiochip0" # Please use gpiochip0 if using Raspberry Pi 4/3 hardware
- chipname = "gpiochip4" # Please use gpiochip4 if using Raspberry Pi 5 hardware
line_offset = 6 out_line_offset = 26
- Open the GPIO chip
chip = gpiod.Chip(chipname)
- Get the input line
line = chip.get_line(line_offset) line.request(consumer="my_program", type=gpiod.LINE_REQ_EV_BOTH_EDGES)
- Get the output line
out_line = chip.get_line(out_line_offset) out_line.request(consumer="my_program", type=gpiod.LINE_REQ_DIR_OUT)
def print_event(event):
if event.type == gpiod.LineEvent.RISING_EDGE:
print("---AC Power Loss OR Power Adapter Failure---")
print("Shutdown in 5 seconds")
time.sleep(5)
out_line.set_value(1)
time.sleep(3)
out_line.set_value(0)
# Perform safe shutdown
subprocess.run(["sudo", "shutdown", "-h", "now"])
elif event.type == gpiod.LineEvent.FALLING_EDGE:
print("---AC Power OK, Power Adapter OK---")
try:
# Wait for events indefinitely
while True:
event = line.event_wait()
if event:
event = line.event_read()
print_event(event)
except KeyboardInterrupt:
print("Exiting...")
finally:
chip.close()
than just create a service.unit and save it in: sudo cp -f ./safe_shutdown.service /lib/systemd/system/
[Unit] Description=Run Python Power Management Daemon
[Service] Type=simple ExecStart=/usr/bin/python3 /usr/local/bin/x728-v2.x-plsd-gpiod.py Restart=always
User=root Group=root
[Install] WantedBy=multi-user.target
sudo systemctl daemon-reload sudo chmod +x /usr/local/bin/xPWR.sh sudo chmod +x /usr/local/bin/x728-v2.x-plsd-gpiod.py sudo systemctl enable xPWR sudo systemctl enable x728-v2.x-plsd-gpiod.py sudo systemctl start xPWR sudo systemctl start x728-v2.x-plsd-gpiod.py
Now everybody can use the raspberry with something you switch off to turn the raspberry off, for example a screen.