Modifying screen brightness on AC state changes
0 Comments Published by Felipe Alfaro Solana September 11th, 2006 in Apple, Linux, Power managementThe acpid daemon listens to the /proc/acpi/event socket. When the Linux kernel any ACPI-related event, like an AC state change, it sends a message to that socket.
When the Linux kernel detects AC power loss, it sends a message to the socket. acpid then runs the /etc/acpi/power.sh script which, in turn, invokes all the scripts under /etc/acpi/battery.d directory, orderly.
When the Linux detects that AC power has been restored, it sends a message to the socket. acpid then runs /etc/acpi/power.sh which, in turn, invokes all the scripts under /etc/acpi/ac.d directory, orderly.
To make the LCD brightness dim when AC power is lost and return the LCD brightness to its previous value once AC power has been restored, we can create two new scripts:
/etc/acpi/ac.d/01-brightness.sh/etc/acpi/battery.d/01-brightness.sh
Both of these scripts use a configuration file, located at /etc/default/brightness. A sample configuration file is shown below:
/etc/default/brightness
# Whether or not enable LCD brightness control depending
# on AC power state.
BRIGHTNESS_CONTROL="yes"
# Binary used to control LCD brightness.
BRIGHTNESS_PROGRAM="/usr/local/bin/bl1"
# Defines the brightness level when running on batteries.
BRIGHTNESS_LEVEL_ON_BATTERY="10"
# Defines the default brightness level for the system when
# running on AC power. This value is superseded by the value
# stored in the ${BRIGHTNESS_LAST_LEVEL_FILE} file.
BRIGHTNESS_LEVEL_ON_AC="15"
# Defines where to store the brightness level used the last
# time the system was running on AC power.
BRIGHTNESS_LAST_LEVEL_FILE="/var/tmp/brightness"
For MacBook Pro, these scripts depend use bl1, which can be found at Basic backlight support for MacBook Pro, for the BRIGHTNESS_PROGRAM, used to control the LCD brightness.
/etc/acpi/ac.d/01-brightness.sh
The following shell script restores the brightness level in use before losing AC power:
#!/bin/bash # Load configuration parameters . /etc/default/brightness exec 2> /dev/null if [ "${BRIGHTNESS_CONTROL}" = "yes" ]; then # Check the value stored in ${BRIGHTNESS_LAST_LEVEL_FILE} # holds a numeric value. OLD=$(cat ${BRIGHTNESS_LAST_LEVEL_FILE}) let NUM=${OLD}+1 let NUM=${NUM}-1 if [ "${OLD}" -eq "${NUM}" ] 2>/dev/null; then # If previously stored value is a number, set the brightness # level to that. VALUE=${OLD} else # If previously stored value is not a number, or undefined # restore the brightness to its default value for AC power. VALUE=${BRIGHTNESS_LEVEL_ON_AC} fi # Sets the new brightness and stores its value /usr/local/bin/bl1 ${VALUE} \ | sed 's/new value: //g' > ${BRIGHTNESS_LAST_LEVEL_FILE} fi
/etc/acpi/battery.d/01-brightness.sh
The following shell script stores the current brightness level in order to restore it once AC power is restored and, since AC power has just been lost, dims the LCD brightness:
#!/bin/bash # Load configuration parameters . /etc/default/brightness if [ "${BRIGHTNESS_CONTROL}" = "yes" ]; then # Gets current brightness level and stores it ${BRIGHTNESS_PROGRAM} \ | sed 's/Current value : //g' > ${BRIGHTNESS_LAST_LEVEL_FILE} # Sets the brightness level used when running on batteries ${BRIGHTNESS_PROGRAM} ${BRIGHTNESS_LEVEL_ON_BATTERY} fi
No Comments to “Modifying screen brightness on AC state changes”
Please Wait
Leave a Reply