Skip to content

Commit ad3dfac

Browse files
authored
Merge pull request #6699 from MingchenZhang/zmc-modulus-opeator
Add modulus operator support
2 parents ee06203 + cce8345 commit ad3dfac

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

docs/Programming Framework.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ IPF can be edited using INAV Configurator user interface, of via CLI
7373
| 37 | MAP_OUTPUT | Scales `Operand A` from [`0` : `1000`] to [`0` : `Operand B`]. Note: input will be constrained and then scaled |
7474
| 38 | RC_CHANNEL_OVERRIDE | Overrides channel set by `Operand A` to value of `Operand B` |
7575
| 39 | SET_HEADING_TARGET | Sets heading-hold target to `Operand A`, in degrees. Value wraps-around. |
76+
| 40 | MOD | Divide `Operand A` by `Operand B` and returns the remainder |
7677

7778

7879
### Operands

src/main/programming/logic_condition.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ static int logicConditionCompute(
324324
return temporaryValue;
325325
break;
326326

327+
case LOGIC_CONDITION_MODULUS:
328+
if (operandB != 0) {
329+
return constrain(operandA % operandB, INT16_MIN, INT16_MAX);
330+
} else {
331+
return operandA;
332+
}
333+
break;
334+
327335
default:
328336
return false;
329337
break;

src/main/programming/logic_condition.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ typedef enum {
6969
LOGIC_CONDITION_MAP_OUTPUT = 37,
7070
LOGIC_CONDITION_RC_CHANNEL_OVERRIDE = 38,
7171
LOGIC_CONDITION_SET_HEADING_TARGET = 39,
72-
LOGIC_CONDITION_LAST = 40,
72+
LOGIC_CONDITION_MODULUS = 40,
73+
LOGIC_CONDITION_LAST = 41,
7374
} logicOperation_e;
7475

7576
typedef enum logicOperandType_s {

0 commit comments

Comments
 (0)