Skip to content

Conversation

@derekhe
Copy link

@derekhe derekhe commented Oct 5, 2025

Add 5s and 10s average of ampere to help calibrate ampere sensor.

Summary by CodeRabbit

  • New Features

    • Added 5s and 10s average amperage metrics to Motors and Power (Battery) views for clearer, smoother current monitoring.
    • UI now displays continuously updated averages alongside existing amperage data.
  • Localization

    • Added English and Simplified Chinese labels and value formats for the new 5s/10s average amperage metrics, ensuring consistent display across locales.

Copilot AI review requested due to automatic review settings October 5, 2025 09:14
@github-actions
Copy link
Contributor

github-actions bot commented Oct 5, 2025

Auto-closing pull request because the source branch is named 'master'. Please create a feature branch instead. https://betaflight.com/docs/development#using-git-and-github

@github-actions github-actions bot closed this Oct 5, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 5, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds 5s/10s amperage average tracking and display for Motors and Power tabs. Introduces history buffers and average calculations in JS, new DOM elements in HTML, and corresponding i18n strings for en and zh_CN locales.

Changes

Cohort / File(s) Summary
Locales (en, zh_CN)
locales/en/messages.json, locales/zh_CN/messages.json
Added i18n keys for 5s/10s amperage averages and value placeholders for Motors and Power Battery sections.
Motors tab logic
src/js/tabs/motors.js
Added 5s/10s amperage history arrays and sizes; on updates, compute averages and update new UI elements. Exposes new properties: amperageHistory5s/10s and amperageHistorySize5s/10s.
Power tab logic
src/js/tabs/power.js
Added 5s/10s amperage history arrays and sizes; on slow updates, compute averages and update UI. Exposes new properties: amperageHistory5s/10s and amperageHistorySize5s/10s.
Motors tab UI
src/tabs/motors.html
Inserted two display rows for 5s/10s amperage averages using new i18n keys and CSS hooks.
Power tab UI
src/tabs/power.html
Added two table rows to show 5s/10s amperage averages with i18n-bound labels and value cells.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Poller as Data Poller
  participant MotorsJS as motors.js
  participant DOM as Motors DOM

  Poller->>MotorsJS: New amperage reading
  MotorsJS->>MotorsJS: Push to 5s/10s histories (trim to sizes)
  MotorsJS->>MotorsJS: Compute 5s and 10s averages
  MotorsJS->>DOM: Update .motors-bat-amperage-average-5s
  MotorsJS->>DOM: Update .motors-bat-amperage-average-10s
  note right of DOM: Uses i18n: motorsAmperageAverage5s/10s and value format keys
Loading
sequenceDiagram
  autonumber
  participant SlowTick as Slow Update Tick
  participant PowerJS as power.js
  participant DOM as Power DOM

  SlowTick->>PowerJS: Read current amperage
  PowerJS->>PowerJS: Update 5s/10s histories (trim)
  PowerJS->>PowerJS: Calculate 5s/10s averages
  PowerJS->>DOM: Set #amperage-average-5s value
  PowerJS->>DOM: Set #amperage-average-10s value
  note right of DOM: Labels via powerBatteryAmperageAverage5s/10s
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e65dc56 and bfe91e9.

📒 Files selected for processing (6)
  • locales/en/messages.json (3 hunks)
  • locales/zh_CN/messages.json (3 hunks)
  • src/js/tabs/motors.js (4 hunks)
  • src/js/tabs/power.js (3 hunks)
  • src/tabs/motors.html (1 hunks)
  • src/tabs/power.html (1 hunks)

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 and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds 5-second and 10-second rolling averages for amperage readings to help with calibrating ampere sensors. The feature provides more stable readings by smoothing out short-term fluctuations.

  • Adds amperage averaging functionality to both power and motors tabs
  • Implements rolling window calculations with configurable history sizes
  • Updates UI to display the new average values alongside existing amperage readings

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/tabs/power.html Adds HTML table rows for displaying 5s and 10s amperage averages
src/tabs/motors.html Adds HTML spans for displaying 5s and 10s amperage averages
src/js/tabs/power.js Implements rolling average calculation logic for power tab
src/js/tabs/motors.js Implements rolling average calculation logic for motors tab
locales/zh_CN/messages.json Adds Chinese translations for new amperage average labels
locales/en/messages.json Adds English translations for new amperage average labels

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +14 to +17
amperageHistory5s: [], // Store last 5 seconds of amperage readings for average calculation
amperageHistorySize5s: 25, // Number of readings to keep for 5 seconds average (5Hz * 5s = 25)
amperageHistory10s: [], // Store last 10 seconds of amperage readings for average calculation
amperageHistorySize10s: 50, // Number of readings to keep for 10 seconds average (5Hz * 10s = 50)
Copy link

Copilot AI Oct 5, 2025

Choose a reason for hiding this comment

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

The comment indicates 5Hz update rate but this assumption should be verified. If the actual update rate differs from 5Hz, the averaging windows will be incorrect. Consider making the update rate configurable or detecting it dynamically.

Suggested change
amperageHistory5s: [], // Store last 5 seconds of amperage readings for average calculation
amperageHistorySize5s: 25, // Number of readings to keep for 5 seconds average (5Hz * 5s = 25)
amperageHistory10s: [], // Store last 10 seconds of amperage readings for average calculation
amperageHistorySize10s: 50, // Number of readings to keep for 10 seconds average (5Hz * 10s = 50)
amperageUpdateRateHz: 5, // Default update rate in Hz; change if actual rate differs
amperageHistory5s: [], // Store last 5 seconds of amperage readings for average calculation
get amperageHistorySize5s() { return this.amperageUpdateRateHz * 5; }, // Number of readings for 5s average
amperageHistory10s: [], // Store last 10 seconds of amperage readings for average calculation
get amperageHistorySize10s() { return this.amperageUpdateRateHz * 10; }, // Number of readings for 10s average

Copilot uses AI. Check for mistakes.
sensorAccelRate: 20,
sensorAccelScale: 2,
amperageHistory5s: [], // Store last 5 seconds of amperage readings for average calculation
amperageHistorySize5s: 20, // Number of readings to keep for 5 seconds average (4Hz * 5s = 20)
Copy link

Copilot AI Oct 5, 2025

Choose a reason for hiding this comment

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

The motors tab uses a different update rate assumption (4Hz) than the power tab (5Hz). This inconsistency could lead to different averaging behavior between tabs. The update rates should be standardized or made configurable.

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 5, 2025

@github-actions
Copy link
Contributor

github-actions bot commented Oct 5, 2025

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