Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions docs/Programming Framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ IPF can be edited using INAV Configurator user interface, of via CLI
* `<operand B type>` - See `Operands` paragraph
* `<operand B value>` - See `Operands` paragraph
* `<flags>` - See `Flags` paragraph
* `<code group>` - Allows the grouping of code lines, to ease readability

### Operations

Expand Down Expand Up @@ -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`

Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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:
Expand Down
18 changes: 12 additions & 6 deletions src/main/fc/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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];
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/main/fc/fc_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/main/programming/logic_condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ void pgResetFn_logicConditions(logicCondition_t *instance)
.type = LOGIC_CONDITION_OPERAND_TYPE_VALUE,
.value = 0
},
.flags = 0
.flags = 0,
.codeGroup = 0
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/programming/logic_condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down