A collection of scripts

ds4-leds: remove

yemou d75a55d3 a2790a0a

Changed files
-42
scritps
-42
scritps/ds4-leds
···
-
#!/bin/sh
-
# Change the LEDs of a DualShock4 Controller
-
-
usage() {
-
printf '%s\n' "usage: ${0##*/} hex|rgb color" \
-
"${0##*/} accepts hex values (ffffff) or rgb values (255,255,255)"
-
}
-
-
[ "$2" ] || { usage; exit 1; }
-
-
hex2rgb() {
-
hex=$1
-
hex_r=${hex%????}
-
hex_g=${hex#??}; hex_g=${hex_g%??}
-
hex_b=${hex#????}
-
-
printf '%d,%d,%d' "0x$hex_r" "0x$hex_g" "0x$hex_b"
-
}
-
-
ds4leds() {
-
vendorid="054C"
-
led_path="/sys/class/leds"
-
-
case $led_path/* in
-
"$led_path/"*"$vendorid:05C4"*":global" ) productid="05C4" ;;
-
"$led_path/"*"$vendorid:0BA0"*":global" ) productid="0BA0" ;;
-
esac
-
-
IFS=, read -r r g b <<-EOF
-
$1
-
EOF
-
-
printf '%s' "$r" | tee "$led_path/"*"$vendorid:$productid"*":red/brightness" > /dev/null
-
printf '%s' "$g" | tee "$led_path/"*"$vendorid:$productid"*":green/brightness" > /dev/null
-
printf '%s' "$b" | tee "$led_path/"*"$vendorid:$productid"*":blue/brightness" > /dev/null
-
}
-
-
case $1 in
-
hex ) ds4leds "$(hex2rgb "$2")" ;;
-
rgb ) ds4leds "$2" ;;
-
*h|*help ) usage; exit 0 ;;
-
esac