0

I am trying to make my device stop charging (echo 0 > /sys/class/power_supply/battery/charging_enabled, the easy part) when the battery's voltage reaches 3920000 µV.

Using cat /sys/class/power_supply/battery/voltage_now or dumpsys battery, I can also tell that the battery is at a certain voltage, like 3916000 (in µV). When the device is not charging, this number is the battery's charge voltage, the number I want. However, when the device is connected to a charger (DC out is normally 5V), this value is neither the battery's voltage, nor the input voltage, but some value in between, because of how charging works.

Because the voltage_now does not reflect the battery's rest voltage when charging, and this number is dependent on which charger I use, I cannot obtain the number I need (3920000) whenever the device should stop charging. So apart from pulse charging and sampling, how should I get the battery's non-charging voltage from the shell while charging?


Note: "manually calculating the battery percentage when the voltage is 3.92V, and then stopping charging when /sys/class/power_supply/battery/capacity reaches that number" is not a satisfactory answer or workaround.

  • I don't know if voltage can be read and not sure that is a reliable way of doing it (what if the battery ages and cannot reach full voltage on full charge?). Alternate method to do that is mentioned in my answer here android.stackexchange.com/q/167260/131553 – beeshyams Mar 9 '18 at 0:07
  • The voltage is reported by voltage_now and it is the battery's current voltage as advertised, but I want the "rest voltage" of the battery if the cable were unplugged at that instant. The rest of the task involving charging_enabled is already implemented the same way as your previous answer. – Brian Mar 9 '18 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.