This forum has been archived. All content is frozen. Please use KDE Discuss instead.

tp_smapi, ye olde kthinkbat and battery info at the mo

Tags: None
(comma "," separated)
User avatar
toad
Global Moderator
Posts
1258
Karma
7
OS
Hi,

remember KDE 3's kthinkbat? It displayed all sorts of info about your battery. The current indicator gives one the percentage but not time remaining or anything else.

To the rescue tp_smapi (at least for thinkpad owners). Below a list of available info for your battery:

cat /sys/devices/platform/smapi/BAT0/installed
cat /sys/devices/platform/smapi/BAT0/state # idle/charging/discharging
cat /sys/devices/platform/smapi/BAT0/cycle_count
cat /sys/devices/platform/smapi/BAT0/current_now # instantaneous current
cat /sys/devices/platform/smapi/BAT0/current_avg # last minute average
cat /sys/devices/platform/smapi/BAT0/power_now # instantaneous power
cat /sys/devices/platform/smapi/BAT0/power_avg # last minute average
cat /sys/devices/platform/smapi/BAT0/last_full_capacity
cat /sys/devices/platform/smapi/BAT0/remaining_percent
cat /sys/devices/platform/smapi/BAT0/remaining_running_time
cat /sys/devices/platform/smapi/BAT0/remaining_charging_time
cat /sys/devices/platform/smapi/BAT0/remaining_capacity
cat /sys/devices/platform/smapi/BAT0/design_capacity
cat /sys/devices/platform/smapi/BAT0/voltage
cat /sys/devices/platform/smapi/BAT0/design_voltage
cat /sys/devices/platform/smapi/BAT0/manufacturer
cat /sys/devices/platform/smapi/BAT0/model
cat /sys/devices/platform/smapi/BAT0/barcoding
cat /sys/devices/platform/smapi/BAT0/chemistry
cat /sys/devices/platform/smapi/BAT0/serial
cat /sys/devices/platform/smapi/BAT0/manufacture_date
cat /sys/devices/platform/smapi/BAT0/first_use_date
cat /sys/devices/platform/smapi/BAT0/temperature # in milli-Celsius
cat /sys/devices/platform/smapi/ac_connected


Now the question - can this be incorporated into the current KDE power management?

I could of course simply make aliases and bang them into my .bashrc or even write a script listing the above, but I'd dearly love to just move the mouse over my battery indicator in the task bar and have this info come up.

Any pointers as to how?

PS.: Hope I'm in the right sub forum for this...

Thanks for your attention!


Debian testing
User avatar
david_edmundson
KDE Developer
Posts
359
Karma
1
OS
Would you really want all that information everytime you moused over the battery indicator? Sure, you might want to see the manufacturer and serial ID, but not /every/ time you mouse over the panel trying to see how much battery life you have left.

My suggestion: maybe this should be a seperate window in the system settings panel?

Also have a look and see how much of that information is presented over DBUS (I think all of it). Look in the systembus in qdbusviewer.

If you come up with a design which is really usable whilst making it still easy to view the battery status in the battery indicator. I'll gladly give you some pointers coding it up.

Dave
User avatar
toad
Global Moderator
Posts
1258
Karma
7
OS
Cheers,

nope, not all of it, that would literally be a blinder ;) Better if there were a basic default set and people could then chop and change as they see fit (perhaps under the advanced tab in power management).

I was trying to avoid a separate anything really, be it a battery monitor or a window in the systemsettings panel as this is only info which goes on top of the existing power management...

Also have a look and see how much of that information is presented over DBUS (I think all of it). Look in the systembus in qdbusviewer.
Hm, I haven't found it, but then that thing is alien to me and I am not sure at all what it all means :P Sorry...

If you come up with a design which is really usable whilst making it still easy to view the battery status in the battery indicator. I'll gladly give you some pointers coding it up.


Okay, you move your mouse over the power management icon in the systray. Current behaviour: nothing happens
Proposed behaviour: remaining time to charge/discharge and current power consumption is displayed by default
To adjust what is displayed go into systemsettings - power management - new field on the left called "Mouse" or "Mouseover" or some such with one tab which displays all available settings but only the default ones are ticked.

Does that make sense?


Debian testing
User avatar
david_edmundson
KDE Developer
Posts
359
Karma
1
OS
Yep, I think we're fairly agreed. I'm all for the the extra panel in the power management of system settings (or perhaps kinfocenter), and personally I'd really like to see a few other things like "time remaining" when I mouse over the panel.

Updating the plasmoid, and editing systemsettings/kinfocenter are effectively two entirely separate pieces of code.

IMHO - we should delay putting in customisation of the plasmoid, to avoid trying to do too much at once.

Only a few features "power remaining" is exposed to the KDE's hardware library (solid) - not all of the features above.
We need to skip this and talk directly to HAL (via DBUS) because of this it's unlikely to be part of KDE SC as it won't work on Windows etc). However, We should still be able to come up with a cloned applet with more features that we can put on kde-apps/kde-look.

I've got a few other projects on the go, but I'll try and knock up some sort of demo:


Edit: Looks like all the information is presented across DBUS ok:
copy this code into a python shell.

import dbus
bus = dbus.SystemBus()
hal_manager_obj = bus.get_object("org.freedesktop.Hal","/org/freedesktop/Hal/Manager")
hal_manager = dbus.Interface(hal_manager_obj, "org.freedesktop.Hal.Manager")
batPath = hal_manager.FindDeviceByCapability("battery")
bat = bus.get_object("org.freedesktop.Hal", batPath[0])
bat.GetAllProperties(dbus_interface="org.freedesktop.Hal.Device")

I propose step1:

we start at a template Qt program - and covert the code above into C++/QtBus, and have it printing all the properties to standard out.
http://doc.qt.nokia.com/4.6//qtdbus.html . We can then move this code about later.

I'd probably use QtCreator to get an application started quickly. DBUS can be confusing at first - have a go, but don't worry if you don't get anywhere.
User avatar
toad
Global Moderator
Posts
1258
Karma
7
OS
Wow! Did as you suggested and it appears to be working :) See below:

Code: Select all
>>> bat.GetAllProperties(dbus_interface="org.freedesktop.Hal.Device")
dbus.Dictionary({dbus.String(u'battery.reporting.technology'): dbus.String(u'Li-ion', variant_level=1), dbus.String(u'info.category'): dbus.String(u'battery', variant_level=1), dbus.String(u'info.parent'): dbus.String(u'/org/freedesktop/Hal/devices/computer', variant_level=1), dbus.String(u'battery.charge_level.last_full'): dbus.Int32(48890, variant_level=1), dbus.String(u'battery.reporting.rate'): dbus.Int32(16305, variant_level=1), dbus.String(u'battery.charge_level.current'): dbus.Int32(34970, variant_level=1), dbus.String(u'battery.rechargeable.is_charging'): dbus.Boolean(False, variant_level=1), dbus.String(u'linux.subsystem'): dbus.String(u'power_supply', variant_level=1), dbus.String(u'battery.voltage.unit'): dbus.String(u'mV', variant_level=1), dbus.String(u'battery.charge_level.rate'): dbus.Int32(16305, variant_level=1), dbus.String(u'battery.type'): dbus.String(u'primary', variant_level=1), dbus.String(u'battery.charge_level.percentage'): dbus.Int32(71, variant_level=1), dbus.String(u'linux.sysfs_path'): dbus.String(u'/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A03:00/device:00/PNP0C09:00/PNP0C0A:00/power_supply/BAT0', variant_level=1), dbus.String(u'battery.charge_level.design'): dbus.Int32(71280, variant_level=1), dbus.String(u'battery.reporting.unit'): dbus.String(u'mWh', variant_level=1), dbus.String(u'battery.voltage.design'): dbus.Int32(11100, variant_level=1), dbus.String(u'battery.is_rechargeable'): dbus.Boolean(True, variant_level=1), dbus.String(u'battery.reporting.current'): dbus.Int32(34970, variant_level=1), dbus.String(u'info.subsystem'): dbus.String(u'power_supply', variant_level=1), dbus.String(u'battery.reporting.design'): dbus.Int32(71280, variant_level=1), dbus.String(u'linux.hotplug_type'): dbus.Int32(2, variant_level=1), dbus.String(u'battery.model'): dbus.String(u'IBM-COMPATIBLE', variant_level=1), dbus.String(u'battery.voltage.current'): dbus.Int32(11176, variant_level=1), dbus.String(u'battery.remaining_time'): dbus.Int32(7721, variant_level=1), dbus.String(u'battery.serial'): dbus.String(u' 7850', variant_level=1), dbus.String(u'info.udi'): dbus.String(u'/org/freedesktop/Hal/devices/computer_power_supply_battery_BAT0', variant_level=1), dbus.String(u'info.capabilities'): dbus.Array([dbus.String(u'battery')], signature=dbus.Signature('s'), variant_level=1), dbus.String(u'battery.technology'): dbus.String(u'lithium-ion', variant_level=1), dbus.String(u'battery.rechargeable.is_discharging'): dbus.Boolean(True, variant_level=1), dbus.String(u'info.product'): dbus.String(u'IBM-COMPATIBLE', variant_level=1), dbus.String(u'battery.present'): dbus.Boolean(True, variant_level=1), dbus.String(u'battery.reporting.last_full'): dbus.Int32(48890, variant_level=1), dbus.String(u'battery.vendor'): dbus.String(u'Tenry', variant_level=1)}, signature=dbus.Signature('sv'))


Your proposed step1 sounds as though we'd be creating an extra entry in systemsettings. So you don't like the idea of incorporating this info into the power management module? Would seem to be the natural kind of place for me, but in the end I don't really mind :)

Will install QTCreator but I am no programmer, no designer, no nothing IT, so bear with me...


Debian testing
User avatar
david_edmundson
KDE Developer
Posts
359
Karma
1
OS
Step 1 is just checking we can do it, and being able to have some code we can copy and paste into whatever we decide to edit.

It's far easier to modify some existing code if you know what you're going to modify it to, and know exactly how to extract various bits of information.

Now for explanation of what that python script did.

- Connect to the system bus
- query HAL to ask for a list of paths to all batteries
- query that path for all information

Step1.1 is just to reproduce the first 2 steps in Qt
The goal being to print a line that looks like '/org/freedesktop/Hal/devices/computer_power_supply_battery_BAT0'


Make sure you read the introduction to DBUS linked to last time.
For the first query:

service = "org.freedesktop.Hal"
path = "/org/freedesktop/Hal/Manager")
interface = "org.freedesktop.Hal.Manager"
method = "findAllDevicesByCapability"


As I said DBus code is rather confusing, so here's what I think the first step is.

in untested Qt:

Code: Select all
QDbusMessage getBatteryPathsMsg = QDbusMessage::createMethodCall(service,path,interface,method);
QDbusMessage reply = QDbusConnection::systemBus().call(getBatteryPathsMsg);

//probably worth printing more stuff from the reply (such as type, and if needs be "error")
qDebug() << reply.member();
qDebug() << reply.arguments();

User avatar
toad
Global Moderator
Posts
1258
Karma
7
OS
Thank you very much for your help, but it is not enough for me or rather I haven't got the foggiest what I am supposed to do to dbus code, qt and qtcreator. It is little more than complete and utter gobbledegook ???

So, I've tried and failed. Instead I wrote myself a little script (well, little more than a bunch of echo commands) and put an alias in my .bashrc so I have detailed battery info at my disposal. Not as easy as moving the battery over the power manager, but at least I was able to do it :)

It'd be great to see this function at some stage in the future, but sadly I am no programmer (gimme literature, but not code!).

Cheers and many thanks - croak.


Debian testing
User avatar
david_edmundson
KDE Developer
Posts
359
Karma
1
OS
No worries. Thanks for at least having a go.

If I find time to make a better battery applet, would you be a tester for me?
User avatar
toad
Global Moderator
Posts
1258
Karma
7
OS
yepyepyepyepyep :D


Debian testing


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]