2 #actions done when the power button is pressed
3 #only argument is the time the button was pressed in seconds
5 if [ "$1" -le "2" ]; then # button was pressed 1-2sec, "suspend"
6 if [ -e /tmp/powerstate ]; then
7 powerstate=$(cat /tmp/powerstate)
11 if [ $powerstate -eq "1" ]; then
13 oldspeed=$(cat /tmp/oldspeed)
14 /usr/pandora/scripts/op_cpuspeed.sh $oldspeed
15 echo 0 > /tmp/powerstate
16 oldbright=$(cat /tmp/oldbright)
17 maxbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/max_brightness)
18 echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank
19 sleep 0.1s # looks cleaner, could flicker without
20 oldspeed=$(cat /tmp/oldspeed)
21 if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then
22 /usr/pandora/scripts/op_bright.sh $oldbright
24 /usr/pandora/scripts/op_bright.sh $maxbright
26 hcistate=$(cat /tmp/hcistate)
27 if [ ! $hcistate ]; then
30 wlstate=$(cat /tmp/wlstate)
31 if [ ! $wlstate ]; then
32 /etc/init.d/wl1251-init start
34 pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
37 kill -18 $PID #send SIGCONT
39 echo 255 > /sys/class/leds/pandora\:\:power/brightness #power LED bright
43 echo 1 > /tmp/powerstate
44 cat /proc/pandora/cpu_mhz_max > /tmp/oldspeed
45 cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness > /tmp/oldbright
46 pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
49 kill -19 $PID #send SIGSTOP
52 hcistate=$(hciconfig hci0 | grep DOWN)
53 if [ $hcistate ]; then
54 echo "down" > /tmp/hcistate
59 wlstate=$(lsmod | grep -m1 wl1251)
60 if [ ! $wlstate ]; then
61 echo "down" > /tmp/wlstate
63 /etc/init.d/wl1251-init stop
65 echo 0 > /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
66 echo 1 > /sys/devices/platform/omapfb/graphics/fb0/blank
67 echo 16 > /sys/class/leds/pandora\:\:power/brightness #dim power LED
68 /usr/pandora/scripts/op_cpuspeed.sh 125
70 elif [ "$1" -ge "3" ]; then #button was pressed 3 sec or longer, shutdown
71 xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}')
74 for i in $(seq $time); do
75 precentage=$(echo $i $time | awk '{ printf("%f\n", $1/$2*100) }')
77 echo "# Shutdown in $(($time-$i))"
81 countdown | su -c 'DISPLAY=:0.0 zenity --progress --auto-close --text "Shutdown in X" --title "Shutdown"' $xfceuser
85 su -c 'DISPLAY=:0.0 zenity --error --text "Shutdown aborted!"' $xfceuser