# Calculate chmod=0755 comment=# load(char,/sys/bus/pci/devices/0000:00:02.0/vendor,root)==0x8086&&load(char,/sys/bus/pci/devices/0000:00:02.0/device,root)==0xa011||load(char,/sys/bus/pci/devices/0000:00:02.0/vendor,root)==0x8086&&load(char,/sys/bus/pci/devices/0000:00:02.0/device,root)==0x2a42
#!/bin/bash
# increase/decrease/set/get the backlight brightness (range 0-255)
#
 
# PCI device on which to operate
DEVICE=00:02.0

# Amount to raise/lower the backlight when called with "up" or "down"
AMOUNT=8

# Minimum backlight value reachable via "down"
MIN=1

# Default backlight level when toggling on
DEFAULT=aa
 
#get current brightness in hex and convert to decimal
var1=`setpci -s $DEVICE F4.B`
var1d=$((0x$var1))
case "$1" in
       up)
               #calculate new brightness
               var2=$(($var1d + $AMOUNT))
               if [[ $var2 -gt 255 ]]
               then
                      var2=255
               fi
               var2=`printf "%x" $var2`
               echo "$0: increasing brightness from 0x$var1 to 0x$var2"
               setpci -s $DEVICE F4.B=$var2
               ;;
       down)
               #calculate new brightness
               var2=$(($var1d - $AMOUNT))
               if [[ $var2 -lt $MIN ]]
               then
                      var2=$MIN
               fi
               var2=`printf "%x" $var2`
               echo "$0: decreasing brightness from 0x$var1 to 0x$var2"
               setpci -s $DEVICE F4.B=$var2
               ;;
       set)
               #n.b. this does allow "set 0" i.e. backlight off
               echo "$0: setting brightness to 0x$2"
               setpci -s $DEVICE F4.B=$2
               ;;
       get)
               echo "$0: current brightness is 0x$var1"
               ;;
       toggle)
               if [ $var1d -eq 0 ] ; then
                       echo "toggling up"
                       setpci -s $DEVICE F4.B=$DEFAULT
               else
                       echo "toggling down"
                       setpci -s $DEVICE F4.B=0
               fi
               ;;
       *)
               echo "usage: $0 {up|down|set <val>|get|toggle}"
               ;;
esac
exit 0
