A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: smooth battery percentage for x4 (#1635)

## Summary

Battery percentage is calculated from the voltage, which is not totally
stable. We smooth the battery percentage using a moving average.

## Additional Context
issue discussion:
https://github.com/crosspoint-reader/crosspoint-reader/issues/1444

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code?
PARTIALLY

authored by

Jon Vexler and committed by
GitHub
81ae9dd7 40e4c969

+8 -2
+8 -2
lib/hal/HalPowerManager.cpp
··· 113 113 return _batteryCachedPercent; 114 114 } 115 115 static const BatteryMonitor battery = BatteryMonitor(BAT_GPIO0); 116 - _batteryCachedPercent = battery.readPercentage(); 117 - return _batteryCachedPercent; 116 + 117 + // smooth the battery %. 118 + if (_batteryCachedPercent == 0) { 119 + _batteryCachedPercent = 10 * battery.readPercentage(); 120 + } else { 121 + _batteryCachedPercent = (_batteryCachedPercent * 9 + battery.readPercentage() * 10) / 10; 122 + } 123 + return _batteryCachedPercent / 10; 118 124 } 119 125 120 126 HalPowerManager::Lock::Lock() {