Post Reply 
I have a way to measure battery power
06-25-2017, 05:03 AM
Post: #1
I have a way to measure battery power
I've seen many posts where people are trying to find the amount of charge in the battery.
I've also seen replies from people working at HP that said it isn't measured very accurately, which sounds right. I've worked with charging chips like these in the past and they often just give a low resolution value (usually in coulombs). Anyhow, regardless of how they measure it, it's displayed in the battery status in the upper RHS of the display.
The rectangle inside the battery icon is 3 pixels wide and 11 pixels high. The exact coordinates to draw a RECT inside the battery icon are 314,4,316,14.
So, all you'd have to do is examine the column of pixels at x = 315. Begin getting the color of the pixels at y = 14, 13, ....4 and if all black it's empty, if all green, it's full, and in between, just find where the color changes and it'll give you the percentage full that the battery is.
It could be that the first pixel just tells you it's not going to shut down yet, and if so, then 2 pixels would mean 10% full, 3 pixels 20% and so on until 11 pixels 100%.
Maybe someone at HP could look at the source code and tell us....
Enjoy...
:-)
Find all posts by this user
Quote this message in a reply
06-26-2017, 05:30 AM
Post: #2
RE: I have a way to measure battery power
Hello,

On the real calculator, the battery power has 4 steps: 100%, 75%, 50% and 25% (0% is dead and the calculator does not run, so I am not counting it).
On virtual calculators, it depends on the underlying OS. Most OS report the battery power as a percentage. Weather it's precision is with a granularity of 1, more or less, I do not know...

Anyhow, your idea is great! good thinking.

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
06-27-2017, 10:43 AM
Post: #3
RE: I have a way to measure battery power
I wrote a utility to give me the value and so far, it's given me 100% and 80%, so it's not following the internal hardware values....but who cares as long as it's close. Here is my utility...
Note that my not equal symbol isn't on my laptop keyboard, so I'm showing it below as <>, but I used the not equal symbol from shift-6.
Enjoy....

EXPORT BATVAL()
BEGIN
LOCAL x,y,c,d;
x:=315;
y:=14;
d:=GETPIX_P(x,y);
IF d<>#8400h THEN // Green value that's used to indicate power
RETURN 0; // if first pixel is not green, no power
END;

FOR y FROM 13 DOWNTO 3 STEP 1 DO // check the rest of the pixels
c:=GETPIX_P(x,y);
IF c<>d THEN // change in pixel color...break out of loop

IF y==3 THEN // If reached 3, means it's full of green = 100%
RETURN 100;
ELSE // otherwise, base on percentage filled
y:=14-y;
y:=y*10;
RETURN y;
END;

END; // if y==3....
d:=c;
END; // FOR y loop
// Never gets here because y==3 is border of battery icon so color change
END; // BEGIN-END
Find all posts by this user
Quote this message in a reply
06-27-2017, 11:21 AM
Post: #4
RE: I have a way to measure battery power
Please let us know it calculated values correlate with measured battery levels, especially at the 25% incremental points, as Cyrille posted...

Speaking of battery level, does deep cycling the battery, or remaining continuously connected to a charge source, create issues? During the discharge phase, at what level does operational change take place? Is there a low battery level warning that can be included in a program?

An A/D port, or comm facilities for an RTU, would be a great enhancement!

-Dale-
Find all posts by this user
Quote this message in a reply
06-27-2017, 09:13 PM (This post was last modified: 06-27-2017 09:22 PM by TravisE.)
Post: #5
RE: I have a way to measure battery power
If it's like most other consumer Li-Ion battery systems, staying plugged in to the charger shouldn't cause significant damage because it's smart enough not to continue to charge when it's not necessary. Leaving the battery near drained for extended periods of time might not be a good idea; I've heard Li-Ion batteries can be destroyed if allowed to self-discharge too far. Deep discharge/charge cycles shouldn't be necessary; they should be just fine with partial cycles (they'll normally last more cycles this way, in fact). The only real reason to purposely do a deep discharge cycle might be to recalibrate the battery gauge occasionally, but this isn't always necessary.

I've noticed that my Prime seems to refuse to charge at all (at least according to the display) unless the battery has dropped at least one bar of charge from “full”. Many devices will try to gently top off the battery even if already fairly close to a full charge; perhaps this more conservative behavior was implemented as a way to help improve the battery lifespan.
Find all posts by this user
Quote this message in a reply
06-28-2017, 01:14 AM
Post: #6
RE: I have a way to measure battery power
if x = 315, y = 14 thru 4 are filled with green #8400h, then it's 100%.
The next level down is 14 thru 6, which according to HP is 75%.
My algorithm will return 80%.
The problem is that 11 pixels apply to 100%, which means the following:
11 pixels = 100%
9 pixels = 75%, but it's 81% of 11 pixels.
I'll report on the next levels when i reach them....
Find all posts by this user
Quote this message in a reply
06-28-2017, 10:50 AM
Post: #7
RE: I have a way to measure battery power
Coding your own, (referenced to your battery), battery meter program could also be done. However, does battery level accuracy, more precise than currently shown, offer any useful merit? You could use the old "vacuum tube tester" concept of red, yellow, and green, bands to represent discharged through charged, battery status, and get a good feeling when the battery reports greenage!

-Dale-
Find all posts by this user
Quote this message in a reply
06-28-2017, 11:02 AM
Post: #8
RE: I have a way to measure battery power
How would you get the battery value? I thought that was the problem. There wasn't a function to give you the battery value. I am reading the status on the display icon and calculating how full it is.
I see no point in creating a new meter fed values from previous meter???
Find all posts by this user
Quote this message in a reply
06-28-2017, 11:20 AM
Post: #9
RE: I have a way to measure battery power
The teensy advantage might be your control over the resolution. In order to get anything more meaningful, you would need to get metrics on the actual battery... hence, the request "Please let us know it calculated values correlate with measured battery levels, especially at the 25% incremental points, as Cyrille posted..."

Otherwise, Cyrille has completely addressed the issue here, including your novel idea to pick apart the level points. There really isn't any earth-shaking point ... it is more a matter of something that could also be done, being done, and provides a hands on opportunity to learn more about the prime, etc.
Find all posts by this user
Quote this message in a reply
06-28-2017, 12:05 PM
Post: #10
RE: I have a way to measure battery power
(06-27-2017 10:43 AM)webmasterpdx Wrote:  I wrote a utility to give me the value and so far, it's given me 100% and 80%, so it's not following the internal hardware values....but who cares as long as it's close. Here is my utility...
Note that my not equal symbol isn't on my laptop keyboard, so I'm showing it below as <>, but I used the not equal symbol from shift-6.
Enjoy....

EXPORT BATVAL()
BEGIN
LOCAL x,y,c,d;
x:=315;
y:=14;
d:=GETPIX_P(x,y);
IF d<>#8400h THEN // Green value that's used to indicate power
RETURN 0; // if first pixel is not green, no power
END;

FOR y FROM 13 DOWNTO 3 STEP 1 DO // check the rest of the pixels
c:=GETPIX_P(x,y);
IF c<>d THEN // change in pixel color...break out of loop

IF y==3 THEN // If reached 3, means it's full of green = 100%
RETURN 100;
ELSE // otherwise, base on percentage filled
y:=14-y;
y:=y*10;
RETURN y;
END;

END; // if y==3....
d:=c;
END; // FOR y loop
// Never gets here because y==3 is border of battery icon so color change
END; // BEGIN-END

Do you really need a loop? There are only 4 possible levels so test the top row. If it's green, you're at 100%, test the next level, if green, you're at 75%, the next level is 50% and the last level is 25% Of course those levels will have to be determined but it shouldn't be too hard to do. You can even test certain pixels in the lightning bolt for yellow to know if the calculator is charging or not.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
06-28-2017, 01:25 PM
Post: #11
RE: I have a way to measure battery power
I wasn't trying to optimize it just to show it could be done. It was just something I threw together quickly. After I've seen it go down, I'll know what it can and can't do. Then I can optimize it.
Find all posts by this user
Quote this message in a reply
06-28-2017, 01:28 PM
Post: #12
RE: I have a way to measure battery power
(06-28-2017 11:20 AM)DrD Wrote:  The teensy advantage might be your control over the resolution. In order to get anything more meaningful, you would need to get metrics on the actual battery... hence, the request "Please let us know it calculated values correlate with measured battery levels, especially at the 25% incremental points, as Cyrille posted..."

Otherwise, Cyrille has completely addressed the issue here, including your novel idea to pick apart the level points. There really isn't any earth-shaking point ... it is more a matter of something that could also be done, being done, and provides a hands on opportunity to learn more about the prime, etc.

The resolution is exactly as cyrille posted I'm sure. I know of no other interface to the battery, unless you know something I don't. There is nothing earth-shaking about this. I just saw that many people were trying to figure out how to read the battery, and it occurred to me to read the status display....that's it, nothing more.
If you do know of another interface to get battery values, please let me know.
Find all posts by this user
Quote this message in a reply
06-28-2017, 02:59 PM
Post: #13
RE: I have a way to measure battery power
(06-28-2017 12:05 PM)toml_12953 Wrote:  Do you really need a loop? There are only 4 possible levels so test the top row.

Only on the HW version of the calculator. Don't forget all the other versions with the various apps. Smile

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
06-28-2017, 04:45 PM (This post was last modified: 06-28-2017 05:25 PM by StephenG1CMZ.)
Post: #14
RE: I have a way to measure battery power
It seems that on the Android, the HP Prime battery status only updates when the screen is tapped.
Until then, it continues to display the previous status.

So it may not be possible to program a "beep" if the charging lead is accidentally disconnected, or monitor the mains supply.

Detail: plug/unplug the lead - Prime display doesnt change (Android battery status does).
Tap the screen once - display updates charging/discharging status.
Triple-tapping the screen (Android optional accessibility screen zoom): charging status doesnt update.

The no-update affects the charging/discharging indication - I don't know yet whether it also affects the charge percentage.

Android 5.0.2
LG G3 s.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
06-28-2017, 05:38 PM (This post was last modified: 06-28-2017 05:40 PM by toml_12953.)
Post: #15
RE: I have a way to measure battery power
(06-28-2017 02:59 PM)Tim Wessman Wrote:  
(06-28-2017 12:05 PM)toml_12953 Wrote:  Do you really need a loop? There are only 4 possible levels so test the top row.

Only on the HW version of the calculator. Don't forget all the other versions with the various apps. Smile

Does the emulator's battery status display have anything to do with the actual phone battery charge? If not, then
there's no reason to write a routine to read it on the emulator.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
06-29-2017, 01:54 AM
Post: #16
RE: I have a way to measure battery power
i doubt if the battery status has any meaning on the virtual calculator.
Find all posts by this user
Quote this message in a reply
06-29-2017, 02:46 AM
Post: #17
RE: I have a way to measure battery power
(06-29-2017 01:54 AM)webmasterpdx Wrote:  i doubt if the battery status has any meaning on the virtual calculator.

Exactly my point. You might as well just make sure it works on a physical Prime since an app doesn't really reflect the state of the phone or tablet battery.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
06-29-2017, 05:35 AM (This post was last modified: 06-29-2017 05:52 AM by StephenG1CMZ.)
Post: #18
RE: I have a way to measure battery power
(06-29-2017 01:54 AM)webmasterpdx Wrote:  i doubt if the battery status has any meaning on the virtual calculator.

On the Android virtual calculator, I have certainly observed it as near-full or near-empty, reflecting the phone's own status - so to that extent at least, it works. Cyrille indicates that the battery status from the OS is reported to the HP Prime as a percentage and I imagine the accuracy and resolution of that could vary from phone to phone.

I haven't checked the PC virtual calculator or Iphone but I assume these work too (of course, on a PC rather than laptop, the battery status might not be useful).

One difficulty the Android does have is updating the display (it requires a screen tap, as detailed in my post above).

Of course, on virtual calculators the virtual environment often provides other means of seeing the battery status, outside of the HP Prime emulation.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
06-29-2017, 06:34 AM
Post: #19
RE: I have a way to measure battery power
Been waiting for the power to go down....
So far....
11 pixels =100%
9 pixels
7 pixels
....that's it so far.
according to the hp guys it's only got 4 stages.....I suspect they might be wrong....as it's going down 2 pixels at a time.
we'll see...
Find all posts by this user
Quote this message in a reply
07-01-2017, 09:03 AM (This post was last modified: 07-01-2017 10:38 AM by webmasterpdx.)
Post: #20
RE: I have a way to measure battery power
I have new data as the power has gone down to the next level. Here is the table so far. I don't know if there is going to be another level before the power goes off or there is going to be a message. I haven't seen a "low power" message yet either. In this table, V is the % value returned by my little app above, HP is the % full according to the HP guys returned by the hardware, C is the color inside the battery icon in RGB hex (and english), Pixels is the number of pixels turned on in the battery icon, and Y is the y value of highest vertical pixel on, where x=315 where the color changes inside the battery icon.
Code:
V   Y  Pixels  HP   C
100 04 11     100 #008400h Bright Green
 80 07 08      75 #008400h Bright Green
 60 09 06      50 #008400h Bright Green
 30 12 03      25 #EFCE29h Yellow

I had to change to code to change 8400 to EFCE29 for it to work now that it's changed from green to yellow. I'll rewrite everything to be more efficient and work no matter what the color when I've gotten all the info I require....when battery goes down to the shutoff point.

I'll update when I get any more info as the power goes down farther (if there is any, other than the power going out).
-Donald[/code]
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)