Skip to content

Log amperage for every current meter type, and default SD-only targets to SD blackbox - #11902

Open
Raffi1202 wants to merge 2 commits into
iNavFlight:maintenance-10.xfrom
Raffi1202:fix/blackbox-target-defaults
Open

Raffi1202 wants to merge 2 commits into
iNavFlight:maintenance-10.xfrom
Raffi1202:fix/blackbox-target-defaults

Conversation

@Raffi1202

@Raffi1202 Raffi1202 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #8966 and #9871.

With current_meter_type = ESC (STM32H750, INAV 5.1 and 6.0) the blackbox log has no amperage field at all, while escTemperature and escRPM are present (#8966). On a BeeRotor F4, status reports SD card: Startup failed with several freshly formatted cards that work on Betaflight 4.4.3, on INAV 5.1 through 7.1, and the board locks up when the Blackbox tab is opened; the reporter found that set blackbox_device = SDCARD makes the card mount, and a maintainer suspected a wrong default (#9871).

Cause

src/main/blackbox/blackbox.c:808 (maintenance-10.x) writes the amperage field only when current.type == CURRENT_SENSOR_ADC. The value comes from getAmperage() (blackbox.c:1831), which taskUpdateBattery() maintains for every meter type under isAmperageConfigured() (src/main/sensors/battery.c:680-683, src/main/fc/fc_tasks.c:136). escRPM/escTemperature are unconditional slow-frame fields (blackbox.c:526-527), so they appear while amperage does not.

DEFAULT_BLACKBOX_DEVICE (blackbox.c:96-101) is SERIAL unless the target defines ENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT. BEEROTORF4/target.h:48-53, GEPRCF722_BT_HD/target.h:79-82 and SPRACINGF7DUAL/target.h:119-127 define USE_SDCARD, have no flash, and lack that define. The only other USE_SDCARD targets without it are ZEEZF7 (SD only on V3, flash default set on purpose) and SITL (USE_SDCARD_SITL).

Change

The amperage condition returns isAmperageConfigured(), so the field is written for every configured current meter type and omitted when there is no current source. The SD-card default define is added to the three targets above; ZEEZF7 and SITL are left as they are. PG_BLACKBOX_CONFIG is not bumped: saved configurations keep their blackbox_device, only defaults and resets change.

Test

Not run on hardware or SITL. Cause verified by reading blackbox.c:808, battery.c:680-683 and the three target headers on maintenance-10.x. Built by fork CI: pending (no run on fix/blackbox-target-defaults, no upstream check on 3961223). Compiled for all targets and the four SITL builds on the fork, green: https://github.com/Raffi1202/inav/actions/runs/34770672196

Flash / RAM

Builds clean on all targets. No size comparison yet: the fork build has no baseline for this branch, and the upstream size report runs once CI is released for this PR.

Docs

No documentation change needed: blackbox_device is documented as a target default (docs/Settings.md:614-624), docs/Blackbox.md:19 already lists current as a logged value, and docs/development/targets/common-issues.md:373-383 already names the define as the fix for this symptom.

Raphael Hunziker added 2 commits September 10, 2026 20:00
BEEROTORF4, GEPRCF722_BT_HD and SPRACINGF7DUAL define USE_SDCARD but not
ENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT, so the blackbox device defaulted
to BLACKBOX_DEVICE_SERIAL even though the SD card slot is the only onboard
logging device on these boards.

Fixes iNavFlight#9871
The amperage field was gated on current_meter_type being ADC, a leftover from
when the condition was still named FLIGHT_LOG_FIELD_CONDITION_AMPERAGE_ADC. The
logged value comes from getAmperage(), which is maintained for every current
meter type, so ESC, CRSF, SmartPort, CAN, INA226 and virtual meters produced no
amperage field at all.

Use isAmperageConfigured(), the same predicate taskUpdateBattery() uses to
decide whether an amperage value is updated, so no field is written when there
is no current source.

Fixes iNavFlight#8966
@Raffi1202
Raffi1202 marked this pull request as ready for review September 11, 2026 15:58
@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Fix amperage logging and SD-only blackbox defaults

🐞 Bug fix ⚙️ Configuration changes 🕐 10-20 Minutes

Grey Divider

AI Description

• Log amperage whenever any current meter source is configured.
• Default three SD-only flight-controller targets to SD-card blackbox storage.
Diagram

graph TD
  A["Current meter"] -->|configured| B["Amperage predicate"] --> C["Blackbox condition"] --> D["Amperage field"]
  E["Target headers"] -->|SD default| F["Device selector"] --> G["SD blackbox"]
Loading
High-Level Assessment

The localized approach is appropriate: reusing isAmperageConfigured keeps blackbox behavior aligned with battery updates, while per-target SD defaults avoid changing behavior for mixed-storage or simulated targets. A global USE_SDCARD-based default would be broader and could regress boards that deliberately prefer flash.

Files changed (4) +4 / -1

Bug fix (1) +1 / -1
blackbox.cEnable amperage logging for every configured current source +1/-1

Enable amperage logging for every configured current source

• Replaces the ADC-only blackbox field condition with isAmperageConfigured(). Amperage is now logged for all supported current-meter types while remaining omitted when no current source exists.

src/main/blackbox/blackbox.c

Other (3) +3 / -0
target.hDefault BEEROTORF4 blackbox logging to SD card +1/-0

Default BEEROTORF4 blackbox logging to SD card

• Enables the target macro that selects the onboard SD card as the default blackbox device instead of serial output.

src/main/target/BEEROTORF4/target.h

target.hDefault GEPRCF722_BT_HD blackbox logging to SD card +1/-0

Default GEPRCF722_BT_HD blackbox logging to SD card

• Marks the configured SPI SD-card slot as the target's default blackbox storage device.

src/main/target/GEPRCF722_BT_HD/target.h

target.hDefault SPRACINGF7DUAL blackbox logging to SD card +1/-0

Default SPRACINGF7DUAL blackbox logging to SD card

• Selects the board's SPI SD-card slot as the default destination for blackbox logs.

src/main/target/SPRACINGF7DUAL/target.h

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can switch off images and animations for a plain-text comment

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

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.

no sdcard found Beerotor F4 No Amperage data in the blackbox when current_meter_type = ESC

2 participants