diff --git a/docs/Programming Framework.md b/docs/Programming Framework.md index f51f841bb9..26f5bec09a 100644 --- a/docs/Programming Framework.md +++ b/docs/Programming Framework.md @@ -80,6 +80,8 @@ IPF can be edited using INAV Configurator user interface, of via CLI | 44 | MAX | Finds the highest value of `Operand A` and `Operand B` | | 45 | FLIGHT_AXIS_ANGLE_OVERRIDE | Sets the target attitude angle for axis. In other words, when active, it enforces Angle mode (Heading Hold for Yaw) on this axis (Angle mode does not have to be active). `Operand A` defines the axis: `0` - Roll, `1` - Pitch, `2` - Yaw. `Operand B` defines the angle in degrees | | 46 | FLIGHT_AXIS_RATE_OVERRIDE | Sets the target rate (rotation speed) for axis. `Operand A` defines the axis: `0` - Roll, `1` - Pitch, `2` - Yaw. `Operand B` defines the rate in degrees per second | +| 47 | EDGE | `Operand A` is activation operator [`boolean`], `Operand B` is the time for the edge to stay active [ms]. After activation, operator will return `true` until the time in Operand B is reached | + ### Operands | Operand Type | Name | Notes | diff --git a/src/main/programming/logic_condition.c b/src/main/programming/logic_condition.c index 89d3a9aefb..241dc1d611 100644 --- a/src/main/programming/logic_condition.c +++ b/src/main/programming/logic_condition.c @@ -90,7 +90,7 @@ static int logicConditionCompute( logicOperation_e operation, int32_t operandA, int32_t operandB, - timeMs_t *timeout + uint8_t lcIndex ) { int temporaryValue; vtxDeviceCapability_t vtxDeviceCapability; @@ -164,9 +164,26 @@ static int logicConditionCompute( break; case LOGIC_CONDITION_EDGE: - if (operandA && timeout == 0) { - + if (operandA && logicConditionStates[lcIndex].timeout == 0 && !(logicConditionStates[lcIndex].flags & LOGIC_CONDITION_FLAG_EDGE_SATISFIED)) { + if (operandB < 100) { + logicConditionStates[lcIndex].timeout = millis() + 100; + } else { + logicConditionStates[lcIndex].timeout = millis() + operandB; + } + logicConditionStates[lcIndex].flags |= LOGIC_CONDITION_FLAG_EDGE_SATISFIED; + return true; + } else if (logicConditionStates[lcIndex].timeout > 0) { + if (logicConditionStates[lcIndex].timeout < millis()) { + logicConditionStates[lcIndex].timeout = 0; + } else { + return true; + } } + + if (!operandA) { + logicConditionStates[lcIndex].flags &= ~LOGIC_CONDITION_FLAG_EDGE_SATISFIED; + } + return false; break; case LOGIC_CONDITION_GVAR_SET: @@ -433,7 +450,7 @@ void logicConditionProcess(uint8_t i) { logicConditions(i)->operation, operandAValue, operandBValue, - &logicConditionStates[i].timeout, + i ); logicConditionStates[i].value = newValue; diff --git a/src/main/programming/logic_condition.h b/src/main/programming/logic_condition.h index 09c7a38cc5..32b4a4206a 100644 --- a/src/main/programming/logic_condition.h +++ b/src/main/programming/logic_condition.h @@ -167,7 +167,8 @@ typedef enum { } logicConditionsGlobalFlags_t; typedef enum { - LOGIC_CONDITION_FLAG_LATCH = 1 << 0, + LOGIC_CONDITION_FLAG_LATCH = 1 << 0, + LOGIC_CONDITION_FLAG_EDGE_SATISFIED = 1 << 1, } logicConditionFlags_e; typedef struct logicOperand_s {