#!/bin/bash
-. /usr/pandora/scripts/op_paths.sh
+. /usr/pandora/scripts/op_common.sh
+xfceuser=$(get_user)
+xfceuser_home=$(get_user_home)
# 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
+led_high="$(cat /etc/pandora/conf/led.conf | grep HighPowerLED: | awk -F\: '{print $2}')"
+led_low="$(cat /etc/pandora/conf/led.conf | grep LowPowerLED: | awk -F\: '{print $2}')"
+led_idle="$(cat /etc/pandora/conf/led.conf | grep IdleLED: | awk -F\: '{print $2}')"
+test -z "$led_high" && led_high=255
+test -z "$led_low" && led_low=16
+test -z "$led_idle" && led_idle=48
+
debug(){
return 1 # 0 when debugging, 1 when not
}
-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
-
-#powerbuttonconfig=$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.powerbuttonconfig)
+test -e $xfceuser_home/.lidconfig && lidconfig=$(cat $xfceuser_home/.lidconfig) # read lid conf. file if it exists
if [ -e /tmp/powerstate ]; then
powerstate="$(cat /tmp/powerstate)"
debug && echo "powerstate=$powerstate"
suspend_net() {
- hcistate=$(hciconfig hci0 | grep DOWN)
- if [ $hcistate ]; then
- echo "down" > /tmp/hcistate
+ # This is kernel 3.x only,
+ # but ignored since 2.6 only has lowpower anyways (no suspend)
+ if (ps -A | grep -q hciattac[h]); then
+ touch /tmp/bt-state-up
+ /usr/pandora/scripts/op_bluetooth_work.sh 0
else
- echo "up" > /tmp/hcistate
- hciconfig hci0 down
+ rm -f /tmp/bt-state-up
fi
+
wlstate=$(lsmod | grep -m1 wl1251)
if [ -z "$wlstate" ]; then
echo "down" > /tmp/wlstate
}
resume_net() {
- hcistate=$(cat /tmp/hcistate)
- if [ "$hcistate" = "up" ]; then
+ if [ -f /tmp/bt-state-up ]; then
+ /usr/pandora/scripts/op_bluetooth_work.sh 1
hciconfig hci0 up pscan
fi
wlstate=$(cat /tmp/wlstate)
do
kill -CONT $PID
done
- echo 255 > /sys/class/leds/pandora\:\:power/brightness #power LED bright
+ echo $led_high > /sys/class/leds/pandora\:\:power/brightness #power LED bright
}
display_on_with_checks() {
lowPowerOff
else
display_on
+ echo $led_high > /sys/class/leds/pandora\:\:power/brightness
fi
}
show_message() {
# TODO: check if desktop is visible; maybe use layer3?
- xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}')
cmd="DISPLAY=:0.0 zenity --info --text \"$1\" --timeout 10"
su -c "$cmd" $xfceuser
}
# if we are here, either we already resumed or the suspend failed
if [ -n "$restore_list" ]; then
- modprobe $restore_list
+ for module in $restore_list; do
+ modprobe $module
+ done
fi
+ # it has been reported that time sometimes drifts during suspend
+ # so we reload hwclock here (WizardStan)
+ hwclock -u -s
+
display_on
resume_net
- echo 255 > /sys/class/leds/pandora\:\:power/brightness
+ echo $led_high > /sys/class/leds/pandora\:\:power/brightness
# wait here a bit to prevent this script from running again (keep op_power.lock)
# in case user did resume using the power switch.
suspend_() {
# dim power LED
- echo 16 > /sys/class/leds/pandora\:\:power/brightness
+ echo $led_low > /sys/class/leds/pandora\:\:power/brightness
if suspend_real; then
# resumed already
}
shutdown(){ # warns the user and shuts the pandora down
- xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}')
time=5
countdown () {
for i in $(seq $time); do
;;
*)
(debug && echo "display_off") || display_off
+ echo $led_idle > /sys/class/leds/pandora\:\:power/brightness
powerstate="liddisplayoff"
;;
esac
powerstate="on"
elif [[ "$1" == 1 ]]; then # activate screensaver
display_off
+ echo $led_idle > /sys/class/leds/pandora\:\:power/brightness
fi
fi