[gentoo-user] acpi battery events, Sony FS740

2007-01-01 Thread »Q«
I'm nearly a complete newbie to power management.  I've been reading
and tinkering for the past three days.  I'm not sure I know enough to
explain my problem clearly, but I'll be glad to try to clarify or post
more info if you can steer me a bit.

I have a Sony Vaio FS740 laptop, and I have power management set up
mostly to my liking, but with one problem.  ACPI receives battery
events when the AC is connect and when it is unconnected, but also at
other times, and I don't know how to distinguish.  If there are no
actions for acpid to take when they happen, the
script /etc/acpi/default.sh sends this to the syslog:

logger: ACPI event unhandled: battery BAT0 0080 0001
logger: ACPI event unhandled: battery BAT0 0080 0001

They come in pairs, and the string is the same whether the cord has
just been attached or removed or neither.

I have an acpid event/action which catches these and then sets the
brightness level depending on whether or not the cord is plugged in.
This works fine when I switch between AC and battery power.  The
problem is that if I want to set some other brightness level manually,
it does no good, because one of the I-don't-know-why-they-happen
battery events will trigger a change in brightness within a couple of
minutes.

Here's the event file for acpid, /etc/acpi/events/pmg_brightness :

-
event=battery.*
action=/etc/acpi/actions/pmg_change_brightness.sh %e
-


And here's /etc/acpi/actions/pmg_change_brightness.sh :

-
#!/bin/bash

# this line was added in hopes of debugging,
# but I see no help from it.
logger "brightness script caught: ${*}"

BRIGHTNESS_AC="4"
BRIGHTNESS_BATTERY="1"

if on_ac_power
then
logger "Setting LCD to brightness ${BRIGHTNESS_AC}"
echo $BRIGHTNESS_AC > /proc/acpi/sony/brightness
else
logger "Setting LCD to brightness ${BRIGHTNESS_BATTERY}"
echo $BRIGHTNESS_BATTERY > /proc/acpi/sony/brightness
fi
-

Whether it's triggered by unplugging or by I-don't-know-what, I get
this in the syslog: 

  logger: brightness script caught: battery BAT0 0080 0001
  logger: Setting LCD to brightness 1

Same thing for plugging in or I-don't-know-what, except the brightness
is set to 4 as expected.

I'd appreciate any insight or help you can give me.

-- 
»Q«

--
gentoo-user@gentoo.org mailing list



Re: [gentoo-user] acpi battery events, Sony FS740

2007-01-02 Thread Iain Buchanan
On Tue, 2007-01-02 at 01:27 -0600, »Q« wrote:
> I'm nearly a complete newbie to power management.  I've been reading
> and tinkering for the past three days.  I'm not sure I know enough to
> explain my problem clearly, but I'll be glad to try to clarify or post
> more info if you can steer me a bit.
> 
> I have a Sony Vaio FS740 laptop, and I have power management set up
> mostly to my liking, but with one problem.  ACPI receives battery
> events when the AC is connect and when it is unconnected, but also at
> other times, and I don't know how to distinguish.  If there are no
> actions for acpid to take when they happen, the
> script /etc/acpi/default.sh sends this to the syslog:
> 
> logger: ACPI event unhandled: battery BAT0 0080 0001
> logger: ACPI event unhandled: battery BAT0 0080 0001

It could be a number of things - perhaps you have a faulty cable /
connection, which is causing ACPI events because it thinks it's just
been unplugged, and replugged.

Or perhaps your thinkpad sends ACPI events when the battery has reached
certain charge levels... don't know - someone with the same laptop will
have to comment.

Do these spontaneous ACPI events only happen when plugged in? or only
when unplugged, or both?

To get around it, perhaps you could keep "state" with a file.  eg
(untested):

-
BRIGHTNESS_AC="4"
BRIGHTNESS_BATTERY="1"
ALREADY_PLUGGED_IN="/.power"

if on_ac_power
then
if -f ${ALREADY_PLUGGED_IN} then
logger "Recieved ACPI power event, but already plugged in!"
else
logger "Setting LCD to brightness ${BRIGHTNESS_AC}"
echo $BRIGHTNESS_AC > /proc/acpi/sony/brightness
touch ${ALREADY_PLUGGED_IN}
fi
else
logger "Setting LCD to brightness ${BRIGHTNESS_BATTERY}"
echo $BRIGHTNESS_BATTERY > /proc/acpi/sony/brightness
rm ${ALREADY_PLUGGED_IN}
fi
-

This will only work for the already-plugged-in-acpi-event, you may have
to do a bit of playing if you also get an already-unplugged-acpi-event,
but I have to leave some fun for you!

HTH!
-- 
Iain Buchanan 

It is better to have loved and lost -- much better.

-- 
gentoo-user@gentoo.org mailing list