Ampere

Post your questions and help other users.

Moderator: Martin

ariloc
Posts: 109
Joined: 05 Jun 2016 21:36

Re: Ampere

Post by ariloc » 04 Nov 2016 20:34

akapelis wrote:
ariloc wrote:That variable isn't available to me. Why is that happening?
Try this...
I tried and the result is 0. Maybe my phone doesn't supports this: Moto E 2nd Gen, Android Marshmallow, no root.

User avatar
heilong
Posts: 77
Joined: 18 Oct 2016 15:20

Re: Ampere

Post by heilong » 04 Nov 2016 22:35

If it's 0, probably it's not supported. This feature requires some hardware support. Probably not every phone has it.

akapelis
Posts: 41
Joined: 13 Jul 2016 20:51

Re: Ampere

Post by akapelis » 06 Nov 2016 22:19

Thank you all'guys, I made some changes. The current is detected every second for five seconds and then i calculate the average current. I adjusted the milli ampere script by adding * (- 1), so when the battery is discharging the sign is negative, whereas when it is charging is positive.
Attachments
Capture+_2016-11-07-00-10-44.png
Capture+_2016-11-07-00-10-44.png (347.19 KiB) Viewed 20836 times
Capture+_2016-11-07-00-09-45.png
Capture+_2016-11-07-00-09-45.png (242.79 KiB) Viewed 20836 times
Capture+_2016-11-07-00-09-29.png
Capture+_2016-11-07-00-09-29.png (291.27 KiB) Viewed 20836 times

User avatar
heilong
Posts: 77
Joined: 18 Oct 2016 15:20

Re: Ampere

Post by heilong » 07 Nov 2016 00:24

Did you try to use battery_current_avg? Does it not give you the results you like?
Why don't you just make a proper loop? Using a separate variable for every sample is quite bad programming... What if you'll change your mind and decide to average over 15 second intervals?

akapelis
Posts: 41
Joined: 13 Jul 2016 20:51

Re: Ampere

Post by akapelis » 07 Nov 2016 06:58

heilong wrote:Did you try to use battery_current_avg? Does it not give you the results you like?
Why don't you just make a proper loop? Using a separate variable for every sample is quite bad programming... What if you'll change your mind and decide to average over 15 second intervals?
Maybe you're right, i will try it, thanks.

akapelis
Posts: 41
Joined: 13 Jul 2016 20:51

Re: Ampere

Post by akapelis » 07 Nov 2016 16:30

Unfortunately the "average current" returns to me always "zero"...
Maybe it's a hardware matter?.

User avatar
heilong
Posts: 77
Joined: 18 Oct 2016 15:20

Re: Ampere

Post by heilong » 07 Nov 2016 17:13

Probably. It is available on my Moto G3 (Osprey). My suggestion:

1) If you just want to calculate and display an average once, do a simple loop. Set a counter variable to the number of samples you want, while counter is > 0, add a sample to an accumulator variable, decrement the counter by 1, and sleep for whatever delay you prefer. When counter is 0, divide your accumulator by the number of iterations (beware of off-by-one errors in your code, make sure the number of iterations is correct, and not +/-1 of what you intended) and here's your average. Easy to adjust the number of iterations.

2) If you want to have a continuously updating notification or widget, it gets more complicated, you need to compute a running average. Keep an array of last X (e.g. 10) samples. Each time you take a new sample, if the array is already full, remove the oldest sample and push the new one in (think like a conveyor belt with starting point and ending point). Decide the size of the array yourself - bigger = more stable, smaller = better response. This way you can, for example, take a new sample every second and get an updated average every second. In the 1st way if you take 10 samples 1 second apart, you can update your display only once per 10 seconds.

akapelis
Posts: 41
Joined: 13 Jul 2016 20:51

Re: Ampere

Post by akapelis » 08 Nov 2016 11:12

Thanks for your suggestion heilong, I'll try it.

akapelis
Posts: 41
Joined: 13 Jul 2016 20:51

Re: Ampere

Post by akapelis » 08 Nov 2016 12:32

What do you think about this heilong?
Attachments
Capture+_2016-11-08-14-28-06.png
Capture+_2016-11-08-14-28-06.png (233.01 KiB) Viewed 20819 times

akapelis
Posts: 41
Joined: 13 Jul 2016 20:51

Re: Ampere

Post by akapelis » 08 Nov 2016 12:34

Could you help me with the second option (array) please?
I would like to ask you another thing, the variable "battery_tecnology" returns the number 340. What does it mean?
Thanks again.

Post Reply