-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Docs: JavaScript Programming - Add let/const and ternary operator documentation #11178
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
Docs: JavaScript Programming - Add let/const and ternary operator documentation #11178
Conversation
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.
Branch Targeting SuggestionYou've targeted the
If This is an automated suggestion to help route contributions to the appropriate branch. |
PR Compliance Guide 🔍All compliance sections have been disabled in the configurations. |
| 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; |
There was a problem hiding this comment.
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;
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
docs/javascript_programming/index.md
docs/javascript_programming/api_definitions_summary.md
PR Type
Enhancement, Documentation
Description
Add
MSP2_INAV_LOGIC_CONDITIONS_CONFIGUREDcommand for optimized configurator performanceExpand JavaScript programming documentation with new features and examples
flight.mode.*propertiespid[0-3].outputUpdate API definitions and version history for INAV 9.0
Diagram Walkthrough
File Walkthrough
fc_msp.c
Implement logic conditions configured bitmask commandsrc/main/fc/fc_msp.c
MSP2_INAV_LOGIC_CONDITIONS_CONFIGUREDcase handlerconfiguration state
operands, flags)
msp_protocol_v2_inav.h
Define MSP2 logic conditions configured commandsrc/main/msp/msp_protocol_v2_inav.h
MSP2_INAV_LOGIC_CONDITIONS_CONFIGUREDwithcode
0x203Cnon-default conditions
JAVASCRIPT_PROGRAMMING_GUIDE.md
Add variables, ternary operators, and API documentationdocs/javascript_programming/JAVASCRIPT_PROGRAMMING_GUIDE.md
assignment (recommended) and callback syntax
named expressions
assignment
flight.mode.*properties withavailable modes list
pid[0-3].outputwith read-onlyaccess clarification
conditions
api_definitions_summary.md
Update API definitions for modes and PID controllersdocs/javascript_programming/api_definitions_summary.md
property notation
output as read-only
JavaScript
index.md
Update feature list and version history for INAV 9.0docs/javascript_programming/index.md