Igor's Blog

I went to the trouble of making an external power button for my Odroid XU4 and then found out that out of the box DietPi completely ignores this button being pressed. Luckily there is a way to make the OS shut down after the power button is pressed.
odroid_shutdown.jpg


Here's what I did to check if the power button presses do anything. I needed to install evtest first.
 Commands
apt-get install evtest


After it was installed, I ran it and got the following output:
 evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0: gpio_keys.7
/dev/input/event1: ADS7846 Touchscreen
/dev/input/event2: UVC Camera (046d:0825)


Selecting '0' gave me this...
 0
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "gpio_keys.7"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 116 (KEY_POWER)
Properties:
Testing ... (interrupt to exit)


...and when I triggered the power button, a bunch of events were fired, so I was on the right track!
 Events
Event: time 1474075323.624805, type 1 (EV_KEY), code 116 (KEY_POWER), value 1
Event: time 1474075323.624805, -------------- EV_SYN ------------
Event: time 1474075323.829555, type 1 (EV_KEY), code 116 (KEY_POWER), value 0
Event: time 1474075323.829555, -------------- EV_SYN ------------




I came across this forum post that gave me some good leads, but it wasn't for an XU4, so using the default systemd power switch rules I came up with something that should work on the XU4...
 /etc/udev/rules.d/70-power-switch-odroidxu4.rules
ACTION=="remove", GOTO="power_switch_end"
SUBSYSTEM=="input", KERNEL=="event*", SUBSYSTEMS=="platform", DRIVERS=="gpio-keys", ATTRS{keys}=="*,116|116,*|116|*,116,*", TAG+="power-switch"
LABEL="power_switch_end"


The above was saved to /etc/udev/rules.d/70-power-switch-odroidxu4.rules and then I ran the following commands to reload the rules...
 Commands
systemctl restart systemd-udevd
udevadm trigger


Then as soon as I triggered the power button, my XU4 started shutting down. Neat!

-i

, , , ,
About — I'm an enthusiastic software engineer and consultant interested in many fields including J2EE, programming, electronics, 3D printing, video games, wood working and gardening.
See my Resume for more information.
The views expressed in this blog are my own and not those of my employer.
comments powered by Disqus
My other posts you may like...
Programming, DIY, Games, Hacks, Tech and more.
Follow me on...
Current and Past Projects
See my Resume

Subscribe


RSS Feed

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
StrFunc() Online
300 George St Blogumentary
Guru JSON-RPC Tester
Extrudifier Object Designer

Recent Blog Posts

NeoOffice Viewer macOS Word Document viewer vs Preview and Microsoft Word

Importance of cleaning the internal fans and heatsinks in a MacBook Pro

Adding an email subscribe feature to your Blog with Blogtrottr

How to remove Google's logo from your G Suite applications

Pedestal fan transformed into a ceiling fan

Testing the Velvet WiFi Hotshot signal strength

Improving slow download speeds on the PS4 and PSN

Add batch image resize functionality to macOS using Automator

Show transfer percentage and speed when copying files in Linux and Bash

So I finally got to try eating some space food

Recent Galleries

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

DIY indoor apartment grow light wiring

Good Friday Electronics fun Easter Bunny LED PCB Kit IBEABU-01.0

Top Categories

Blogs I follow

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth

Friends

RAWS Parts Online
Alpha Dimensions Hosting
Kristensen Photography
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Please follow me on...