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 if [ $oldspeed -gt 14 ] && [ $oldspeed -le 900 ]; then
14 echo $oldspeed > /proc/pandora/cpu_mhz_max
16 echo 500 > /proc/pandora/cpu_mhz_max
18 echo 0 > /tmp/powerstate
19 oldbright=$(cat /tmp/oldbright)
20 maxbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/max_brightness)
21 echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank
22 sleep 0.1s # looks cleaner, could flicker without
23 oldspeed=$(cat /tmp/oldspeed)
24 if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then
25 /usr/pandora/scripts/op_bright.sh $oldbright
27 /usr/pandora/scripts/op_bright.sh $maxbright
29 hcistate=$(cat /tmp/hcistate)
30 if [ ! $hcistate ]; then
33 wlstate=$(cat /tmp/wlstate)
34 if [ ! $wlstate ]; then
35 /etc/init.d/wl1251-init start
37 pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
40 kill -18 $PID #send SIGCONT
42 echo 255 > /sys/class/leds/pandora\:\:power/brightness #power LED bright
46 echo 1 > /tmp/powerstate
47 cat /proc/pandora/cpu_mhz_max > /tmp/oldspeed
48 cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness > /tmp/oldbright
49 pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
52 kill -19 $PID #send SIGSTOP
55 hcistate=$(hciconfig hci0 | grep DOWN)
56 if [ $hcistate ]; then
57 echo "down" > /tmp/hcistate
62 wlstate=$(lsmod | grep -m1 wl1251)
63 if [ ! $wlstate ]; then
64 echo "down" > /tmp/wlstate
66 /etc/init.d/wl1251-init stop
68 echo 0 > /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
69 echo 1 > /sys/devices/platform/omapfb/graphics/fb0/blank
70 echo 16 > /sys/class/leds/pandora\:\:power/brightness #dim power LED
71 echo 14 > /proc/pandora/cpu_mhz_max
73 elif [ "$1" -ge "3" ]; then #button was pressed 3 sec or longer, shutdown
74 xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}')
77 for i in $(seq $time); do
78 precentage=$(echo $i $time | awk '{ printf("%f\n", $1/$2*100) }')
80 echo "# Shutdown in $(($time-$i))"
84 countdown | su -c 'DISPLAY=:0.0 zenity --progress --auto-close --text "Shutdown in X" --title "Shutdown"' $xfceuser
88 su -c 'DISPLAY=:0.0 zenity --error --text "Shutdown aborted!"' $xfceuser