Thomas,

The attached script does that.

The kernel backlight devices are not so new. They are used to blank
backlights in framebuffer mode when DPMS doesn't work. Currently there
is only support for some exotic PDA backlights.

But I thought of the same to port the mactel-linux backlight tool to
such an in-kernel backlight driver. This has the obvious advantage that
you get a device file for which you can set propper permissions with
udev instead of the suid binary that we have now! Anybody up to writing
the driver?

Odi

Thomas Meyer wrote:
> Hi.
> 
> Is there a daemon, that polls the current ambient light sensor values
> (someone should create an ambient light device class...) and sets the
> keyboard light value (led class devices) and the led panel backlight
> (totaly new, current linus-git-tree; backlight class devices)
> automatically?
> 
> With kind regards Thomas
#!/bin/sh
# Keyboard backlight control for my MacBook Pro
# (C) 2006 by Ortwin Glück
#
# external config: all values 0-255
# kbd light off above this much ambient light
LIGHT_LEVEL=160
# brightest kbd light below this little ambient light
DARK_LEVEL=30
# kbd no brigther than this
MAX_BRIGHT=255
# kdb no lower than this
MIN_BRIGHT=80

# devices
BRIGHT="/sys/bus/platform/devices/applesmc/leds:smc:kbd_backlight/brightness"
LIGHT="/sys/bus/platform/devices/applesmc/light"
# speed when adjusting kdb light
SHORT_SLEEP=0.1
# reaction time
NORMAL_SLEEP=1

# reads the max ambient light from the two sensors
ambient_light() {
        local s=$(cat ${LIGHT})
        if [[ $s =~ "([[:digit:]]+),([[:digit:]]+)" ]]; then
                local a=${BASH_REMATCH[1]}
                local b=${BASH_REMATCH[2]}
                if [ $a -gt $b ]; then
                        light=$a
                else
                        light=$b
                fi
        else
                echo "unexpected value: $s"
                light=$LIGHT_LEVEL
        fi
}

# calculates the target brightness level (with cutoff)
calc_bright() {
        if [ $light -lt $LIGHT_LEVEL ]; then
                local lpct=$((100 * ($light - $DARK_LEVEL) / ($LIGHT_LEVEL - 
$DARK_LEVEL)))
                [ $lpct -gt 0 ] || lpct=0
                bright=$((($MIN_BRIGHT + ($MAX_BRIGHT - $MIN_BRIGHT) * (100 - 
$lpct)) / 100))
        else
                bright=0
        fi
}

# adjusts brightness towards target
# returns 0 when target reached
adj_bright() {
        local cb=$(cat ${BRIGHT})
        local dist=$(($cb - $bright))
        if [ $dist -gt 0 ]; then
                [ $dist -gt 5 ] || return 0
                let cb-=5
        else
                [ $dist -lt -5 ] || return 0
                let cb+=5
        fi
        #echo "l: $light, kbd: $cb -> $bright"
        echo "$cb" > $BRIGHT
        return 1
}


renice 19 -p $$ >/dev/null 2>&1
# adjustment loop
while [ 1 ]; do
        ambient_light
        calc_bright
        adj_bright
        if [ $? ]; then
                sleep 0.1
        else
                sleep 1
        fi
done
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Mactel-linux-devel mailing list
Mactel-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mactel-linux-devel

Reply via email to