d6d4fa5dbbee0725a5545e9af66ce5522678346a
[pandora-libraries.git] / testdata / scripts / op_power.sh
1 #!/bin/bash
2 #actions done when the power button is pressed
3 #only argument is the time the button was pressed in  seconds
4
5 if [ "$1" -le "3" ]; then # button was pressed 1-3sec, "suspend"
6   powerstate=$(cat /tmp/powerstate)
7   if [$powerstate -eq "1" ]; then
8     #in lowpower mode
9     echo 0 > /tmp/powerstate
10     oldbright=$(cat /tmp/oldbright)
11     maxbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/max_brightness)
12     oldspeed=$(cat /tmp/oldspeed)
13     if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then 
14       /usr/pandora/scripts/op_bright.sh $oldbright 
15     else
16       /usr/pandora/scripts/op_bright.sh $maxbright
17     fi
18     if [ $oldspeed -ge 14 ] && [ $oldspeed -le 1000 ]; then 
19      echo $oldspeed > /proc/pandora/cpu_mhz_max 
20     else
21       echo 500 > /proc/pandora/cpu_mhz_max
22     fi
23     pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
24     for PID in $pidlist
25     do
26       kill -18 $PID #send SIGCONT
27     done
28   else
29     #in normal mode
30     echo 1 > /tmp/powerstate
31     cat /proc/pandora/cpu_mhz_max > /tmp/oldspeed
32     cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness > /tmp/oldbright
33     pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
34     for PID in $pidlist
35     do
36       kill -19 $PID #send SIGSTOP
37     done
38     hciconfig hci0 down
39     /etc/init.d/S30wlxxx-init stop
40     echo 0 > /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
41     echo 14 > /proc/pandora/cpu_mhz_max
42   fi
43 elif [ "$1" -ge "4" ]; then #button was pressed 4 sec or longer, shutdown
44   shutdown -h now
45 fi
46