Skip to content

Conversation

@sensei-hacker
Copy link
Member

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

User description

Summary

Adds comprehensive documentation for let/const variables and ternary operator support in the JavaScript transpiler.

Changes

docs/javascript_programming/JAVASCRIPT_PROGRAMMING_GUIDE.md

  • Added new "Variables" section explaining let/const vs gvar usage
  • Documented let/const as compile-time named expressions
  • Added ternary operator section with examples
  • Clarified when to use compile-time vs runtime variables

docs/javascript_programming/index.md

  • Updated feature list to reflect let/const variable name preservation
  • Minor formatting improvements

docs/javascript_programming/api_definitions_summary.md

  • Updated to reflect current transpiler capabilities

PR Type

Enhancement, Documentation


Description

  • Add MSP2_INAV_LOGIC_CONDITIONS_CONFIGURED command for optimized configurator performance

    • Returns 8-byte bitmask indicating non-default logic conditions
    • Reduces MSP requests from 64 to 1+N for faster OSD/programming tab loading
  • Expand JavaScript programming documentation with new features and examples

    • Add let/const variables and ternary operator documentation with use cases
    • Document flight mode detection via flight.mode.* properties
    • Document PID controller output access via pid[0-3].output
    • Update sticky() syntax to show both variable assignment and callback patterns
  • Update API definitions and version history for INAV 9.0


Diagram Walkthrough

flowchart LR
  A["MSP Protocol"] -->|"Add MSP2_INAV_LOGIC_CONDITIONS_CONFIGURED"| B["8-byte Bitmask"]
  B -->|"Indicates configured conditions"| C["Faster Configurator Loading"]
  D["JavaScript Guide"] -->|"Add let/const & ternary"| E["Improved Code Readability"]
  D -->|"Document flight.mode.* & pid[].output"| F["Extended API Coverage"]
  D -->|"Update sticky() patterns"| G["Better Examples"]
Loading

File Walkthrough

Relevant files
Enhancement
fc_msp.c
Implement logic conditions configured bitmask command       

src/main/fc/fc_msp.c

  • Add new MSP2_INAV_LOGIC_CONDITIONS_CONFIGURED case handler
  • Implement 64-bit bitmask generation by checking each logic condition's
    configuration state
  • Compare against default reset values (enabled, activatorId, operation,
    operands, flags)
  • Return bitmask as two 32-bit values for MSP protocol compatibility
+23/-0   
Configuration changes
msp_protocol_v2_inav.h
Define MSP2 logic conditions configured command                   

src/main/msp/msp_protocol_v2_inav.h

  • Define new MSP2 command MSP2_INAV_LOGIC_CONDITIONS_CONFIGURED with
    code 0x203C
  • Add inline comment explaining the command returns 8-byte bitmask of
    non-default conditions
+1/-0     
Documentation
JAVASCRIPT_PROGRAMMING_GUIDE.md
Add variables, ternary operators, and API documentation   

docs/javascript_programming/JAVASCRIPT_PROGRAMMING_GUIDE.md

  • Expand sticky() documentation with two syntax options: variable
    assignment (recommended) and callback syntax
  • Add new "Variables" section documenting let/const for compile-time
    named expressions
  • Add ternary operator documentation with examples for conditional value
    assignment
  • Document flight mode detection via flight.mode.* properties with
    available modes list
  • Document PID controller outputs via pid[0-3].output with read-only
    access clarification
  • Update example code to use variable assignment pattern for sticky
    conditions
  • Update hysteresis example to demonstrate variable assignment syntax
+124/-16
api_definitions_summary.md
Update API definitions for modes and PID controllers         

docs/javascript_programming/api_definitions_summary.md

  • Update flight.mode list to include all available modes with nested
    property notation
  • Clarify PID controller properties: remove configure/enabled, keep only
    output as read-only
  • Add note explaining PID parameters are configured in UI, not
    JavaScript
+4/-4     
index.md
Update feature list and version history for INAV 9.0         

docs/javascript_programming/index.md

  • Add flight mode detection and PID controller outputs to feature list
  • Update version history from generic date to "INAV 9.0" release version
  • Expand version history with comprehensive feature list
  • Update last modified date to 2025-12-10
+13/-7   

Returns 8-byte bitmask indicating which logic conditions differ from defaults.
Enables configurator optimization to reduce MSP requests from 64 to 1+N.
…conditions-enabled-mask

Add MSP2_INAV_LOGIC_CONDITIONS_CONFIGURED command to make the OSD and programming tabs load much faster
- Add PID controller output documentation (pid[0-3].output)
- Add flight mode detection documentation (flight.mode.*)
- Update sticky syntax to use variable assignment pattern
- Update version history for INAV 9.0
- Fix API definitions summary for PID controllers
Added documentation for:
- Let/const variables for compile-time named expressions
- Ternary operator for conditional value assignment
- Benefits and use cases for each feature
- Examples showing practical usage

These features improve code readability and maintainability by allowing
developers to use meaningful variable names that preserve through
compile/decompile cycles.
@github-actions
Copy link

Branch Targeting Suggestion

You've targeted the master branch with this PR. Please consider if a version branch might be more appropriate:

  • maintenance-9.x - If your change is backward-compatible and won't create compatibility issues between INAV firmware and Configurator 9.x versions. This will allow your PR to be included in the next 9.x release.

  • maintenance-10.x - If your change introduces compatibility requirements between firmware and configurator that would break 9.x compatibility. This is for PRs which will be included in INAV 10.x

If master is the correct target for this change, no action is needed.


This is an automated suggestion to help route contributions to the appropriate branch.

@qodo-code-review
Copy link
Contributor

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

Comment on lines 564 to +589
sbufWriteU32(dst, logicConditionGetValue(i));
}
break;
case MSP2_INAV_LOGIC_CONDITIONS_CONFIGURED:
{
// Returns 8-byte bitmask where bit N = 1 if logic condition N is configured (non-default)
uint64_t mask = 0;
for (int i = 0; i < MAX_LOGIC_CONDITIONS; i++) {
const logicCondition_t *lc = logicConditions(i);
// Check if any field differs from default reset values
bool isConfigured = (lc->enabled != 0) ||
(lc->activatorId != -1) ||
(lc->operation != 0) ||
(lc->operandA.type != LOGIC_CONDITION_OPERAND_TYPE_VALUE) ||
(lc->operandA.value != 0) ||
(lc->operandB.type != LOGIC_CONDITION_OPERAND_TYPE_VALUE) ||
(lc->operandB.value != 0) ||
(lc->flags != 0);
if (isConfigured) {
mask |= ((uint64_t)1 << i);
}
}
sbufWriteU32(dst, (uint32_t)(mask & 0xFFFFFFFF)); // Lower 32 bits
sbufWriteU32(dst, (uint32_t)((mask >> 32) & 0xFFFFFFFF)); // Upper 32 bits
}
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: Validate and reserve the required payload size before writing to the stream buffer to avoid out-of-bounds writes. [Learned best practice, importance: 6]

New proposed code:
 case MSP2_INAV_LOGIC_CONDITIONS_STATUS:
-    for (int i = 0; i < MAX_LOGIC_CONDITIONS; i++) {
-        sbufWriteU32(dst, logicConditionGetValue(i));
+    {
+        const unsigned needed = MAX_LOGIC_CONDITIONS * 4;
+        if (!sbufEnsureWrite(dst, needed)) { return false; }
+        for (int i = 0; i < MAX_LOGIC_CONDITIONS; i++) {
+            sbufWriteU32(dst, logicConditionGetValue(i));
+        }
     }
     break;
 case MSP2_INAV_LOGIC_CONDITIONS_CONFIGURED:
     {
-        // Returns 8-byte bitmask where bit N = 1 if logic condition N is configured (non-default)
         uint64_t mask = 0;
         for (int i = 0; i < MAX_LOGIC_CONDITIONS; i++) {
             const logicCondition_t *lc = logicConditions(i);
-            // Check if any field differs from default reset values
             bool isConfigured = (lc->enabled != 0) ||
                                 (lc->activatorId != -1) ||
                                 (lc->operation != 0) ||
                                 (lc->operandA.type != LOGIC_CONDITION_OPERAND_TYPE_VALUE) ||
                                 (lc->operandA.value != 0) ||
                                 (lc->operandB.type != LOGIC_CONDITION_OPERAND_TYPE_VALUE) ||
                                 (lc->operandB.value != 0) ||
                                 (lc->flags != 0);
             if (isConfigured) {
                 mask |= ((uint64_t)1 << i);
             }
         }
-        sbufWriteU32(dst, (uint32_t)(mask & 0xFFFFFFFF));        // Lower 32 bits
-        sbufWriteU32(dst, (uint32_t)((mask >> 32) & 0xFFFFFFFF)); // Upper 32 bits
+        if (!sbufEnsureWrite(dst, 8)) { return false; }
+        sbufWriteU32(dst, (uint32_t)(mask & 0xFFFFFFFF));
+        sbufWriteU32(dst, (uint32_t)((mask >> 32) & 0xFFFFFFFF));
     }
     break;

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.

1 participant