From 502c9e34eef744065855b0e033191f0d8bd4ab73 Mon Sep 17 00:00:00 2001 From: Oxore Date: Mon, 1 Jan 2024 00:36:01 +0300 Subject: Add instructions on udev autorun --- Readme.md | 23 +++++++++++++++++++++-- ds4-keyboard-udev-autorun.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100755 ds4-keyboard-udev-autorun.sh diff --git a/Readme.md b/Readme.md index ef21d32..826d15e 100644 --- a/Readme.md +++ b/Readme.md @@ -54,7 +54,7 @@ Device D0:BC:C1:A2:BE:9F Wireless Controller Perfect! We've got a connection. -## Run +## Run manually First of all you need to be able to open `/dev/uinput` as a user, unless you decided to do everything from root. Do this for your `user` as root if you want @@ -102,7 +102,26 @@ Then run the program like this: ./main /dev/input/event23 ``` -## Usage +## Run automatically via udev + +If you want to run the program every time you connect the gamepad the following instruction may help. Or may not, who knows. At least it worked out for me. + +Copy `ds4-keyboard-udev-autorun.sh` and `main` files from this repo somewhere to be convenient for you. For example I put them both in `/etc/udev/rules.d` directory. + +Create a file `/etc/udev/rules.d/50-ds4.rules` and add the following contents: + +``` +SUBSYSTEM=="input", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="05c4", RUN+="/etc/udev/rules.d/ds4-keyboard-udev-autorun.sh $devpath /etc/udev/rules.d/main" +SUBSYSTEM=="input", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="09cc", RUN+="/etc/udev/rules.d/ds4-keyboard-udev-autorun.sh $devpath /etc/udev/rules.d/main" +``` + +To make `udev` use new rules and re-trigger events to execute them right away without rebooting, you can run the following command as root: + +``` +udevadm control --reload-rules && udevadm trigger +``` + +## Usage Now you can issue keyboard keypresses by pressing some combinations of the gamepad buttons as shown in the following chart: diff --git a/ds4-keyboard-udev-autorun.sh b/ds4-keyboard-udev-autorun.sh new file mode 100755 index 0000000..7d4ead3 --- /dev/null +++ b/ds4-keyboard-udev-autorun.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# Program will just exit on any failed check (an expression in square brackets) due to -e flag. +set -e + +devpath=$1 +program=$2 +[ -n "$devpath" ] +[ -n "$program" ] + +event_name=$(basename $devpath) +is_event= +case "$event_name" in + event*) is_event="yes" ;; + *);; +esac +[ "$is_event" = "yes" ] +devpath="/sys$devpath" + +# A bunch of heuristic checks to determine that it is actually the controller +# and neither a touchpad nor motion sensors which all have an event input +# device and share the same udev attributes. +cap_path=$devpath/device/capabilities +[ -f $cap_path/abs ] +[ -f $cap_path/ev ] +[ -f $cap_path/ff ] +[ -f $cap_path/key ] +[ -f $cap_path/led ] +[ -f $cap_path/msc ] +[ -f $cap_path/rel ] +[ -f $cap_path/snd ] +[ -f $cap_path/sw ] +[ "$(cat $cap_path/abs)" = "3003f" ] +[ "$(cat $cap_path/ev)" = "1b" ] +[ "$(cat $cap_path/ff)" = "0" ] +[ "$(cat $cap_path/key)" = "7fdb000000000000 0 0 0 0" ] +[ "$(cat $cap_path/led)" = "0" ] +[ "$(cat $cap_path/msc)" = "10" ] +[ "$(cat $cap_path/rel)" = "0" ] +[ "$(cat $cap_path/snd)" = "0" ] +[ "$(cat $cap_path/sw)" = "0" ] + +$program /dev/input/$event_name -- cgit v1.2.3