From e71c019e9f5999a80f3a9bcd8976d3125e61d9c0 Mon Sep 17 00:00:00 2001 From: Michael Mrozek Date: Thu, 22 Sep 2011 01:56:18 +0200 Subject: [PATCH] op_lid.sh, op_lidsettings.sh, op_power.sh: Fixed some bugs --- .../pandora-system/pandora-scripts/op_lid.sh | 47 +--- .../pandora-scripts/op_lidsettings.sh | 6 +- .../pandora-scripts/op_power.sh | 255 ++++++++++++------ 3 files changed, 174 insertions(+), 134 deletions(-) diff --git a/recipes/pandora-system/pandora-scripts/op_lid.sh b/recipes/pandora-system/pandora-scripts/op_lid.sh index 544676b..c61cda7 100644 --- a/recipes/pandora-system/pandora-scripts/op_lid.sh +++ b/recipes/pandora-system/pandora-scripts/op_lid.sh @@ -3,49 +3,4 @@ #only argument is 0 for open 1 for closed #may also be called after inactivity, like X DPMS -config=$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidstate) - -if [[ ! -e /tmp/powerstate || "$(cat /tmp/powerstate)" = "2" ]]; then #do nothing when in powersave mode unless we went into it because of a closed lid - if [ "$1" = "1" ]; then #lid was closed - case "$config" in - "shutdown") - /usr/pandora/scripts/op_power.sh 5 - ;; - "lowpower") - /usr/pandora/scripts/op_power.sh 1 - echo "2" > /tmp/powerstate - ;; - *) - echo "$config" - brightness=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/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 1 > /sys/devices/platform/omapfb/graphics/fb0/blank - esac - elif [ "$1" = "0" ]; then # lid was opened - case "$config" in - "lowpower") - /usr/pandora/scripts/op_power.sh 1 - ;; - *) - #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) - oldbright=0 - if [ -f /tmp/oldbright ]; then - oldbright=$(cat /tmp/oldbright) - fi - if [ $oldbright -eq 0 ]; then - oldbright=$(cat /etc/pandora/conf/brightness.state) - fi - if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then - /usr/pandora/scripts/op_bright.sh $oldbright - else - /usr/pandora/scripts/op_bright.sh $maxbright - fi - ;; - esac - fi -fi \ No newline at end of file +/usr/pandora/scripts/op_power.sh $1 lid diff --git a/recipes/pandora-system/pandora-scripts/op_lidsettings.sh b/recipes/pandora-system/pandora-scripts/op_lidsettings.sh index c52adcd..aa0cc01 100644 --- a/recipes/pandora-system/pandora-scripts/op_lidsettings.sh +++ b/recipes/pandora-system/pandora-scripts/op_lidsettings.sh @@ -1,6 +1,6 @@ #!/bin/bash # change what to do when the lid is closed/opened -case "$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidstate)" in +case "$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidconfig)" in "lowpower") current="the Pandora goes into low power mode" ;; @@ -12,6 +12,6 @@ case "$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{pri ;; esac -sel=$(zenity --title="Lid settings" --height=230 --list --column "id" --column "Please select" --hide-column=1 --text="What should happen when you close the Pandora's lid?\nAt the moment $current when you close the lid." "brightness" "Turn off the screen." "lowpower" "Go into low power mode (same as when pressing the +sel=$(zenity --title="Lid settings" --height=250 --list --column "id" --column "Please select" --hide-column=1 --text="What should happen when you close the Pandora's lid?\n(the opposite of the selected action is performed when opening the lid again)\nAt the moment $current when you close the lid." "brightness" "Turn off the screen." "lowpower" "Go into low power mode (same as when pressing the power button for less than 3 seconds)" "shutdown" "Shut the pandora down.") || exit -echo "$sel" > $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidstate +echo "$sel" > $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidconfig diff --git a/recipes/pandora-system/pandora-scripts/op_power.sh b/recipes/pandora-system/pandora-scripts/op_power.sh index 42b92ef..b422d92 100644 --- a/recipes/pandora-system/pandora-scripts/op_power.sh +++ b/recipes/pandora-system/pandora-scripts/op_power.sh @@ -1,89 +1,174 @@ #!/bin/bash -#actions done when the power button is pressed -#only argument is the time the button was pressed in seconds -if [ "$1" -le "2" ]; then # button was pressed 1-2sec, "suspend" - if [ -e /tmp/powerstate ]; then - powerstate=$(cat /tmp/powerstate) - else - powerstate=0 - fi - if [ $powerstate -ne 0 ]; then - #switch from lowpower to normal mode - oldspeed=$(cat /tmp/oldspeed) - /usr/pandora/scripts/op_cpuspeed.sh $oldspeed - echo 0 > /tmp/powerstate - oldbright=$(cat /tmp/oldbright) - maxbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/max_brightness) - echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank - sleep 0.1s # looks cleaner, could flicker without - oldspeed=$(cat /tmp/oldspeed) - if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then - /usr/pandora/scripts/op_bright.sh $oldbright - else - /usr/pandora/scripts/op_bright.sh $maxbright - fi - hcistate=$(cat /tmp/hcistate) - if [ ! $hcistate ]; then - hciconfig hci0 up pscan - fi - wlstate=$(cat /tmp/wlstate) - if [ ! $wlstate ]; then - /etc/init.d/wl1251-init start - fi - pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p') - for PID in $pidlist - do - kill -18 $PID #send SIGCONT - done - echo 255 > /sys/class/leds/pandora\:\:power/brightness #power LED bright - rm /tmp/powerstate - else - #switch from normal to lowpower mode - echo 1 > /tmp/powerstate - cat /proc/pandora/cpu_mhz_max > /tmp/oldspeed - cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/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 - hcistate=$(hciconfig hci0 | grep DOWN) - if [ $hcistate ]; then - echo "down" > /tmp/hcistate - else - hciconfig hci0 down - fi - rm /tmp/wlstate - wlstate=$(lsmod | grep -m1 wl1251) - if [ ! $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 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 - fi -elif [ "$1" -ge "3" ]; then #button was pressed 3 sec or longer, shutdown - xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}') - time=5 - countdown () { - for i in $(seq $time); do - precentage=$(echo $i $time | awk '{ printf("%f\n", $1/$2*100) }') - echo $precentage - echo "# Shutdown in $(($time-$i))" - sleep 1 - done - } - countdown | su -c 'DISPLAY=:0.0 zenity --progress --auto-close --text "Shutdown in X" --title "Shutdown"' $xfceuser - if [ $? -eq 0 ]; then - shutdown -h now - else - su -c 'DISPLAY=:0.0 zenity --error --text "Shutdown aborted!"' $xfceuser - fi +( test -e /tmp/op_power.lock && exit 2 ) || touch "/tmp/op_power.lock" + +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) + +if [ -e /tmp/powerstate ]; then + powerstate="$(cat /tmp/powerstate)" +else + powerstate="on" +fi + +debug && echo "powerstate=$powerstate" + +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 + 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 + hcistate=$(hciconfig hci0 | grep DOWN) + if [ $hcistate ]; then + echo "down" > /tmp/hcistate + else + hciconfig hci0 down + fi + rm /tmp/wlstate + wlstate=$(lsmod | grep -m1 wl1251) + if [ ! $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 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 +} + +lowPowerOff(){ # switch from lowpower to normal mode + 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) + echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank + sleep 0.1s # looks cleaner, could flicker without + oldspeed=$(cat /tmp/oldspeed) + if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then + /usr/pandora/scripts/op_bright.sh $oldbright + else + /usr/pandora/scripts/op_bright.sh $maxbright + fi + hcistate=$(cat /tmp/hcistate) + if [ ! $hcistate ]; then + hciconfig hci0 up pscan + fi + wlstate=$(cat /tmp/wlstate) + if [ ! $wlstate ]; then + /etc/init.d/wl1251-init start + fi + pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p') + for PID in $pidlist + do + kill -18 $PID #send SIGCONT + done + echo 255 > /sys/class/leds/pandora\:\:power/brightness #power LED bright +} + +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 + precentage=$(echo $i $time | awk '{ printf("%f\n", $1/$2*100) }') + echo $precentage + echo "# Shutdown in $(($time-$i))" + sleep 1 + done + } + countdown | su -c 'DISPLAY=:0.0 zenity --progress --auto-close --text "Shutdown in X" --title "Shutdown"' $xfceuser + if [ $? -eq 0 ]; then + 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) + oldbright=0 + if [ -f /tmp/oldbright ]; then + oldbright=$(cat /tmp/oldbright) + fi + if [ $oldbright -eq 0 ]; then + oldbright=$(cat /etc/pandora/conf/brightness.state) + fi + if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then + /usr/pandora/scripts/op_bright.sh $oldbright + else + /usr/pandora/scripts/op_bright.sh $maxbright + fi +} + +displayOff(){ # turns the display off + brightness=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/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 1 > /sys/devices/platform/omapfb/graphics/fb0/blank +} + +if [[ "$2" == "" ]]; then + if [[ "$1" -le 2 ]]; then # power button was pressed 1-2sec, "suspend" + if [[ "$powerstate" == "buttonlowpower" ]]; then + (debug && echo "lowPowerOff") || lowPowerOff + powerstate="on" + elif [[ "$powerstate" == "on" ]]; then + (debug && echo "lowPowerOn") || lowPowerOn + powerstate="buttonlowpower" + fi + elif [[ "$1" -ge 3 ]]; then # power button was pressed 3 sec or longer, shutdown + if [[ "$powerstate" == "on" ]]; then + (debug && echo "shutdown") || shutdown + fi + fi +elif [[ "$2" == "lid" ]]; then + if [[ "$1" == 0 ]]; then # lid was opened + if [[ "$powerstate" == lid* ]]; then + case "$lidconfig" in + "lowpower") + (debug && echo "lowPowerOff") || lowPowerOff + powerstate="on" + ;; + *) + (debug && echo "displayOn") || displayOn + powerstate="on" + ;; + esac + fi + elif [[ "$1" == 1 ]]; then # lid was closed + if [[ "$powerstate" == "on" ]]; then + case "$lidconfig" in + "shutdown") + (debug && echo "shutdown") || shutdown + ;; + "lowpower") + (debug && echo "lowPowerOn") || lowPowerOn + powerstate="lidlowpower" + ;; + *) + (debug && echo "displayOff") || displayOff + powerstate="liddisplayoff" + ;; + esac + fi + fi + fi +debug && echo "powerstate=$powerstate" +echo "$powerstate" > /tmp/powerstate fi -- 2.39.2