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

Merged
merged 2 commits into from
Aug 9, 2025

Conversation

Forceu
Copy link
Contributor

@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.41, as this seems to be the level that BF4.0.0 was using, when the uint16 precision for battery voltage was introduced

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.

Closes #505

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.41 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.41 and above, referencing the newly added script. No other logic is altered.

Changes

File(s) Change Summary
Battery configuration page
src/SCRIPTS/BF/PAGES/battery.lua
Added a new Lua script defining the battery configuration page, including UI layout, labels, fields, and MSP command codes.
Pages list update
src/SCRIPTS/BF/pages.lua
Modified API version check from 1.45 to 1.41 to include the "Battery" page in the PageFiles list, 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.41
        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 a76cd41 and 1acac3c.

📒 Files selected for processing (1)
  • src/SCRIPTS/BF/PAGES/battery.lua (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/SCRIPTS/BF/PAGES/battery.lua
✨ 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.

@haslinghuis
Copy link
Member

@Forceu please rebase now CI is fixed

@Forceu
Copy link
Contributor Author

Forceu commented Aug 3, 2025

@Forceu please rebase now CI is fixed

Rebased with the latest commit and added spaces as requested, min API is now 1.41

Changed API to 1.41
haslinghuis
haslinghuis previously approved these changes Aug 3, 2025
@haslinghuis haslinghuis requested a review from klutvott123 August 3, 2025 19:48
@Forceu
Copy link
Contributor Author

Forceu commented Aug 3, 2025

Sorry I misunderstood the requested additional space, I thought it was meant for the strings, not for formatting. Fixed in 1acac3c

Copy link
Member

@haslinghuis haslinghuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lols yeah space was for indentation in line 17

Copy link
Member

@klutvott123 klutvott123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 🙂

@klutvott123 klutvott123 merged commit 528dbff into betaflight:master Aug 9, 2025
2 checks passed
fields[#fields + 1] = { t = "Warning Cell", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 500, vals = { 12, 13 }, scale = 100 }

labels[#labels + 1] = { t = "Capacity Settings", x = x, y = inc.y(lineSpacing) }
fields[#fields + 1] = { t = "Battery Capacity", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 0, steps = 25, max = 10000, vals = { 4, 5 } }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this. You would have to use "mult", not "steps" as there's no such thing. Look at the code in ui.lua

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks for pointing it out! Yeah I already wrote about in the initial post, as I wasn't sure what to use for steps instead. If you want to, I can create another PR changing it 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do 🙂

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.

Req: Battery voltage warnings setup via LUA from radio
3 participants