2023-09-20 02:14:32 +00:00
|
|
|
#!/bin/sh
|
2023-10-23 22:44:47 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2023-10-24 16:00:57 +00:00
|
|
|
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
|
2023-09-20 02:14:32 +00:00
|
|
|
|
2023-09-20 11:37:21 +00:00
|
|
|
# A simple tool to manipulate the controller LEDs using outb, thanks
|
2023-09-20 11:50:55 +00:00
|
|
|
# in large part to Maya Matuszczyk (https://github.com/Maccraft123)
|
|
|
|
# for help with reverse engineering.
|
2023-09-20 11:37:21 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
. /etc/profile
|
|
|
|
|
|
|
|
OUTB="/usr/bin/outb"
|
|
|
|
|
|
|
|
ADDR_PORT="0x4e"
|
|
|
|
DATA_PORT="0x4f"
|
|
|
|
|
|
|
|
DEBUG=false
|
|
|
|
|
|
|
|
function debug_out() {
|
|
|
|
$DEBUG && echo "ledcontrol: $*"
|
|
|
|
}
|
|
|
|
|
|
|
|
function led_ctl() {
|
|
|
|
${OUTB} ${ADDR_PORT} 0x2e
|
|
|
|
${OUTB} ${DATA_PORT} 0x11
|
|
|
|
${OUTB} ${ADDR_PORT} 0x2f
|
|
|
|
${OUTB} ${DATA_PORT} 0xd1 # high
|
|
|
|
|
|
|
|
${OUTB} ${ADDR_PORT} 0x2e
|
|
|
|
${OUTB} ${DATA_PORT} 0x10
|
|
|
|
${OUTB} ${ADDR_PORT} 0x2f
|
|
|
|
${OUTB} ${DATA_PORT} ${1} # low
|
|
|
|
|
|
|
|
${OUTB} ${ADDR_PORT} 0x2e
|
|
|
|
${OUTB} ${DATA_PORT} 0x12
|
|
|
|
${OUTB} ${ADDR_PORT} 0x2f
|
|
|
|
${OUTB} ${DATA_PORT} ${2} # data
|
|
|
|
}
|
|
|
|
|
|
|
|
function led_open() {
|
|
|
|
led_ctl 0x87 0xa5
|
|
|
|
}
|
|
|
|
|
|
|
|
function led_close() {
|
|
|
|
led_ctl ${1} 0x01
|
|
|
|
}
|
|
|
|
|
|
|
|
function led_ack() {
|
|
|
|
led_open
|
|
|
|
led_ctl 0x70 0x0
|
|
|
|
led_close 0x86
|
|
|
|
}
|
|
|
|
|
|
|
|
function led_state() {
|
|
|
|
# 0x31 = off
|
|
|
|
# 0x37 = on
|
|
|
|
for ZONE in 0xb2 0x72
|
|
|
|
do
|
|
|
|
led_open
|
|
|
|
led_ctl ${ZONE} ${1}
|
|
|
|
led_ctl 0xc6 0x01
|
|
|
|
led_ack
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-09-20 03:00:53 +00:00
|
|
|
function led_enable() {
|
2023-09-20 02:14:32 +00:00
|
|
|
led_state 0x37
|
|
|
|
led_ack
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0xbf 0x0
|
|
|
|
led_close 0xc6
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0x7f 0x0
|
|
|
|
led_close 0xc6
|
|
|
|
|
|
|
|
led_ack
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0xc0 0x0
|
|
|
|
led_close 0xc6
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0x80 0x0
|
|
|
|
led_close 0x86
|
|
|
|
|
|
|
|
led_ack
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0xc1 0x5
|
|
|
|
led_close 0xc6
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0x81 0x5
|
|
|
|
led_close 0xc6
|
|
|
|
|
|
|
|
led_ack
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0xc2 0x5
|
|
|
|
led_close 0xc6
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0x82 0x5
|
|
|
|
led_close 0x86
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0x70 0x0
|
|
|
|
led_close 0x86
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0xc3 0x5
|
|
|
|
led_close 0x86
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0x83 0x5
|
|
|
|
led_close 0x86
|
|
|
|
|
|
|
|
led_ack
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0xc4 0x5
|
|
|
|
led_close 0xc6
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0x84 0x5
|
|
|
|
led_close 0x86
|
|
|
|
|
|
|
|
led_ack
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0xc5 0x7
|
|
|
|
led_close 0xc6
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0x85 0x7
|
|
|
|
led_close 0x86
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0x70 0x0
|
|
|
|
led_close 0x86
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0xc5 0x7
|
|
|
|
led_close 0xc6
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0x85 0x7
|
|
|
|
led_close 0x86
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0x70 0x0
|
|
|
|
led_close 0x86
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0xb2 0xba
|
|
|
|
led_close 0xc6
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0x72 0xba
|
|
|
|
led_close 0x86
|
|
|
|
|
|
|
|
led_open
|
|
|
|
led_ctl 0x70 0x0
|
|
|
|
led_close 0x86
|
|
|
|
|
|
|
|
led_ack
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-09-20 03:00:53 +00:00
|
|
|
function led_color() {
|
2023-09-20 12:11:41 +00:00
|
|
|
# Zone 1 (Left Stick)
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
2023-09-20 12:11:41 +00:00
|
|
|
led_ctl 0xB3 ${1} # Quadrant 1
|
2023-09-20 02:14:32 +00:00
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0xB4 ${2}
|
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0xB5 ${3}
|
|
|
|
led_ack
|
|
|
|
|
|
|
|
led_open
|
2023-09-20 12:11:41 +00:00
|
|
|
led_ctl 0xB6 ${1} # Quadrant 2
|
2023-09-20 02:14:32 +00:00
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0xB7 ${2}
|
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0xB8 ${3}
|
|
|
|
led_ack
|
|
|
|
|
|
|
|
led_open
|
2023-09-20 12:11:41 +00:00
|
|
|
led_ctl 0xB9 ${1} # Quadrant 3
|
2023-09-20 02:14:32 +00:00
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0xBA ${2}
|
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0xBB ${3}
|
|
|
|
led_ack
|
|
|
|
|
|
|
|
led_open
|
2023-09-20 12:11:41 +00:00
|
|
|
led_ctl 0xBC ${1} # Quadrant 4
|
2023-09-20 02:14:32 +00:00
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0xBD ${2}
|
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0xBE ${3}
|
|
|
|
led_ack
|
|
|
|
|
2023-09-20 12:11:41 +00:00
|
|
|
# Zone 2 (Right Stick)
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
2023-09-20 12:11:41 +00:00
|
|
|
led_ctl 0x73 ${1} # Quadrant 1
|
2023-09-20 02:14:32 +00:00
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0x74 ${2}
|
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0x75 ${3}
|
|
|
|
led_ack
|
|
|
|
|
|
|
|
led_open
|
2023-09-20 12:11:41 +00:00
|
|
|
led_ctl 0x76 ${1} # Quadrant 2
|
2023-09-20 02:14:32 +00:00
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0x77 ${2}
|
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0x78 ${3}
|
|
|
|
led_ack
|
|
|
|
|
|
|
|
led_open
|
2023-09-20 12:11:41 +00:00
|
|
|
led_ctl 0x79 ${1} # Quadrant 3
|
2023-09-20 02:14:32 +00:00
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0x7A ${2}
|
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0x7B ${3}
|
|
|
|
led_ack
|
|
|
|
|
|
|
|
led_open
|
2023-09-20 12:11:41 +00:00
|
|
|
led_ctl 0x7C ${1} # Quadrant 4
|
2023-09-20 02:14:32 +00:00
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0x7D ${2}
|
|
|
|
led_ack
|
2023-09-20 12:11:41 +00:00
|
|
|
|
2023-09-20 02:14:32 +00:00
|
|
|
led_open
|
|
|
|
led_ctl 0x7E ${3}
|
|
|
|
led_ack
|
|
|
|
}
|
|
|
|
|
|
|
|
function intensity() {
|
|
|
|
printf "0x%X\n" $((${1} / ${2}))
|
|
|
|
}
|
|
|
|
|
|
|
|
GETBRIGHTNESS=$(get_setting led.brightness)
|
|
|
|
if [ ! -z "${2}" ]
|
|
|
|
then
|
|
|
|
LEDBRIGHTNESS=${2}
|
|
|
|
debug_out "Arg[2]: ${2}"
|
|
|
|
elif [ ! -z "${GETBRIGHTNESS}" ]
|
|
|
|
then
|
|
|
|
LEDBRIGHTNESS=${GETBRIGHTNESS}
|
|
|
|
debug_out "GETBRIGHTESS: ${GETBRIGHTNESS}"
|
|
|
|
else
|
2023-09-20 12:16:40 +00:00
|
|
|
debug_out "NO SETTING: min"
|
|
|
|
LEDBRIGHTNESS=min
|
|
|
|
set_setting led.brightness min
|
2023-09-20 02:14:32 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
case ${LEDBRIGHTNESS} in
|
|
|
|
max)
|
|
|
|
LEDBRIGHTNESS=1
|
|
|
|
set_setting led.brightness max
|
|
|
|
;;
|
|
|
|
mid)
|
2023-09-20 12:11:41 +00:00
|
|
|
LEDBRIGHTNESS=4
|
2023-09-20 02:14:32 +00:00
|
|
|
set_setting led.brightness mid
|
|
|
|
;;
|
|
|
|
min)
|
2023-09-20 12:11:41 +00:00
|
|
|
LEDBRIGHTNESS=8
|
2023-09-20 02:14:32 +00:00
|
|
|
set_setting led.brightness min
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case ${1} in
|
2024-01-23 18:05:47 +00:00
|
|
|
poweroff)
|
|
|
|
led_state 0x31
|
|
|
|
;;
|
2023-09-20 02:14:32 +00:00
|
|
|
off)
|
|
|
|
led_state 0x31
|
|
|
|
set_setting led.color off
|
|
|
|
;;
|
|
|
|
on)
|
|
|
|
led_state 0x37
|
|
|
|
set_setting led.color on
|
2023-09-20 12:11:41 +00:00
|
|
|
led_enable
|
2023-09-20 02:14:32 +00:00
|
|
|
;;
|
|
|
|
red)
|
|
|
|
COLOR=$(intensity 0xFF ${LEDBRIGHTNESS})
|
|
|
|
ledcontrol off
|
|
|
|
led_color ${COLOR} 0x00 0x00
|
|
|
|
set_setting led.color red
|
2023-09-20 12:11:41 +00:00
|
|
|
led_enable
|
2023-09-20 02:14:32 +00:00
|
|
|
;;
|
|
|
|
green)
|
|
|
|
COLOR=$(intensity 0xFF ${LEDBRIGHTNESS})
|
|
|
|
ledcontrol off
|
|
|
|
led_color 0x00 ${COLOR} 0x00
|
|
|
|
set_setting led.color green
|
2023-09-20 12:11:41 +00:00
|
|
|
led_enable
|
2023-09-20 02:14:32 +00:00
|
|
|
;;
|
|
|
|
blue)
|
|
|
|
COLOR=$(intensity 0xFF ${LEDBRIGHTNESS})
|
|
|
|
ledcontrol off
|
|
|
|
led_color 0x00 0x00 ${COLOR}
|
|
|
|
set_setting led.color blue
|
2023-09-20 12:11:41 +00:00
|
|
|
led_enable
|
2023-09-20 02:14:32 +00:00
|
|
|
;;
|
|
|
|
teal)
|
|
|
|
COLOR=$(intensity 0xFF ${LEDBRIGHTNESS})
|
|
|
|
ledcontrol off
|
|
|
|
led_color 0x00 ${COLOR} ${COLOR}
|
|
|
|
set_setting led.color teal
|
2023-09-20 12:11:41 +00:00
|
|
|
led_enable
|
2023-09-20 02:14:32 +00:00
|
|
|
;;
|
|
|
|
purple)
|
|
|
|
COLOR=$(intensity 0xFF ${LEDBRIGHTNESS})
|
|
|
|
ledcontrol off
|
|
|
|
led_color ${COLOR} 0x00 ${COLOR}
|
|
|
|
set_setting led.color purple
|
2023-09-20 12:11:41 +00:00
|
|
|
led_enable
|
2023-09-20 02:14:32 +00:00
|
|
|
;;
|
|
|
|
white)
|
|
|
|
COLOR=$(intensity 0xFF ${LEDBRIGHTNESS})
|
|
|
|
ledcontrol off
|
|
|
|
led_color ${COLOR} ${COLOR} ${COLOR}
|
|
|
|
set_setting led.color white
|
2023-09-20 12:11:41 +00:00
|
|
|
led_enable
|
2023-09-20 02:14:32 +00:00
|
|
|
;;
|
|
|
|
default)
|
|
|
|
del_setting led.color
|
|
|
|
;;
|
|
|
|
brightness)
|
|
|
|
set_setting led.brightness ${2}
|
2023-09-20 12:11:41 +00:00
|
|
|
ledcontrol $(get_setting led.color)
|
2023-09-20 02:14:32 +00:00
|
|
|
;;
|
2024-01-15 03:14:48 +00:00
|
|
|
list)
|
|
|
|
cat <<EOF
|
|
|
|
default
|
|
|
|
off
|
|
|
|
red
|
|
|
|
green
|
|
|
|
blue
|
|
|
|
teal
|
|
|
|
purple
|
|
|
|
white
|
|
|
|
EOF
|
|
|
|
;;
|
2023-09-20 02:14:32 +00:00
|
|
|
*)
|
|
|
|
COLOR=$(get_setting led.color)
|
|
|
|
if [ ! -z "${COLOR}" ]
|
|
|
|
then
|
|
|
|
ledcontrol ${COLOR}
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|