How to capture power button pressed signal?

Hello,

I have an Orin NX 16G module, and an IIC device connected to board.
I want to capture the power button pressed signal when it going to power off, so i can terminate the IIC device properly.

How can i capture the power button pressed signal?
Looking for reply, thanks!

Are you talking about devkit or 3rd-party board? There is no power button on devkit, only a header with pwr_btn signal.

Hi, Trumany.
Thanks for your reply.
Yes, I’m using a devkit with carrier board. And a button connnected to the pwr_btn pin.
Finally, I got https://unix.stackexchange.com/questions/242129/how-to-set-power-button-to-shutdown-instead-of-suspend, and it works!
Post bellow, hope it helps who meet the same question.

$ cat /usr/local/bin/shutdown_button_monitor.sh
#!/bin/sh

# ansible managed

# systemd-logind prints a line of the form 
# Dez 21 11:12:10 box03.yeepa.de systemd-logind[748]: Power key pressed.
# on key press, but doesn't handle the button because gnome3 blocks systemd from doing so.
# See `systemd-inhibit` for that.

# first sleep a minute so we have chance to disable this scritp if it runs amok
sleep 1m

# so we workaround gnome a bit here.
journalctl -u systemd-logind --follow --lines=0 | \
while read line ; do
    if echo "$line" | grep --quiet 'Power key pressed'
    then
        systemctl poweroff
    fi
done

and the service file that starts / restarts it

$ cat /etc/systemd/system/shutdown_button_monitor.service
# ansible managed

[Unit]
Description=Power off the machine if the power button is pressed
# Workaround for gnomes block of the shutdown button
# https://unix.stackexchange.com/questions/242129/gnome-3-how-to-set-power-button-to-shutdown-instead-of-suspend#242452
# Monitor these blocks yourself with `systemd-inhibit`

[Service]
User=root
ExecStart=/usr/local/bin/shutdown_button_monitor.sh
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.