Skip to content

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Dec 19, 2025

User description

Summary

This PR resolves the merge conflict in #2202 by adding support for dynamic power_min from the flight controller while maintaining compatibility with INAV 9.0 RCx.

Original PR: #2202 by @bkleiner
Conflict cause: PR #2206 added MSP VTX support which uses 0-based power indexing (index 0 = power off), while #2202 assumed all devices are 1-based.

Changes

1. Added power_min Field

  • Added FC.VTX_CONFIG.power_min field (default: 1)
  • Allows dynamic minimum power index from firmware

2. Enhanced MSP Parser (js/msp/MSPHelper.js)

  • Added defensive buffer length checking for backward compatibility
  • Reads power_min from firmware if available (INAV 9.1+)
  • Falls back to device-type logic for firmware 9.0:
    • MSP VTX: min = 0 (supports power off at index 0)
    • SmartAudio/Tramp: min = 1 (power off not supported)
  • Fixed typo: "wether" → "whether"

3. Resolved Merge Conflict (js/vtx.js)

  • Removed both POWER_MIN constant and getMinPower()/getMaxPower() functions
  • Kept DEV_MSP = 6 constant from master
  • Eliminates all hardcoded device-type power logic

4. Updated VTX Power UI (tabs/configuration.js)

  • Changed from VTX.POWER_MIN to FC.VTX_CONFIG.power_min
  • Now uses dynamic values from firmware

Compatibility

✅ Configurator 9.1 (this PR) + Firmware 9.0

Firmware sends 11 bytes, configurator detects missing power_min and falls back to device-type logic

  • MSP VTX correctly shows power indices 0-4
  • SmartAudio/Tramp correctly show power indices 1-N

✅ Configurator 9.0 (current) + Firmware 9.1 (future)

Old configurator ignores extra bytes, uses hardcoded logic

  • No breaking changes created

Firmware Enhancement (Future)

The configurator is ready to receive power_min from firmware. To complete this feature, add one byte to MSP_VTX_CONFIG response in firmware:

// In src/main/fc/fc_msp.c, case MSP_VTX_CONFIG:
sbufWriteU8(dst, vtxDevice->capability.powerCount);

// NEW: Add minimum valid power index
uint8_t minPowerIndex = 0;
if (deviceType == VTXDEV_SMARTAUDIO || deviceType == VTXDEV_TRAMP) {
    minPowerIndex = 1;
}
sbufWriteU8(dst, minPowerIndex);  // Byte 12

Once firmware sends this byte, the configurator will automatically use it instead of the fallback logic.

Benefits

✅ Preserves PR #2202's original intent - eliminates hardcoded device-type logic
✅ Single source of truth - firmware owns all VTX capabilities
✅ Fixes MSP VTX power off support (index 0 now accessible)
✅ Backward compatible with firmware 9.0
✅ Forward compatible - ready for firmware 9.1 enhancement
✅ No breaking changes in either upgrade direction

Testing

  • ✅ JavaScript syntax validation passed
  • ✅ Merge conflict fully resolved
  • ✅ Defensive buffer parsing prevents crashes with older firmware
  • 🔲 Hardware testing needed (MSP, SmartAudio, Tramp VTX devices)

Related

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Changes generate no new warnings
  • Added defensive buffer checking for backward compatibility
  • Tested syntax validation
  • Hardware testing (requires devices)

Description

  • Add dynamic VTX power configuration from firmware with backward compatibility

    • New fields: band_count, channel_count, power_count, power_min in FC.VTX_CONFIG
    • Reads power_min from firmware (INAV 9.1+) with fallback logic for 9.0
  • Enhanced MSP parser with defensive buffer checking

    • Validates buffer length before reading VTX table data
    • Falls back to device-type logic (MSP VTX: min=0, others: min=1) if firmware doesn't send power_min
    • Fixed typo: "wether" → "whether"
  • Removed hardcoded power level functions from VTX module

    • Deleted getMinPower() and getMaxPower() functions
    • Eliminates device-type specific power logic from configurator
  • Updated VTX power UI to use firmware values

    • Changed from VTX.getMinPower/getMaxPower() to FC.VTX_CONFIG.power_min and power_count

Diagram Walkthrough

flowchart LR
  FW["Firmware 9.0/9.1<br/>MSP_VTX_CONFIG"] -->|sends power_min| MSPHelper["MSPHelper.js<br/>Parse with buffer check"]
  MSPHelper -->|fallback device logic| FC["FC.VTX_CONFIG<br/>power_min, power_count"]
  FC -->|dynamic values| ConfigUI["Configuration UI<br/>Power dropdown"]
  VTX["VTX.js<br/>Remove hardcoded logic"] -.->|eliminated| ConfigUI
Loading

File Walkthrough

Relevant files
Enhancement
fc.js
Add VTX configuration fields for power levels                       

js/fc.js

  • Added four new fields to FC.VTX_CONFIG: band_count, channel_count,
    power_count, power_min
  • Set default value of power_min to 1 for backward compatibility
+4/-0     
MSPHelper.js
Enhance MSP parser with dynamic power configuration           

js/msp/MSPHelper.js

  • Added defensive buffer length checking before reading VTX table data
  • Reads band_count, channel_count, power_count from firmware if
    available
  • Implements fallback logic for power_min: MSP VTX uses 0, others use 1
    if firmware doesn't send it
  • Fixed typo: "wether" → "whether"
+20/-1   
configuration.js
Update VTX power UI to use firmware values                             

tabs/configuration.js

  • Changed power dropdown generation to use FC.VTX_CONFIG.power_min
    instead of VTX.getMinPower()
  • Changed power dropdown upper bound to use FC.VTX_CONFIG.power_count
    instead of VTX.getMaxPower()
  • Now uses dynamic firmware values instead of hardcoded device-type
    logic
+1/-3     
Bug fix
vtx.js
Remove hardcoded VTX power level functions                             

js/vtx.js

  • Removed getMinPower() function that returned device-type specific
    minimum power index
  • Removed getMaxPower() function that returned device-type specific
    maximum power index
  • Eliminates hardcoded device-type power logic from configurator
+0/-17   

bkleiner and others added 2 commits October 1, 2024 10:03
Resolves merge conflict in PR iNavFlight#2202 by adding support for dynamic
power_min from firmware while maintaining backward compatibility.

Changes:
- Added FC.VTX_CONFIG.power_min field (default 1)
- Updated MSPHelper.js to read power_min from firmware (INAV 9.1+)
- Added defensive buffer checking for backward compatibility with 9.0
- Falls back to device-type logic if firmware doesn't send power_min
  (MSP VTX: min=0, others: min=1)
- Resolved merge conflict in js/vtx.js by removing both POWER_MIN
  constant and getMinPower()/getMaxPower() functions
- Updated tabs/configuration.js to use FC.VTX_CONFIG.power_min instead
  of VTX.POWER_MIN

This implementation:
- Works with current firmware 9.0 (graceful fallback)
- Ready for future firmware 9.1 with power_min support
- Eliminates hardcoded device-type logic in configurator
- Maintains single source of truth in firmware

Related: iNavFlight#2202
Related: iNavFlight#2206
Related: iNavFlight/inav#10395

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Dec 19, 2025

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

@sensei-hacker sensei-hacker changed the base branch from master to maintenance-9.x December 19, 2025 15:52
@iNavFlight iNavFlight deleted a comment from github-actions bot Dec 19, 2025
Move power_min fallback outside buffer length check to handle edge
case where packet is truncated after vtxtable_available flag.

Addresses Qodo suggestion #1 for more robust parsing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@sensei-hacker
Copy link
Member Author

sensei-hacker commented Dec 19, 2025

Implemented suggestion #1 for robustness. Suggestion #2 is incorrect: powerCount should be the maximum valid index, not count. Current loop correctly includes all indices.

sensei-hacker added a commit to sensei-hacker/inav_unofficial_targets that referenced this pull request Dec 19, 2025
Adds minPowerIndex (byte 12) to MSP_VTX_CONFIG response to indicate
the minimum valid power index for the VTX device.

- MSP VTX: minPowerIndex = 0 (supports power off at index 0)
- SmartAudio/Tramp: minPowerIndex = 1 (power off not supported)

This allows configurator to correctly display all available power
levels without hardcoding device-specific logic.

Backward compatible: old configurators will ignore the extra byte.

Related: iNavFlight/inav-configurator#2486

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@sensei-hacker
Copy link
Member Author

Requires iNavFlight/inav#11190 to be fully effective (otherwise the fallback is used)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants