2023-02-05 22:42:47 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2023-02-05 23:49:23 +00:00
|
|
|
# Copyright (C) 2023-present Fewtarius
|
2023-02-05 22:42:47 +00:00
|
|
|
|
|
|
|
#
|
2023-02-05 23:49:23 +00:00
|
|
|
# A simple tool to manipulate the controller LEDs using ectool, thanks to
|
2023-02-05 22:42:47 +00:00
|
|
|
# Maya (https://github.com/Maccraft123) for reverse engineering.
|
|
|
|
#
|
|
|
|
# Schema:
|
|
|
|
#
|
|
|
|
# 0x6d - LED PWM control (0x03)
|
|
|
|
#
|
|
|
|
# 0xb1 - Support for 4 zones and RGB color
|
|
|
|
#
|
2023-02-05 23:05:06 +00:00
|
|
|
# RGB colors:
|
2023-02-05 22:42:47 +00:00
|
|
|
#
|
2023-02-05 23:05:06 +00:00
|
|
|
# 1 - Red
|
|
|
|
# 2 - Green
|
|
|
|
# 3 - Blue
|
2023-02-05 22:42:47 +00:00
|
|
|
#
|
2023-02-05 23:05:06 +00:00
|
|
|
# Zones:
|
2023-02-05 22:42:47 +00:00
|
|
|
#
|
2023-02-05 23:05:06 +00:00
|
|
|
# Right (2), Down (5), Left (8) , Up (11)
|
2023-02-05 22:42:47 +00:00
|
|
|
#
|
2023-02-05 23:05:06 +00:00
|
|
|
# Note: Set 0xb1 to 02 for off.
|
2023-02-05 22:42:47 +00:00
|
|
|
#
|
2023-02-05 22:56:24 +00:00
|
|
|
# 0xb2 - Sets brightness, requires b1 to be set at the same time.
|
|
|
|
#
|
2023-02-05 23:05:06 +00:00
|
|
|
# 00-ff - brightness from 0-255. Not noticeable to me above 128.
|
2023-02-05 22:56:24 +00:00
|
|
|
#
|
2023-02-05 22:42:47 +00:00
|
|
|
# 0xbf - Set expected mode
|
|
|
|
#
|
2023-02-05 23:06:33 +00:00
|
|
|
# 0x10 - Enable
|
|
|
|
# 0xe2 - Tint (+ Red for Purple, + Green for Teal)
|
|
|
|
# 0xe3-0e5 - Tint + blink (unused)
|
2023-02-05 22:42:47 +00:00
|
|
|
#
|
2023-02-05 23:06:33 +00:00
|
|
|
# 0xff - Close channel
|
2023-02-05 22:42:47 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
. /etc/profile
|
|
|
|
|
|
|
|
ECTOOL="/usr/sbin/ectool"
|
|
|
|
DEBUG=false
|
|
|
|
|
|
|
|
function debug_out() {
|
2023-02-06 13:53:46 +00:00
|
|
|
$DEBUG && echo "ledcontrol: $*"
|
2023-02-05 22:42:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ec_writecmd() {
|
|
|
|
${ECTOOL} -w 0x6d -z 0x03 >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
function mode() {
|
|
|
|
debug_out "Set mode ${1}"
|
|
|
|
${ECTOOL} -w 0xbf -z ${1} >/dev/null 2>&1
|
|
|
|
${ECTOOL} -w 0xbf -z ff >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
function off() {
|
|
|
|
ec_writecmd
|
|
|
|
for twice in 1 2
|
|
|
|
do
|
|
|
|
### RGB off command
|
|
|
|
${ECTOOL} -w 0xb1 -z 0x02 >/dev/null 2>&1
|
2023-02-06 12:24:56 +00:00
|
|
|
${ECTOOL} -w 0xb2 -z 0xc0 >/dev/null 2>&1
|
2023-02-05 22:42:47 +00:00
|
|
|
mode 0x10
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function brightness() {
|
|
|
|
debug_out "Set brightness ${1}"
|
|
|
|
${ECTOOL} -w 0xb2 -z 0x${1} >/dev/null 2>&1
|
|
|
|
mode 0x10
|
|
|
|
}
|
|
|
|
|
|
|
|
function color() {
|
|
|
|
## Writing twice seems more reliable than inserting a delay.
|
|
|
|
for twice in 1 2
|
|
|
|
do
|
|
|
|
for zone in 2 5 8 11
|
|
|
|
do
|
|
|
|
zone=$(( ${zone} + ${1} ))
|
|
|
|
zone=$(printf '%02x' ${zone})
|
|
|
|
debug_out "Set color 0x${zone}"
|
|
|
|
${ECTOOL} -w 0xb1 -z 0x${zone} >/dev/null 2>&1
|
|
|
|
brightness ${2}
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-02-06 16:26:50 +00:00
|
|
|
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
|
|
|
|
debug_out "NO SETTING: max"
|
|
|
|
LEDBRIGHTNESS=max
|
|
|
|
set_setting led.brightness max
|
|
|
|
fi
|
2023-02-06 12:24:56 +00:00
|
|
|
|
|
|
|
case ${LEDBRIGHTNESS} in
|
|
|
|
max)
|
2023-02-05 22:42:47 +00:00
|
|
|
LEDBRIGHTNESS=ff
|
2023-02-06 16:26:50 +00:00
|
|
|
set_setting led.brightness max
|
2023-02-06 12:24:56 +00:00
|
|
|
;;
|
|
|
|
mid)
|
2023-02-06 12:31:46 +00:00
|
|
|
LEDBRIGHTNESS=a8
|
2023-02-06 16:26:50 +00:00
|
|
|
set_setting led.brightness mid
|
2023-02-06 12:24:56 +00:00
|
|
|
;;
|
2023-02-06 16:26:50 +00:00
|
|
|
min)
|
2023-02-06 12:31:46 +00:00
|
|
|
LEDBRIGHTNESS=54
|
2023-02-06 16:26:50 +00:00
|
|
|
set_setting led.brightness min
|
2023-02-06 12:24:56 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2023-02-05 22:42:47 +00:00
|
|
|
debug_out "led brightness: ${LEDBRIGHTNESS}"
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
red)
|
|
|
|
off
|
|
|
|
color 1 ${LEDBRIGHTNESS}
|
|
|
|
set_setting led.color red
|
|
|
|
;;
|
|
|
|
green)
|
|
|
|
off
|
|
|
|
color 2 ${LEDBRIGHTNESS}
|
|
|
|
set_setting led.color green
|
|
|
|
;;
|
|
|
|
blue)
|
|
|
|
off
|
|
|
|
color 3 ${LEDBRIGHTNESS}
|
|
|
|
set_setting led.color blue
|
|
|
|
;;
|
|
|
|
teal)
|
|
|
|
off
|
|
|
|
mode 0xe2
|
|
|
|
color 2 ${LEDBRIGHTNESS}
|
|
|
|
set_setting led.color teal
|
|
|
|
;;
|
|
|
|
purple)
|
|
|
|
off
|
|
|
|
mode 0xe2
|
|
|
|
color 1 ${LEDBRIGHTNESS}
|
|
|
|
set_setting led.color purple
|
|
|
|
;;
|
|
|
|
off)
|
|
|
|
off
|
|
|
|
set_setting led.color off
|
|
|
|
;;
|
|
|
|
default)
|
|
|
|
del_setting led.color
|
|
|
|
del_setting led.brightness
|
|
|
|
;;
|
2023-02-06 12:24:56 +00:00
|
|
|
brightness)
|
|
|
|
COLOR=$(get_setting led.color)
|
|
|
|
if [ ! -z "${COLOR}" ]
|
|
|
|
then
|
|
|
|
off
|
2023-02-06 13:53:46 +00:00
|
|
|
ledcontrol ${COLOR} ${LEDBRIGHTNESS}
|
2023-02-06 12:24:56 +00:00
|
|
|
fi
|
|
|
|
;;
|
2023-02-05 22:42:47 +00:00
|
|
|
*)
|
|
|
|
COLOR=$(get_setting led.color)
|
|
|
|
if [ ! -z "${COLOR}" ]
|
|
|
|
then
|
|
|
|
off
|
2023-02-06 13:53:46 +00:00
|
|
|
ledcontrol ${COLOR} ${LEDBRIGHTNESS}
|
2023-02-05 22:42:47 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|