op_xfcemenu.sh: Changed to bsp's script (slightly modified) which works with the...
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_ledsettings.sh
1 #!/bin/bash
2 # Released under the GPL
3 # LED-Settings, v1.0, written by Michael Mrozek aka EvilDragon 2013.
4
5  . /usr/pandora/scripts/op_paths.sh
6
7 while mainsel=$(zenity --title="LED-Settings" --width="400" --height="370" --list --column "id" --column "Please select" --hide-column=1 --text="Welcome to the LED-Settings-Dialogue.\n\nWhat do you want to do?\n" "normal" "Set Power LED Brightness (normal mode)" "power" "Set Power LED Brightness (powersave)" "sd1" "Enable / Disable SD1 LED" "sd2" "Enable / Disable SD2 LED" "wifi" "Enable / Disable WiFi LED" "bt" "Enable / Disable Bluetooth LED"  --ok-label="Change Setting" --cancel-label="Exit"); do
8
9 case $mainsel in
10
11   "normal")
12    curbright=$(cat /etc/pandora/conf/led.conf | grep HighPowerLED: | awk -F\: '{print $2}')
13    while newbright=$(zenity --scale --text "Set brightness of Power LED (normal mode)" --min-value=0 --max-value=255 --value=$curbright --step 1 --ok-label="Set new brightness" --cancel-label="Save and exit"); do
14       curbright=$newbright
15       echo $curbright > /sys/class/leds/pandora\:\:power/brightness
16    done
17    sed -i "s/.*HighPowerLED.*/HighPowerLED:$curbright/g" /etc/pandora/conf/led.conf 
18    zenity --info --title="Power LED Brightness Set" --text "The new power LED Brightness setting has been saved." --timeout 6
19    ;;   
20   
21   "power")
22    normbright=$(cat /sys/class/leds/pandora\:\:power/brightness)
23    curbright=$(cat /etc/pandora/conf/led.conf | grep LowPowerLED: | awk -F\: '{print $2}')
24    echo $curbright > /sys/class/leds/pandora\:\:power/brightness
25    while newbright=$(zenity --scale --text "Set brightness of Power LED (Powersave mode)" --min-value=0 --max-value=255 --value=$curbright --step 1 --ok-label="Set new brightness" --cancel-label="Save and exit"); do
26       curbright=$newbright
27       echo $curbright > /sys/class/leds/pandora\:\:power/brightness
28    done
29    sed -i "s/.*LowPowerLED.*/LowPowerLED:$curbright/g" /etc/pandora/conf/led.conf 
30    zenity --info --title="Power LED Brightness Set" --text "The new power LED Brightness setting (Powersave mode) has been saved." --timeout 6
31    echo $normbright > /sys/class/leds/pandora\:\:power/brightness
32    ;;   
33   
34   "sd1")
35   if zenity --question --title="Enable / Disable LED?" --text="Do you want to enable or disable the LED for SD Card 1?" --ok-label="Enable it" --cancel-label="Disable it"; then
36     echo mmc0 > /sys/class/leds/pandora\:\:sd1/trigger
37     sed -i "s/.*pandora::sd1.*/pandora::sd1 mmc0/g" /etc/default/leds 
38   else
39     echo none > /sys/class/leds/pandora\:\:sd1/trigger
40     sed -i "s/.*pandora::sd1.*/pandora::sd1 none/g" /etc/default/leds 
41   fi
42   ;;
43   
44   "sd2")
45   if zenity --question --title="Enable / Disable LED?" --text="Do you want to enable or disable the LED for SD Card 2?" --ok-label="Enable it" --cancel-label="Disable it"; then
46     echo mmc1 > /sys/class/leds/pandora\:\:sd2/trigger
47     sed -i "s/.*pandora::sd2.*/pandora::sd2 mmc1/g" /etc/default/leds 
48   else
49     echo none > /sys/class/leds/pandora\:\:sd2/trigger
50     sed -i "s/.*pandora::sd2.*/pandora::sd2 none/g" /etc/default/leds 
51   fi
52   ;;
53   
54   "bt")
55   if zenity --question --title="Enable / Disable LED?" --text="Do you want to enable or disable the LED for the Bluetooth LED?" --ok-label="Enable it" --cancel-label="Disable it"; then
56     echo bluetooth > /sys/class/leds/pandora\:\:bluetooth/trigger
57     sed -i "s/.*pandora::bluetooth.*/pandora::bluetooth bluetooth/g" /etc/default/leds 
58     if hciconfig "$INTERFACE" | grep UP &>/dev/null
59     then
60         echo default-on > /sys/class/leds/pandora\:\:bluetooth/trigger
61         echo 255 > /sys/class/leds/pandora\:\:bluetooth/brightness
62     fi
63   else
64     echo none > /sys/class/leds/pandora\:\:bluetooth/trigger
65     sed -i "s/.*pandora::bluetooth.*/pandora::bluetooth none/g" /etc/default/leds 
66   fi
67   ;;
68   
69   "wifi")
70   if zenity --question --title="Enable / Disable LED?" --text="Do you want to enable or disable the WiFi LED?" --ok-label="Enable it" --cancel-label="Disable it"; then
71     sed -i "s/.*pandora::wifi.*/pandora::wifi phy0radio/g" /etc/default/leds 
72     if [ "`lsmod | grep wl1251`" ]
73     then
74         phy_idx=0
75         for a in `seq 20` ; do
76                 if [ -e /sys/class/net/wlan0 ] ; then
77                         phy_idx=$(cat /sys/class/net/wlan0/phy80211/index)
78                         break
79                 else
80                         sleep 0.2
81                 fi
82         done
83
84         # restore phy related LED triggers (they come from mac80211.ko)
85         if [ -e /sys/class/leds/ ] ; then
86                 for led in /sys/class/leds/* ; do
87                         trigger=$(grep "$(basename $led)" /etc/default/leds | grep phy | \
88                                         awk '{print $2}' | sed -e 's/.*phy[0-9]*\(.*\)/\1/')
89                         if [ "x$trigger" != "x" ] ; then
90                                 echo "phy${phy_idx}$trigger" > "$led/trigger"
91                         fi
92                 done
93         fi
94     fi
95     zenity --info --title="WiFi LED Set" --text "The WiFi LED has been enabled.\nPlease note: You need to disable and re-enable WiFi before it switches on again." --timeout 6
96   else
97     echo none > /sys/class/leds/pandora\:\:wifi/trigger
98     sed -i "s/.*pandora::wifi.*/pandora::wifi none/g" /etc/default/leds 
99   fi
100   ;;
101 esac
102 done
103