You are not logged in.

#1 2011-11-22 20:23:48

Jankosevic
Member
Registered: 2008-07-06
Posts: 82

Change brightness does not work anymore

Hello,

I was using this neat script in /etc/acpi/handler.sh to change the brightness of my laptop screen:

  hotkey)
        event="$2"\ "$3"
        case "$event" in
            "ATKD 0000002"*) 
            acpi_fakekey $KEY_BRIGHTNESSDOWN
            brightness=`echo $3 | sed 's/0000002//'`
            setpci -s 00:02.0 F4.B=${brightness}f
            ;;
            "ATKD 0000001"*) 
            acpi_fakekey $KEY_BRIGHTNESSUP
            brightness=`echo $3 | sed 's/0000001//'`
            setpci -s 00:02.0 F4.B=${brightness}f
            ;;
        esac
        ;;

from: https://bbs.archlinux.org/viewtopic.php … 23#p758723

Anyhow, after one of the last kernel updates it does not work anymore and I don't know why.

acpi_listen gives me:

video/brightnessdown BRTDN 00000087 00000000
hotkey ATK0100:00 0000002e 00000018
hotkey ATK0100:00 0000002e 00000019
hotkey ATK0100:00 0000002e 0000001a
video/brightnessup BRTUP 00000086 00000000
hotkey ATK0100:00 0000001f 000000f9
hotkey ATK0100:00 0000001f 000000fa
hotkey ATK0100:00 0000001f 000000fb

What do I need to change or add? Which outputs might be useful for you?
Thanks for any hints!

Last edited by Jankosevic (2011-11-22 20:25:50)

Offline

#2 2011-11-25 10:02:46

Jankosevic
Member
Registered: 2008-07-06
Posts: 82

Re: Change brightness does not work anymore

Which additional information can I provide to you??
It is really an annoying problem...

Offline

#3 2011-11-25 12:14:22

roygbiv
Member
Registered: 2011-05-18
Posts: 204

Re: Change brightness does not work anymore

From my point of view it seems you need to change these entries ($2 $3)

"ATKD 0000001"*)

to

"ATK0100:00 0000001"*)

Offline

#4 2012-03-26 16:24:52

Jankosevic
Member
Registered: 2008-07-06
Posts: 82

Re: Change brightness does not work anymore

I know this comes very late, but I switched to an external monitor.
Now I implemented roygbiv's suggestions but it still does not work. What else can I try? smile

Offline

#5 2012-03-27 20:38:06

Jankosevic
Member
Registered: 2008-07-06
Posts: 82

Re: Change brightness does not work anymore

I would be happy for any suggestions...if I use the command "setpci -s 00:02.0 F4.B=FF" manually...it works just fine...

Offline

#6 2012-04-17 02:04:17

cupantae
Member
Registered: 2010-03-15
Posts: 18

Re: Change brightness does not work anymore

Hey there,

I just wrote a fairly neat script for this, for my Acer Aspire 5732z. It is relevant for any Googlers who want a script for using setpci to change brightness. I intend for this to be a full guide, which seems to me to be missing from the internet:

#!/bin/bash

## To be run as root.
if [ $(id -u) -ne 0 ]
   then echo "Run this as root."
   exit 1
fi

# Get value in hex and convert to decimal:
CURRENT=$[0x`setpci -s 0:2.0 f4.b`]

case $1 in
down)
	NEW=$[$CURRENT+16]
	if [ $NEW -gt 255 ]
		then NEWHEX=ff
		else NEWHEX=$(printf '%x' $NEW)
	fi
	setpci -s 0:2.0 f4.b=$NEWHEX
	;;	
up)
	NEW=$[$CURRENT-16]
	if [ $NEW -lt 0 ]
		then NEWHEX=0
		else NEWHEX=$(printf '%x' $NEW)
	fi
	setpci -s 0:2.0 f4.b=$NEWHEX
	;;	
esac

exit 0

Save that as /usr/sbin/brightness and chown root, chmod 755.
Now running

# brightness up

or

# brightness down

will do the trick. Note that on my laptop the values are swapped: 00 is brightest; ff is darkest. If this is not the case for you, swap the words up) and down).

This has the advantage over other scripts I've seen that you don't have to let people use setpci without a password (NOT a good idea!). To use this as a user "username", (say, with a keybinding), do:

# visudo

and add this to the end:

username ALL=(ALL) ALL NOPASSWD: /usr/sbin/brightness

but know what it is you're doing beforehand (man sudoers)!


By the way, I didn't read any of the posts above me.

Offline

#7 2012-10-08 16:27:22

dreieck
Member
Registered: 2012-10-08
Posts: 4

Re: Change brightness does not work anymore

cupantae wrote:

Hey there,

I just wrote a fairly neat script for this, for my Acer Aspire 5732z. [...]

Thanks!

Based on your inspiration, I wrote a bit more elaborate script (and called it 'lcdbrightness'). Remember to create the directory '/usr/local/var/run/lcdbrightness/' before using the script. Here is it:

#!/bin/bash

STATEFILE=/usr/local/var/run/lcdbrightness/state
STATEFILE_TIME="${STATEFILE}.timestamp"

DEFAULTBRIGHTNESS="80"
PCIDEV="00:02.0"
PCIREG="f4"


printusage()
{
  cat << EOUSAGE
'$0' -- Setting the LCD brightness by setting PCI registers via 'setpci'.
WARNING! DANGEROUS! Direct PCI register setting. If you set the wrong ones,
or the wrong PCI device even, you can screw up your system.

Configured to set the following hardware:
  PCI Device: '${PCIDEV}'.
  Register of that PCI device: '${PCIREG}' (one byte).
Those settings can be changed within '$0'.

Usage:
  $0 [<argument>]
Where the behaviour is the following:
* If no argument is given, or the argument is "show": Print out current setting (a byte in
  hex, i.e. a hex-number between (and including) 00 and ff).
* If argument is a hex-value between (and including) 00 and ff: Set brightness
  to that level.
* If argument is "off": Store current setting in '${STATEFILE}', and
  set brightness to "00".
* If argument is "on": Restore setting from '${STATEFILE}', or, if
  '${STATEFILE}' is not there, restore to '${DEFAULTBRIGHTNESS}'.
* If argument is "default": Set to '${DEFAULTBRIGHTNESS}'.
* If argument is "+X" or "upX": Step up by X, but at most to "ff". X has to be a hex value in between (and including) 00 and ff.
* If argument is "+" or "up": Step up by one (if not already at "ff").
* If argument is "-X" or "downX": Step down by X, but at most to "00". X has to be a hex value in between (and including) 00 and ff.
* If argument is "-" or "down": Step down by one (if not already at "00").
* If argument is "help", print out this help message.
* If argument does not follow any of those conventions, default to
  abort with this help message printed out.
EOUSAGE
}



### Initialisation: If no special command line arguments are ###
### detected, do the following:                              ###

ARG="$1"
ARGNR="$#"
VALUE='invalid'
MODE='invalid'

### End of initialisation.                                   ###

checkvalue()
{
  result=false
  BRIGHTNESS="${1}"
  if [ -n "${BRIGHTNESS}" ]; then
    if echo "${BRIGHTNESS}" | grep -Eq -e '^[0-9a-fA-F]{1,2}$'; then
      result=true
    else
      result=false
    fi
  else
    echo "$0: Error in function 'setsetting()': No argument was passed (this should NOT have happend. This is a BUG in '$0'.)"
    result=false
    return 111
  fi
  if "${result}"; then
    return 0
  else
    return 1
  fi
}

getsetting()
{
  setpci -s "${PCIDEV}" "${PCIREG}".b
}

setsetting()
{
  BRIGHTNESS="${1}"
  if [ -n "${BRIGHTNESS}" ]; then
    if checkvalue "${BRIGHTNESS}"; then
      setpci -s "${PCIDEV}" "${PCIREG}".b="${BRIGHTNESS}"
    else
      echo "$0: Error in function 'setsetting()': Passed brightness-argument '${BRIGHTNESS}' is not valid (has to be a hex value from '00' to 'ff'). Not applying setting." > /dev/stderr
      return 1
    fi
  else
    echo "$0: Error in function 'setsetting()': No argument was passed (this should NOT have happend. This is a BUG in '$0'.)" > /dev/stderr
    return 111
  fi
}

save()
{
  getsetting > "${STATEFILE}" && {
    date --rfc-3339=seconds > "${STATEFILE_TIME}" || true
  }
}

load()
### this function actually prints out the information, and deletes it afterwards.
{
  BRIGHTNESS=''
  if [ -r "${STATEFILE}" ]; then
    BRIGHTNESS="$(cat "${STATEFILE}")"
  fi
  if [ -z "${BRIGHTNESS}" ]; then
    BRIGHTNESS="${DEFAULTBRIGHTNESS}"
  fi
  echo "${BRIGHTNESS}"
  echo '' > "${STATEFILE}" && {
    date --rfc-3339=seconds > "${STATEFILE_TIME}" || true
  }
}

hexadd()
{
  VAL1="${1}"
  VAL2="${2}"
  OPERATION="+"
  if [ -n "${3}" ]; then
    OPERATION="${3}"
  fi
  if [ "${OPERATION}"x == "+"x ]; then
    printf '%x' "$[0x${VAL1} + 0x${VAL2}]"
  else
    printf '%x' "$[0x${VAL1} - 0x${VAL2}]"
  fi
}

hexadd_clip()
{
  RESULT="$(hexadd "${@}")"
  if [ "$[0x${RESULT}]" -gt 255 ]; then
    RESULT=ff
  elif [ "$[0x${RESULT}]" -lt 0 ]; then
    RESULT=00
  fi
  echo "${RESULT}"
}

if [ "${ARGNR}"x == "0"x ] || [ "${ARG}"x == "show"x ]; then
  MODE=show
elif echo "${ARG}" | grep -Eq -e '^[0-9a-fA-F]{1,2}$'; then
  MODE=set
elif [ "${ARG}"x == "off"x ]; then
  MODE=off
elif [ "${ARG}"x == "on"x ]; then
  MODE=on
elif [ "${ARG}"x == "default"x ]; then
  MODE=default
elif echo "${ARG}" | grep -Eq -e '^(\+|up)[0-9a-fA-F]{0,2}$'; then
  MODE=incr
elif echo "${ARG}" | grep -Eq -e '^(\-|down)[0-9a-fA-F]{0,2}$'; then
  MODE=decr
elif [ "${ARG}"x == "help"x ]; then
  MODE=help
else
  MODE=wrongarg
fi

case "${MODE}" in
  show)
    getsetting
  ;;
  set)
    VALUE="${ARG}"
    setsetting "${VALUE}"
  ;;
  off)
    save && {
      VALUE=00
      setsetting "${VALUE}"
    }
  ;;
  on)
    VALUE="$(load)"
    setsetting "${VALUE}"
  ;;
  default)
    VALUE="${DEFAULTBRIGHTNESS}"
    setsetting "${VALUE}"
  ;;
  incr)
    STEP="$(echo "${ARG}" | sed --regexp-extended 's/^(up|\+)//g')"
    if [ -z "${STEP}" ]; then
      STEP="1"
    fi
    checkvalue "${STEP}" || {
      echo "$0: Error: Specified step value '${STEP}' invalid. Allowed: Hex-values in the range {00,...,ff}. Not applying any changes, and aborting." > /dev/stderr
      exit 23
    }
    CURRENT="$(getsetting)"
    VALUE="$(hexadd_clip "${CURRENT}" "${STEP}")"
    setsetting "${VALUE}"
  ;;
  decr)
    STEP="$(echo "${ARG}" | sed --regexp-extended 's/^(down|\-)//g')"
    if [ -z "${STEP}" ]; then
      STEP="1"
    fi
    checkvalue "${STEP}" || {
      echo "$0: Error: Specified step value '${STEP}' invalid. Allowed: Hex-values in the range {00,...,ff}. Not applying any changes, and aborting." > /dev/stderr
      exit 25
    }
    CURRENT="$(getsetting)"
    VALUE="$(hexadd_clip "${CURRENT}" "${STEP}" '-')"
    setsetting "${VALUE}"
  ;;
  help)
    printusage
    exit "$?"
  ;;
  wrongarg)
    {
      echo "$0: Error: Wrong argument specified. Aborting, after printing what you specified and the help message."
      echo ""
      echo "You specified in total '${ARGNR}' arguments, where the first one (and only considered) was '${ARG}'."
      echo ""
      printusage
    } > /dev/stderr
    exit 1
  ;;
  *)
    {
      echo "$0: DEBUG: Reached a programme state which should never be reached."
      echo "Instead, errors due to wrongly specified arguments should already have been captured."
      echo "Please debug '$0' accordingly."
      echo "The 'MODE' variable was: '${MODE}'."
      echo "Aborting."
    } > /dev/stderr
    exit 111
  ;;
esac

Although on my thinkpad X200 tablet brightness-setting by hand (using the brighness keys) works, via the BIOS, and enabling and disabling the panel via 'vbetool dpms on' resp. '[...] off', I found it quite handy to be able to set the brighness to "00", means backlight off, but panel still active (In bright sunlight I am able to read dark text on bright background, thus saving battery power).

The above script has as well to be run as root.
And remember to set the correct PCI ID for you.

Bye,
dreieck.

Offline

Board footer

Powered by FluxBB