I tried and the result is 0. Maybe my phone doesn't supports this: Moto E 2nd Gen, Android Marshmallow, no root.akapelis wrote:Try this...ariloc wrote:That variable isn't available to me. Why is that happening?
Ampere
Moderator: Martin
Re: Ampere
Re: Ampere
If it's 0, probably it's not supported. This feature requires some hardware support. Probably not every phone has it.
Re: Ampere
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 (347.19 KiB) Viewed 20845 times
-
- Capture+_2016-11-07-00-09-45.png (242.79 KiB) Viewed 20845 times
-
- Capture+_2016-11-07-00-09-29.png (291.27 KiB) Viewed 20845 times
Re: Ampere
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?
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?
Re: Ampere
Maybe you're right, i will try it, thanks.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?
Re: Ampere
Unfortunately the "average current" returns to me always "zero"...
Maybe it's a hardware matter?.
Maybe it's a hardware matter?.
Re: Ampere
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.
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.
Re: Ampere
Thanks for your suggestion heilong, I'll try it.
Re: Ampere
What do you think about this heilong?
- Attachments
-
- Capture+_2016-11-08-14-28-06.png (233.01 KiB) Viewed 20828 times
Re: Ampere
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.
I would like to ask you another thing, the variable "battery_tecnology" returns the number 340. What does it mean?
Thanks again.