feat: battery/charge status and analog trigger+stick calibration (PR 5/9) - #40
Merged
thePunderWoman merged 1 commit intoSep 8, 2026
Merged
Conversation
…5/9) Bundles three subsystems that are all "ADC reading + calibration," the same shape of problem: - BatteryMonitor (battery.h/.cpp): raw VSYS ADC -> battery percentage, via the R_VSYS1/R_VSYS2 divide-by-3 network and a linear approximation between empty/full cell voltage (documented as a v1 simplification of a real Li-ion discharge curve). Charge-state decoding from STAT1/STAT2 is pulled directly from the bq25185 datasheet's (SLUSF65A) Table 7-2 "Status Pins State Table" rather than guessed. - AnalogCalibration (calibration.h/.cpp): raw trigger/stick ADC -> calibrated 0-100 / -100..100, using stored min/max/center. Stick axes get a small deadzone around center so a resting stick reads exactly 0. - TriggerCalibrationFlow / StickCalibrationFlow: pure guided-calibration state machines (release-then-pull for the trigger; center-then-roll for the stick). Not wired to any UI yet — that lands with the menu system in PR 6/7 — but the reusable logic exists and is fully tested now. - CalibrationStore (calibration_store.cpp): thin Preferences/NVS adapter persisting calibration data, excluded from native build/coverage alongside oled.cpp/rgb_led.cpp. SnipsController.ino reads all four analog channels plus STAT1/STAT2 each second and logs the calibrated/decoded results — packet protocol to actually transmit this lands in PR 8. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
thePunderWoman
deleted the
firmware-rewrite/pr5-battery-analog-calibration
branch
September 8, 2026 00:54
This was referenced Sep 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
PR 5 of the firmware rewrite (PR 1: #35, PR 2: #36, PR 3: #38, PR 4: #39). Bundles three subsystems that share the same shape of problem — ADC reading + calibration.
BatteryMonitor(include/battery.h/src/battery.cpp): raw VSYS ADC → battery percentage via theR_VSYS1/R_VSYS2divide-by-3 network and a linear approximation between empty/full cell voltage (flagged as a v1 simplification of a real Li-ion discharge curve — easy to refine later). Charge-state decoding from STAT1/STAT2 is pulled directly from the bq25185 datasheet's (SLUSF65A) Table 7-2 "Status Pins State Table" rather than guessed at.AnalogCalibration(include/calibration.h/src/calibration.cpp): raw trigger/stick ADC → calibrated 0-100 / -100..100 using stored min/max/center, with a small deadzone around stick center so a resting stick reads exactly 0.TriggerCalibrationFlow/StickCalibrationFlow: pure guided-calibration state machines (release-then-pull for the trigger; center-then-roll for the stick). Not wired to any UI yet — that's the menu system in PR 6/7 — but the reusable logic exists and is fully tested now.CalibrationStore(src/calibration_store.cpp): thinPreferences/NVS adapter persisting calibration data, joiningoled.cpp/rgb_led.cppin the native build/coverage exclusion list.SnipsController.inoreads all four analog channels plus STAT1/STAT2 once a second and logs the calibrated/decoded results — the packet protocol to actually transmit this over XBee lands in PR 8.Test plan
pio test -e native— all 65 test cases passgcovr --exclude 'src/SnipsController\.ino' --exclude 'src/oled\.cpp' --exclude 'src/rgb_led\.cpp' --exclude 'src/calibration_store\.cpp' --fail-under-line 90— 100% line coverage across all logic filespio run -e esp32s3— builds successfully🤖 Generated with Claude Code