Skip to content

added battery presets for changing chemistry types#542

Open
tmacinc wants to merge 1 commit into
betaflight:masterfrom
tmacinc:master
Open

added battery presets for changing chemistry types#542
tmacinc wants to merge 1 commit into
betaflight:masterfrom
tmacinc:master

Conversation

@tmacinc

@tmacinc tmacinc commented Jul 5, 2026

Copy link
Copy Markdown

Added Presets to the Battery page for easy switching of types.

The new betaflight battery profiles and switch option might make this unnecessary. But it's a nice option to see and confirm the settings before you arm as part of your preflight if you're a user that switches types frequently.

Summary by CodeRabbit

  • New Features
    • Added a battery type preset selector with common options like Custom, LiPo, LiIon, and LiHV.
    • The battery settings screen can now automatically match the preset based on existing cell voltage values.
    • Changing the battery type now updates the related voltage fields to keep settings consistent.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 003a528b-782f-4995-acc3-97a3ac7b3def

📥 Commits

Reviewing files that changed from the base of the PR and between 46e1911 and 892ac00.

📒 Files selected for processing (1)
  • src/SCRIPTS/BF/PAGES/battery.lua

📝 Walkthrough

Walkthrough

This change adds a Battery Type preset selector (Custom, LiPo, LiIon, LiHV) to the battery configuration page. A hidden scratch byte tracks UI edit-mode state during load, is stripped before saving, and preset selection auto-updates min/max/warn cell voltage fields.

Changes

Battery Type Preset

Layer / File(s) Summary
Preset table and field definition
src/SCRIPTS/BF/PAGES/battery.lua
Adds batteryPresets lookup table with min/max/warn thresholds and a new battTypeField with a hidden scratch byte and postEdit wiring.
Load/save handling and preset application
src/SCRIPTS/BF/PAGES/battery.lua
Adds postLoad to auto-detect the matching preset and append the scratch byte, preSave to strip it and emit a 13-byte payload, and applyBatteryPreset to map preset values into cell fields and pack scaled integers into self.values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant FC as Flight Controller
  participant postLoad
  participant battTypeField
  participant applyBatteryPreset
  participant preSave

  FC->>postLoad: provide min/max/warn cell values
  postLoad->>battTypeField: set matched preset value
  battTypeField->>applyBatteryPreset: postEdit triggered
  applyBatteryPreset->>applyBatteryPreset: update min/max/warn fields
  applyBatteryPreset-->>FC: pack scaled values into self.values
  preSave->>preSave: strip scratch byte
  preSave-->>FC: emit 13-byte MSP_SET_BATTERY_CONFIG payload
Loading

Poem

A hop, a byte, a preset's cheer,
LiPo, LiIon, LiHV appear! 🔋
I tuck a scratch byte in my burrow tight,
Then trim it clean before the flight.
Thump-thump, the battery config's just right! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: adding battery chemistry presets to the Battery page.
Description check ✅ Passed The description states the feature and its user benefit, which is enough for this change and broadly fits the template's expectations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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