Next up in my Papyrix study is a topic I've long been wondering about, but have previously have only found code which exposes this info rather than actually reads it... Battery charge levels!
On Xteink devices it may read from a BQ27220 chip over a serial line, caching results. There's 3 different for the 3 different properties it might read, sharing a common support method. Or it invokes an Arduino API to read how many mV the battery's providing on a certain pin.
1/2!
Upon this raw input are methods for:
* Combining the current percentage with previous at a 10:9 ratio, remembering a 10th of the last sample.
* Converting those mV into V.
* Repeatedly sampling charge level to see if its increasing.
* Apply a fitted formula (-144.939v³ + 1655.8629v² - 6158.852v + 7501.3202) clamped & rounded to convert mV to percentages.
And there's methods which reads properties from BQ27220 if available, falling back to deriving from mV readout.
2/2 Fin for today!