diff --git a/docs/Programming Framework.md b/docs/Programming Framework.md index 3052b4f8ef5..e141c2a31d3 100644 --- a/docs/Programming Framework.md +++ b/docs/Programming Framework.md @@ -28,6 +28,7 @@ IPF can be edited using INAV Configurator user interface, of via CLI * `` - See `Operands` paragraph * `` - See `Operands` paragraph * `` - See `Flags` paragraph +* `` - Allows the grouping of code lines, to ease readability ### Operations @@ -196,13 +197,13 @@ All flags are reseted on ARM and DISARM event. ### Dynamic THROTTLE scale -`logic 0 1 0 23 0 50 0 0 0` +`logic 0 1 0 23 0 50 0 0 0 0` Limits the THROTTLE output to 50% when Logic Condition `0` evaluates as `true` ### Set VTX power level via Smart Audio -`logic 0 1 0 25 0 3 0 0 0` +`logic 0 1 0 25 0 3 0 0 0 0` Sets VTX power level to `3` when Logic Condition `0` evaluates as `true` @@ -211,27 +212,27 @@ Sets VTX power level to `3` when Logic Condition `0` evaluates as `true` Solves the problem from [https://github.com/iNavFlight/inav/issues/4439](https://github.com/iNavFlight/inav/issues/4439) ``` -logic 0 1 0 26 0 0 0 0 0 -logic 1 1 0 27 0 0 0 0 0 +logic 0 1 0 26 0 0 0 0 0 0 +logic 1 1 0 27 0 0 0 0 0 0 ``` Inverts ROLL and PITCH input when Logic Condition `0` evaluates as `true`. Moving Pitch stick up will cause pitch down (up for rear facing camera). Moving Roll stick right will cause roll left of a quad (right in rear facing camera) ### Cut motors but keep other throttle bindings active -`logic 0 1 0 29 0 1000 0 0 0` +`logic 0 1 0 29 0 1000 0 0 0 0` Sets Thhrottle output to `0%` when Logic Condition `0` evaluates as `true` ### Set throttle to 50% and keep other throttle bindings active -`logic 0 1 0 29 0 1500 0 0 0` +`logic 0 1 0 29 0 1500 0 0 0 0` Sets Thhrottle output to about `50%` when Logic Condition `0` evaluates as `true` ### Set throttle control to different RC channel -`logic 0 1 0 29 1 7 0 0 0` +`logic 0 1 0 29 1 7 0 0 0 0` If Logic Condition `0` evaluates as `true`, motor throttle control is bound to RC channel 7 instead of throttle channel @@ -240,10 +241,10 @@ If Logic Condition `0` evaluates as `true`, motor throttle control is bound to R Set VTX channel with a POT on the radio assigned to RC channel 6 ``` -logic 0 1 -1 15 1 6 0 1000 0 -logic 1 1 -1 37 4 0 0 7 0 -logic 2 1 -1 14 4 1 0 1 0 -logic 3 1 -1 31 4 2 0 0 0 +logic 0 1 -1 15 1 6 0 1000 0 0 +logic 1 1 -1 37 4 0 0 7 0 0 +logic 2 1 -1 14 4 1 0 1 0 0 +logic 3 1 -1 31 4 2 0 0 0 0 ``` Steps: @@ -257,10 +258,10 @@ Steps: Set VTX power with a POT on the radio assigned to RC channel 6. In this example we scale POT to 4 power level `[1:4]` ``` -logic 0 1 -1 15 1 6 0 1000 0 -logic 1 1 -1 37 4 0 0 3 0 -logic 2 1 -1 14 4 1 0 1 0 -logic 3 1 -1 25 4 2 0 0 0 +logic 0 1 -1 15 1 6 0 1000 0 0 +logic 1 1 -1 37 4 0 0 3 0 0 +logic 2 1 -1 14 4 1 0 1 0 0 +logic 3 1 -1 25 4 2 0 0 0 0 ``` Steps: diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index 5d75c0342a0..2ae4bd44314 100644 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -1874,7 +1874,7 @@ static void cliServoMix(char *cmdline) static void printLogic(uint8_t dumpMask, const logicCondition_t *logicConditions, const logicCondition_t *defaultLogicConditions) { - const char *format = "logic %d %d %d %d %d %d %d %d %d"; + const char *format = "logic %d %d %d %d %d %d %d %d %d %d"; for (uint32_t i = 0; i < MAX_LOGIC_CONDITIONS; i++) { const logicCondition_t logic = logicConditions[i]; @@ -1889,7 +1889,8 @@ static void printLogic(uint8_t dumpMask, const logicCondition_t *logicConditions logic.operandA.value == defaultValue.operandA.value && logic.operandB.type == defaultValue.operandB.type && logic.operandB.value == defaultValue.operandB.value && - logic.flags == defaultValue.flags; + logic.flags == defaultValue.flags && + logic.codeGroup == defaultValue.codeGroup; cliDefaultPrintLinef(dumpMask, equalsDefault, format, i, @@ -1900,7 +1901,8 @@ static void printLogic(uint8_t dumpMask, const logicCondition_t *logicConditions logic.operandA.value, logic.operandB.type, logic.operandB.value, - logic.flags + logic.flags, + logic.codeGroup ); } cliDumpPrintLinef(dumpMask, equalsDefault, format, @@ -1912,14 +1914,15 @@ static void printLogic(uint8_t dumpMask, const logicCondition_t *logicConditions logic.operandA.value, logic.operandB.type, logic.operandB.value, - logic.flags + logic.flags, + logic.codeGroup ); } } static void cliLogic(char *cmdline) { char * saveptr; - int args[9], check = 0; + int args[10], check = 0; uint8_t len = strlen(cmdline); if (len == 0) { @@ -1937,6 +1940,7 @@ static void cliLogic(char *cmdline) { OPERAND_B_TYPE, OPERAND_B_VALUE, FLAGS, + CODE_GROUP, ARGS_COUNT }; char *ptr = strtok_r(cmdline, " ", &saveptr); @@ -1960,7 +1964,8 @@ static void cliLogic(char *cmdline) { args[OPERAND_A_VALUE] >= -1000000 && args[OPERAND_A_VALUE] <= 1000000 && args[OPERAND_B_TYPE] >= 0 && args[OPERAND_B_TYPE] < LOGIC_CONDITION_OPERAND_TYPE_LAST && args[OPERAND_B_VALUE] >= -1000000 && args[OPERAND_B_VALUE] <= 1000000 && - args[FLAGS] >= 0 && args[FLAGS] <= 255 + args[FLAGS] >= 0 && args[FLAGS] <= 255 && + args[CODE_GROUP] >= 0 && args[CODE_GROUP] <= 9 ) { logicConditionsMutable(i)->enabled = args[ENABLED]; @@ -1971,6 +1976,7 @@ static void cliLogic(char *cmdline) { logicConditionsMutable(i)->operandB.type = args[OPERAND_B_TYPE]; logicConditionsMutable(i)->operandB.value = args[OPERAND_B_VALUE]; logicConditionsMutable(i)->flags = args[FLAGS]; + logicConditionsMutable(i)->codeGroup = args[CODE_GROUP]; cliLogic(""); } else { diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index f0194a72c5a..d28a8722e92 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -548,6 +548,7 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF sbufWriteU8(dst, logicConditions(i)->operandB.type); sbufWriteU32(dst, logicConditions(i)->operandB.value); sbufWriteU8(dst, logicConditions(i)->flags); + sbufWriteU8(dst, logicConditions(i)->codeGroup); } break; case MSP2_INAV_LOGIC_CONDITIONS_STATUS: @@ -2045,7 +2046,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) #ifdef USE_PROGRAMMING_FRAMEWORK case MSP2_INAV_SET_LOGIC_CONDITIONS: sbufReadU8Safe(&tmp_u8, src); - if ((dataSize == 15) && (tmp_u8 < MAX_LOGIC_CONDITIONS)) { + if ((dataSize == 16) && (tmp_u8 < MAX_LOGIC_CONDITIONS)) { logicConditionsMutable(tmp_u8)->enabled = sbufReadU8(src); logicConditionsMutable(tmp_u8)->activatorId = sbufReadU8(src); logicConditionsMutable(tmp_u8)->operation = sbufReadU8(src); @@ -2054,6 +2055,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) logicConditionsMutable(tmp_u8)->operandB.type = sbufReadU8(src); logicConditionsMutable(tmp_u8)->operandB.value = sbufReadU32(src); logicConditionsMutable(tmp_u8)->flags = sbufReadU8(src); + logicConditionsMutable(tmp_u8)->codeGroup = sbufReadU8(src); } else return MSP_RESULT_ERROR; break; diff --git a/src/main/programming/logic_condition.c b/src/main/programming/logic_condition.c index 19b0cb6e2da..15e715568e9 100644 --- a/src/main/programming/logic_condition.c +++ b/src/main/programming/logic_condition.c @@ -75,7 +75,8 @@ void pgResetFn_logicConditions(logicCondition_t *instance) .type = LOGIC_CONDITION_OPERAND_TYPE_VALUE, .value = 0 }, - .flags = 0 + .flags = 0, + .codeGroup = 0 ); } } diff --git a/src/main/programming/logic_condition.h b/src/main/programming/logic_condition.h index 68e69d68c84..b3bf60e4913 100644 --- a/src/main/programming/logic_condition.h +++ b/src/main/programming/logic_condition.h @@ -173,6 +173,7 @@ typedef struct logicCondition_s { logicOperand_t operandA; logicOperand_t operandB; uint8_t flags; + uint8_t codeGroup; } logicCondition_t; PG_DECLARE_ARRAY(logicCondition_t, MAX_LOGIC_CONDITIONS, logicConditions);