pandora-scripts: unhardcode some sysfs paths
authorGrazvydas Ignotas <notasas@gmail.com>
Fri, 10 Feb 2012 23:33:13 +0000 (01:33 +0200)
committerGrazvydas Ignotas <notasas@gmail.com>
Sat, 11 Feb 2012 01:02:04 +0000 (03:02 +0200)
trying to support new kernels better

recipes/pandora-system/pandora-scripts.bb
recipes/pandora-system/pandora-scripts/op_bright.sh
recipes/pandora-system/pandora-scripts/op_bright_down.sh
recipes/pandora-system/pandora-scripts/op_bright_up.sh
recipes/pandora-system/pandora-scripts/op_lcdsettings.sh
recipes/pandora-system/pandora-scripts/op_paths.sh [new file with mode: 0644]
recipes/pandora-system/pandora-scripts/op_power.sh
recipes/pandora-system/pandora-state.bb
recipes/pandora-system/pandora-state/rc.pandora-state

index 71c781b..e9db8eb 100644 (file)
@@ -6,9 +6,10 @@ COMPATIBLE_MACHINE = "omap3-pandora"
 DEPENDS = "zenity dbus"
 RDEPENDS = "zenity dbus"
 
-PR = "r78"
+PR = "r79"
 
 SRC_URI = " \
+          file://op_paths.sh \
           file://op_bright.sh \
           file://op_cpuspeed.sh \
           file://op_cpuspeed.pnd \          
@@ -81,6 +82,7 @@ SRC_URI = " \
 
 do_install() {
           install -d ${D}${prefix}/pandora/scripts/
+          install -m 0755 ${WORKDIR}/op_paths.sh ${D}${prefix}/pandora/scripts/
           install -m 0755 ${WORKDIR}/op_bright.sh ${D}${prefix}/pandora/scripts/
           install -m 0755 ${WORKDIR}/op_cpuspeed.sh ${D}${prefix}/pandora/scripts/
          install -m 0755 ${WORKDIR}/op_cpusettings.sh ${D}${prefix}/pandora/scripts/
index dcf223a..709b3af 100755 (executable)
@@ -1,9 +1,12 @@
 #!/bin/bash
-#get value range
+
+. /usr/pandora/scripts/op_paths.sh
+
+# get value range
 minbright=3
-maxbright="$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/max_brightness)"
-curbright="$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness)"
-device=/sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
+maxbright="$(cat $SYSFS_BACKLIGHT/max_brightness)"
+curbright="$(cat $SYSFS_BACKLIGHT/brightness)"
+
 if [ ! $1 ]; then
 newbright=$(zenity --scale --text "Set brightness" --min-value=$minbright --max-value=$maxbright --value=$curbright --step 1)
 else
@@ -12,5 +15,5 @@ fi
 if [ $newbright ]; then
         if [ $newbright -le $minbright ]; then newbright=$minbright; fi
         if [ $newbright -ge $maxbright ]; then newbright=$maxbright; fi
-       echo $newbright > $device
+       echo $newbright > $SYSFS_BACKLIGHT_BRIGHTNESS
 fi
index 2e79385..ca66d64 100644 (file)
@@ -1,5 +1,8 @@
 #!/bin/bash
-cur=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness);
+
+. /usr/pandora/scripts/op_paths.sh
+
+cur=$(cat $SYSFS_BACKLIGHT_BRIGHTNESS)
 if [ "$cur" -gt "40" ]; then
    new=$(($cur-10))
 elif [ "$cur" -gt "30" ]; then 
@@ -16,4 +19,4 @@ if [ "$new" -lt "3" ]; then
    new=0
 fi
 
-echo $new > /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
+echo $new > $SYSFS_BACKLIGHT_BRIGHTNESS
index 2619004..42e6575 100644 (file)
@@ -1,5 +1,10 @@
 #!/bin/bash
-cur=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness);
+
+. /usr/pandora/scripts/op_paths.sh
+
+cur=$(cat $SYSFS_BACKLIGHT_BRIGHTNESS)
+max=$(cat $SYSFS_BACKLIGHT/max_brightness)
+
 if [ "$cur" -gt "35" ]; then
    new=$(($cur+10))
 elif [ "$cur" -gt "20" ]; then 
@@ -14,10 +19,8 @@ elif [ "$cur" -eq "0" ]; then
    new=3
 fi
 
-if [ "$new" -gt "54" ]; then
-   new=54
+if [ "$new" -gt "$max" ]; then
+   new=$max
 fi
 
-
-
-echo $new > /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
+echo $new > $SYSFS_BACKLIGHT_BRIGHTNESS
index f163695..0f9ec5a 100644 (file)
@@ -3,15 +3,16 @@
 # LCD-Settings, v1.0, written by Michael Mrozek aka EvilDragon 2010. Brightness-Settings-Part written by vimacs.
 # This scripts allows you to create, load and save Gamma-Settings and to change the LCD Brightness.
 
+. /usr/pandora/scripts/op_paths.sh
+
 while mainsel=$(zenity --title="LCD-Settings" --width="300" --height="280" --list --column "id" --column "Please select" --hide-column=1 --text="What do you want to do?" "bright" "Change LCD Brightness" "gamma" "Manage LCD Gamma" "filter" "Select current video filter" "filterdef" "Select default video filter" "sblank" "Enable/disable screen blanking" ); do
 
 case $mainsel in
 
   "bright")
     minbright=3
-    maxbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/max_brightness)
-    curbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness)
-    device=/sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
+    maxbright=$(cat $SYSFS_BACKLIGHT/max_brightness)
+    curbright=$(cat $SYSFS_BACKLIGHT/brightness)
     if [ ! $1 ]; then
       newbright=$(zenity --scale --text "Set brightness" --min-value=$minbright --max-value=$maxbright --value=$curbright --step 1)
     else
@@ -20,7 +21,7 @@ case $mainsel in
     if [ $newbright ]; then
         if [ $newbright -le $minbright ]; then newbright=$minbright; fi
         if [ $newbright -ge $maxbright ]; then newbright=$maxbright; fi
-         echo $newbright > $device
+         echo $newbright > $SYSFS_BACKLIGHT_BRIGHTNESS
     fi;;
 
    "gamma")
@@ -30,25 +31,25 @@ case $mainsel in
       gamma=$(grep "$selection" /etc/pandora/conf/gamma.conf | awk -F\; '{print $3}')
 
     if [ "${gamma}" = "syssyscreatenew" ]; then
-      cat /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma > /tmp/gamma.current
+      cat $SYSFS_GAMMA > /tmp/gamma.current
       op_gammatool
       if zenity --question --title="Confirm new gamma setting" --text="Do you want to keep the current gamma setting or revert to the previous one?" --ok-label="Keep it" --cancel-label="Revert"; then
        if zenity --question --title="Save as profile" --text="Do you want to save the new gamma setting as new profile?\n\nNote: You can also test it out first and save it later by restarting the Gamma Manager" --ok-label="Save it now" --cancel-label="Don't save it now"; then    
          while ! name=$(zenity --title="Save current settings" --entry --text "Please enter a Name for the new profile.") || [ "x$name" = "x" ] ; do
            zenity --title="Error" --error --text="Please enter a name for the profile.." --timeout 6
          done
-         curr=$(cat /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma)
+         curr=$(cat $SYSFS_GAMMA)
          desc=$(zenity --title="Save current settings" --entry --text "Please enter a description for the new profile.")
          echo "$name;$desc;$curr" >> /etc/pandora/conf/gamma.conf    
          zenity --info --title="Profile created" --text "The current gamma settings have been saved as a new profile." --timeout 6
        fi
      else
-       cat /tmp/gamma.current > /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma
+       cat /tmp/gamma.current > $SYSFS_GAMMA
      fi
     elif [ "${gamma}" = "syssyssavecurrent" ]; then
-      curr=$(cat /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma)
+      curr=$(cat $SYSFS_GAMMA)
     while ! name=$(zenity --title="Save current settings" --entry --text "Please enter a Name for the new profile.") || [ "x$name" = "x" ] ; do
-           zenity --title="Error" --error --text="Please enter a name for the profile.." --timeout 6
+      zenity --title="Error" --error --text="Please enter a name for the profile.." --timeout 6
     done
       desc=$(zenity --title="Save current settings" --entry --text "Please enter a description for the new profile.")
       echo "$name;$desc;$curr" >> /etc/pandora/conf/gamma.conf    
@@ -69,7 +70,7 @@ case $mainsel in
       fi
      fi
     else
-    echo $gamma > /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma
+      echo $gamma > $SYSFS_GAMMA
     fi
     fi;;
 
diff --git a/recipes/pandora-system/pandora-scripts/op_paths.sh b/recipes/pandora-system/pandora-scripts/op_paths.sh
new file mode 100644 (file)
index 0000000..418788f
--- /dev/null
@@ -0,0 +1,21 @@
+
+# files changing between kernel versions
+
+if [ -e /sys/class/backlight/pandora-backlight ]; then
+       SYSFS_BACKLIGHT=/sys/class/backlight/pandora-backlight
+elif [ -e /sys/class/backlight/twl4030-pwm0-bl ]; then
+       SYSFS_BACKLIGHT=/sys/class/backlight/twl4030-pwm0-bl
+else
+       echo "ERROR: backlight control not found" >&2
+       SYSFS_BACKLIGHT=/dev/null
+fi
+SYSFS_BACKLIGHT_BRIGHTNESS=${SYSFS_BACKLIGHT}/brightness
+
+if [ -e /sys/devices/omapdss/display0/gamma ]; then
+       SYSFS_GAMMA=/sys/devices/omapdss/display0/gamma
+elif [ -e /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma ]; then
+       SYSFS_GAMMA=/sys/devices/platform/omap2_mcspi.1/spi1.1/gamma
+else
+       echo "ERROR: gamma control not found" >&2
+       SYSFS_GAMMA=/dev/null
+fi
index b2acf74..cc290aa 100644 (file)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+. /usr/pandora/scripts/op_paths.sh
+
 ( test -e /tmp/op_power.lock && exit 2 ) || touch "/tmp/op_power.lock"
 
 debug(){
@@ -20,7 +22,7 @@ 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
+       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
@@ -41,7 +43,7 @@ lowPowerOn(){ #switch from normal to lowpower mode
                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
@@ -51,7 +53,7 @@ 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)
+       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)
@@ -98,7 +100,7 @@ shutdown(){ # warns the user and shuts the pandora down
 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)
@@ -114,11 +116,11 @@ displayOn(){ # turns the display on
 }
 
 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
 }
 
index 6bacbe7..dafe2b0 100755 (executable)
@@ -3,7 +3,9 @@ LICENSE = "GPLv2"
 
 COMPATIBLE_MACHINE = "omap3-pandora"
 
-PR = "r7"
+RDEPENDS = "pandora-scripts"
+
+PR = "r8"
 inherit update-rc.d
 
 INITSCRIPT_NAME = "pandora-state"
index a1f6d46..09d6bfe 100644 (file)
 DESC="OpenPandora Save and Restore LCD Settings"
 NAME="pandora-state"
 
+. /usr/pandora/scripts/op_paths.sh
+
 d_stop() {
        echo "Saving Pandora specific settings"
-       bright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness)
+       bright=$(cat $SYSFS_BACKLIGHT_BRIGHTNESS)
        if [ $bright != "0" ]; then
-           cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness > /etc/pandora/conf/brightness.state
+           echo $bright > /etc/pandora/conf/brightness.state
        fi
        touch /etc/pandora/shutdown
-       cat /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma > /etc/pandora/conf/gamma.state
+       cat $SYSFS_GAMMA > /etc/pandora/conf/gamma.state
         cat -v /proc/pandora/nub0/mode | sed -n '1p' > /etc/pandora/conf/nubs.state
        cat -v /proc/pandora/nub0/mouse_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
        cat -v /proc/pandora/nub0/scrollx_sensitivity | sed -n '1p' >> /etc/pandora/conf/nubs.state
@@ -35,9 +37,12 @@ d_stop() {
 
 d_start() {
        echo "Restoring Pandora specific settings"
+       bright=$(cat /etc/pandora/conf/brightness.state)
+       if [ "$bright" -gt "0" ]; then
+               echo $bright > $SYSFS_BACKLIGHT_BRIGHTNESS
+       fi
        cat /etc/pandora/conf/dirty_expire_centisecs >  /proc/sys/vm/dirty_expire_centisecs
-       cat /etc/pandora/conf/brightness.state > /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness 
-       cat /etc/pandora/conf/gamma.state > /sys/devices/platform/omap2_mcspi.1/spi1.1/gamma
+       cat /etc/pandora/conf/gamma.state > $SYSFS_GAMMA
        if [ -f /etc/pandora/conf/filter.state ]; then
                filter=$(cat /etc/pandora/conf/filter.state)
                /usr/pandora/scripts/op_videofir.sh $filter