Untitled
unknown
plain_text
24 days ago
2.5 kB
2
Indexable
Never
#source ./config.sh #source ./functions.sh id="" color="" # register=0x00 while [ $# -gt 0 ] do case $1 in --id) id="$2" shift 2 ;; --color) color="$2" shift 2 ;; -h | --help) echo "test_LED --id <LED_id> --color <color>" echo -e "--id\t\tEnter the LED ID you want to test." echo -e "--color\t\tEnter the color you want to be displayed." exit 0 ;; *) echo "Unknown parameter passed: $1" exit 1 ;; esac done echo "id=$id , color=$color" # # LED test # sudo /usr/sbin/i2cset -y 1 0x30 0xa0 0x36 # # #1110 #id="user" #color="B" echo "id=$id , color=$color" setRegValue () { local _color="$1" local value if [[ $_color = "R" || $_color = "G" ]] then ([[ $_color = "R" ]]) && value=$2 || value=$3 else printf "error input, this color doesn't exist.\n" >&2 fi echo $value } getIDXreg() { local array=("diag" "loc" "psu1" "psu2" "fan" "user" "ports") local _id="$1" local idx=7 for i in "${!array[@]}" do if [ "${array[$i]}" == "$_id" ] then idx=$i break fi done echo $idx } getColor() { case "$1" in R) echo 1 ;; G) echo 2 ;; B) echo 3 ;; O) echo 4 ;; *) echo 0 ;; esac } #echo color: $(getColor G) setRGB () { local _id=$(getIDXreg "$id") local _color=$(getColor "$color") local tmp_color=0x00 local value local register if [[ $_id -eq 7 || $_color -eq 0 ]] then echo "handle error" exit 1 fi #handle error if [[ $_id -eq 6 ]] then tmp_color=$(( ( 8 >> $_color ) ^ 0x07)) elif [[ $_color -eq 3 ]] then echo "handle error" exit 1 elif [[ $_color -eq 4 ]] then tmp_color=0x08 elif [[ $(($_id % 5)) -lt 2 ]] # 0 ,1 ,5 then tmp_color=$((0x00 + $_color)) else tmp_color=$((0x08 + $_color)) fi if [[ $(( $_id % 2 )) -eq 1 ]] then value=$(( tmp_color << 4 )) else value=$tmp_color fi local register=$(( 0xa1 + ($_id >> 1) )) #echo $register $value echo $(printf "Register:0x%02x Value:0x%02x" "$register" "$value" ) } setRGB #ret=$(setRGB) #echo "id : $id" #echo "color/action : $color" #echo "value = $ret" exit 0
Leave a Comment