You are not logged in.

#1 2011-09-07 21:47:50

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Acpid handler.sh problem AC adapter [solved]

Hi guys,

I just want to set the brightness depending on whether my laptop is connected to AC or not. Therefore I tried the following in handler.sh

#!/bin/sh
# Default acpi script that takes an entry for all actions

# NOTE: This is a 2.6-centric script.  If you use 2.4.x, you'll have to
#       modify it to not use /sys

minspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq`
maxspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq`
setspeed="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"

set $*

case "$1" in
    button/power)
        #echo "PowerButton pressed!">/dev/tty5
        case "$2" in
            PBTN|PWRF)  logger "PowerButton pressed: $2" ;;
            *)          logger "ACPI action undefined: $2" ;;
        esac
        ;;
    button/sleep)
        case "$2" in
            SLPB)   echo -n mem >/sys/power/state ;;
            *)      logger "ACPI action undefined: $2" ;;
        esac
        ;;
    ac_adapter)
        case "$2" in
            AC|ACAD|ADP0|AC0)
                case "$4" in
                    00000080)
                        echo -n $minspeed >$setspeed
			xbacklight -set 0
                        #/etc/laptop-mode/laptop-mode start
                    ;;
                    00000000)
                        echo -n $maxspeed >$setspeed
			xbacklight -set 0
                        #/etc/laptop-mode/laptop-mode stop
                    ;;
                esac
                ;;
            *)  logger "ACPI action undefined: $2" ;;
        esac
        ;;
    battery)
        case "$2" in
            BAT0)
                case "$4" in
                    00000081)   #echo "offline" >/dev/tty5
				xbacklight -set 0
                    ;;
                    00000001)   #echo "online"  >/dev/tty5
				xbacklight -set 0
                    ;;
                esac
                ;;
            CPU0)	
                ;;
            *)  logger "ACPI action undefined: $2" ;;
        esac
        ;;
    button/lid)
        #echo "LID switched!">/dev/tty5
        ;;
    *)
        logger "ACPI group/action undefined: $1 / $2"
        ;;
esac

You can see that for testing purposes I added xbacklight on the AC as well as BAT handler. I got the states from acpi_listen.

# Disconnecting AC
ac_adapter AC0 00000080 00000000
hotkey ATKD 00000057 0000000d
processor CPU0 00000081 00000000
processor CPU1 00000081 00000000
battery BAT0 00000080 00000001
battery BAT0 00000081 00000001
ac_adapter AC0 00000080 00000000
# Connecting AC again
ac_adapter AC0 00000080 00000001
hotkey ATKD 00000058 0000000d
processor CPU0 00000081 00000000
processor CPU1 00000081 00000000
battery BAT0 00000080 00000001
battery BAT0 00000081 00000001
ac_adapter AC0 00000080 00000001

Last edited by orschiro (2011-09-14 12:13:42)

Offline

#2 2011-09-11 05:04:54

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Acpid handler.sh problem AC adapter [solved]

Anyone?

Offline

#3 2011-09-11 10:34:54

laloch
Member
Registered: 2010-02-04
Posts: 186

Re: Acpid handler.sh problem AC adapter [solved]

orschiro wrote:

Anyone?

It would be much easier to help if you'd actually ask a question ;-)
Does the xbacklight work at all? ...from console
Does it work in root context?
Try to disable X access control (xhost +local:)

Offline

#4 2011-09-11 21:43:10

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Acpid handler.sh problem AC adapter [solved]

Hi laloch,

Sorry about that. I tried to set the backlight through xbacklight -set 0 to zero when the Laptop is using battery. Therefore I defined xbacklight -set 0 at every possible position within handler.sh but none of that acpi events works. That's why I posted you the output of acpi_listen.

And yes, xbacklight works properly. So it is just a problem with acpid's handler.sh

Does this make clearer what I want?

Regards

Last edited by orschiro (2011-09-11 21:43:44)

Offline

#5 2011-09-11 22:03:46

laloch
Member
Registered: 2010-02-04
Posts: 186

Re: Acpid handler.sh problem AC adapter [solved]

If you replace the xbacklight by

logger "some message"

, does the message appear in /var/log/messages? If it doesn't, you probably need to add acpid to DAEMONS array in /etc/rc.conf

Offline

#6 2011-09-11 22:14:40

laloch
Member
Registered: 2010-02-04
Posts: 186

Re: Acpid handler.sh problem AC adapter [solved]

The xbacklight clearly needs an X server access...

[laloch@uriel ~]$ su
Password: 
[root@uriel laloch]# xbacklight 
No protocol specified
Cannot open display ":0"

Edit:
Do you have something in /sys/class/backlight directory?

Last edited by laloch (2011-09-11 22:18:11)

Offline

#7 2011-09-11 22:26:18

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Acpid handler.sh problem AC adapter [solved]

I changed my handler.sh to the following:

#!/bin/sh
# Default acpi script that takes an entry for all actions

# NOTE: This is a 2.6-centric script.  If you use 2.4.x, you'll have to
#       modify it to not use /sys

minspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq`
maxspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq`
setspeed="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"

set $*

case "$1" in
    button/power)
        #echo "PowerButton pressed!">/dev/tty5
        case "$2" in
            PBTN|PWRF)  logger "PowerButton pressed: $2" ;;
            *)          logger "ACPI action undefined: $2" ;;
        esac
        ;;
    button/sleep)
        case "$2" in
            SLPB)   echo -n mem >/sys/power/state ;;
            *)      logger "ACPI action undefined: $2" ;;
        esac
        ;;
    ac_adapter)
        case "$2" in
            AC|ACAD|ADP0|AC0)
                case "$4" in
                    00000080)
                        #echo -n $minspeed >$setspeed
			DISPLAY=:0.0 xbacklight -set 0
                        #/etc/laptop-mode/laptop-mode start
                    ;;
                    00000000)
                        #echo -n $maxspeed >$setspeed
			DISPLAY=:0.0 xbacklight -set 0
                        #/etc/laptop-mode/laptop-mode stop
                    ;;
                esac
                ;;
            *)  logger "ACPI action undefined: $2" ;;
        esac
        ;;
    battery)
        case "$2" in
            BAT0)
                case "$4" in
                    00000081)   #echo "offline" >/dev/tty5
				DISPLAY=:0.0 xbacklight -set 0
                    ;;
                    00000001)   #echo "online"  >/dev/tty5
				DISPLAY=:0.0 xbacklight -set 0
				logger "xbacklight issue"
                    ;;
                esac
                ;;
            CPU0)	
                ;;
            *)  logger "ACPI action undefined: $2" ;;
        esac
        ;;
    button/lid)
        #echo "LID switched!">/dev/tty5
	/usr/sbin/pm-suspend 
	DISPLAY=:0.0 su -c - robert /usr/bin/slimlock
        ;;
    *)
        logger "ACPI group/action undefined: $1 / $2"
        ;;
esac

Receiving the following message in var/log/messages:

Sep 12 10:24:51 localhost logger: ACPI group/action undefined: processor / CPU0
Sep 12 10:24:51 localhost logger: ACPI group/action undefined: processor / CPU1
Sep 12 10:24:51 localhost logger: xbacklight issue
Sep 12 10:24:51 localhost logger: xbacklight issue

Unfortunately xbacklight is still not working. Any other ideas?

Last edited by orschiro (2011-09-11 22:26:48)

Offline

#8 2011-09-11 22:32:14

laloch
Member
Registered: 2010-02-04
Posts: 186

Re: Acpid handler.sh problem AC adapter [solved]

Run xhost +local:
The xbacklight should work then, but I don't see this as "proper" solution. /sys/class/backlight would be better.

Offline

#9 2011-09-14 12:13:21

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Acpid handler.sh problem AC adapter [solved]

Hi laloch,

Thanks again for your help. Instead of using xbacklight I now write the brightness directly in the brightness file in the /sys/class/backlight/acpi_video0 folder. The complete handler.sh can be found in the wiki.

Regards

Offline

Board footer

Powered by FluxBB