#!/bin/sh # SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2023-present Fewtarius # # A simple tool to manipulate the controller LEDs using ectool, thanks to # Ayn for the sample code. # # Schema: # # 0xB3 - RGB Mode # 0xAA - Save # # 0xB0 - Red # 0xB1 - Green # 0xB2 - Blue # . /etc/profile RGB_RED="0xB0" RGB_GREEN="0xB1" RGB_BLUE="0xB2" RGB_MODE="0xB3" RGB_SAVE="0xAA" ECTOOL="/usr/sbin/ectool" DEBUG=false function debug_out() { $DEBUG && echo "ledcontrol: $*" } function ec_save() { ${ECTOOL} -w ${RGB_MODE} -z ${RGB_SAVE} >/dev/null 2>&1 } function ec_set() { debug_out "Set EC ${1} ${2}" ${ECTOOL} -w ${1} -z ${2} >/dev/null 2>&1 } function off() { ec_save ec_set ${RGB_RED} 0x00 ec_set ${RGB_GREEN} 0x00 ec_set ${RGB_BLUE} 0x00 ec_save } case $1 in red) off ec_set ${RGB_RED} 0xFF ec_set ${RGB_GREEN} 0x00 ec_set ${RGB_BLUE} 0x00 ec_save set_setting led.color red ;; green) off ec_set ${RGB_RED} 0x00 ec_set ${RGB_GREEN} 0xFF ec_set ${RGB_BLUE} 0x00 ec_save set_setting led.color green ;; blue) off ec_set ${RGB_RED} 0x00 ec_set ${RGB_GREEN} 0x00 ec_set ${RGB_BLUE} 0xFF ec_save set_setting led.color blue ;; teal) off ec_set ${RGB_RED} 0x00 ec_set ${RGB_GREEN} 0x80 ec_set ${RGB_BLUE} 0x80 ec_save set_setting led.color teal ;; purple) off ec_set ${RGB_RED} 0x80 ec_set ${RGB_GREEN} 0x00 ec_set ${RGB_BLUE} 0x80 ec_save set_setting led.color purple ;; off) off set_setting led.color off ;; default) del_setting led.color ;; *) COLOR=$(get_setting led.color) if [ ! -z "${COLOR}" ] then ledcontrol ${COLOR} fi ;; esac