Author Topic: Powerdevil not identifying AC removal or plugin  (Read 1172 times)

Offline dj_bridges

  • Hero Member
  • *****
  • Posts: 638
Powerdevil not identifying AC removal or plugin
« on: August 23, 2010, 05:09:37 AM »
My laptop recently died and just got a newer one to replace it. Anyways I installed PCLOS 2010 MiniMe and noticed that when plugging in or removing the AC adaptor, the system didn't seem to recognise any change (although it did show the battery as discharging or charging correctly). As a result if plugging in the adaptor, I would keep getting warnings that power was now at x% etc. Thinking that it might be resolved in KDE 4.5 this morning i did a full update. Unfortunately the problem still persists.

Any idea why nothing is registering when plugging in or removing AC power?
PCLinuxOS 2012 running KDE4 on Lenovo ThinkPad T420, Quad core Intel i5 @ 2.6GHz, 6Gb Ram, 400 Gb HDD

Offline Ertain

  • Sr. Member
  • ****
  • Posts: 365
  • I come in peace. And for some nachos.
Re: Powerdevil not identifying AC removal or plugin
« Reply #1 on: August 27, 2010, 07:18:43 PM »
I've been trying to resolve that for a week.

It has something to do with a combination of ACPI and PowerDevil.  There are some settings that PowerDevil doesn't immediately pick up on.  When you plug in your laptop ACPI (and to a lesser extent acpid) may pick up the adapter setting, but PowerDevil will not change.  For example, if you check /sys/class/power_supply/BAT0/status it may say "Charging", while if you look at /sys/class/power_supply/ADP0/online it will give the number 0, indicating that it's not plugged in.  Something is not getting reported correctly.

When I start up my laptop without it plugged in pclos will sometimes behave properly.  Also I messed around with the modules that are loaded.  I tried starting and stopping ACPI and acpid, but those don't seem to help.
"She's the boss, apple sauce!"
 -Frank Cho

Offline dj_bridges

  • Hero Member
  • *****
  • Posts: 638
Re: Powerdevil not identifying AC removal or plugin
« Reply #2 on: August 31, 2010, 03:47:08 AM »
Ertain - thanks for your reply. I have also noticed that booting up without the power supply connected seems to make the system work as expected. This does seem like a strange problem. Am glad its not just me, but hope someone can identify the issue.

Are we on similar machines - I am on a toshiba A300 Sat Pro....
PCLinuxOS 2012 running KDE4 on Lenovo ThinkPad T420, Quad core Intel i5 @ 2.6GHz, 6Gb Ram, 400 Gb HDD

Offline Ertain

  • Sr. Member
  • ****
  • Posts: 365
  • I come in peace. And for some nachos.
Re: Powerdevil not identifying AC removal or plugin
« Reply #3 on: August 31, 2010, 11:35:39 PM »
I have a Satellite A305D.  Yep, something's up. ???
"She's the boss, apple sauce!"
 -Frank Cho

Offline dj_bridges

  • Hero Member
  • *****
  • Posts: 638
Re: Powerdevil not identifying AC removal or plugin
« Reply #4 on: September 01, 2010, 02:41:04 AM »
Well its good that we are making some sort of progress, even if a solution isn't in sight. Anyone else with a Toshiba laptop notice this issue?
PCLinuxOS 2012 running KDE4 on Lenovo ThinkPad T420, Quad core Intel i5 @ 2.6GHz, 6Gb Ram, 400 Gb HDD

Offline Ertain

  • Sr. Member
  • ****
  • Posts: 365
  • I come in peace. And for some nachos.
Re: Powerdevil not identifying AC removal or plugin
« Reply #5 on: September 01, 2010, 08:32:43 PM »
Here's some more information.

If you look at the file /proc/acpi/ac_adapter/ADP0/state with it unplugged it will say off-line.  However, the file /sys/class/power_supply/ADP0/online is not updated (the file should have 0).  Something isn't lining up behind the scenes and changing the states.
"She's the boss, apple sauce!"
 -Frank Cho

Offline Ertain

  • Sr. Member
  • ****
  • Posts: 365
  • I come in peace. And for some nachos.
Re: Powerdevil not identifying AC removal or plugin
« Reply #6 on: September 06, 2010, 08:03:29 PM »
Btw, just to help out a little.  Here's a command which might tell your laptop when you've unplugged your adapter:
Code: [Select]
ac_adapters="$(hal-find-by-capability --capability ac_adapter)"

# When you plug in, set the option for --bool to "true".  When you
# unplug the laptop, set the option to "false".
sudo hal-set-property --udi "$ac_adapters" --key ac_adapter.present --bool "<true|false>"
I use it after I unplug my laptop, or when I plug it in.  Hope it helps.
"She's the boss, apple sauce!"
 -Frank Cho

Offline dj_bridges

  • Hero Member
  • *****
  • Posts: 638
Re: Powerdevil not identifying AC removal or plugin
« Reply #7 on: January 17, 2011, 03:36:18 AM »
Been meaning to work on this problem, but have only just got round to it. Anyway for anyone who wants a script to constantly monitor for AC changes here is what I now use:

Code: [Select]
#! /bin/sh

# Script to check for the AC status and update Powerdevil accordingly
ac_adapters="$(hal-find-by-capability --capability ac_adapter)"
PREVIOUS="false" # Start with a value
N=1 #Spurious string to ensure while loop continues

while [ $N ]; do
    #Read in the state of the battery
    STATE=`cat /proc/acpi/ac_adapter/ADP0/state | sed s/.*://`
   
    #Convert on-line / off-line to true / false
    if [ $STATE = "on-line" ]; then
      BOOL="true"
      else
      BOOL="false"
    fi

    #Test whether the state has changed
    if [ "$BOOL" != "$PREVIOUS" ]; then
      sudo hal-set-property --udi "$ac_adapters" --key ac_adapter.present --bool "$BOOL"
    fi

    # REcord what the current state is to test on next cycle
    PREVIOUS=$BOOL

    #Sleep for 10 seconds until next round
    sleep 10
done

Then just make a link so that it autostarts on boot-up.

Hope this helps somebody. Thanks ertain for your sterling work to get this sorted.........
PCLinuxOS 2012 running KDE4 on Lenovo ThinkPad T420, Quad core Intel i5 @ 2.6GHz, 6Gb Ram, 400 Gb HDD

Offline Ertain

  • Sr. Member
  • ****
  • Posts: 365
  • I come in peace. And for some nachos.
Re: Powerdevil not identifying AC removal or plugin
« Reply #8 on: January 17, 2011, 12:31:29 PM »
The pleasure is all mine.

Now let's see if this solves the problem.
"She's the boss, apple sauce!"
 -Frank Cho