#!/bin/bash
-( test -e /tmp/op_power.lock && exit 2 ) || touch "/tmp/op_power.lock"
+. /usr/pandora/scripts/op_paths.sh
+
+# XXX: better use lockfile (or something), but it's not in current firmware
+test -e /tmp/op_power.lock && exit 2
+touch /tmp/op_power.lock
debug(){
return 1 # 0 when debugging, 1 when not
lowPowerOn(){ #switch from normal to lowpower mode
cat /proc/pandora/cpu_mhz_max > /tmp/oldspeed
- cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness > /tmp/oldbright
+ cat $SYSFS_BACKLIGHT_BRIGHTNESS > /tmp/oldbright
pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
for PID in $pidlist
do
kill -19 $PID #send SIGSTOP
done
- rm /tmp/hcistate
+ test -f /tmp/hcistate && rm /tmp/hcistate
hcistate=$(hciconfig hci0 | grep DOWN)
if [ $hcistate ]; then
echo "down" > /tmp/hcistate
else
hciconfig hci0 down
fi
- rm /tmp/wlstate
+ test -f /tmp/wlstate && rm /tmp/wlstate
wlstate=$(lsmod | grep -m1 wl1251)
- if [ ! $wlstate ]; then
+ if [ -z "$wlstate" ]; then
echo "down" > /tmp/wlstate
else
ifconfig wlan0 down
rmmod board_omap3pandora_wifi wl1251_sdio wl1251
fi
- echo 0 > /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
+ echo 0 > $SYSFS_BACKLIGHT_BRIGHTNESS
echo 1 > /sys/devices/platform/omapfb/graphics/fb0/blank
echo 16 > /sys/class/leds/pandora\:\:power/brightness #dim power LED
/usr/pandora/scripts/op_cpuspeed.sh 125
oldspeed=$(cat /tmp/oldspeed)
/usr/pandora/scripts/op_cpuspeed.sh $oldspeed
oldbright=$(cat /tmp/oldbright)
- maxbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/max_brightness)
+ maxbright=$(cat $SYSFS_BACKLIGHT/max_brightness)
echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank
sleep 0.1s # looks cleaner, could flicker without
oldspeed=$(cat /tmp/oldspeed)
hciconfig hci0 up pscan
fi
wlstate=$(cat /tmp/wlstate)
- if [ ! $wlstate ]; then
+ if [ -z "$wlstate" ]; then
/etc/init.d/wl1251-init start
fi
pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
}
countdown | su -c 'DISPLAY=:0.0 zenity --progress --auto-close --text "Shutdown in X" --title "Shutdown"' $xfceuser
if [ $? -eq 0 ]; then
- shutdown -h now
+ /sbin/shutdown -h now
else
su -c 'DISPLAY=:0.0 zenity --error --text "Shutdown aborted!"' $xfceuser
fi
displayOn(){ # turns the display on
#echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank
#sleep 0.1s # looks cleaner, could flicker without
- maxbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/max_brightness)
+ maxbright=$(cat $SYSFS_BACKLIGHT/max_brightness)
oldbright=0
if [ -f /tmp/oldbright ]; then
oldbright=$(cat /tmp/oldbright)
}
displayOff(){ # turns the display off
- brightness=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness)
+ brightness=$(cat $SYSFS_BACKLIGHT_BRIGHTNESS)
if [ $brightness -gt 0 ]; then
echo $brightness > /tmp/oldbright
fi
- echo 0 > /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
+ echo 0 > $SYSFS_BACKLIGHT_BRIGHTNESS
#echo 1 > /sys/devices/platform/omapfb/graphics/fb0/blank
}
fi
debug && echo "powerstate=$powerstate"
echo "$powerstate" > /tmp/powerstate
-fi
+rm -f /tmp/op_power.lock