Skip to content

Commit ec877c3

Browse files
authored
Fix semver for itermThrottleThreshold & antiGravity (betaflight#5054)
1 parent 16a4b1a commit ec877c3

1 file changed

Lines changed: 28 additions & 7 deletions

File tree

src/components/tabs/pid-tuning/PidSubTab.vue

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@
813813
<USwitch v-model="antiGravityEnabled" size="sm" />
814814
</SettingRow>
815815
<div v-if="antiGravityEnabled" class="flex flex-wrap items-end gap-3 pl-4">
816-
<div class="flex flex-col gap-1">
816+
<div v-if="isPreApi145" class="flex flex-col gap-1">
817817
<span class="text-xs text-dimmed" v-html="$t('pidTuningAntiGravityMode')"></span>
818818
<USelect
819819
v-model="advancedTuning.antiGravityMode"
@@ -838,7 +838,7 @@
838838
class="w-16"
839839
/>
840840
</div>
841-
<div class="flex flex-col gap-1">
841+
<div v-if="isPreApi145" class="flex flex-col gap-1">
842842
<span class="text-xs text-dimmed" v-html="$t('pidTuningAntiGravityThres')"></span>
843843
<UInputNumber
844844
v-model="advancedTuning.itermThrottleThreshold"
@@ -1119,6 +1119,8 @@ const cellCountItems = computed(() => [
11191119
{ value: 8, label: t("pidTuningCellCount8S") },
11201120
]);
11211121
1122+
// For API < 1.45, iterm throttle threshold was removed in API 1.45+
1123+
const isPreApi145 = computed(() => semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45));
11221124
// For API < 1.47, derivative and dmax column headers are swapped (PR #4173)
11231125
const isPreApi147 = computed(() => semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_47));
11241126
const derivativeLabel = computed(() => (isPreApi147.value ? "pidTuningDMax" : "pidTuningDerivative"));
@@ -1357,14 +1359,33 @@ const itermRelaxEnabled = computed({
13571359
});
13581360
13591361
const antiGravityEnabled = computed({
1360-
get: () => FC.ADVANCED_TUNING.antiGravityGain !== 0,
1361-
set: (val) => (FC.ADVANCED_TUNING.antiGravityGain = val ? FC.ADVANCED_TUNING.antiGravityGain || 80 : 0),
1362+
get: () =>
1363+
isPreApi145.value
1364+
? FC.ADVANCED_TUNING.itermAcceleratorGain !== 0
1365+
: FC.ADVANCED_TUNING.antiGravityGain !== 0,
1366+
set: (val) => {
1367+
if (isPreApi145.value) {
1368+
FC.ADVANCED_TUNING.itermAcceleratorGain = val ? FC.ADVANCED_TUNING.itermAcceleratorGain || 1000 : 0;
1369+
} else {
1370+
FC.ADVANCED_TUNING.antiGravityGain = val ? FC.ADVANCED_TUNING.antiGravityGain || 80 : 0;
1371+
}
1372+
},
13621373
});
13631374
1364-
// Anti-gravity gain display value (divided by 10 for display)
1375+
// Anti-gravity gain display value (divided by 10 for API 1.45+, divided by 1000 for older)
13651376
const antiGravityGainValue = computed({
1366-
get: () => FC.ADVANCED_TUNING.antiGravityGain / 10,
1367-
set: (val) => (FC.ADVANCED_TUNING.antiGravityGain = Math.round(Number.parseFloat(val) * 10)),
1377+
get: () =>
1378+
isPreApi145.value
1379+
? FC.ADVANCED_TUNING.itermAcceleratorGain / 1000
1380+
: FC.ADVANCED_TUNING.antiGravityGain / 10,
1381+
set: (val) => {
1382+
const parsed = Number.parseFloat(val);
1383+
if (isPreApi145.value) {
1384+
FC.ADVANCED_TUNING.itermAcceleratorGain = Math.round(parsed * 1000);
1385+
} else {
1386+
FC.ADVANCED_TUNING.antiGravityGain = Math.round(parsed * 10);
1387+
}
1388+
},
13681389
});
13691390
13701391
const itermRotationEnabled = computed({

0 commit comments

Comments
 (0)