Guest User

ogzy

a guest
Jul 18th, 2008
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.73 KB | None | 0 0
  1. #!/bin/sh
  2. # dimmer.sh
  3. # written by Rob Stockley (rob dash stockley at mowgli dot net dot nz)
  4. # to incrementally change the LCD brightness on a Compaq TC1100 tablet.
  5. # Tested only with Kubuntu 7.04. All comments and suggestions welcome.
  6.  
  7. ME=`whoami`
  8. if [ $ME = root ]; then
  9.     DISPLAYOWNER=`w -h | awk '{print $1" "$2" "$3}' | grep ":0"`
  10.     USER=`echo $DISPLAYOWNER | awk '{print $1}'`
  11. #   echo working on: $USER
  12.     su -l $USER <<ENDSU
  13.     /usr/bin/dimmer.sh $1 dummy;
  14.  
  15. ENDSU
  16.     exit 0
  17. fi
  18. # first need to establish whether config file exists and we can write to it
  19. echo $HOME
  20. NV_CONFIG="$HOME/.nvidia-settings-rc"
  21. if ! [ -w $NV_CONFIG ]; then
  22.     echo "$NV_CONFIG is either missing or not writable. Before you run this script you need to run the nvidia-settings GUI application. When you quit the GUI the current driver settings should be written to $NV_CONFIG."
  23.     nvidia-settings
  24. #    exit 0
  25. fi
  26.  
  27. # now need to read current brightness values
  28. CUR_R=`grep RedBrightness $NV_CONFIG | awk 'BEGIN { FS = "=" } ; { print $2 }'`
  29. CUR_G=`grep GreenBrightness $NV_CONFIG | awk 'BEGIN { FS = "=" } ; { print $2 }'`
  30. CUR_B=`grep BlueBrightness $NV_CONFIG | awk 'BEGIN { FS = "=" } ; { print $2 }'`
  31.  
  32. # stepping 0.2 gives me five dim and five bright settings
  33. STEP="0.2"
  34. case $1 in
  35.     --reset)
  36.         # reset to driver defaults
  37.         NEW_R='0.0000'
  38.         NEW_G='0.0000'
  39.         NEW_B='0.0000'
  40.         ;;
  41.     --dec)
  42.         # decrease brightness and check limits
  43.         NEW_R=`echo "scale=4; $CUR_R - $STEP" | bc`
  44.         if [ `echo "scale=4; $NEW_R < -1.0" | bc` -eq 1 ]; then
  45.             NEW_R=-1.0
  46.         fi
  47.         NEW_G=`echo "scale=4; $CUR_G - $STEP" | bc`
  48.         if [ `echo "scale=4; $NEW_G < -1.0" | bc` -eq 1 ]; then
  49.             NEW_G=-1.0
  50.         fi
  51.         NEW_B=`echo "scale=4; $CUR_B - $STEP" | bc`
  52.         if [ `echo "scale=4; $NEW_B < -1.0" | bc` -eq 1 ]; then
  53.             NEW_B=-1.0
  54.         fi
  55.         ;;
  56.     --inc)
  57.         # increase brightness and check limits
  58.         NEW_R=`echo "scale=4; $CUR_R + $STEP" | bc`
  59.         if [ `echo "scale=4; $NEW_R > 1.0" | bc` -eq 1 ]; then
  60.             NEW_R=1.0
  61.         fi
  62.         NEW_G=`echo "scale=4; $CUR_G + $STEP" | bc`
  63.         if [ `echo "scale=4; $NEW_G > 1.0" | bc` -eq 1 ]; then
  64.             NEW_G=1.0
  65.         fi
  66.         NEW_B=`echo "scale=4; $CUR_B + $STEP" | bc`
  67.         if [ `echo "scale=4; $NEW_B > 1.0" | bc` -eq 1 ]; then
  68.             NEW_B=1.0
  69.         fi
  70.         ;;
  71.     --help)
  72.         echo "Script: $0"
  73.         echo "Purpose: Change the LCD brightness on a"
  74.         echo "Compaq TC1100 using Nvidia restricted driver. "
  75.         echo "Written by Rob Stockley, October 2007"
  76.         echo
  77.         echo "Usage: $0 [ --reset | --dim | --inc | --help ]"
  78.         echo "Options:"
  79.         echo "  --dec     decrease the brightness a little"
  80.         echo "  --inc     increace the brightness a little"
  81.         echo "  --reset   reset to standard brightness"
  82.         echo "  --help    print this message"
  83.         exit 0
  84.         ;;
  85.     *)
  86.         echo "Usage: $0 [ --reset | --dim | --inc | --help ]"
  87.         exit 0
  88.         ;;
  89. esac
  90.  
  91. # fix cases where bc leaves us with leading -.
  92. NEW_R=`echo $NEW_R | sed 's/-\./-0\./'`
  93. NEW_G=`echo $NEW_G | sed 's/-\./-0\./'`
  94. NEW_B=`echo $NEW_B | sed 's/-\./-0\./'`
  95.  
  96. # if we get to here then patch the .nvidia-settings-rc
  97. patch -s $NV_CONFIG << EOF
  98. --- .nvidia-settings-rc 2007-10-10 21:45:26.000000000 +1300
  99. +++ .nvidia-settings-rc.new 2007-10-11 10:00:52.000000000 +1300
  100. @@ -36,3 +36,3 @@
  101. -0/RedBrightness=$CUR_R
  102. -0/GreenBrightness=$CUR_G
  103. -0/BlueBrightness=$CUR_B
  104. +0/RedBrightness=$NEW_R
  105. +0/GreenBrightness=$NEW_G
  106. +0/BlueBrightness=$NEW_B
  107. EOF
  108.  
  109. # finally the nvidia driver needs to load the new configuration
  110. nvidia-settings -l -c :0
Advertisement
Add Comment
Please, Sign In to add comment