Skip to content

feat: battery/charge status and analog trigger+stick calibration (PR 5/9) - #40

Merged
thePunderWoman merged 1 commit into
mainfrom
firmware-rewrite/pr5-battery-analog-calibration
Sep 8, 2026
Merged

feat: battery/charge status and analog trigger+stick calibration (PR 5/9)#40
thePunderWoman merged 1 commit into
mainfrom
firmware-rewrite/pr5-battery-analog-calibration

Conversation

@thePunderWoman

Copy link
Copy Markdown
Owner

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 the R_VSYS1/R_VSYS2 divide-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): thin Preferences/NVS adapter persisting calibration data, joining oled.cpp/rgb_led.cpp in the native build/coverage exclusion list.

SnipsController.ino reads 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 pass
  • gcovr --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 files
  • pio run -e esp32s3 — builds successfully
  • Flash to real hardware once boards arrive: confirm battery %/charge state and trigger/stick readings look sane over serial; note trigger/stick will read the uncalibrated full ADC range until the guided calibration UI exists (PR 6/7)

🤖 Generated with Claude Code

…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
thePunderWoman merged commit 5e049af into main Sep 8, 2026
2 checks passed
@thePunderWoman
thePunderWoman deleted the firmware-rewrite/pr5-battery-analog-calibration branch September 8, 2026 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant