valr / cbatticon

A lightweight and fast battery icon that sits in your system tray
GNU General Public License v2.0
170 stars 40 forks source link

Thinkpad tp_smapi support - wrong status display #31

Open dglava opened 8 years ago

dglava commented 8 years ago

I'm experiencing some funky behaviour when using cbatticon with a Thinkpad (T410 in this case). It's mostly related to the battery status display. Occasionally I would notice that the icon and battery status aren't corresponding to their actual state. For example:

$ cbatticon -d
ac path: /sys/class/power_supply/AC
workaround: current rate is not available, estimating rate
battery path: /sys/class/power_supply/BAT0
battery present: 1
battery status: 1 - Unknown
ac online: 1
battery string: Battery is charging (49%)
tooltip: Battery is charging (49%)
icon name: battery-good-charging

It says that the battery is charging, while in fact it isn't. The tooltip and icon don't match. They're saying that the battery is discharging and showing the "battery-good-symbolic" icon, but the debug output says that it's charging and displaying the "battery-good-charging" icon. Both of those are wrong.

This has to do with the tp_smapi feature which sets a percentage at which the battery starts and stops charging. If the battery's charge is between those thresholds and the AC is plugged in, the laptop is powered via AC and the battery is "idle".

Cbatticon seems to query the /sys/class/power_supply/ data. For the case mentioned above, the status is indeed Unknown.

$ cat /sys/class/power_supply/BAT0/status 
Unknown

The tp_smapi module provides more precise data through the /sys/devices/platform/smapi/ filesystem. Querying that shows us the correct battery status: "idle".

cat /sys/devices/platform/smapi/BAT0/state 
idle

Would it be possible to utilize that information when the tp_smapi module is installed for Thinkpad laptops? If not, is there a way to fix this using a different approach?

valr commented 8 years ago

Interesting question. It's indeed not a standard behaviour at all. I'll have a look at the documentation you've provided (thanks for that) and see if the specific path /sys/devices/platform/smapi/ contains standard data, in which case it could be "as simple as" targetting the right path.

I'll let you know when I've done the analysis

dglava commented 7 years ago

Hi. Has there been any progress on this? I'm willing to help if you need any information or output from the Thinkpad tp_smapi filesystem.

Here's the information it exposes:

$ ls /sys/devices/platform/smapi
BAT0        power       driver      modalias    subsystem
BAT1        ac_connected    driver_override smapi_request   uevent

The most interesting data here is the ac_connected which tells if the AC is plugged in (1) or not (0) and the BATx directories which contain information about the batteries.

$ ls /sys/devices/platform/smapi/BAT0
barcoding     dump          last_full_capacit remaining_percent
charging_max_curr first_use_date    manufacture_date  remaining_running
charging_max_volt force_discharge   manufacturer      remaining_running
chemistry     group0_voltage    model         serial
current_avg   group1_voltage    power_avg         start_charge_thre
current_now   group2_voltage    power_now         state
cycle_count   group3_voltage    remaining_capacit stop_charge_thres
design_capacity   inhibit_charge_mi remaining_chargin temperature
design_voltage    installed     remaining_percent voltage