3 . /usr/pandora/scripts/op_paths.sh
5 # XXX: better use lockfile (or something), but it's not in current firmware
6 test -e /tmp/op_power.lock && exit 2
7 touch /tmp/op_power.lock
10 return 1 # 0 when debugging, 1 when not
13 test -e $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidconfig && lidconfig=$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidconfig) # read lid conf. file if it exists
15 #powerbuttonconfig=$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.powerbuttonconfig)
17 if [ -e /tmp/powerstate ]; then
18 powerstate="$(cat /tmp/powerstate)"
23 debug && echo "powerstate=$powerstate"
25 lowPowerOn(){ #switch from normal to lowpower mode
26 cat /proc/pandora/cpu_mhz_max > /tmp/oldspeed
27 cat $SYSFS_BACKLIGHT_BRIGHTNESS > /tmp/oldbright
28 pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
31 kill -19 $PID #send SIGSTOP
33 test -f /tmp/hcistate && rm /tmp/hcistate
34 hcistate=$(hciconfig hci0 | grep DOWN)
35 if [ $hcistate ]; then
36 echo "down" > /tmp/hcistate
40 test -f /tmp/wlstate && rm /tmp/wlstate
41 wlstate=$(lsmod | grep -m1 wl1251)
42 if [ -z "$wlstate" ]; then
43 echo "down" > /tmp/wlstate
46 rmmod board_omap3pandora_wifi wl1251_sdio wl1251
48 echo 0 > $SYSFS_BACKLIGHT_BRIGHTNESS
49 echo 1 > /sys/devices/platform/omapfb/graphics/fb0/blank
50 echo 16 > /sys/class/leds/pandora\:\:power/brightness #dim power LED
51 /usr/pandora/scripts/op_cpuspeed.sh 125
54 lowPowerOff(){ # switch from lowpower to normal mode
55 oldspeed=$(cat /tmp/oldspeed)
56 /usr/pandora/scripts/op_cpuspeed.sh $oldspeed
57 oldbright=$(cat /tmp/oldbright)
58 maxbright=$(cat $SYSFS_BACKLIGHT/max_brightness)
59 echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank
60 sleep 0.1s # looks cleaner, could flicker without
61 oldspeed=$(cat /tmp/oldspeed)
62 if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then
63 /usr/pandora/scripts/op_bright.sh $oldbright
65 /usr/pandora/scripts/op_bright.sh $maxbright
67 hcistate=$(cat /tmp/hcistate)
68 if [ ! $hcistate ]; then
69 hciconfig hci0 up pscan
71 wlstate=$(cat /tmp/wlstate)
72 if [ -z "$wlstate" ]; then
73 /etc/init.d/wl1251-init start
75 pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
78 kill -18 $PID #send SIGCONT
80 echo 255 > /sys/class/leds/pandora\:\:power/brightness #power LED bright
83 shutdown(){ # warns the user and shuts the pandora down
84 xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}')
87 for i in $(seq $time); do
88 precentage=$(echo $i $time | awk '{ printf("%f\n", $1/$2*100) }')
90 echo "# Shutdown in $(($time-$i))"
94 countdown | su -c 'DISPLAY=:0.0 zenity --progress --auto-close --text "Shutdown in X" --title "Shutdown"' $xfceuser
98 su -c 'DISPLAY=:0.0 zenity --error --text "Shutdown aborted!"' $xfceuser
102 displayOn(){ # turns the display on
103 #echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank
104 #sleep 0.1s # looks cleaner, could flicker without
105 maxbright=$(cat $SYSFS_BACKLIGHT/max_brightness)
107 if [ -f /tmp/oldbright ]; then
108 oldbright=$(cat /tmp/oldbright)
110 if [ $oldbright -eq 0 ]; then
111 oldbright=$(cat /etc/pandora/conf/brightness.state)
113 if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then
114 /usr/pandora/scripts/op_bright.sh $oldbright
116 /usr/pandora/scripts/op_bright.sh $maxbright
120 displayOff(){ # turns the display off
121 brightness=$(cat $SYSFS_BACKLIGHT_BRIGHTNESS)
122 if [ $brightness -gt 0 ]; then
123 echo $brightness > /tmp/oldbright
125 echo 0 > $SYSFS_BACKLIGHT_BRIGHTNESS
126 #echo 1 > /sys/devices/platform/omapfb/graphics/fb0/blank
129 if [[ "$2" == "" ]]; then
130 if [[ "$1" -le 2 ]]; then # power button was pressed 1-2sec, "suspend"
131 if [[ "$powerstate" == "buttonlowpower" ]]; then
132 (debug && echo "lowPowerOff") || lowPowerOff
134 elif [[ "$powerstate" == "on" ]]; then
135 (debug && echo "lowPowerOn") || lowPowerOn
136 powerstate="buttonlowpower"
138 elif [[ "$1" -ge 3 ]]; then # power button was pressed 3 sec or longer, shutdown
139 if [[ "$powerstate" == "on" ]]; then
140 (debug && echo "shutdown") || shutdown
143 elif [[ "$2" == "lid" ]]; then
144 if [[ "$1" == 0 ]]; then # lid was opened
145 if [[ "$powerstate" == lid* ]]; then
148 (debug && echo "lowPowerOff") || lowPowerOff
152 (debug && echo "displayOn") || displayOn
157 elif [[ "$1" == 1 ]]; then # lid was closed
158 if [[ "$powerstate" == "on" ]]; then
161 (debug && echo "shutdown") || shutdown
164 (debug && echo "lowPowerOn") || lowPowerOn
165 powerstate="lidlowpower"
168 (debug && echo "displayOff") || displayOff
169 powerstate="liddisplayoff"
175 debug && echo "powerstate=$powerstate"
176 echo "$powerstate" > /tmp/powerstate
178 rm -f /tmp/op_power.lock