# Pbbuttonsd for the Macbook Pro

## bruda

Note. The most recent pbbuttonsd version as per this thread is now the official release  0.8.0 (the ebuild is mine though so not official I guess).   I introduced in the ebuild the new use flag "macbook" which will configure the daemon for the Intel based Macs.  The "doc" flag now causes the doxygen documentation to be built and put into /usr/share/doc as usual.

Hi all,

This is intended as a continuation of the discusion on the matter in the MacBook Pro Core 2 Duo thread.  I have made some attempts at making pbbuttonsd work on the new Macbooks and Matthias Grimm (the maintainer of the daemon) was kind enough to include my hacks into a new, test version of the thing.  Here is the result:

 *bruda wrote:*   

> I have talked to Matthias and since he does not mind having more than one beta tester here is the teste version of pbbuttonsd: http://turing.ubishops.ca/misc/pbbuttonsd-0.7.9.8.ebuild.  This works correctly only with gtkpbbuttons 0.6.9 (in the sense that the older gtkpbbuttons expect light to be measured on a 16-values scale but the newer versions of pbbuttonsd provide a 100-values scale) so you need to install that (I use for the purpose the following slightly modified ebuild: http://turing.ubishops.ca/misc/gtkpbbuttons-0.6.9.ebuild).  Note that this test version has a different name for the config file.  I quote Matthias:
> 
>  *Quote:*   The attached version got a new configurations handling with is not fully compatible with the old one. The new configuration file is called pbbuttonsd.cnf so it won't conflict with the old one. Nevertheless you should have a look at the new configuration file because the old one is _not_ automatically converted.
> 
> As you suggested it should be made clear that it is only a test version and should not be used in any production environment. Nevertheless I'm interested in any feedback (positive or negative). Your code will be part of the upcoming release if no negative side effects will be reported. I will try to get basic ACPI battery functions working until release date. 
> ...

 

For the record (and for self-containment purposes) here is some subsequent discusion:

 *Scott Price wrote:*   

> The good news:  All of the buttons work!   
> 
> The bad news:  
> 
> #1 The first thing it does is shut off my display and turn the keyboard light on full.    I can easily use the keys to fix that, but it is kind of annoying.   It almost seems as if the program is getting the two backlights confused.  Like it should be doing the opposite.
> ...

 

 *bruda wrote:*   

>  *Scott Price wrote:*   The good news:  All of the buttons work!     
> 
> Cool  
> 
>  *Quote:*   #1 The first thing it does is shut off my display and turn the keyboard light on full.    I can easily use the keys to fix that, but it is kind of annoying.   It almost seems as if the program is getting the two backlights confused.  Like it should be doing the opposite. 
> ...

 

 *kaiRy wrote:*   

> When I emerge pbbuttonsd with the ibam flag and when I start the service it tell me that "/var/lib/ibam doesn't exist" and when I emerge it withouth this flag the emerge fails.

 

 *bruda wrote:*   

>  *kaiRy wrote:*   When I emerge pbbuttonsd with the ibam flag and when I start the service it tell me that "/var/lib/ibam doesn't exist". 
> 
> Have you tried creating the directory?  As far as I remember the ebuild creates it, but still...

 

----------

## kaiRy

I create it and it works but I had the same problem Black Screen and full keyboard backlight.

All buttons work but I can't change the volume level.. it doesn't detect my alsa server

----------

## Scott Price

I had to change the mixer values for my computer.  

```

[MODULE MIXER ALSA]

Card=default

Channels=PCM, Front, Headphone

```

And make sure not to use quotes.  It takes them literally.   :Wink: 

Scott  =)

----------

## bruda

Could it be that you are setting too low a minimal value for backlight?  My display goes blank (or almost) with a backlight value under 30 (absolute value out of 255, ~12%), so it might be that your machine thinks that the room is really dark so it adjust the keyboard illumination to maximum and the display backlight to minimum (and if this minimum is too low it effectively blanks it).  What is the output of your sensors?  Are they stuck at 0 (or -1, which is an error condition)?

I am having no problems of this kind.  Could be that I am running an x86_64 system (amd64 stable with a few exceptions) but I seriously doubt it.  In any case, the first thing to check would be that the SMC interace (its ambient component to be precise) works as advertised.

If somebody wants to poke into the source code note that the SMC interface is all in src/module_imac.c.

----------

## Scott Price

Okay, I did the light sensor test.  These are the results:

```

Light: Left: 21, Right: 26

Light: Left: 20, Right: 26

Light: Left: 27, Right: 1

Light: Left: 26, Right: 0

Light: Left: 30, Right: 0

Light: Left: 2, Right: 19

Light: Left: 0, Right: 26

Light: Left: 0, Right: 26

Light: Left: 26, Right: 27

Light: Left: 26, Right: 27

Light: Left: 27, Right: 30

Light: Left: 27, Right: 30

Light: Left: 27, Right: 29

Light: Left: 27, Right: 29

Light: Left: 23, Right: 28

Light: Left: 32, Right: 42

Light: Left: 59, Right: 65

Light: Left: 67, Right: 86

Light: Left: 70, Right: 90

Light: Left: 68, Right: 94

Light: Left: 68, Right: 82

Light: Left: 21, Right: 24

Light: Left: 31, Right: 31

Light: Left: 29, Right: 30

Light: Left: 29, Right: 30

Light: Left: 29, Right: 31

```

You can see when I put my hand over each side, then when I held it so that it saw more light.  It seems to be working.

Scott  =)

----------

## bruda

Seems to be working alright.  I presume you adjusted the minimal backlight to something that makes sense too.  Would it be too much to ask you whether the sensor readout is correct in the daemon?  This would imply adding a debug statement in getRawAmbient() along the following lines:

```
printf("getRawAmbient: left %d, right %d", left, right);
```

right after the return.  This gives you the sensor values as pbbuttonsd sees them every second or so.

If the values are correct and your bounds are sane then it might well be that we are seeing the same problem (the backlight control failing for yet unknown reasons) with two different manifestations.  I really want to check it out, honestly, but please don't hold your breath.

----------

## kaiRy

 *Scott Price wrote:*   

> I had to change the mixer values for my computer.  
> 
> ```
> 
> [MODULE MIXER ALSA]
> ...

 

 :Embarassed:  Where should I set this ???   :Embarassed: 

----------

## bruda

 *kaiRy wrote:*   

>  *Scott Price wrote:*   I had to change the mixer values for my computer.  
> 
> ```
> 
> [MODULE MIXER ALSA]
> ...

 

In /etc/pbbuttonsd.cnf  :Wink: 

----------

## kaiRy

I put it in /etc/pbbuttonsd.conf but no change   :Confused:   it's weird.

----------

## Scott Price

 *kaiRy wrote:*   

> I put it in /etc/pbbuttonsd.conf but no change    it's weird.

 

Not /etc/pbbuttons.cOnf just /etc/pbbuttons.cnf  The experimental version slightly changed the file name so it wouldn't overwrite the old conf file.

Scott  =)

----------

## bruda

 *Matthias Grimm wrote:*   

> I made a little progress as well. I started a module_acpi.c and battery and power source information will already be read and transmitted to the pbbuttonsd high level modules. Furthermore I fixed the compiling problem with ibam that was reported in the forum.
> 
> Last but not least I found a bug in driver_mixer_alsa.c that might have caused the segfault. Nevertheless I would be thankful for any further information and a copy of the configfile that caused the crash.
> 
> To check my ACPI code I need some data. Could you please send me the contents of /proc/acpi from your machine? Maybe some of the other testers could do the same.
> ...

 

----------

## Scott Price

```

[prices@crazyharry ~]% ls -asl /proc/acpi/

total 0

0 dr-xr-xr-x 11 root root 0 Dec 13 20:02 .

0 dr-xr-xr-x 88 root root 0 Dec 13 20:01 ..

0 dr-xr-xr-x  3 root root 0 Dec 13 20:09 ac_adapter

0 -rw-r--r--  1 root root 0 Dec 13 20:09 alarm

0 dr-xr-xr-x  3 root root 0 Dec 13 20:09 battery

0 dr-xr-xr-x  5 root root 0 Dec 13 20:09 button

0 -r--------  1 root root 0 Dec 13 20:09 dsdt

0 dr-xr-xr-x  3 root root 0 Dec 13 20:09 embedded_controller

0 -r--------  1 root root 0 Dec 13 20:02 event

0 -r--------  1 root root 0 Dec 13 20:09 fadt

0 dr-xr-xr-x  2 root root 0 Dec 13 20:09 fan

0 -r--r--r--  1 root root 0 Dec 13 20:09 info

0 dr-xr-xr-x  2 root root 0 Dec 13 20:09 power_resource

0 dr-xr-xr-x  4 root root 0 Dec 13 20:09 processor

0 dr-xr-xr-x  2 root root 0 Dec 13 20:09 thermal_zone

0 dr-xr-xr-x  3 root root 0 Dec 13 20:09 video

0 -rw-r--r--  1 root root 0 Dec 13 20:09 wakeup

```

Just that, or does he want more?

I will have to try to make that config file again.  I didn't save it.

Scott  =)

----------

## bruda

I personally did an ls -lRF /proc/acpi.  I would presume that he wants to see the content of some subdirectories if not all.

----------

## Scott Price

```

[prices@crazyharry ~]% ls -lRF /proc/acpi

/proc/acpi:

total 0

dr-xr-xr-x 3 root root 0 Dec 13 21:06 ac_adapter/

-rw-r--r-- 1 root root 0 Dec 13 21:06 alarm

dr-xr-xr-x 3 root root 0 Dec 13 21:06 battery/

dr-xr-xr-x 5 root root 0 Dec 13 21:06 button/

-r-------- 1 root root 0 Dec 13 21:06 dsdt

dr-xr-xr-x 3 root root 0 Dec 13 21:06 embedded_controller/

-r-------- 1 root root 0 Dec 13 20:02 event

-r-------- 1 root root 0 Dec 13 21:06 fadt

dr-xr-xr-x 2 root root 0 Dec 13 21:06 fan/

-r--r--r-- 1 root root 0 Dec 13 21:06 info

dr-xr-xr-x 2 root root 0 Dec 13 21:06 power_resource/

dr-xr-xr-x 4 root root 0 Dec 13 21:06 processor/

dr-xr-xr-x 2 root root 0 Dec 13 21:06 thermal_zone/

dr-xr-xr-x 3 root root 0 Dec 13 21:06 video/

-rw-r--r-- 1 root root 0 Dec 13 21:06 wakeup

/proc/acpi/ac_adapter:

total 0

dr-xr-xr-x 2 root root 0 Dec 13 21:06 ADP1/

/proc/acpi/ac_adapter/ADP1:

total 0

-r--r--r-- 1 root root 0 Dec 13 21:06 state

/proc/acpi/battery:

total 0

dr-xr-xr-x 2 root root 0 Dec 13 21:06 BAT0/

/proc/acpi/battery/BAT0:

total 0

-rw-r--r-- 1 root root 0 Dec 13 21:06 alarm

-r--r--r-- 1 root root 0 Dec 13 21:06 info

-r--r--r-- 1 root root 0 Dec 13 21:06 state

/proc/acpi/button:

total 0

dr-xr-xr-x 3 root root 0 Dec 13 21:06 lid/

dr-xr-xr-x 4 root root 0 Dec 13 21:06 power/

dr-xr-xr-x 3 root root 0 Dec 13 21:06 sleep/

/proc/acpi/button/lid:

total 0

dr-xr-xr-x 2 root root 0 Dec 13 21:06 LID0/

/proc/acpi/button/lid/LID0:

total 0

-r--r--r-- 1 root root 0 Dec 13 21:06 info

-r--r--r-- 1 root root 0 Dec 13 21:06 state

/proc/acpi/button/power:

total 0

dr-xr-xr-x 2 root root 0 Dec 13 21:06 PWRB/

dr-xr-xr-x 2 root root 0 Dec 13 21:06 PWRF/

/proc/acpi/button/power/PWRB:

total 0

-r--r--r-- 1 root root 0 Dec 13 21:06 info

/proc/acpi/button/power/PWRF:

total 0

-r--r--r-- 1 root root 0 Dec 13 21:06 info

/proc/acpi/button/sleep:

total 0

dr-xr-xr-x 2 root root 0 Dec 13 21:06 SLPB/

/proc/acpi/button/sleep/SLPB:

total 0

-r--r--r-- 1 root root 0 Dec 13 21:06 info

/proc/acpi/embedded_controller:

total 0

dr-xr-xr-x 2 root root 0 Dec 13 21:06 EC/

/proc/acpi/embedded_controller/EC:

total 0

-r--r--r-- 1 root root 0 Dec 13 21:06 info

/proc/acpi/fan:

total 0

/proc/acpi/power_resource:

total 0

/proc/acpi/processor:

total 0

dr-xr-xr-x 2 root root 0 Dec 13 21:06 CPU0/

dr-xr-xr-x 2 root root 0 Dec 13 21:06 CPU1/

/proc/acpi/processor/CPU0:

total 0

-r--r--r-- 1 root root 0 Dec 13 21:06 info

-rw-r--r-- 1 root root 0 Dec 13 21:06 limit

-r--r--r-- 1 root root 0 Dec 13 21:06 power

-rw-r--r-- 1 root root 0 Dec 13 21:06 throttling

/proc/acpi/processor/CPU1:

total 0

-r--r--r-- 1 root root 0 Dec 13 21:06 info

-rw-r--r-- 1 root root 0 Dec 13 21:06 limit

-r--r--r-- 1 root root 0 Dec 13 21:06 power

-rw-r--r-- 1 root root 0 Dec 13 21:06 throttling

/proc/acpi/thermal_zone:

total 0

/proc/acpi/video:

total 0

dr-xr-xr-x 7 root root 0 Dec 13 21:06 GFX0/

/proc/acpi/video/GFX0:

total 0

dr-xr-xr-x 2 root root 0 Dec 13 21:06 DD01/

dr-xr-xr-x 2 root root 0 Dec 13 21:06 DD02/

dr-xr-xr-x 2 root root 0 Dec 13 21:06 DD03/

dr-xr-xr-x 2 root root 0 Dec 13 21:06 DD04/

dr-xr-xr-x 2 root root 0 Dec 13 21:06 DD05/

-r--r--r-- 1 root root 0 Dec 13 21:06 DOS

-r--r--r-- 1 root root 0 Dec 13 21:06 POST

-r--r--r-- 1 root root 0 Dec 13 21:06 POST_info

-r--r--r-- 1 root root 0 Dec 13 21:06 ROM

-r--r--r-- 1 root root 0 Dec 13 21:06 info

/proc/acpi/video/GFX0/DD01:

total 0

-r--r--r-- 1 root root 0 Dec 13 21:06 EDID

-rw-r--r-- 1 root root 0 Dec 13 21:06 brightness

-r--r--r-- 1 root root 0 Dec 13 21:06 info

-rw-r--r-- 1 root root 0 Dec 13 21:06 state

/proc/acpi/video/GFX0/DD02:

total 0

-r--r--r-- 1 root root 0 Dec 13 21:06 EDID

-rw-r--r-- 1 root root 0 Dec 13 21:06 brightness

-r--r--r-- 1 root root 0 Dec 13 21:06 info

-rw-r--r-- 1 root root 0 Dec 13 21:06 state

/proc/acpi/video/GFX0/DD03:

total 0

-r--r--r-- 1 root root 0 Dec 13 21:06 EDID

-rw-r--r-- 1 root root 0 Dec 13 21:06 brightness

-r--r--r-- 1 root root 0 Dec 13 21:06 info

-rw-r--r-- 1 root root 0 Dec 13 21:06 state

/proc/acpi/video/GFX0/DD04:

total 0

-r--r--r-- 1 root root 0 Dec 13 21:06 EDID

-rw-r--r-- 1 root root 0 Dec 13 21:06 brightness

-r--r--r-- 1 root root 0 Dec 13 21:06 info

-rw-r--r-- 1 root root 0 Dec 13 21:06 state

/proc/acpi/video/GFX0/DD05:

total 0

-r--r--r-- 1 root root 0 Dec 13 21:06 EDID

-rw-r--r-- 1 root root 0 Dec 13 21:06 brightness

-r--r--r-- 1 root root 0 Dec 13 21:06 info

-rw-r--r-- 1 root root 0 Dec 13 21:06 state

```

----------

## bruda

Hi,

Matthias has released a new version--this time a release candidate.  It seems to work well for me (I have been trying it for the last hour or so), if anybody else is interested the ebuild is at http://turing.ubishops.ca/misc/pbbuttonsd-0.8.0_rc1.ebuild.  This version needs libsmbios, ebuild for which is included in this overlay.

----------

## Scott Price

The keyboard backlight doesn't work for me on 0.8.0rc1.

Scott  =)

----------

## bruda

So noted.  How does it all fare in 0.8.0_rc2?

----------

## Scott Price

Everything seems to work (including the keyboard backlight) in rc2.

Scott  =)

----------

## bruda

Thank you.  Now if you have the time could you please re-download the ebuild (otherwise the debug flag will not work), use the "debug" use flag to rebuild the daemon and launch it from the command line.  It should print information on ambient light sensors and other things, but I am curious whether it understands the AC/battery switches correctly.  Whenever the AC is pulled an event like

```
Config    : P TAG_POWERCHANGED         : 0
```

should appear.  Conversely, when the AC is plugged in, the event should be

```
Config    : P TAG_POWERCHANGED         : 1
```

Repeat for a number of times and let me know whether this reporting is reliable (it does not appear to be on my machine and I am curious to see whether I am the only one).  Many thanks in advance.

----------

## bruda

Nevermind, the RC3 version is out and fixes (for me) this problem.  Now you can use different limits for backlight auto-adjustment when on battery and on AC and the limits you define are actually taken into consideration.

The keyboard illumination auto-adjustment seems to be the only one having notable problems, at least this is my experience.  This is being worked on.  But then if anybody spots any other problem please post them.

----------

## bruda

One more version out: 0.8.0_rc4, which changes the auto-adjustment parameters in quite a nice manner.  This is not yet documented in the manual page, so I am including here Matthias' explanation on the matter:

```

The main improvement here is the new model to control the LCD and

keyboard brightness to get rid of ambiguous config options :-). The man

page is not updated yet so I briefly describe the new model here.

There are six new config options: Three for LCD control and three for the

keyboard illumination. Both work exactly the same. All other autoadjustment

parameters and the threshold parameter become obsolete.

      LCD_AutoadjMode=linear

      LCD_AutoadjParm_onBattery=0,1,54,100

      LCD_AutoadjParm_onAC=0,1,94,100

The "AutoadjMode" sets the model to use. Possible values are:

  1. "off"        - no automatic, ambient light dependent brightness

                    adjustment

  2. "linear"     - use a linear transformation from ambient light to

                    brightness level

  3. "hysteresis" - switch brightness between certain levels dependent

                    of ambient light

The "AutoadjParm" defines two ambient level/brightness level pairs each

that defines two characteristic points of the ambient light/brightness

level transformation in percent. The following sketches will make it

more clear:

   level = f(ambient)

 

      lêvel     2                    lêvel          2

       |         o------              |      +--<--o-----

       |        /                     |      |     |

       |       /                      |      |     |

       |------o                       |------o-->--+

       |       1                      |     1

       +--------ambient-light->       +---------ambient-light->

             linear                      hysteresis

The above example uses the linear model with parameter 0,1,94,100.

This means that from an ambient light level from 0% to 94% the LCD

brightness level will be linearly adjusted from 1% to 100%.

If we use the parameters 20,10,40,90 the brightness level will be 10%

as long as the ambient light level is below or equal to 20%. If the

ambient light level increases the backlight level will linearly

increase too until it reaches its maximum of 90%. This will happen at

ambient level of 40%. Above 40% ambient light the backlight brightness

stick to 90%.

If you use the same parameter with the hysteresis model the backlight

level will jump to 90% after the ambient light level became more than

40% and switch back to 10% when the ambient light decreases below 20%.

```

----------

## bruda

An official release covering all that has been discussed here is now out, so I guess this is the last message of this thread.

----------

