maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   OS2008 / Maemo 4 / Chinook - Diablo (https://talk.maemo.org/forumdisplay.php?f=29)
-   -   N800 Battery Meter (https://talk.maemo.org/showthread.php?t=7590)

solca 2009-01-23 03:04

Re: N800 Battery Meter
 
Quote:

Originally Posted by BrentDC (Post 259425)
Hey solca. I was working on a program to read retu data and estimate battery level (this was in Maemo/Hildon, not Android). It used a battery level history file to predict how much % was left. It was extremely volitile for the reasons you mention. I figured that some "smoothing" was needed to make it more accurate, but the only way to do this is to know the current battery draw, but was unable to retrieve this data from the system (it is possible though, because an application called "Field Test Display"* can read it).

BTW, you can catch charging/discharging events via dbus, though I couldn't quite figure out how to do it.

*=With the bme plugin.

Does that "Field Test Display" read it from dbus?

No, I would like to query AC plugs/unplugs events by reading from somewhere (/dev/retu) but no luck so far...

BrentDC 2009-01-23 04:38

Re: N800 Battery Meter
 
I have no idea what it read it from; I could only find a .deb and not the source. I found out who the maintainer was (someone at Nokia), and thought about sending an email, but never did.

Here it is: http://timeless.justdave.net/reposit...pdates/diablo/

(you need to install both the ftd* files to get info on the battery).

Matan 2009-01-23 12:42

Re: N800 Battery Meter
 
Quote:

Originally Posted by solca (Post 259410)
Hi KotCzarny!
And do you know where to obtain if AC is plugged or not?

You can tell if AC is connected by reading ADC number 3. I believe it shows input voltage level (or something similar). It appears to give three levels:

0 - No power source connected

about 0x100 - power source connected, charging

about 0x170 - power source connected, not charging.

If it is indeed showing input voltage level, then the reading will depend on charger used. A well regulated source will give the same level, whether charging or not.

solca 2009-01-27 09:43

Re: N800 Battery Meter
 
Quote:

Originally Posted by Matan (Post 259465)
You can tell if AC is connected by reading ADC number 3. I believe it shows input voltage level (or something similar). It appears to give three levels:

0 - No power source connected

about 0x100 - power source connected, charging

about 0x170 - power source connected, not charging.

If it is indeed showing input voltage level, then the reading will depend on charger used. A well regulated source will give the same level, whether charging or not.

Exactly as you describe it! :D

Now I can detect AC plug/unplug and batt full which is a huge improvement for battery metering in NITdroid. Before this I was relying on very imprecise heuristics based on register #8 which is completely erratic (or misunderstood). Thx!

I was wondering if you know what the other registers means?

@Nokia: it's time to release the RETU/TAHVO ASICs documentation! :rolleyes:

ciroip 2009-01-28 21:27

Re: N800 Battery Meter
 
Im testing various way to check the battery status for a python application. Using the dbus make the tablet 'fart' everytime I check the level if the charger is connected. I really like the idea to read directly the os values using kcbatt (and having some alternative values to compare to the usual dbus based programs) but it seem only works if the app is 'root'
Any idea how solve?
https://garage.maemo.org/frs/downloa...hot_kcbatt.jpg

BrentDC 2009-01-29 02:30

Re: N800 Battery Meter
 
I don't know of any way to read retu as user...

My Python program just used "subprocess.Popen('sudo ./retu-adc', shell=True)" to read it. It doesn't really do anything new...but at least you don't need to actually run the whole program as root (but you need the proper software installed to enable sudo to do that).

ciroip 2009-01-29 03:32

Re: N800 Battery Meter
 
Quote:

Originally Posted by BrentDC (Post 260682)
I don't know of any way to read retu as user...

My Python program just used "subprocess.Popen('sudo ./retu-adc', shell=True)" ....

a thousand way to reach the same result :) .
The point is that for that clock the battery check is just an 'extra feature' and if Ill not able to figure out a decent way to read that values Ill probably decide to remove all that part. thank you for the hint anyway, Seem to remeber I tried to read the retu directly from python but probably doing something wrong (Im not a programmer at all :( )

BrentDC 2009-01-29 04:15

Re: N800 Battery Meter
 
Just get yourself Matan's retu-adc program and it is pretty easy to check... BTW, I'm not much of a programmer either :) I just know a little Python and trial and error usually results in the desired effect. :)

BrentDC 2009-01-29 04:28

Re: N800 Battery Meter
 
1 Attachment(s)
Ok, I dug up my python code and here it is. I couldn't find my newest version of it, though :confused: I have no idea where it went...

Code:

#!/bin/env python

# Copyright (C) 2009, Brent Chiodo

import commands
import time
import dbus, dbus.service

def average(list):
        total = 0
        count = 0

        for each in list:
                count = count + 1
                total = total + float(each)
        return total / count

date_stamp = commands.getoutput('date +"%-m-%-d-%-Y"' + '.csv')
cycle = 0
battery_log = []

commands.getoutput("mkdir pybattery_logs/")

while(cycle < 480):

  add_time = commands.getoutput('date +"%l:%M %p"')
  battery_level = commands.getoutput('sudo ./check_retu 8 9')
  battery_log.append(battery_level)

  if len(battery_log) > 120:
      del battery_log[0]

  logfile = open('pybattery_logs/' + date_stamp, 'a')
  logfile.write('"%s","%s"\n' % (add_time, battery_level))
  logfile.close()

  if len(battery_log) < 11:
      battery_average = average(battery_log)

  else:
      battery_average = average(battery_log[-10:-1])

  if ((battery_average - 300) / 200 > 1):
      print "Battery: 100%"

  else:
      print "Battery: %.1f%s" % ((((battery_average - 300) / 200) * 100), '%')

  cycle + 1

  print battery_log[-1]

  time.sleep(60)

check_retu is a hacked version of Matan's retu-adc. It is attached.

This program basically just polls the retu every minute and writes it to a log file. It then uses that data to calculate (albeit completely unrefined) the battery level. Feel free to use this code :)

Edit: The forum messed up th indenting. You'll need to fix it.

Matan 2009-01-29 12:13

Re: N800 Battery Meter
 
If you want to access retu as a user, just run

chmod a+rw /dev/retu

(You need to run this every time you boot).


About using the info from python scripts - you can use ioctls directly from python, there is no need to use retu-adc program or variant.

Something like:

import fcntl
f = open("/dev/retu")
adc8 = fcntl.ioctl(f, 0x6003, 8)

Matan 2009-01-29 12:22

Re: N800 Battery Meter
 
Quote:

Originally Posted by solca (Post 260134)
@Nokia: it's time to release the RETU/TAHVO ASICs documentation! :rolleyes:


Extremely unlikely - those chips are used in many Nokia phones, not only in the tablets. Furthermore - those are probably generic GPIO/ADC/RTC/etc. devices. The real question is what is connected to which GPIOs, ADC ports, and how.

ciroip 2009-01-29 20:33

Re: N800 Battery Meter
 
Quote:

Originally Posted by Matan (Post 260764)
If you want to access retu as a user, just run

chmod a+rw /dev/retu

(You need to run this every time you boot).


About using the info from python scripts - you can use ioctls directly from python, there is no need to use retu-adc program or variant.

Something like:

import fcntl
f = open("/dev/retu")
adc8 = fcntl.ioctl(f, 0x6003, 8)

Ill reserve to 'thankyou' for when (and if) I will understand what you are actually saying :)

Lord Raiden 2009-03-23 19:13

Re: N800 Battery Meter
 
I for one would like to toss my hat into the ring and say that a battery meter with colored text denoting battery remaining would be best. It's "sorta" done that way already in regular Linux, but I'd like to see it that way in the NITS too. IE, it's green text until it hits 25%, yellow until it hits 10%, and red the rest of the way down. Then when you click on the text, it can say "estimated" run time and idle time.

zanne 2009-06-03 16:45

Re: N800 Battery Meter
 
sorry if this can be considered cross-posting, but i don't know which is the more appropriate thread for my questions...

bye bye

zanne 2009-06-04 11:55

Re: N800 Battery Meter
 
solution found :-)

but the meter seems to be not very accurate:
Code:

Nokia-N810-23-14:/home/user# ./kcbatt -q   
98
Nokia-N810-23-14:/home/user# ./kcbatt -q
99
Nokia-N810-23-14:/home/user# ./kcbatt -q
99
Nokia-N810-23-14:/home/user# ./kcbatt -q
98

is it normal?

(btw, for who doesn't know, "-q" option shows the % value of the battery)

tia.

bye bye

zanne 2009-06-04 16:22

Re: N800 Battery Meter
 
1 Attachment(s)
after a lot of frustration, i found out that one guy in my department wrote a program that (in the middle of other operations) checks the battery level of the nokia N810 devices; is written in C++ and uses dbus library that asks to hal, so i think that is also valid for N770 and N800.

after a few modifications i'm now able to check correctly the status of the battery! :D

in attached you can find the source code, with the hope that it will be helpful to someone.

bye bye


All times are GMT. The time now is 16:59.

vBulletin® Version 3.8.8