3 . /usr/pandora/scripts/op_paths.sh
5 ( test -e /tmp/op_power.lock && exit 2 ) || touch "/tmp/op_power.lock"
8 return 1 # 0 when debugging, 1 when not
11 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
13 #powerbuttonconfig=$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.powerbuttonconfig)
15 if [ -e /tmp/powerstate ]; then
16 powerstate="$(cat /tmp/powerstate)"
21 debug && echo "powerstate=$powerstate"
23 lowPowerOn(){ #switch from normal to lowpower mode
24 cat /proc/pandora/cpu_mhz_max > /tmp/oldspeed
25 cat $SYSFS_BACKLIGHT_BRIGHTNESS > /tmp/oldbright
26 pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
29 kill -19 $PID #send SIGSTOP
31 test -f /tmp/hcistate && rm /tmp/hcistate
32 hcistate=$(hciconfig hci0 | grep DOWN)
33 if [ $hcistate ]; then
34 echo "down" > /tmp/hcistate
38 test -f /tmp/wlstate && rm /tmp/wlstate
39 wlstate=$(lsmod | grep -m1 wl1251)
40 if [ -z "$wlstate" ]; then
41 echo "down" > /tmp/wlstate
44 rmmod board_omap3pandora_wifi wl1251_sdio wl1251
46 echo 0 > $SYSFS_BACKLIGHT_BRIGHTNESS
47 echo 1 > /sys/devices/platform/omapfb/graphics/fb0/blank
48 echo 16 > /sys/class/leds/pandora\:\:power/brightness #dim power LED
49 /usr/pandora/scripts/op_cpuspeed.sh 125
52 lowPowerOff(){ # switch from lowpower to normal mode
53 oldspeed=$(cat /tmp/oldspeed)
54 /usr/pandora/scripts/op_cpuspeed.sh $oldspeed
55 oldbright=$(cat /tmp/oldbright)
56 maxbright=$(cat $SYSFS_BACKLIGHT/max_brightness)
57 echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank
58 sleep 0.1s # looks cleaner, could flicker without
59 oldspeed=$(cat /tmp/oldspeed)
60 if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then
61 /usr/pandora/scripts/op_bright.sh $oldbright
63 /usr/pandora/scripts/op_bright.sh $maxbright
65 hcistate=$(cat /tmp/hcistate)
66 if [ ! $hcistate ]; then
67 hciconfig hci0 up pscan
69 wlstate=$(cat /tmp/wlstate)
70 if [ -z "$wlstate" ]; then
71 /etc/init.d/wl1251-init start
73 pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
76 kill -18 $PID #send SIGCONT
78 echo 255 > /sys/class/leds/pandora\:\:power/brightness #power LED bright
81 shutdown(){ # warns the user and shuts the pandora down
82 xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}')
85 for i in $(seq $time); do
86 precentage=$(echo $i $time | awk '{ printf("%f\n", $1/$2*100) }')
88 echo "# Shutdown in $(($time-$i))"
92 countdown | su -c 'DISPLAY=:0.0 zenity --progress --auto-close --text "Shutdown in X" --title "Shutdown"' $xfceuser
96 su -c 'DISPLAY=:0.0 zenity --error --text "Shutdown aborted!"' $xfceuser
100 displayOn(){ # turns the display on
101 #echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank
102 #sleep 0.1s # looks cleaner, could flicker without
103 maxbright=$(cat $SYSFS_BACKLIGHT/max_brightness)
105 if [ -f /tmp/oldbright ]; then
106 oldbright=$(cat /tmp/oldbright)
108 if [ $oldbright -eq 0 ]; then
109 oldbright=$(cat /etc/pandora/conf/brightness.state)
111 if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then
112 /usr/pandora/scripts/op_bright.sh $oldbright
114 /usr/pandora/scripts/op_bright.sh $maxbright
118 displayOff(){ # turns the display off
119 brightness=$(cat $SYSFS_BACKLIGHT_BRIGHTNESS)
120 if [ $brightness -gt 0 ]; then
121 echo $brightness > /tmp/oldbright
123 echo 0 > $SYSFS_BACKLIGHT_BRIGHTNESS
124 #echo 1 > /sys/devices/platform/omapfb/graphics/fb0/blank
127 if [[ "$2" == "" ]]; then
128 if [[ "$1" -le 2 ]]; then # power button was pressed 1-2sec, "suspend"
129 if [[ "$powerstate" == "buttonlowpower" ]]; then
130 (debug && echo "lowPowerOff") || lowPowerOff
132 elif [[ "$powerstate" == "on" ]]; then
133 (debug && echo "lowPowerOn") || lowPowerOn
134 powerstate="buttonlowpower"
136 elif [[ "$1" -ge 3 ]]; then # power button was pressed 3 sec or longer, shutdown
137 if [[ "$powerstate" == "on" ]]; then
138 (debug && echo "shutdown") || shutdown
141 elif [[ "$2" == "lid" ]]; then
142 if [[ "$1" == 0 ]]; then # lid was opened
143 if [[ "$powerstate" == lid* ]]; then
146 (debug && echo "lowPowerOff") || lowPowerOff
150 (debug && echo "displayOn") || displayOn
155 elif [[ "$1" == 1 ]]; then # lid was closed
156 if [[ "$powerstate" == "on" ]]; then
159 (debug && echo "shutdown") || shutdown
162 (debug && echo "lowPowerOn") || lowPowerOn
163 powerstate="lidlowpower"
166 (debug && echo "displayOff") || displayOff
167 powerstate="liddisplayoff"
173 debug && echo "powerstate=$powerstate"
174 echo "$powerstate" > /tmp/powerstate