Skip to content

Add page to change battery parameters #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Forceu
Copy link

@Forceu Forceu commented Jul 24, 2025

This PR adds a page to the script where the following battery settings can be changed:

  • Minimum Cell Voltage
  • Maximum Cell Voltage
  • Warning Cell Voltage
  • Battery Capacity

I wanted to add a button for applying LiPo and Li-Ion presets, but had too many problems with it, so I excluded it from the commit.

This PR would supersede #515, which uses a different approach and did not work for me.

I set it to minimum API v1.45, as I was unsure since when Betaflight uses uint16 values for battery voltage instead of the legacy uint8 values - feel free to change this, if an older min API version is better.

Also is it possible to add a step value for the capacity input? So that it is changed in increments of 25 mAh instead of 1? I could not find anything about that in the code.

Summary by CodeRabbit

  • New Features
    • Introduced a new Battery configuration page, allowing users to view and adjust voltage and capacity settings.
    • The Battery page is available for systems with API version 1.45 or higher.

Copy link

coderabbitai bot commented Jul 24, 2025

Walkthrough

A new battery configuration page is introduced via a Lua script, defining UI layout, labels, and fields for voltage and capacity settings. The main pages list is updated to include the "Battery" page for API versions 1.45 and above, referencing the newly added script. No existing logic is altered.

Changes

File(s) Change Summary
src/SCRIPTS/BF/PAGES/battery.lua Added a new Lua script defining the battery configuration page, including UI layout, labels, fields.
src/SCRIPTS/BF/pages.lua Appended a "Battery" page entry to the PageFiles list for API ≥ 1.45, referencing battery.lua.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MainPages (pages.lua)
    participant BatteryPage (battery.lua)

    User->>MainPages: Open configuration menu
    MainPages->>MainPages: Check apiVersion
    alt apiVersion >= 1.45
        MainPages->>BatteryPage: Load battery configuration page
        BatteryPage->>User: Display battery settings UI
    end
    User->>BatteryPage: View or edit voltage/capacity fields
    BatteryPage->>MainPages: Send read/write MSP commands as needed
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Poem

A battery page now hops into view,
With volts and amps for you to review.
Lua scripts align, the margins just right,
New fields and labels, a coder's delight.
Now with a click, your settings are set—
Charged up and ready, no need to fret!
🐰🔋✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a90024 and 30f8a9e.

📒 Files selected for processing (2)
  • src/SCRIPTS/BF/PAGES/battery.lua (1 hunks)
  • src/SCRIPTS/BF/pages.lua (1 hunks)
🔇 Additional comments (5)
src/SCRIPTS/BF/pages.lua (1)

43-46: LGTM! Clean integration of the battery page.

The conditional block follows the established pattern and correctly places the battery configuration page in the navigation structure. The API version requirement (1.45) aligns with the feature availability.

src/SCRIPTS/BF/PAGES/battery.lua (4)

1-13: Well-structured template initialization.

The code follows the established pattern for loading UI templates and setting up coordinate systems. The helper functions for position increments are a clean approach.


19-21: Battery capacity field configuration looks appropriate.

The capacity field with 25mAh steps and 10000mAh maximum is reasonable for typical drone batteries. The 16-bit storage (vals={4,5}) should handle this range adequately.


22-31: Confirm MSP command codes and payload length

I wasn’t able to find MSP_BATTERY_CONFIG or MSP_SET_BATTERY_CONFIG definitions in the Lua files—please double-check against your protocol header (for example, msp.h or equivalent) to ensure:

  • Command codes 32/33 are indeed the battery-config read/write opcodes
  • minBytes = 13 matches the actual number of payload bytes sent by the flight controller
  • None of the fields entries reference a byte index beyond byte 13

14-18: Confirm voltage field scaling and indices in battery.lua

The centi-unit pattern (scale = 100) and a max = 500 (5.00 V) aligns with other BF UI pages (e.g. PWM “Idle Throttle %”, rates, rescue speeds), but please cross-check against the MSP battery config in the firmware:

  • In src/SCRIPTS/BF/PAGES/battery.lua (lines 15-17):
    scale = 100 – ensure this maps to centi-volts in MSP_BATTERY_CONFIG
    max = 500 – confirm 5.00 V is valid for all supported cell chemistries
    vals = {8,9}, {10,11}, {12,13} – verify these byte pairs match the MSP field order

Cross-reference the MSP protocol docs or firmware CLI code to confirm these constraints and indices.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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