#!/bin/sh # SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2023-present Fewtarius . /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 } led_enable() { 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 } led_color() { # Zone 1 led_open led_ctl 0xB3 ${1} led_ack led_open led_ctl 0xB4 ${2} led_ack led_open led_ctl 0xB5 ${3} led_ack led_open led_ctl 0xB6 ${1} led_ack led_open led_ctl 0xB7 ${2} led_ack led_open led_ctl 0xB8 ${3} led_ack led_open led_ctl 0xB9 ${1} led_ack led_open led_ctl 0xBA ${2} led_ack led_open led_ctl 0xBB ${3} led_ack led_open led_ctl 0xBC ${1} led_ack led_open led_ctl 0xBD ${2} led_ack led_open led_ctl 0xBE ${3} led_ack # Zone 2 led_open led_ctl 0x73 ${1} led_ack led_open led_ctl 0x74 ${2} led_ack led_open led_ctl 0x75 ${3} led_ack led_open led_ctl 0x76 ${1} led_ack led_open led_ctl 0x77 ${2} led_ack led_open led_ctl 0x78 ${3} led_ack led_open led_ctl 0x79 ${1} led_ack led_open led_ctl 0x7A ${2} led_ack led_open led_ctl 0x7B ${3} led_ack led_open led_ctl 0x7C ${1} led_ack led_open led_ctl 0x7D ${2} led_ack 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 debug_out "NO SETTING: max" LEDBRIGHTNESS=mid set_setting led.brightness max fi case ${LEDBRIGHTNESS} in max) LEDBRIGHTNESS=1 set_setting led.brightness max ;; mid) LEDBRIGHTNESS=2 set_setting led.brightness mid ;; min) LEDBRIGHTNESS=4 set_setting led.brightness min ;; esac case ${1} in off) led_state 0x31 set_setting led.color off exit ;; on) led_state 0x37 set_setting led.color on ;; red) COLOR=$(intensity 0xFF ${LEDBRIGHTNESS}) ledcontrol off led_color ${COLOR} 0x00 0x00 set_setting led.color red ;; green) COLOR=$(intensity 0xFF ${LEDBRIGHTNESS}) ledcontrol off led_color 0x00 ${COLOR} 0x00 set_setting led.color green ;; blue) COLOR=$(intensity 0xFF ${LEDBRIGHTNESS}) ledcontrol off led_color 0x00 0x00 ${COLOR} set_setting led.color blue ;; teal) COLOR=$(intensity 0xFF ${LEDBRIGHTNESS}) ledcontrol off led_color 0x00 ${COLOR} ${COLOR} set_setting led.color teal ;; purple) COLOR=$(intensity 0xFF ${LEDBRIGHTNESS}) ledcontrol off led_color ${COLOR} 0x00 ${COLOR} set_setting led.color purple ;; white) COLOR=$(intensity 0xFF ${LEDBRIGHTNESS}) ledcontrol off led_color ${COLOR} ${COLOR} ${COLOR} set_setting led.color white ;; default) del_setting led.color ;; brightness) set_setting led.brightness ${2} ;; *) COLOR=$(get_setting led.color) if [ ! -z "${COLOR}" ] then ledcontrol ${COLOR} exit 0 fi ;; esac led_enable