battery - fix BATTERY_NOT_PRESENT detection, detection logic change (#13599)
commit5fd38528bab19368be06e787fa1ea6219013d0be
authorPetr Ledvina <ledvinap@gmail.com>
Sat, 4 May 2024 08:47:06 +0000 (4 10:47 +0200)
committerGitHub <noreply@github.com>
Sat, 4 May 2024 08:47:06 +0000 (4 10:47 +0200)
tree476062ab8e83a783cd4047b71da5556bb601a792
parent62aebac3fcb6ad4445e3cb2113427a56df2f7924
battery - fix BATTERY_NOT_PRESENT detection, detection logic change (#13599)

* battery - fix BATTERY_NOT_PRESENT detection, detection logic change

Detection logic is refactored - battery voltage delta is tested each
50ms, voltage is considered stable when difference of last 10 samples
is smaller than 100mV
This makes stable threshold more forgiving than #13350 (time for
comparison is 50 instead of 500ms).

* battery - improve stable voltage detection

- voltageStablePrevFiltered every time delta is exceeded
- voltage within range is ANDed over 100ms periods
- voltage is stable if it was within range for 10 out of 11 periods
  - slowly changing voltage will update threshold, but voltage will be
    considered stable
  - 1 update/s (100mV/s) is tolerated

* battery - fuix typos, improve comments
src/main/sensors/battery.c
src/main/sensors/voltage.c
src/main/sensors/voltage.h