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.

3
  • 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, 2018 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, 2018 at 15:53
  • You may like to look at the Magisk module used in this answer. But the kernel needs to support this android.stackexchange.com/q/223812/131553
    – beeshyams
    Apr 12, 2020 at 14:31

0

You must log in to answer this question.

Browse other questions tagged .