alpha
Login
or
Join now
yemou.pink
/
scripts
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
This repository has no description
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
add ds4-leds
author
yemou
date
5 years ago
(Nov 15, 2020, 4:26 AM UTC)
commit
fe4f1645
fe4f16452c48e61c82fd8e863ecf6f7c524ec11e
parent
8f558972
8f5589720949f932741746ade4c34fcac728caa9
+37
1 changed file
Expand all
Collapse all
Unified
Split
scritps
ds4-leds
+37
scritps/ds4-leds
Reviewed
···
1
1
+
#!/bin/sh
2
2
+
# Change the LEDs of a DualShock4 Controller
3
3
+
4
4
+
usage() {
5
5
+
printf '%s\n' "usage: ${0##*/} hex|rgb color" \
6
6
+
"${0##*/} accepts hex values (ffffff) or rgb values (255,255,255)"
7
7
+
}
8
8
+
9
9
+
[ "$2" ] || { usage; exit 1; }
10
10
+
11
11
+
hex2rgb() {
12
12
+
hex=$1
13
13
+
hex_r=${hex%????}
14
14
+
hex_g=${hex#??}; hex_g=${hex_g%??}
15
15
+
hex_b=${hex#????}
16
16
+
printf '%d,%d,%d' "0x$hex_r" "0x$hex_g" "0x$hex_b"
17
17
+
}
18
18
+
19
19
+
ds4leds() {
20
20
+
vendorid="054C"
21
21
+
productid="05C4"
22
22
+
led_path="/sys/class/leds"
23
23
+
24
24
+
IFS=, read -r rgb_r rgb_g rgb_b <<-EOF
25
25
+
$1
26
26
+
EOF
27
27
+
28
28
+
printf '%s' "$rgb_r" | tee "$led_path/"*"$vendorid:$productid"*":red/brightness" > /dev/null
29
29
+
printf '%s' "$rgb_g" | tee "$led_path/"*"$vendorid:$productid"*":green/brightness" > /dev/null
30
30
+
printf '%s' "$rgb_b" | tee "$led_path/"*"$vendorid:$productid"*":blue/brightness" > /dev/null
31
31
+
}
32
32
+
33
33
+
case $1 in
34
34
+
hex ) ds4leds "$(hex2rgb "$2")" ;;
35
35
+
rgb ) ds4leds "$2" ;;
36
36
+
*h|*help ) usage; exit 0 ;;
37
37
+
esac