Skip to content

Commit

Permalink
Merge pull request #10246 from iNavFlight/MrD_Fix-programming-paramet…
Browse files Browse the repository at this point in the history
…ers-with-too-small-ints

Fix programming framework parameters using int16 instead of in32
  • Loading branch information
MrD-RC authored Jul 21, 2024
2 parents 8f1297b + 59f5737 commit d9f6db1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions src/main/programming/logic_condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ static int logicConditionCompute(

void logicConditionProcess(uint8_t i) {

const int activatorValue = logicConditionGetValue(logicConditions(i)->activatorId);
const int32_t activatorValue = logicConditionGetValue(logicConditions(i)->activatorId);

if (logicConditions(i)->enabled && activatorValue && !cliMode) {

Expand All @@ -522,9 +522,9 @@ void logicConditionProcess(uint8_t i) {
* Latched LCs can only go from OFF to ON, not the other way
*/
if (!(logicConditionStates[i].flags & LOGIC_CONDITION_FLAG_LATCH)) {
const int operandAValue = logicConditionGetOperandValue(logicConditions(i)->operandA.type, logicConditions(i)->operandA.value);
const int operandBValue = logicConditionGetOperandValue(logicConditions(i)->operandB.type, logicConditions(i)->operandB.value);
const int newValue = logicConditionCompute(
const int32_t operandAValue = logicConditionGetOperandValue(logicConditions(i)->operandA.type, logicConditions(i)->operandA.value);
const int32_t operandBValue = logicConditionGetOperandValue(logicConditions(i)->operandB.type, logicConditions(i)->operandB.value);
const int32_t newValue = logicConditionCompute(
logicConditionStates[i].value,
logicConditions(i)->operation,
operandAValue,
Expand Down Expand Up @@ -650,15 +650,15 @@ static int logicConditionGetFlightOperandValue(int operand) {
switch (operand) {

case LOGIC_CONDITION_OPERAND_FLIGHT_ARM_TIMER: // in s
return constrain((uint32_t)getFlightTime(), 0, INT16_MAX);
return constrain((uint32_t)getFlightTime(), 0, INT32_MAX);
break;

case LOGIC_CONDITION_OPERAND_FLIGHT_HOME_DISTANCE: //in m
return constrain(GPS_distanceToHome, 0, INT16_MAX);
return constrain(GPS_distanceToHome, 0, INT32_MAX);
break;

case LOGIC_CONDITION_OPERAND_FLIGHT_TRIP_DISTANCE: //in m
return constrain(getTotalTravelDistance() / 100, 0, INT16_MAX);
return constrain(getTotalTravelDistance() / 100, 0, INT32_MAX);
break;

case LOGIC_CONDITION_OPERAND_FLIGHT_RSSI:
Expand Down Expand Up @@ -713,18 +713,18 @@ static int logicConditionGetFlightOperandValue(int operand) {

case LOGIC_CONDITION_OPERAND_FLIGHT_AIR_SPEED: // cm/s
#ifdef USE_PITOT
return constrain(getAirspeedEstimate(), 0, INT16_MAX);
return constrain(getAirspeedEstimate(), 0, INT32_MAX);
#else
return false;
#endif
break;

case LOGIC_CONDITION_OPERAND_FLIGHT_ALTITUDE: // cm
return constrain(getEstimatedActualPosition(Z), INT16_MIN, INT16_MAX);
return constrain(getEstimatedActualPosition(Z), INT32_MIN, INT32_MAX);
break;

case LOGIC_CONDITION_OPERAND_FLIGHT_VERTICAL_SPEED: // cm/s
return constrain(getEstimatedActualVelocity(Z), INT16_MIN, INT16_MAX);
return constrain(getEstimatedActualVelocity(Z), INT32_MIN, INT32_MAX);
break;

case LOGIC_CONDITION_OPERAND_FLIGHT_TROTTLE_POS: // %
Expand Down Expand Up @@ -793,7 +793,7 @@ static int logicConditionGetFlightOperandValue(int operand) {
break;

case LOGIC_CONDITION_OPERAND_FLIGHT_3D_HOME_DISTANCE: //in m
return constrain(calc_length_pythagorean_2D(GPS_distanceToHome, getEstimatedActualPosition(Z) / 100.0f), 0, INT16_MAX);
return constrain(calc_length_pythagorean_2D(GPS_distanceToHome, getEstimatedActualPosition(Z) / 100.0f), 0, INT32_MAX);
break;

case LOGIC_CONDITION_OPERAND_FLIGHT_CRSF_LQ:
Expand Down Expand Up @@ -938,8 +938,8 @@ static int logicConditionGetFlightModeOperandValue(int operand) {
}
}

int logicConditionGetOperandValue(logicOperandType_e type, int operand) {
int retVal = 0;
int32_t logicConditionGetOperandValue(logicOperandType_e type, int operand) {
int32_t retVal = 0;

switch (type) {

Expand Down Expand Up @@ -994,7 +994,7 @@ int logicConditionGetOperandValue(logicOperandType_e type, int operand) {
/*
* conditionId == -1 is always evaluated as true
*/
int logicConditionGetValue(int8_t conditionId) {
int32_t logicConditionGetValue(int8_t conditionId) {
if (conditionId >= 0) {
return logicConditionStates[conditionId].value;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/main/programming/logic_condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ extern uint64_t logicConditionsGlobalFlags;

void logicConditionProcess(uint8_t i);

int logicConditionGetOperandValue(logicOperandType_e type, int operand);
int32_t logicConditionGetOperandValue(logicOperandType_e type, int operand);

int logicConditionGetValue(int8_t conditionId);
int32_t logicConditionGetValue(int8_t conditionId);
void logicConditionUpdateTask(timeUs_t currentTimeUs);
void logicConditionReset(void);

Expand Down

0 comments on commit d9f6db1

Please sign in to comment.