A collection of scripts
1#!/bin/sh
2# Change the LEDs of a DualShock4 Controller
3
4usage() {
5 printf '%s\n' "usage: ${0##*/} hex|rgb color" \
6 "${0##*/} accepts hex values (ffffff) or rgb values (255,255,255)"
7}
8
9[ "$2" ] || { usage; exit 1; }
10
11hex2rgb() {
12 hex=$1
13 hex_r=${hex%????}
14 hex_g=${hex#??}; hex_g=${hex_g%??}
15 hex_b=${hex#????}
16
17 printf '%d,%d,%d' "0x$hex_r" "0x$hex_g" "0x$hex_b"
18}
19
20ds4leds() {
21 vendorid="054C"
22 led_path="/sys/class/leds"
23
24 case $led_path/* in
25 "$led_path/"*"$vendorid:05C4"*":global" ) productid="05C4" ;;
26 "$led_path/"*"$vendorid:0BA0"*":global" ) productid="0BA0" ;;
27 esac
28
29 IFS=, read -r r g b <<-EOF
30 $1
31 EOF
32
33 printf '%s' "$r" | tee "$led_path/"*"$vendorid:$productid"*":red/brightness" > /dev/null
34 printf '%s' "$g" | tee "$led_path/"*"$vendorid:$productid"*":green/brightness" > /dev/null
35 printf '%s' "$b" | tee "$led_path/"*"$vendorid:$productid"*":blue/brightness" > /dev/null
36}
37
38case $1 in
39 hex ) ds4leds "$(hex2rgb "$2")" ;;
40 rgb ) ds4leds "$2" ;;
41 *h|*help ) usage; exit 0 ;;
42esac