Power down/up bt and wl
[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   if [ -e /tmp/powerstate ]; then 
7     powerstate=$(cat /tmp/powerstate)
8   else
9     powerstate=0
10   fi
11   if [$powerstate -eq 1 ]; then
12     #in lowpower mode
13     echo 0 > /tmp/powerstate
14     oldbright=$(cat /tmp/oldbright)
15     maxbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/max_brightness)
16     oldspeed=$(cat /tmp/oldspeed)
17     if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then 
18       /usr/pandora/scripts/op_bright.sh $oldbright 
19     else
20       /usr/pandora/scripts/op_bright.sh $maxbright
21     fi
22     if [ $oldspeed -ge 14 ] && [ $oldspeed -le 1000 ]; then 
23      echo $oldspeed > /proc/pandora/cpu_mhz_max 
24     else
25       echo 500 > /proc/pandora/cpu_mhz_max
26     fi
27     hciconfig hci0 up
28     /etc/init.d/S30wlxxx-init start
29     pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
30     for PID in $pidlist
31     do
32       kill -18 $PID #send SIGCONT
33     done
34   else
35     #in normal mode
36     echo 1 > /tmp/powerstate
37     cat /proc/pandora/cpu_mhz_max > /tmp/oldspeed
38     cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness > /tmp/oldbright
39     pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
40     for PID in $pidlist
41     do
42       kill -19 $PID #send SIGSTOP
43     done
44     hciconfig hci0 down
45     /etc/init.d/S30wlxxx-init stop
46     echo 0 > /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
47     echo 14 > /proc/pandora/cpu_mhz_max
48   fi
49 elif [ "$1" -ge "4" ]; then #button was pressed 4 sec or longer, shutdown
50   shutdown -h now
51 fi
52