Untitled
unknown
plain_text
24 days ago
2.4 kB
3
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 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() { local num [[ $1 == "R" ]] && num=1 || [[ $1 == "G" ]] && num=2 || [[ $1 == "B" ]] && num=3 || [[ $1 == "O" ]] && num=4 || num=0 echo $num } 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" fi #handle error if [[ $_id -eq 6 ]] then tmp_color=$(( ( 8 >> $_color ) ^ 0x07)) fi if [[ $_color -eq 4 ]] then tmp_color=0x08 fi if [[ $(($_id % 5)) -lt 2 ]] # 0 ,1 ,5 then tmp_color=$((0x00 + $_color)) else tmp_color=$((0x08 + $_color)) fi if [[ $(( $_id % 2 )) -lt 1 ]] then value=$(( tmp_color << 4 )) else value=$tmp_color fi local register=$(( 0xa1 + $_id >> 1 )) local ret=$(dec_to_bin $value) echo $ret } ret=$(setRGB) echo "id : $id" echo "color/action : $color" echo "value = $ret" exit 0
Leave a Comment