mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-16 04:45:22 +03:00
Added some more logic
Added delay, almost equal, and timer. Not yet tested.
This commit is contained in:
parent
1ca3527f92
commit
026e40c297
2 changed files with 48 additions and 6 deletions
|
@ -105,6 +105,11 @@ static int logicConditionCompute(
|
||||||
return operandA == operandB;
|
return operandA == operandB;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case LOGIC_CONDITION_APPROX_EQUAL:
|
||||||
|
uint16_t offest = operandA / 100;
|
||||||
|
return ((operandB >= (operandA - offest)) && (operandB <= (operandA + offest)));
|
||||||
|
break;
|
||||||
|
|
||||||
case LOGIC_CONDITION_GREATER_THAN:
|
case LOGIC_CONDITION_GREATER_THAN:
|
||||||
return operandA > operandB;
|
return operandA > operandB;
|
||||||
break;
|
break;
|
||||||
|
@ -164,13 +169,13 @@ static int logicConditionCompute(
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LOGIC_CONDITION_EDGE:
|
case LOGIC_CONDITION_EDGE:
|
||||||
if (operandA && logicConditionStates[lcIndex].timeout == 0 && !(logicConditionStates[lcIndex].flags & LOGIC_CONDITION_FLAG_EDGE_SATISFIED)) {
|
if (operandA && logicConditionStates[lcIndex].timeout == 0 && !(logicConditionStates[lcIndex].flags & LOGIC_CONDITION_FLAG_TIMEOUT_SATISFIED)) {
|
||||||
if (operandB < 100) {
|
if (operandB < 100) {
|
||||||
logicConditionStates[lcIndex].timeout = millis() + 100;
|
logicConditionStates[lcIndex].timeout = millis() + 100;
|
||||||
} else {
|
} else {
|
||||||
logicConditionStates[lcIndex].timeout = millis() + operandB;
|
logicConditionStates[lcIndex].timeout = millis() + operandB;
|
||||||
}
|
}
|
||||||
logicConditionStates[lcIndex].flags |= LOGIC_CONDITION_FLAG_EDGE_SATISFIED;
|
logicConditionStates[lcIndex].flags |= LOGIC_CONDITION_FLAG_TIMEOUT_SATISFIED;
|
||||||
return true;
|
return true;
|
||||||
} else if (logicConditionStates[lcIndex].timeout > 0) {
|
} else if (logicConditionStates[lcIndex].timeout > 0) {
|
||||||
if (logicConditionStates[lcIndex].timeout < millis()) {
|
if (logicConditionStates[lcIndex].timeout < millis()) {
|
||||||
|
@ -181,11 +186,44 @@ static int logicConditionCompute(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!operandA) {
|
if (!operandA) {
|
||||||
logicConditionStates[lcIndex].flags &= ~LOGIC_CONDITION_FLAG_EDGE_SATISFIED;
|
logicConditionStates[lcIndex].flags &= ~LOGIC_CONDITION_FLAG_TIMEOUT_SATISFIED;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case LOGIC_CONDITION_DELAY:
|
||||||
|
if (operandA) {
|
||||||
|
if (logicConditionStates[lcIndex].flags & LOGIC_CONDITION_FLAG_TIMEOUT_SATISFIED) {
|
||||||
|
return true;
|
||||||
|
} else if (logicConditionStates[lcIndex].timeout > millis()) {
|
||||||
|
logicConditionStates[lcIndex].flags |= LOGIC_CONDITION_FLAG_TIMEOUT_SATISFIED;
|
||||||
|
return true;
|
||||||
|
} else if (logicConditionStates[lcIndex].timeout == 0) {
|
||||||
|
logicConditionStates[lcIndex].timeout = millis() + operandB;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logicConditionStates[lcIndex].timeout = 0;
|
||||||
|
logicConditionStates[lcIndex].flags &= ~LOGIC_CONDITION_FLAG_TIMEOUT_SATISFIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOGIC_CONDITION_TIMER:
|
||||||
|
if (logicConditionStates[lcIndex].timeout > millis() && currentVaue) {
|
||||||
|
logicConditionStates[lcIndex].timeout millis() + operandB;
|
||||||
|
return false;
|
||||||
|
} else if ((logicConditionStates[lcIndex].timeout == 0) || (logicConditionStates[lcIndex].timeout > millis() && currentVaue)) {
|
||||||
|
logicConditionStates[lcIndex].timeout millis() + operandA;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return currentVaue;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOGIC_CONDITION_DELTA:
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
|
||||||
case LOGIC_CONDITION_GVAR_SET:
|
case LOGIC_CONDITION_GVAR_SET:
|
||||||
gvSet(operandA, operandB);
|
gvSet(operandA, operandB);
|
||||||
return operandB;
|
return operandB;
|
||||||
|
|
|
@ -77,7 +77,11 @@ typedef enum {
|
||||||
LOGIC_CONDITION_FLIGHT_AXIS_ANGLE_OVERRIDE = 45,
|
LOGIC_CONDITION_FLIGHT_AXIS_ANGLE_OVERRIDE = 45,
|
||||||
LOGIC_CONDITION_FLIGHT_AXIS_RATE_OVERRIDE = 46,
|
LOGIC_CONDITION_FLIGHT_AXIS_RATE_OVERRIDE = 46,
|
||||||
LOGIC_CONDITION_EDGE = 47,
|
LOGIC_CONDITION_EDGE = 47,
|
||||||
LOGIC_CONDITION_LAST = 48,
|
LOGIC_CONDITION_DELAY = 48,
|
||||||
|
LOGIC_CONDITION_TIMER = 49,
|
||||||
|
LOGIC_CONDITION_DELTA = 50,
|
||||||
|
LOGIC_CONDITION_APPROX_EQUAL = 51,
|
||||||
|
LOGIC_CONDITION_LAST = 52,
|
||||||
} logicOperation_e;
|
} logicOperation_e;
|
||||||
|
|
||||||
typedef enum logicOperandType_s {
|
typedef enum logicOperandType_s {
|
||||||
|
@ -167,8 +171,8 @@ typedef enum {
|
||||||
} logicConditionsGlobalFlags_t;
|
} logicConditionsGlobalFlags_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
LOGIC_CONDITION_FLAG_LATCH = 1 << 0,
|
LOGIC_CONDITION_FLAG_LATCH = 1 << 0,
|
||||||
LOGIC_CONDITION_FLAG_EDGE_SATISFIED = 1 << 1,
|
LOGIC_CONDITION_FLAG_TIMEOUT_SATISFIED = 1 << 1,
|
||||||
} logicConditionFlags_e;
|
} logicConditionFlags_e;
|
||||||
|
|
||||||
typedef struct logicOperand_s {
|
typedef struct logicOperand_s {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue