yashsingh1/xdaforums huggingface dataset:
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
I am uploading a corrected attempt #4 (4a) that should fix the problem where a battery seems to stick at some high percentage and never gets to 100%.

I have been trying to get the driver to do a coarse calibration at startup, only if it detects the ds2746 has been reset, to help adjust the meter when we switch batteries. I spent the weekend recording charge and discharge logs for my new battery, and reduced the data to a set of equations that relate voltage and current to level. With the same battery, it can guess a level plus or minus 10%. But when I try with my old battery, it is like 50% off. So I think that approach cannot work very well.

For the initrd solution, I'm thinking of a menu "Adjust battery level" with a sub-menu "10% 20% 30% 40% 50% ... 100%". When you select a level, the script writes to /proc or /sys filesystem (same place as you can write battery_capacity). I can update the battery code to check the value, and adjust accordingly. An additional script in /system/bin could do the same from command line, if anyone wants to tweak the battery level without rebooting.
[Tilt, TyTN II, MDA Vario III Android Development] l1q1d:
I'm looking for a more automatic solution but i need to exec the script on shutdown. My idea is:

:start

power on

recover info by initrd

normal use

shutdown -> save on /data or /sd

on power go to :start

The menu would be a good idea but i think i can write a simple android app instead.
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Just remember the use case of swapping batteries.

We can tell when the phone lost power (as it will when you swap batteries) by looking at the ds2746 status register.
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Attempt #5: added coarse synchronization at boot

Attempt #5 adds radical changes:

adds a very crude coarse synchronization at boot under two conditions:

1) If the ds2746 status register says that it has been reset,

The battery level is set based on voltage and current.

2) If the parameter "haret_divisor" is not zero,

The units are scaled by 1000 / haret_divisor, then haret_divisor is reset to 0.

#1 is a poor attempt to handle the situation where someone has two batteries and swaps them. I found myself doing that after buying my new battery.

#2 is an equally poor attempt to handle something I cannot explain. WinMo seems to scale the battery units by somewhere between 2 and 2.4x what they are in Android/Linux. Since I can't yet figure out why or how it happens, I added a way we can convert back to the units we like when running Android under Haret.

Add this parameter to your default.txt file:

board-kaiser-battery.battery_capacity=1350 (your actual battery capacity)

board-kaiser-battery.haret_divisor=2200 (a guess: 2000 ... 2400 seem close)

Also, attempt #5 goes back to the averaging method used in attempts #1 and #2, except that the math has been corrected.

This is a test/debug version, not recommended for wide distribution, but for developers. It is, in particular, not tested yet on Polaris. If the feedback is positive, I will still want to clean up the code a bit. I think the formulas need improvement for a very weak battery that is being charged.
[Tilt, TyTN II, MDA Vario III Android Development] spaic:
any test release for the SD install?

For now I am using the test 2 with a froyo 2.2 (the one in your sig)

As an observation, I have been having locks (some kind of "sleep of death").

I a using froyo 2.2, OS monitor and battery dog (to get nice battery graphs), with test 2 of this battery fix kernel, install os SD(haret).
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
I could never get the 2.6.32 kernel to work with haret. When I use haret, I have always been using the older kernel.

For Haret, use the zImage in battery-test-5-2.6.25.zip,

and put this into default.txt:

board-kaiser-battery.battery_capacity=1350 (or whatever you have)

board-kaiser-battery.haret_divisor=2200

Of course you'll need the modules to match the kernel version (like wlan.ko and ramzswap.ko and company). Do you need me to put up an androidupdate.tar with those?

EDIT: When rebooting from Android to WinMo, always pull out the battery! Otherwise, WinMo will think the battery is very low.
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Cleaned up first post to reflect what I have learned.

I think attempt 4a is decent, and attempt 5 actually has the potential of being very good, with a little refinement. Please let me know what you think.

I'd especially like to hear from Polaris users, since I only have Kaiser.
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Updated first post, give it a try.

I don't know about locks. It is very stable for me, except for one very reproducible lock. When I am connected with adb, then put my computer to sleep, the phone locks, probably waiting for adb.
[Tilt, TyTN II, MDA Vario III Android Development] MathijsNL:
Guys, this info might help.

Back in the days i used winmo, and using it for work (gps), my battery drained every saturday till the phone would go out. After getting the battery out and in again, i would get a 30% reading on my battery. This way i could use my phone for 1-2 ho.urs (with gps use).

My point of saying this is because some people say/think that winmo sho.ws a correct battery level, but apperently (in my case) winmo also had it wrong sometimes... just saying this to prevent tbhinking flaws :)
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Agreed. That happens with a good battery, where the actual mAh might slightly exceed the rated mAh. On the other hand, with an older battery, I was always seeing jumps in WinMo, just like in Android.

WinMo calibrates with voltage when the ds2746 has been reset, when voltage is high, current is positive but under 60mA, and also when voltage is low. But WinMo also shuts off the device if it thinks the battery level is too low. I think maybe the Polaris does that in Android, but Kaiser does not shut down until voltage drops to 3V.

WinMo's battery meter isn't perfect, but it is a model of how we can do things. I don't think it is possible to get much better than what I have in attempt #5. I have re-collected charging data and will reduce it to a set of equations today. That will improve the coarse calibration when charging with a very low battery.

I will also add a dmesg indicator of how many mAh the kernel thinks your battery really has. It won't use that number in calculations, but will provide it for your information, so you can re-adjust your battery_capacity parameter.

Also, I am considering changing the usage of battery_capacity parameter to match what nbh_editor / atools produce without using the advanced entry.

Other than that, I think I'm finished. Except for temperature.
[Tilt, TyTN II, MDA Vario III Android Development] elander:
Hi again, is it possible to use attemp #5 (kernel ver. 2.6.25) with myn´s warm donut, as I like that android build better than froyo, and if so, would I need to use the modules you put up or I could just use the ones on the myn´s donut thread? thanks a million.!!
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Should be able to edit with nbh-editor to donut, and use 2.6.25 with Myn's modules. I just put the modules there in case you want to run a different version kernel from what the android build was made for.
[Tilt, TyTN II, MDA Vario III Android Development] highcoder:
@Elander:

Yes you can use it with Myn´s Warm Donut. But you should remove the "builtin" Battery fix inside the androidinstall.tar. You have to delete the following codelines in sysinit.rc:

#battery patch
chmod 777 /sys/module/board_kaiser_battery/parameters/battery_capacity
write /sys/module/board_kaiser_battery/parameters/battery_capacity 2000

otherwise your capacity-modification that you do with the NBH-Editor has NO effect so your battery has always 2000mAh.
[Tilt, TyTN II, MDA Vario III Android Development] illegal2008:
i'm flashed 2.6.25 from attempt 5 but can't boot-only black screen?Any ideas?
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
HaRET or NAND? If HaRET, what default.txt?
[Tilt, TyTN II, MDA Vario III Android Development] illegal2008:
nand with KAISIMG-PANEL2-320-TILT1-FROYO.NBH from attempt 5

with atool I selected DONUT, panel 2, normal keyboard, advanced battery 1350
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
I don't know, that should work.

I'll try it tonight.
[Tilt, TyTN II, MDA Vario III Android Development] illegal2008:
realy strange.now i'm booting Donut with kaisimg-panel2-320-tilt-eclair-02-07-10.nbh -no problem
[Tilt, TyTN II, MDA Vario III Android Development] elander:
thanks for the hint, but I can't find that piece of code in the sysinit.rc, (I opened the androidinstall.rar and opened the sysini.rc with notepad and did a search but couldn't find it) so does that means that what I have installed does not have those codelines therefore I can go ahead and install this nbh with no worries? thanks in advance.
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Sorry, I see the same. It looks like the current tinboot doesn't build NBH for 2.6.25, or I don't know how to use it.

I used nbhcreator, and it seems to work better. At least I get to the install menu.

However, with Donut I get another error further on. Froyo seems to work.
[Tilt, TyTN II, MDA Vario III Android Development] elander:
I have the same problem, will try 2.6.32
[Tilt, TyTN II, MDA Vario III Android Development] rcperez:
heat/0 volts

just got my battery battered by android, since it totally drained it and heated it at the same time now my battery is dying out on me, cant make a call, cant go online, cant do videos.

As we all no Lipoly batteries are very sensitive to heat, pressure and draining it more than 5% is a big no no.

Oh well off to a new replacement battery.
[Tilt, TyTN II, MDA Vario III Android Development] spaic:
I switched to flash... and on my first attempt I tried kernel 2.6.25, had the same problem with the black screen.

Switched to kernel 2.6.32 and it worked.

I used froyo, panel 1, overclock>500, nordic keyboard, advanced battery 1350.

The rest of my setup is in my sig, updated.
[Tilt, TyTN II, MDA Vario III Android Development] illegal2008:
any way to get Donut working with attempt 5?
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Please l1q1d can you build your older kernel with my attempts 4b and 5 and post them here? Also please PM me or post what I can do to build it myself. The tools I use for 2.6.32 don't make good NBH for old kernel. :-(

By the way I am testing attempt 6. I want it to be good for general release so am taking my time, but it is based on attempt 5.
[Tilt, TyTN II, MDA Vario III Android Development] l1q1d:
I release all files tomorrow, i'm busy with nand problems now
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Seeking Opinion

The editing tools nbh-editor and atools multiply the mAh by 1.6, but I think that it works better without doing that. Coincidentally or maybe not, in the code we see that battery_capacity * 1.6 = ds2746 units. So, if you have a 1350 mAh battery, the editor turns battery_capacity into 2160, which is 3456 units. To my experience, that setting makes the battery meter jump around a lot.

So, the choices are:

a) leave things as they are.

b) convince Loserskater and l1q1d to remove the scale factor from the editors.

c) change the code so that battery_capacity is in ds2746 units.

I think (c) might be good because it decreases some of the math.
[Tilt, TyTN II, MDA Vario III Android Development] l1q1d:
It's not a big problem to change it but we lose backword compatibility and i don't like it much

All new release files

http://androidhtc.git.sourceforge.net/git/gitweb.cgi?p=androidhtc/kernel-release.git;a=shortlog
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
So you don't like choice (b). How about (c), where the editors do the 1.6 conversion, but the kernel doesn't? I think that is the best. It keeps the editors unchanged, and might reduce the "units" versus "mAh" confusion for new people.
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Attempt #6: Release Candidate

I have been using this for a couple of days and I really like it.

Major changes:

1) More accurate coarse calibration data when charging.

2) Use battery_capacity as dmesg units without conversion since nbh-editor already applies the conversion.

3) Calculate and display an adjusted battery_capacity value reflecting the calibrations the kernel has done since boot. The adjusted value is NOT used to calculate battery level, it is only a suggestion to the user.

4) More parameters in /sys/module/board_kaiser_battery/parameters:

* battery_capacity: the number of units in 100% charged battery (existing)

* adjusted_capacity: kernel's re-adjusted battery capacity (new)

* haret_divisor: multiplies units by 1000/(haret_divisor). Put "2200" in your default.txt file, or experiment if that doesn't seem right. (since #5)

* set_percentage: sets the battery level to the percentage specified. Can be put into a boot script.

I have only uploaded a 2.6.32 version since I don't seem to know how to make NBH files for 2.6.25. Sorry!

EDIT: Also using a tweak of l1q1d's last board-kaiser-keypad.c edit, so the backlight is on whenever the keyboard is open and lighting is low. Since I only open the keyboard when I am using it, I like it that way. Maybe you won't.
[Tilt, TyTN II, MDA Vario III Android Development] scooter1556:
Great job n2jrt, so to clarify, with the latest attempt #6 you still need to use nbh editor but you set the simple settings to 1350 as with previous kernels from dzo? Also, does your latest kernel include l1q1d's NAND fixes?? Thanks again :-)
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
The default is already right for1350 mAh.

It includes the latest NAND stuff at the time I built the kernel.

Note that after I built the kernel and posted, l1q1d checked in another NAND fix. Also, attempt #6 is in the standard kernel repository now (Thanks l1q1d).

If anyone has problems with this new code, please post and I'll look at it.
[Tilt, TyTN II, MDA Vario III Android Development] elander:
So when you say "the default is already right for 1350mah" do you mean that attempt #6 does not need to be edited with atools in order to put 1350mah. In advance setting? We can just download it, change panel and keyboard if neccesary and flash it as it is?
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Correct. You don't have to change the battery capacity with nbh-editor if you have a 1350 mAh battery.

I don't remember when I changed the default, but it was one of the early attempts.

Did anyone else have trouble finding this thread today? It got moved to HTC Sapphire somehow.
[Tilt, TyTN II, MDA Vario III Android Development] scooter1556:
Cheers n2jrt, yea, the Kaiser forum was totally f***ed yesterday, i thought for a minute we might have lost posts again but thankfully not. I take it the default of 1350 has been commited to git also? I'm gonna have a go at compiling it now and see what i get. Thanks again for all your efforts.
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Slight cleanup of attempt #6:

Please l1q1d can you PM me how I might be able to update the git repository myself? I have a minor cleanup of the source file that I would like to commit. I tried, using my sourceforge account, but apparently that is not sufficient.

The file is attached to this message. It fixes a minor issue (actually a nasty bug with no apparent side effects): when I write the updated status register, it is one byte, but the write function always pushes two bytes MSB first. So, only the MSB gets written to the status register and that is always zero. It has the desired effect of clearing the PORF bit, but also clears some other bits that I didn't intend.

I didn't make "attempt 6a" since the bug has no effect that I can tell. Still I want it cleaned up. Can you please update the repository with this file, and PM me how I might go about getting permission? Thanks!

Also the 2.6.25 branch should probably get updated as well.
[Tilt, TyTN II, MDA Vario III Android Development] elander:
Hello n2rjt, I´m using attempt # 6 2.6.32 (I didn´t edit the battery settings on atools, just the panel to 2 and keyboard as tilt) and I´m having issues with sleep, when I plug it to charge it I push the power button to put it to sleep but it can be awaken by any button so it´s like its not sleeping just the screen is off (I have been having this issue since attempt #3 or so I guess) but now in attempt # 6 it´s been worse since :

A- it won´t sleep for real even when not connected to a charger(i.e I can wake it up by pushing any button.)

B- it will discharge REALLY fast, (maybe cuz it doesn´t sleep)and also jumped once from 40% or something,although it later after charged when down past that number.

C- it has lit the green led as when finished charging even though dmesg says 200mah+ current(when this happens I just let it be till it gets to 0mah current or something).

D- its telling me i have 2663/2700 units and something like 2548 adjusted and 98%

A and B maybe a problem with my panel type(I don´t know maybe I´m on panel 2 when it should be 3 and the mismatch gives me sleeping troubles).

C and D maybe related to my "noobness" as it is problably working the way you intended it to and I just don´t get it, if that´s the case please ignore C and D and feel free to virtually (not physically) slap me in the face for being a noob, lo. thanks in advance.!!

P.S: I´m not trying to say attempt 6 is broken or something as I´m aware that each Kaiser (along with every battery) will respond slighty different to it, I just want to give you some feedback on this and get advice on how to solve this if it is a individual issue I´m having.
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Something is recently wrong in the kernel. The highpower drain and insomnia are issues that I also see. I don't see a way they would be related to battery meter code. I guess to be sure I should try a build of the original battery code with all else being modern.

For the others, I think perhaps something in your startup code in android is setting battery_capacity to 2700 when it should be 1350*1.6. I see that the adjusted units are much closer to correct. When the capacity is set too high, the meter will jump.
[Tilt, TyTN II, MDA Vario III Android Development] elander:
So should I try to set 1350 mah in advance as I did before? (by the way i´m using warbyte donut repack which he claims to be free from any code related to battery as opossed to myns warm donut which has a battery patch that sets it to 2000mah) so I guess i´m about to flash my kaiser again, Jeje. thanks for your help!.
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Set the capacity but not using the advanced entry, the standard one where it asks for the rated capacity in mAh.
[Tilt, TyTN II, MDA Vario III Android Development] shanbh:
n2rjt

Thank you for your work! Now i don't need to install the same system every two or three days, since used your attemp 5 and 6 week' ago!!!
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Thanks to l1q1d for fixing the nand! I just used what he checked in.
[Tilt, TyTN II, MDA Vario III Android Development] giannihsd:
NAND...

where I can find the latest patched nand flash that solve the drain battery problems?

Thank's
[Tilt, TyTN II, MDA Vario III Android Development] illegal2008:
Yes,many thanks for working nand!
[Tilt, TyTN II, MDA Vario III Android Development] spaic:
Banged up battery

I have a totally banged up battery.

If I find a correct capacity (let's say it has reached 50% of the nominal), will the kernel module "correct" it?

Usually I leave the phone to charge over night, and i think it gets a little messed up somehow, because I cannot have the battery smoothly discharge to zero.

I know it is a bettery issue mainly, as the voltage drops heavily on heavy use, but I was hoping for an improvement on the meter.

I will post a discharge log soon.

(maybe I shoud buy a new battery also...)
[Tilt, TyTN II, MDA Vario III Android Development] daedric:
Same here... from 4200 mV to 3200 in less than a minute...

To make matters worse... unpluggedit lasts what... 10 min and then... endless reboot... until pluged again.

Sent from my Full Android running on my Kaiser
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
I think these batteries only last about a year, at least with Android.

A Li-Ion battery is good for about 300 charge cycles.

We take a charge cycle daily (at least!)

Having said that, I have one bad old battery and have done a lot of testing with it.

If you start with it empty, take out the battery, put it in, plug in to charger, start with the latest kernel, then let it charge to full, look at the adjusted units in the dmesg log. That is what you should set your battery_capacity to.

Don't do that if you have two batteries: it's probably best to set battery_capacity based on your best battery or the battery you most often use, not your old worn-out spare.

With my old battery, the adjusted units get to 900. That's about 560 mAh, from a 1600 mAh battery. Each time I have tested the old battery it has lower capacity. Almost time to recycle it, but today I keep it charged as an emergency spare.

The adjusted capacity measurement isn't perfect; it's only good for one charge cycle right now, and becomes inaccurate after that. I have a fix that will make it accurate for more than one cycle. If it ever gets to be accurate enough, I'll start using it instead of battery_capacity in the level calculations. Until then, if you have two wildly different batteries, you have to tune your kernel to one of them.
[Tilt, TyTN II, MDA Vario III Android Development] -Arturo-:
n2rjt I have some problems with the battery readings. I'm using the latest kernel with your battery script. I flashed the kernel a few days ago and indeed the meter shows that battery goes down by 1% but something is wrong as the juice runs out too fast(at least that's what the meter shows) I made a small test to see when will the phone switches itself off so I started with 100% after about 3 hours of medium usage the battery showed 1%. Now here's the funny thing the phone has been running for over 30 minutes on full brightnss with both wifi and bluetooth on since it hit 1%. Actually it is still on. Currently in OSMonitor I have these readings 3542mV -480 mA charge 1% (0/2160 units, 2160 adjusted). I've used A tools but only to change panel type I didn't touch the battery settings.

Since my battery is almost three years old(original) I'm going to follow the steps in quoted text to calibrate it correctly unless you have other ideas?

Thanks
[Tilt, TyTN II, MDA Vario III Android Development] n2rjt:
Arturo, that is very interesting.

What kind of phone do you have? Kaiser? Polaris?

What capacity battery? 1350 mAh I assume since you said original.

Are you using HaRET or NAND?

Also, did you leave the phone on the charger, or unplug it when it hit 100%?
[Tilt, TyTN II, MDA Vario III Android Development] -Arturo-:
Ok N2rjt before I answer the question I just want to report that after following the steps for calibrating meter for old batteries, OS monitor showed me 2512 units - adjusted.

It's a Kaiser with stock 1350 mah samsung battery. I'm on nand with data on ext2 partition.

About the last question ..I probably left it charging for a while after it hit 100%.

So now I should put 2512 under advanced settings in a- tools right?

Also that unit number - 2512 what would that be in mah?

Thanks.

Also I've noticed that battery charges really fast up to 100% and then slows down significantly.
[Tilt, TyTN II, MDA Vario III Android Development] elander:
n2rjt, I've tried to pm you a couple of times but I don't know if there's something wrong with my account or what, did you recieved any of them? I have an idea that may or may not be helpful, and I would like to know what do you think of it.