Skip to content

Commit 5143d10

Browse files
SuMerefacchinm
authored andcommitted
distro: add event handling of KEY_VOLUMEUP and KEY_VOLUMEDOWN pressed at boot
1 parent d45ab58 commit 5143d10

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description=Provides bindings for volumeup and volumedown keys on boot
3+
After=multi-user.target
4+
5+
[Service]
6+
Type=oneshot
7+
ExecStart=/opt/arduino/scripts/keybinding_check.sh
8+
9+
[Install]
10+
WantedBy=multi-user.target
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
function check_key()
4+
{
5+
device=$1
6+
event=$2
7+
keycode=$3
8+
9+
evtest --query ${device} ${event} ${keycode}
10+
11+
ret_val=$?
12+
echo $ret_val
13+
}
14+
15+
exec_path_vold="/opt/arduino/scripts/volumedown.sh"
16+
exec_path_volu="/opt/arduino/scripts/volumeup.sh"
17+
18+
volumedown=$(check_key /dev/input/event0 EV_KEY KEY_VOLUMEDOWN)
19+
volumeup=$(check_key /dev/input/event0 EV_KEY KEY_VOLUMEUP)
20+
21+
echo "Volume Down status: ${volumedown}"
22+
echo "Volume Up status: ${volumeup}"
23+
24+
if [ $volumeup -ne 0 ] && [ $volumedown -ne 0 ]; then
25+
echo "Both Volume Up and Volume Down keys are pressed. Ignoring both."
26+
exit 0
27+
fi
28+
29+
if [ ${volumedown} -ne 0 ]; then
30+
bash ${exec_path_vold}
31+
elif [ ${volumeup} -ne 0 ]; then
32+
bash ${exec_path_volu}
33+
fi
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# This script is triggered when the pin configured as Volume Down in JCTL connector is shorted to GND.
4+
# This script is launched once at startup.
5+
# Feel free to hack it to implement your own functionality.
6+
# Otherwise, it will switch the USB mode to Host.
7+
#
8+
# MPU POWER o o 1V8
9+
#
10+
# MPU RESET o ■ GND
11+
#
12+
# TX o o VOLUME UP
13+
#
14+
# RX o o VOLUME DOWN
15+
# |
16+
# USB BOOT o ■ GND
17+
18+
echo "host" > /sys/kernel/debug/usb/4e00000.usb/mode
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# This script is triggered when the pin configured as Volume Up in JCTL connector is shorted to GND.
4+
# This script is launched once at startup.
5+
# Feel free to hack it to implement your own functionality.
6+
# Otherwise, it will switch the USB mode to Device.
7+
#
8+
# MPU POWER o o 1V8
9+
#
10+
# MPU RESET o ■ GND
11+
# |
12+
# TX o o VOLUME UP
13+
#
14+
# RX o o VOLUME DOWN
15+
#
16+
# USB BOOT o ■ GND
17+
18+
echo "device" > /sys/kernel/debug/usb/4e00000.usb/mode

0 commit comments

Comments
 (0)