[MOD][KERNEL] Battery Life eXtender (BLX)

Search This thread

Ezekeel

Retired Recognized Developer
Jun 21, 2011
715
1,680
Older types of rechargable batteries exhibited a 'memory effect' which made it neccessary to completely charge/discharge the battery when using to prevent degradation of the capacity. Modern Lithium-Ion batteries like in the Nexus S do not show this problem and thus it is not necessary to use the battery in complete (dis)charge cycles. In fact on the contrary, it is commonly accepted that both very low and very high charge states accelerate the degradation of the battery capacity (that is why you should store Li-Ion batteries at around 40% charge).

While a low charge state can be simply avoided by charging the device more often, the battery in the Nexus S by default is charged to around 95% capacity and I could not find any app or tweak to stop the charging at a lower capacity. Thus the only way was to use the manual override and pull the cable which is annoying since one had to monitor the charge state.

So I implemented a simple tweak I called Battery Life eXtender (BLX) which can be used to set a limit for the capacity to which the battery will be charged by passing a value between 0 and 101 to 'charging_limit' in '/sys/class/misc/batterylifeextender' (101 by default).


Changes to the source code: http://www.pastie.org/2516542


BUGFIX:

The battery status is set to 'full' once the user defined charging limit is reached.

Bug fix: http://www.pastie.org/2534319


BUGFIX #2:

The charging limit is set to 96 by default which will mimic the behaviour of the stock kernel. Also, the maximum value accepted by 'charging_limit' is set to 96.

Bug fix: http://www.pastie.org/2560599


BUGFIX #3:

1. Made BLX compatible with the 100% charging 'fix'.
2. If the charging limit is set to the maximum charging limit, charging will not be stopped until the interrupt signal is received from the MAX8998 chip.

Bugfix: http://www.pastie.org/2751140


No further patches will be published here. I have set up a git repo for all my tweaks. Each mod has its own branch to keep the tweaks cleanly separated and one can simply pull the latest patches from the corresponding branch.

https://github.com/Ezekeel/GLaDOS-nexus-s/tree/blx



I do not accept donations and since I reached my 50GB limit of free space on SpiderOak, thanks to all of you kind people who got an account using my referral link, I could not ask for more.
Instead if you really want to donate your hard earned money to someone who deserves and needs it, consider donating to the Free Software Foundation at fsf.org: These guys are at the frontline when it comes to keeping Linux free and fighting these greedy bastards who think they are entitled to collect royalties and other fees from Linux users due to some silly patents - and if Linux falls, Android will be next.
 
Last edited:

Ezekeel

Retired Recognized Developer
Jun 21, 2011
715
1,680
i charge my ns to 100% all the time, i wish that i could charge it even more. lol!

Yeah, the drawback of course is the shorter battery runtime. If even a fully charged battery still is not enough for you to get over the day, this tweak is not for you. However, I mostly use the Nexus for internet, email and music and for me a fully charged battery last for about 3 days. So in my case when setting the charging limit to let's say 80% that is still plenty of reserves.

Before I wrote this tweak I thought about if it actually makes sense to try and prolong the lifetime of these batteries because they can be easily replaced and are also pretty cheap. However it seemed like a good idea purely from an environmental point of view (even if there is no climate change like Rick PArry totally has convinced me).
 

simms22

Recognized Contributor - R.I.P
Jun 4, 2009
34,056
25,931
BROOKLYN!
www.androidcommunity.com
Yeah, the drawback of course is the shorter battery runtime. If even a fully charged battery still is not enough for you to get over the day, this tweak is not for you. However, I mostly use the Nexus for internet, email and music and for me a fully charged battery last for about 3 days. So in my case when setting the charging limit to let's say 80% that is still plenty of reserves.

Before I wrote this tweak I thought about if it actually makes sense to try and prolong the lifetime of these batteries because they can be easily replaced and are also pretty cheap. However it seemed like a good idea purely from an environmental point of view (even if there is no climate change like Rick PArry totally has convinced me).

i thought about the need to prolong the batterys life too. i thought about how long id be using my phone as a primary device before i get a new one vs the actual life of the battery. i figured id replace the phone before the battery actually died. of course, there is that odd random chance that the battery will die much quicker than expected. my original g1 battery from 2008 is still good, and i abused that phone for a long time. but, there is something else that i didnt think about. there are lots of people in the world that are less fortunate than i am. and they need their devices to last them as long as the devices can because they cant afford getting new ones. and that includes the battery too. they would appreciate something like this. of course, there is that envirenmental thing that you touched upon. less crap destroying our wonderful planet :)
 

Borky_16

Retired Recognized Developer
Jun 7, 2010
563
116
Salzburg
Yeah, the drawback of course is the shorter battery runtime. If even a fully charged battery still is not enough for you to get over the day, this tweak is not for you. However, I mostly use the Nexus for internet, email and music and for me a fully charged battery last for about 3 days. So in my case when setting the charging limit to let's say 80% that is still plenty of reserves.

Before I wrote this tweak I thought about if it actually makes sense to try and prolong the lifetime of these batteries because they can be easily replaced and are also pretty cheap. However it seemed like a good idea purely from an environmental point of view (even if there is no climate change like Rick PArry totally has convinced me).

so it is not for hardcore user? I have to recharge the phone every evening *argh* !

Sent from my Google Nexus S using xda premium
 

jaoyina

Member
Jan 30, 2011
44
0
Yeah, the drawback of course is the shorter battery runtime. If even a fully charged battery still is not enough for you to get over the day, this tweak is not for you. However, I mostly use the Nexus for internet, email and music and for me a fully charged battery last for about 3 days. So in my case when setting the charging limit to let's say 80% that is still plenty of reserves.

Before I wrote this tweak I thought about if it actually makes sense to try and prolong the lifetime of these batteries because they can be easily replaced and are also pretty cheap. However it seemed like a good idea purely from an environmental point of view (even if there is no climate change like Rick PArry totally has convinced me).

What kind of battery you are using, why my battery can only last 1 day with few calls, message and a couple of hours internet.
 
Last edited:

gotjazz

Senior Member
Apr 10, 2011
464
36
nice - but not something I see myself using so one little question in advance: If I use a kernel that has this and I just delete this config file - will my ns behave as if it had never been there?
 

Ezekeel

Retired Recognized Developer
Jun 21, 2011
715
1,680
I appreciate your work Ezekeel.

I have one suggestion: Can you make one thread with all your MODs included so that it is not fragmented all over the Android Development forum?

That would be very kind of you.

You mean joining all the thread in a single one or creating an additional thread as an index which links to the individual threads?


What kind of battery you are using, why my battery can only last 1 day with few calls, message and a couple of hours internet.

The stock battery with 3G disabled and CPU freq limited to 800GHz.


nice - but not something I see myself using so one little question in advance: If I use a kernel that has this and I just delete this config file - will my ns behave as if it had never been there?

The charging limit is set to 101 by default, so as long as you do not set a different limit this tweak will do nothing at all.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 83
    Older types of rechargable batteries exhibited a 'memory effect' which made it neccessary to completely charge/discharge the battery when using to prevent degradation of the capacity. Modern Lithium-Ion batteries like in the Nexus S do not show this problem and thus it is not necessary to use the battery in complete (dis)charge cycles. In fact on the contrary, it is commonly accepted that both very low and very high charge states accelerate the degradation of the battery capacity (that is why you should store Li-Ion batteries at around 40% charge).

    While a low charge state can be simply avoided by charging the device more often, the battery in the Nexus S by default is charged to around 95% capacity and I could not find any app or tweak to stop the charging at a lower capacity. Thus the only way was to use the manual override and pull the cable which is annoying since one had to monitor the charge state.

    So I implemented a simple tweak I called Battery Life eXtender (BLX) which can be used to set a limit for the capacity to which the battery will be charged by passing a value between 0 and 101 to 'charging_limit' in '/sys/class/misc/batterylifeextender' (101 by default).


    Changes to the source code: http://www.pastie.org/2516542


    BUGFIX:

    The battery status is set to 'full' once the user defined charging limit is reached.

    Bug fix: http://www.pastie.org/2534319


    BUGFIX #2:

    The charging limit is set to 96 by default which will mimic the behaviour of the stock kernel. Also, the maximum value accepted by 'charging_limit' is set to 96.

    Bug fix: http://www.pastie.org/2560599


    BUGFIX #3:

    1. Made BLX compatible with the 100% charging 'fix'.
    2. If the charging limit is set to the maximum charging limit, charging will not be stopped until the interrupt signal is received from the MAX8998 chip.

    Bugfix: http://www.pastie.org/2751140


    No further patches will be published here. I have set up a git repo for all my tweaks. Each mod has its own branch to keep the tweaks cleanly separated and one can simply pull the latest patches from the corresponding branch.

    https://github.com/Ezekeel/GLaDOS-nexus-s/tree/blx



    I do not accept donations and since I reached my 50GB limit of free space on SpiderOak, thanks to all of you kind people who got an account using my referral link, I could not ask for more.
    Instead if you really want to donate your hard earned money to someone who deserves and needs it, consider donating to the Free Software Foundation at fsf.org: These guys are at the frontline when it comes to keeping Linux free and fighting these greedy bastards who think they are entitled to collect royalties and other fees from Linux users due to some silly patents - and if Linux falls, Android will be next.
    8
    Ezekeel, I arrived a little late to this Nexus S party (only bought it two/three weeks ago) so I only learned about your BLX mod now. In the light of my ignorance about this "buisness", how is this implementation compared to your BLX?

    BLX is for limiting the full charge to a value lower than the maximum capacity; it does not allow charging to 100%.

    I took a look at that patch and while some parts make sense and should give a more accurate measure of the current charge, some other parts are just phony trickery to get the battery show 100%. It does not actually change how the battery is charged, it just adjusts the way the capacity is shown.

    According to the datasheet (http://datasheets.maxim-ic.com/en/ds/MAX17040-MAX17041.pdf), the MAX17040_SOC_MSB register contains the capacity in % while the MAX17040_SOC_LSB contains the value after the decimal point in 1/256%.

    So this code
    msb = max17040_read_reg(client, MAX17040_SOC_MSB);
    lsb = max17040_read_reg(client, MAX17040_SOC_LSB);

    temp = msb * 100 + ((lsb * 100) / 256);
    calculates the capacity in % x 100.

    In the following
    if (temp >= 100)
    temp_soc = temp;
    else {
    if (temp >= 70)
    temp_soc = 100;
    else
    temp_soc = 0;
    }
    for a capacity >= 0.7% we roundup to 1% which seems unnecessary to me since in the following
    soc = temp_soc / 100;

    if (temp_soc % 100 >= 50)
    soc += 1;
    for a capacity >= x.5% we roundup to next full x+1%.

    These are the parts which make sense to me and which should increase the accuracy of the charge shown.

    The following
    if (soc >= 26)
    soc += 4;
    else
    soc = (30 * temp_soc) / 26 / 100;
    is just a cheap trick to scale up the maximum charge capacity shown from 96% to 100%. For charge >= 26% +4% are added, so 26% becomes 30% and 96% becomes 100%, while below 26% we increase the charge by scaling with the quotient 30/26, so 26% becomes 30% to give us a smooth curve when 26% are passed.

    If you take a look at page 4 of the datasheet, the top right diagram you see that the error between the shown and real capacity is a rather complicated function. It is not simply linear and also there is a difference in the error depending on whether we are currently charging or discharging. Thus I seriously doubt that this oversimplified error correction from above actually improves the accuracy of the capacity once you leave the area around 95-100%. It is just some sort of placebo to appease the more simple-minded folks. ;)
    4
    i charge my ns to 100% all the time, i wish that i could charge it even more. lol!

    Yeah, the drawback of course is the shorter battery runtime. If even a fully charged battery still is not enough for you to get over the day, this tweak is not for you. However, I mostly use the Nexus for internet, email and music and for me a fully charged battery last for about 3 days. So in my case when setting the charging limit to let's say 80% that is still plenty of reserves.

    Before I wrote this tweak I thought about if it actually makes sense to try and prolong the lifetime of these batteries because they can be easily replaced and are also pretty cheap. However it seemed like a good idea purely from an environmental point of view (even if there is no climate change like Rick PArry totally has convinced me).
    3
    I appreciate your work Ezekeel.

    I have one suggestion: Can you make one thread with all your MODs included so that it is not fragmented all over the Android Development forum?

    That would be very kind of you.
    2
    Any one please explain...
    How it use??? :rolleyes:
    Any CWM.zip ??
    Thanks

    Sent from my GT-I9100 using xda premium

    This is a mod for the kernel. Only kernel devs can use this. It can't be flashed through cwm.

    Sent from my Nexus S
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone