op_power.sh: Now using led.conf for LED brightness settings
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_power.sh
index 85843d8..f6e3fee 100644 (file)
@@ -5,6 +5,8 @@
 # XXX: better use lockfile (or something), but it's not in current firmware
 test -e /tmp/op_power.lock && exit 2
 touch /tmp/op_power.lock
+highpow="$(cat /etc/pandora/conf/led.conf | grep HighPowerLED: | awk -F\: '{print $2}')"
+lowpow="$(cat /etc/pandora/conf/led.conf | grep LowPowerLED: | awk -F\: '{print $2}')"
 
 debug(){
        return 1 # 0 when debugging, 1 when not
@@ -109,6 +111,7 @@ lowPowerOn(){ #switch from normal to lowpower mode
 lowPowerOff(){ # switch from lowpower to normal mode
        oldspeed=$(cat /tmp/oldspeed)
        /usr/pandora/scripts/op_cpuspeed.sh -n $oldspeed
+       rm -f /tmp/oldspeed
 
        display_on
        resume_net
@@ -118,7 +121,19 @@ lowPowerOff(){ # switch from lowpower to normal mode
        do
                kill -CONT $PID
        done
-       echo 255 > /sys/class/leds/pandora\:\:power/brightness #power LED bright
+       echo $highpow > /sys/class/leds/pandora\:\:power/brightness #power LED bright
+}
+
+display_on_with_checks() {
+       # after turning on the display, we don't want lowpower state
+       # (which could be active because of some races)
+       if [ "$powerstate" = "buttonlowpower" -o "$powerstate" = "lidlowpower" -o \
+            -e /tmp/oldspeed ]
+       then
+               lowPowerOff
+       else
+               display_on
+       fi
 }
 
 show_message() {
@@ -197,12 +212,14 @@ Please do not remove SD cards while pandora is suspended, doing so will corrupt
 
        # if we are here, either we already resumed or the suspend failed
        if [ -n "$restore_list" ]; then
-               modprobe $restore_list
+               for module in $restore_list; do
+                       modprobe $module
+               done
        fi
 
        display_on
        resume_net
-       echo 255 > /sys/class/leds/pandora\:\:power/brightness
+       echo $highpow > /sys/class/leds/pandora\:\:power/brightness
 
        # wait here a bit to prevent this script from running again (keep op_power.lock)
        # in case user did resume using the power switch.
@@ -213,7 +230,7 @@ Please do not remove SD cards while pandora is suspended, doing so will corrupt
 
 suspend_() {
        # dim power LED
-       echo 16 > /sys/class/leds/pandora\:\:power/brightness
+       echo $lowpow > /sys/class/leds/pandora\:\:power/brightness
 
        if suspend_real; then
                # resumed already
@@ -277,7 +294,7 @@ elif [[ "$2" == "lid" ]]; then
                                        powerstate="on"
                                ;;
                                *)
-                                       (debug && echo "display_on") || display_on
+                                       (debug && echo "display_on") || display_on_with_checks
                                        powerstate="on"
                                ;;
                        esac
@@ -305,7 +322,8 @@ elif [[ "$2" == "screensaver" ]]; then
        unset DISPLAY
 
        if [[ "$1" == 0 ]]; then # deactivate screensaver
-               display_on
+               display_on_with_checks
+               powerstate="on"
        elif [[ "$1" == 1 ]]; then # activate screensaver
                display_off
        fi