op_lcdsettings: Added new configuration to enable / disable automatic screen blanking
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_lcdsettings.sh
1 #!/bin/bash
2 # Released under the GPL
3 # LCD-Settings, v1.0, written by Michael Mrozek aka EvilDragon 2010. Brightness-Settings-Part written by vimacs.
4 # This scripts allows you to create, load and save Gamma-Settings and to change the LCD Brightness.
5
6 while mainsel=$(zenity --title="LCD-Settings" --width="300" --height="280" --list --column "id" --column "Please select" --hide-column=1 --text="What do you want to do?" "bright" "Change LCD Brightness" "gamma" "Manage LCD Gamma" "filter" "Select current video filter" "filterdef" "Select default video filter" "sblank" "Enable/disable screen blanking" ); do
7
8 case $mainsel in
9
10   "bright")
11     minbright=3
12     maxbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/max_brightness)
13     curbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness)
14     device=/sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
15     if [ ! $1 ]; then
16       newbright=$(zenity --scale --text "Set brightness" --min-value=$minbright --max-value=$maxbright --value=$curbright --step 1)
17     else
18       newbright=$1
19     fi
20     if [ $newbright ]; then
21         if [ $newbright -le $minbright ]; then newbright=$minbright; fi
22         if [ $newbright -ge $maxbright ]; then newbright=$maxbright; fi
23           echo $newbright > $device
24     fi;;
25
26    "gamma")
27     if selection=$(cat /etc/pandora/conf/gamma.conf | awk -F\; '{print $1 "\n" $2 }' | zenity --width=700 --height=400 --title="Gamma Manager" --list --column "Name" --column "Description" --text "Please select a Gamma Profile" ); then
28       echo $selection
29
30       gamma=$(grep "$selection" /etc/pandora/conf/gamma.conf | awk -F\; '{print $3}')
31
32     if [ "${gamma}" = "syssyscreatenew" ]; then
33       cat /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma > /tmp/gamma.current
34       op_gammatool
35       if zenity --question --title="Confirm new gamma setting" --text="Do you want to keep the current gamma setting or revert to the previous one?" --ok-label="Keep it" --cancel-label="Revert"; then
36         if zenity --question --title="Save as profile" --text="Do you want to save the new gamma setting as new profile?\n\nNote: You can also test it out first and save it later by restarting the Gamma Manager" --ok-label="Save it now" --cancel-label="Don't save it now"; then    
37          while ! name=$(zenity --title="Save current settings" --entry --text "Please enter a Name for the new profile.") || [ "x$name" = "x" ] ; do
38             zenity --title="Error" --error --text="Please enter a name for the profile.." --timeout 6
39          done
40          curr=$(cat /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma)
41          desc=$(zenity --title="Save current settings" --entry --text "Please enter a description for the new profile.")
42          echo "$name;$desc;$curr" >> /etc/pandora/conf/gamma.conf    
43          zenity --info --title="Profile created" --text "The current gamma settings have been saved as a new profile." --timeout 6
44        fi
45      else
46        cat /tmp/gamma.current > /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma
47      fi
48     elif [ "${gamma}" = "syssyssavecurrent" ]; then
49       curr=$(cat /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma)
50     while ! name=$(zenity --title="Save current settings" --entry --text "Please enter a Name for the new profile.") || [ "x$name" = "x" ] ; do
51             zenity --title="Error" --error --text="Please enter a name for the profile.." --timeout 6
52     done
53       desc=$(zenity --title="Save current settings" --entry --text "Please enter a description for the new profile.")
54       echo "$name;$desc;$curr" >> /etc/pandora/conf/gamma.conf    
55       zenity --info --title="Profile created" --text "The current gamma settings have been saved as a new profile." --timeout 6
56     elif [ ${gamma} = "syssysdeleteprofile" ]; then    
57       if selection2=$(cat /etc/pandora/conf/gamma.conf | grep -v syssys | awk -F\; '{print $1 "\n" $2 }' | zenity --width=700 --height=400 --title="Delete gamma profile" --list --column "Name" --column "Description" --text "Please select a Gamma Profile to Delete" ); then
58         if [ "${selection2}" = "Default Gamma" ]; then
59           zenity --title="Error" --error --text="You cannot delete the default Gamma settings" --timeout 6
60       else
61         if zenity --question --title="Confirm Profile Removal" --text="Are you REALLY sure you want to remove the profile $selection2?\n\nThere will be NO other confirmation and this can NOT be undone!" --ok-label="Yes, remove the profile!" --cancel-label="Don't remove the profile"; then
62           remove=$(grep "$selection2" /etc/pandora/conf/gamma.conf)
63           cat /etc/pandora/conf/gamma.conf | grep -v "$remove" > /tmp/gamma.conf
64           mv /tmp/gamma.conf /etc/pandora/conf/gamma.conf
65           zenity --info --title="Profile deleted" --text "The profile has been deleted." --timeout 6
66         else
67           zenity --info --title="Profile not deleted" --text "The profile has not been deleted." --timeout 6
68         fi
69       fi
70      fi
71     else
72     echo $gamma > /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma
73     fi
74     fi;;
75
76     "filter")
77     if selection=$(head -1 /etc/pandora/conf/dss_fir/* | sed 's:==> ::' | sed 's: <==::' | sed '/^$/d' | zenity --width=700 --height=200 --title="Videofilter" --hide-column=1 --list --column "filter" --column "Videofilter" --text "Please select a videofilter" ); then
78       videofilter=$(basename $selection)
79       sudo /usr/pandora/scripts/op_videofir.sh $videofilter
80       zenity --info --title="Videofilter applied" --text "The videofilter has been applied." --timeout 6
81     fi;;
82     
83     "filterdef")
84     if selection=$(head -1 /etc/pandora/conf/dss_fir/* | sed 's:==> ::' | sed 's: <==::' | sed '/^$/d' | zenity --width=700 --height=200 --title="Videofilter" --hide-column=1 --list --column "filter" --column "Videofilter" --text "Please select a videofilter which will automatically be set on startup" ); then
85       videofilter=$(basename $selection)
86       echo $videofilter > /etc/pandora/conf/filter.state
87       zenity --info --title="Default Videofilter set" --text "The default video filter has been set." --timeout 6
88     fi;;
89
90     "sblank")
91      user=$(cat /tmp/currentuser)
92      if zenity --question --title="Screen blanking" --text="Do you want to enable or disable the automatic screen blanking?" --ok-label="Enable it" --cancel-label="Disable it"; then 
93         sed -i "s/.*xset.*/# DISPLAY=:0 xset s off/g" /home/${user}/.xinitrc
94          zenity --info --title="Screen blanking" --text "The automatic screen blanking has been enabled." --timeout 6
95          DISPLAY=:0 xset s on
96         else
97           sed -i "s/.*xset.*/DISPLAY=:0 xset s off/g" /home/${user}/.xinitrc
98           zenity --info --title="Screen blanking" --text "The automatic screen blanking has been disabled." --timeout 6
99           DISPLAY=:0 xset s off
100     fi;;
101 esac
102 done
103
104
105 DISPLAY=:0 xset s off