Active Topics

 


Reply
Thread Tools
solca's Avatar
Posts: 109 | Thanked: 196 times | Joined on Sep 2008 @ Guatemala
#41
Originally Posted by BrentDC View Post
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...
__________________
NITdroid
 
BrentDC's Avatar
Posts: 903 | Thanked: 632 times | Joined on Apr 2008
#42
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).
 
Posts: 1,224 | Thanked: 1,763 times | Joined on Jul 2007
#43
Originally Posted by solca View Post
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.
 

The Following 2 Users Say Thank You to Matan For This Useful Post:
solca's Avatar
Posts: 109 | Thanked: 196 times | Joined on Sep 2008 @ Guatemala
#44
Originally Posted by Matan View Post
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!

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!
__________________
NITdroid
 
ciroip's Avatar
Posts: 334 | Thanked: 366 times | Joined on Nov 2008 @ Italy
#45
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?
__________________
I can't do it. No one can help.
[SIGPIC][/SIGPIC]

Flip Alarm Clock - 3DMania Theme - Synesthesia - Deluxepain
http://ciroip.blogspot.com/
http://twitter.com/ciroippolito
 
BrentDC's Avatar
Posts: 903 | Thanked: 632 times | Joined on Apr 2008
#46
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).
 

The Following User Says Thank You to BrentDC For This Useful Post:
ciroip's Avatar
Posts: 334 | Thanked: 366 times | Joined on Nov 2008 @ Italy
#47
Originally Posted by BrentDC View Post
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 )
__________________
I can't do it. No one can help.
[SIGPIC][/SIGPIC]

Flip Alarm Clock - 3DMania Theme - Synesthesia - Deluxepain
http://ciroip.blogspot.com/
http://twitter.com/ciroippolito
 
BrentDC's Avatar
Posts: 903 | Thanked: 632 times | Joined on Apr 2008
#48
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.
 

The Following User Says Thank You to BrentDC For This Useful Post:
BrentDC's Avatar
Posts: 903 | Thanked: 632 times | Joined on Apr 2008
#49
Ok, I dug up my python code and here it is. I couldn't find my newest version of it, though 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.
Attached Files
File Type: gz check_retu.tar.gz (3.2 KB, 146 views)

Last edited by BrentDC; 2009-01-29 at 04:33.
 

The Following User Says Thank You to BrentDC For This Useful Post:
Posts: 1,224 | Thanked: 1,763 times | Joined on Jul 2007
#50
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)
 
Reply


 
Forum Jump


All times are GMT. The time now is 07:35.