Rev 2 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/bin/bash
#####################################################################
# Simple script to catch the changes to backlight events on sony #
# in combination with nvidiabl. #
# #
# Tested with a Sony Vaio VPCCW1S1E Laptop. #
# #
# This has been tested on openSUSE 11.2, 11.3 & 11.4 and #
# Ubuntu 11.10 but should work on any distributions. #
# #
# Released under the BSDL Licens #
# #
# Developer: oSource Development #
# DevTeam: Marcus Uddenhed #
# Version: 0.3.9 #
# #
# Web: http://www.osource.se/ #
# #
# Last Updated: 2014-05-18 18:43 #
# #
#####################################################################
### BEGIN INIT INFO
# Provides: oBacklight
# Required-Start: $acpid
# Required-Stop:
# Default-Start: 5
# Default-Stop: 0 1 2 3 6
# Short-Description: Provides a backlight event handler for nvidiabl
# Description: Captures all backlight events from ACPI Events and feeds them to nvidiabl.
### END INIT INFO
init() {
## Default parameters
BMT="1" # Set Brightness Mode Types.
# Available types: 1, 2, 3, 4
ACPIS="1" # Set correct System ACPI codes.
# Available settings: 1, 2, 3
## Various brightness modes
# Mode 1 (Default)
if [ "$BMT" == "1" ]
then
BBL="2" # Default brightness level when on battery.
DID="1" # The amount of steps to increase/decrease with on backlight changes.
MBV="7" # Max brightness value possible on your system.
fi
# Mode 2
if [ "$BMT" == "2" ]
then
BBL="40"
DID="10"
MBV="127"
fi
# Mode 3
if [ "$BMT" == "3" ]
then
BBL="4"
DID="1"
MBV="32"
fi
# Mode 4
# Tested on a VPCCW15FL, thanks to Esteban
if [ "$BMT" == "4" ]
then
BBL="40"
DID="17"
MBV="120"
fi
## ACPI Codes for various systems.
# ACPIS 1(Default)
# Works on some Sony Vaio VPCCW1S1E
if [ "$ACPIS" == "1" ]
then
ACBU="00000001 00000011" # ACPI brightness up event
ACBD="00000001 00000010" # ACPI brightness down event
ACOB="00000081 00000000" # ACPI brightness on battery event
fi
# ACPIS 2
# Works on some Sony Vaio VPCCW1S1E
if [ "$ACPIS" == "2" ]
then
ACBU="00000086 00000000"
ACBD="00000087 00000000"
ACOB="00000081 00000000"
fi
# ACPIS 3
# Works on Dell Vostro 3700
if [ "$ACPIS" == "3" ]
then
ACBU="00000086 00000000"
ACBD="00000087 00000000"
ACOB="00000080 00000000"
fi
# Set correct values in configuration files on startup
echo "$MBV" > /sys/class/backlight/nvidia_backlight/brightness
echo "$MBV" > /root/oBacklight.def
# Check if oBacklight.def exists
if [ ! -e "/root/oBacklight.def" ]
then
echo "$MBV" > /root/oBacklight.def
fi
}
start() {
/etc/init.d/oBacklight run &
}
stop() {
echo $(cat /sys/class/backlight/nvidia_backlight/brightness) > /root/oBacklight.def
killall -r oBacklight
}
run() {
while [ exit != 130 ]
do
GVAR=$(cat /sys/class/backlight/nvidia_backlight/brightness)
CMD=$(acpi_listen -c 1 | egrep -o " [0-9].+" | egrep -o "[0-9].+")
# Brightness down acpi event
if [ "$CMD" == "$ACBD" ]
then
if [ "$GVAR" -ge "$DID" ] # Thanks to damdim @ nvnews forum for this fix.
then
SVAR=$(($GVAR - $DID))
echo $SVAR > /sys/class/backlight/nvidia_backlight/brightness
echo $SVAR > /root/oBacklight.def
else
SVAR="0"
echo $SVAR > /sys/class/backlight/nvidia_backlight/brightness
echo $SVAR > /root/oBacklight.def
fi
fi
# Brightness up acpi event
if [ "$CMD" == "$ACBU" ]
then
if [ "$GVAR" -le $(($MBV-$DID)) ] # Thanks to damdim @ nvnews forum for this fix.
then
SVAR=$(($GVAR + $DID))
echo $SVAR > /sys/class/backlight/nvidia_backlight/brightness
echo $SVAR > /root/oBacklight.def
else
SVAR=$MBV
echo $SVAR > /sys/class/backlight/nvidia_backlight/brightness
echo $SVAR > /root/oBacklight.def
fi
fi
# AC to battery change
if [ "$CMD" == "$ACOB" ]
then
if [ "$GVAR" > "$BBL" ]
then
echo $BBL > /sys/class/backlight/nvidia_backlight/brightness
echo $BBL > /root/oBacklight.def
fi
fi
done
}
case $1 in
start)
start
;;
stop)
stop
;;
run)
init
run
;;
*)
echo "start|stop|run"
;;
esac