<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.geekworm.com/index.php?action=history&amp;feed=atom&amp;title=CommentStreams%3ABde16dada61dbb5d25cab17c52c7c11c</id>
	<title>CommentStreams:Bde16dada61dbb5d25cab17c52c7c11c - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.geekworm.com/index.php?action=history&amp;feed=atom&amp;title=CommentStreams%3ABde16dada61dbb5d25cab17c52c7c11c"/>
	<link rel="alternate" type="text/html" href="https://wiki.geekworm.com/index.php?title=CommentStreams:Bde16dada61dbb5d25cab17c52c7c11c&amp;action=history"/>
	<updated>2026-07-26T05:11:11Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://wiki.geekworm.com/index.php?title=CommentStreams:Bde16dada61dbb5d25cab17c52c7c11c&amp;diff=34695&amp;oldid=prev</id>
		<title>195.192.96.124: Migrated comment #5365</title>
		<link rel="alternate" type="text/html" href="https://wiki.geekworm.com/index.php?title=CommentStreams:Bde16dada61dbb5d25cab17c52c7c11c&amp;diff=34695&amp;oldid=prev"/>
		<updated>2024-12-09T08:22:31Z</updated>

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