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 printf '%d,%d,%d' "0x$hex_r" "0x$hex_g" "0x$hex_b"
17}
18
19ds4leds() {
20 vendorid="054C"
21 led_path="/sys/class/leds"
22
23 case $led_path/* in
24 "$led_path/"*"$vendorid:05C4"*":global" ) productid="05C4" ;;
25 "$led_path/"*"$vendorid:0BA0"*":global" ) productid="0BA0" ;;
26 esac
27
28 IFS=, read -r rgb_r rgb_g rgb_b <<-EOF
29 $1
30 EOF
31 printf '%s' "$rgb_r" | tee "$led_path/"*"$vendorid:$productid"*":red/brightness" > /dev/null
32 printf '%s' "$rgb_g" | tee "$led_path/"*"$vendorid:$productid"*":green/brightness" > /dev/null
33 printf '%s' "$rgb_b" | tee "$led_path/"*"$vendorid:$productid"*":blue/brightness" > /dev/null
34}
35
36case $1 in
37 hex ) ds4leds "$(hex2rgb "$2")" ;;
38 rgb ) ds4leds "$2" ;;
39 *h|*help ) usage; exit 0 ;;
40esac