Increase battery measurement precision and frequency #2398
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This removes the battery smoothing that prevents the reported percentage from going up while off charge. I'm personally not a fan of it, as if someone uses high brightness than if the battery is measured while the screen is on the battery charge is underestimated significantly, and this results in the percentage staying at this underestimate for a long time since it's not allowed back up. But maybe this will be confusing to users? I'm not sure what the best choice is here. We could also keep the clamping but have some smoothing applied to the battery value so the occasional measurement while the screen is on doesn't tank it too much?
Example of how it looks, note there are a few spots of missing data as out of range on bluetooth. AOD is used here.
[1]
Battery measured from 4180mV-3500mV, so 680mV range. ADC ref: 0.6v, ADC gain: 1/4, HW gain: 1/2, so the ADC can measure from 0V to 0.6*4*2=4.8V, 4800mV total. So about 14.2% of the measurement range is used ~(2-3). So with 10bit ADC (current resolution), assuming no measurement noise (unrealistic, expect at least 1bit noise), we have 10 bit - 3 bit = 7 bits of resolution or 128 possible values (just more than the 100 percentage points).
However, the mapping from voltage to percentage is nonlinear. 3776mV-3723mV accounts for 26%, actual range 53mV (2-6.5). 10 bit - 6.5bit = 3.5 bit or 11 values, which is less than the 26 percentage points it is mapped to. So some of the percentages are impossible.