From e806299c2407b741c6c9adeb197adee963b3bdda Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Fri, 7 Jun 2024 15:37:34 +0200 Subject: [PATCH] Increment minimal supported API to 1_44 (firmware 4.3) (4/4) (#4011) * Increment supported API - MSP and others * Cleanup webstm32 * Cleanup AutoDetect * Cleanup Setup * Fix indentation --- .../EscDshotDirectionComponent.js | 8 - src/js/Features.js | 8 +- src/js/RateCurve.js | 73 ++- src/js/data_storage.js | 5 - src/js/fc.js | 90 ++-- src/js/msp/MSPHelper.js | 423 +++++++++--------- src/js/protocols/webstm32.js | 35 +- src/js/tabs/failsafe.js | 44 +- src/js/tabs/gps.js | 10 +- src/js/tabs/setup.js | 6 +- src/js/utils/AutoDetect.js | 4 +- src/js/utils/EscProtocols.js | 20 +- 12 files changed, 304 insertions(+), 422 deletions(-) diff --git a/src/components/EscDshotDirection/EscDshotDirectionComponent.js b/src/components/EscDshotDirection/EscDshotDirectionComponent.js index 9d3db2f48f..d87a11c5da 100644 --- a/src/components/EscDshotDirection/EscDshotDirectionComponent.js +++ b/src/components/EscDshotDirection/EscDshotDirectionComponent.js @@ -1,10 +1,8 @@ import { i18n } from "../../js/localization.js"; import GUI from "../../js/gui.js"; -import semver from "semver"; import EscDshotDirectionMotorDriver from "./EscDshotDirectionMotorDriver.js"; import DshotCommand from "../../js/utils/DshotCommand.js"; import FC from "../../js/fc.js"; -import { API_VERSION_1_44 } from '../../js/data_storage.js'; import { getMixerImageSrc } from "../../js/utils/common.js"; import $ from "jquery"; @@ -339,12 +337,6 @@ class EscDshotDirectionComponent this._domWrongMixerMessage.show(); } - if (!semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - // if BF4.2 or older - show the error message - anyError = true; - this._domWrongFirmwareMessage.show(); - } - if (anyError) { this._domMainContentBlock.hide(); this._domWarningContentBlock.hide(); diff --git a/src/js/Features.js b/src/js/Features.js index 6ad3880e28..4eaa3d142f 100644 --- a/src/js/Features.js +++ b/src/js/Features.js @@ -1,5 +1,5 @@ import { bit_check, bit_set, bit_clear } from "./bit"; -import { API_VERSION_1_44, API_VERSION_1_45, API_VERSION_1_46 } from './data_storage'; +import { API_VERSION_1_45, API_VERSION_1_46 } from './data_storage'; import semver from "semver"; import { tracking } from "./Analytics"; import $ from 'jquery'; @@ -32,12 +32,6 @@ const Features = function (config) { {bit: 28, group: 'antiGravity', name: 'ANTI_GRAVITY', haveTip: true, hideName: true}, ]; - if (semver.lt(config.apiVersion, API_VERSION_1_44)) { // DYNAMIC_FILTER got removed from FEATURES in BF 4.3 / API 1.44 - features.push( - {bit: 29, group: 'other', name: 'DYNAMIC_FILTER'}, - ); - } - self._features = features; if (config.buildOptions?.length) { diff --git a/src/js/RateCurve.js b/src/js/RateCurve.js index a677a5deb3..c131b6e553 100644 --- a/src/js/RateCurve.js +++ b/src/js/RateCurve.js @@ -1,10 +1,9 @@ import FC from "./fc"; -import { API_VERSION_1_43 } from "./data_storage"; -import semver from "semver"; const minRc = 1000; const midRc = 1500; const maxRc = 2000; + const RateCurve = function (useLegacyCurve) { this.useLegacyCurve = useLegacyCurve; this.maxAngularVel = null; @@ -168,39 +167,37 @@ const RateCurve = function (useLegacyCurve) { currentRates.superexpo = true; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - switch (FC.RC_TUNING.rates_type) { - case FC.RATES_TYPE.RACEFLIGHT: - currentRates.roll_rate *= 100; - currentRates.pitch_rate *= 100; - currentRates.yaw_rate *= 100; - currentRates.rc_rate *= 1000; - currentRates.rc_rate_yaw *= 1000; - currentRates.rc_rate_pitch *= 1000; - currentRates.rc_expo *= 100; - currentRates.rc_yaw_expo *= 100; - currentRates.rc_pitch_expo *= 100; - - break; - case FC.RATES_TYPE.ACTUAL: - currentRates.roll_rate *= 1000; - currentRates.pitch_rate *= 1000; - currentRates.yaw_rate *= 1000; - currentRates.rc_rate *= 1000; - currentRates.rc_rate_yaw *= 1000; - currentRates.rc_rate_pitch *= 1000; - - break; - case FC.RATES_TYPE.QUICKRATES: - currentRates.roll_rate *= 1000; - currentRates.pitch_rate *= 1000; - currentRates.yaw_rate *= 1000; - - break; - default: // add future rates types here - - break; - } + switch (FC.RC_TUNING.rates_type) { + case FC.RATES_TYPE.RACEFLIGHT: + currentRates.roll_rate *= 100; + currentRates.pitch_rate *= 100; + currentRates.yaw_rate *= 100; + currentRates.rc_rate *= 1000; + currentRates.rc_rate_yaw *= 1000; + currentRates.rc_rate_pitch *= 1000; + currentRates.rc_expo *= 100; + currentRates.rc_yaw_expo *= 100; + currentRates.rc_pitch_expo *= 100; + + break; + case FC.RATES_TYPE.ACTUAL: + currentRates.roll_rate *= 1000; + currentRates.pitch_rate *= 1000; + currentRates.yaw_rate *= 1000; + currentRates.rc_rate *= 1000; + currentRates.rc_rate_yaw *= 1000; + currentRates.rc_rate_pitch *= 1000; + + break; + case FC.RATES_TYPE.QUICKRATES: + currentRates.roll_rate *= 1000; + currentRates.pitch_rate *= 1000; + currentRates.yaw_rate *= 1000; + + break; + default: // add future rates types here + + break; } return currentRates; @@ -212,11 +209,7 @@ RateCurve.prototype.rcCommandRawToDegreesPerSecond = function (rcData, rate, rcR if (rate !== undefined && rcRate !== undefined && rcExpo !== undefined) { let rcCommandf = this.rcCommand(rcData, 1, deadband); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - rcCommandf = rcCommandf / (500 - deadband); - } else { - rcCommandf = rcCommandf / 500; - } + rcCommandf /= (500 - deadband); const rcCommandfAbs = Math.abs(rcCommandf); diff --git a/src/js/data_storage.js b/src/js/data_storage.js index c69e238c1e..cb6af53dcb 100644 --- a/src/js/data_storage.js +++ b/src/js/data_storage.js @@ -1,9 +1,4 @@ export const API_VERSION_1_39 = '1.39.0'; -export const API_VERSION_1_40 = '1.40.0'; - -export const API_VERSION_1_41 = '1.41.0'; -export const API_VERSION_1_42 = '1.42.0'; -export const API_VERSION_1_43 = '1.43.0'; export const API_VERSION_1_44 = '1.44.0'; export const API_VERSION_1_45 = '1.45.0'; export const API_VERSION_1_46 = '1.46.0'; diff --git a/src/js/fc.js b/src/js/fc.js index fece876ff7..4094a52033 100644 --- a/src/js/fc.js +++ b/src/js/fc.js @@ -1,5 +1,5 @@ import { bit_check } from "./bit"; -import { API_VERSION_1_42, API_VERSION_1_43, API_VERSION_1_44, API_VERSION_1_45, API_VERSION_1_46 } from './data_storage'; +import { API_VERSION_1_45, API_VERSION_1_46 } from './data_storage'; import semver from "semver"; const INITIAL_CONFIG = { @@ -803,16 +803,10 @@ const FC = { 'SPEKTRUM2048/SRXL', 'TARGET_CUSTOM', 'FPORT', + 'SPEKTRUM SRXL2', + 'IRC GHOST', ]; - if (semver.gte(apiVersion, API_VERSION_1_42)) { - serialRxTypes.push('SPEKTRUM SRXL2'); - } - - if (semver.gte(apiVersion, API_VERSION_1_44)) { - serialRxTypes.push('IRC GHOST'); - } - if (semver.gte(apiVersion, API_VERSION_1_46)) { // Default to NONE and move SPEKTRUM1024 to the end (firmware PR #12500) serialRxTypes[0] = 'NONE'; @@ -907,12 +901,7 @@ const FC = { }, boardHasFlashBootloader() { - let hasFlashBootloader = false; - if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_42)) { - hasFlashBootloader = bit_check(this.CONFIG.targetCapabilities, this.TARGET_CAPABILITIES_FLAGS.HAS_FLASH_BOOTLOADER); - } - - return hasFlashBootloader; + return bit_check(this.CONFIG.targetCapabilities, this.TARGET_CAPABILITIES_FLAGS.HAS_FLASH_BOOTLOADER); }, FILTER_TYPE_FLAGS: { @@ -932,31 +921,30 @@ const FC = { versionFilterDefaults.dterm_lowpass2_hz = 150; versionFilterDefaults.dterm_lowpass2_type = this.FILTER_TYPE_FLAGS.BIQUAD; - if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_42)) { - versionFilterDefaults.gyro_lowpass_hz = 200; - versionFilterDefaults.gyro_lowpass_dyn_min_hz = 200; - versionFilterDefaults.gyro_lowpass_dyn_max_hz = 500; - versionFilterDefaults.gyro_lowpass_type = this.FILTER_TYPE_FLAGS.PT1; - versionFilterDefaults.gyro_lowpass2_hz = 250; - versionFilterDefaults.gyro_lowpass2_type = this.FILTER_TYPE_FLAGS.PT1; - versionFilterDefaults.dterm_lowpass_hz = 150; - versionFilterDefaults.dterm_lowpass_dyn_min_hz = 70; - versionFilterDefaults.dterm_lowpass_dyn_max_hz = 170; - versionFilterDefaults.dterm_lowpass_type = this.FILTER_TYPE_FLAGS.PT1; - versionFilterDefaults.dterm_lowpass2_hz = 150; - versionFilterDefaults.dterm_lowpass2_type = this.FILTER_TYPE_FLAGS.PT1; - } - - if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_44)) { - versionFilterDefaults.dyn_notch_q = 300; - versionFilterDefaults.gyro_lowpass_hz = 250; - versionFilterDefaults.gyro_lowpass_dyn_min_hz = 250; - versionFilterDefaults.gyro_lowpass2_hz = 500; - versionFilterDefaults.dterm_lowpass_hz = 75; - versionFilterDefaults.dterm_lowpass_dyn_min_hz = 75; - versionFilterDefaults.dterm_lowpass_dyn_max_hz = 150; - } - + // Introduced in 1.42 + versionFilterDefaults.gyro_lowpass_hz = 200; + versionFilterDefaults.gyro_lowpass_dyn_min_hz = 200; + versionFilterDefaults.gyro_lowpass_dyn_max_hz = 500; + versionFilterDefaults.gyro_lowpass_type = this.FILTER_TYPE_FLAGS.PT1; + versionFilterDefaults.gyro_lowpass2_hz = 250; + versionFilterDefaults.gyro_lowpass2_type = this.FILTER_TYPE_FLAGS.PT1; + versionFilterDefaults.dterm_lowpass_hz = 150; + versionFilterDefaults.dterm_lowpass_dyn_min_hz = 70; + versionFilterDefaults.dterm_lowpass_dyn_max_hz = 170; + versionFilterDefaults.dterm_lowpass_type = this.FILTER_TYPE_FLAGS.PT1; + versionFilterDefaults.dterm_lowpass2_hz = 150; + versionFilterDefaults.dterm_lowpass2_type = this.FILTER_TYPE_FLAGS.PT1; + + // Introduced in 1.44 + versionFilterDefaults.dyn_notch_q = 300; + versionFilterDefaults.gyro_lowpass_hz = 250; + versionFilterDefaults.gyro_lowpass_dyn_min_hz = 250; + versionFilterDefaults.gyro_lowpass2_hz = 500; + versionFilterDefaults.dterm_lowpass_hz = 75; + versionFilterDefaults.dterm_lowpass_dyn_min_hz = 75; + versionFilterDefaults.dterm_lowpass_dyn_max_hz = 150; + + // Introduced in 1.45 if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_45)) { versionFilterDefaults.dyn_notch_min_hz = 100; } @@ -965,22 +953,14 @@ const FC = { }, getPidDefaults() { - let versionPidDefaults = this.DEFAULT_PIDS; // if defaults change they should go here - if (semver.eq(this.CONFIG.apiVersion, API_VERSION_1_43)) { - versionPidDefaults = [ - 42, 85, 35, 23, 90, - 46, 90, 38, 25, 95, - 45, 90, 0, 0, 90, - ]; - } - if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_44)) { - versionPidDefaults = [ - 45, 80, 40, 30, 120, - 47, 84, 46, 34, 125, - 45, 80, 0, 0, 120, - ]; - } + // Introduced in 1.44 + const versionPidDefaults = [ + 45, 80, 40, 30, 120, + 47, 84, 46, 34, 125, + 45, 80, 0, 0, 120, + ]; + return versionPidDefaults; }, diff --git a/src/js/msp/MSPHelper.js b/src/js/msp/MSPHelper.js index 8e9a17a863..32dd0e7b94 100644 --- a/src/js/msp/MSPHelper.js +++ b/src/js/msp/MSPHelper.js @@ -8,7 +8,7 @@ import semver from 'semver'; import vtxDeviceStatusFactory from "../utils/VtxDeviceStatus/VtxDeviceStatusFactory"; import MSP from "../msp"; import MSPCodes from "./MSPCodes"; -import { API_VERSION_1_42, API_VERSION_1_43, API_VERSION_1_44, API_VERSION_1_45, API_VERSION_1_46 } from '../data_storage'; +import { API_VERSION_1_45, API_VERSION_1_46 } from '../data_storage'; import EscProtocols from "../utils/EscProtocols"; import huffmanDecodeBuf from "../huffman"; import { defaultHuffmanTree, defaultHuffmanLenIndex } from "../default_huffman_tree"; @@ -444,14 +444,12 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.RC_TUNING.RC_PITCH_EXPO = parseFloat((data.readU8() / 100).toFixed(2)); FC.RC_TUNING.throttleLimitType = data.readU8(); FC.RC_TUNING.throttleLimitPercent = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - FC.RC_TUNING.roll_rate_limit = data.readU16(); - FC.RC_TUNING.pitch_rate_limit = data.readU16(); - FC.RC_TUNING.yaw_rate_limit = data.readU16(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - FC.RC_TUNING.rates_type = data.readU8(); - } + FC.RC_TUNING.roll_rate_limit = data.readU16(); + FC.RC_TUNING.pitch_rate_limit = data.readU16(); + FC.RC_TUNING.yaw_rate_limit = data.readU16(); + FC.RC_TUNING.rates_type = data.readU8(); + FC.RC_TUNING.rates_type = data.readU8(); + FC.RC_TUNING.rates_type = data.readU8(); break; case MSPCodes.MSP_PID: // PID data arrived, we need to scale it and save to appropriate bank / array @@ -497,12 +495,10 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.MOTOR_CONFIG.minthrottle = data.readU16(); // 0-2000 FC.MOTOR_CONFIG.maxthrottle = data.readU16(); // 0-2000 FC.MOTOR_CONFIG.mincommand = data.readU16(); // 0-2000 - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - FC.MOTOR_CONFIG.motor_count = data.readU8(); - FC.MOTOR_CONFIG.motor_poles = data.readU8(); - FC.MOTOR_CONFIG.use_dshot_telemetry = data.readU8() != 0; - FC.MOTOR_CONFIG.use_esc_sensor = data.readU8() != 0; - } + FC.MOTOR_CONFIG.motor_count = data.readU8(); + FC.MOTOR_CONFIG.motor_poles = data.readU8(); + FC.MOTOR_CONFIG.use_dshot_telemetry = data.readU8() != 0; + FC.MOTOR_CONFIG.use_esc_sensor = data.readU8() != 0; break; case MSPCodes.MSP_COMPASS_CONFIG: FC.COMPASS_CONFIG.mag_declination = data.read16() / 10; @@ -513,10 +509,9 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.GPS_CONFIG.auto_config = data.readU8(); FC.GPS_CONFIG.auto_baud = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - FC.GPS_CONFIG.home_point_once = data.readU8(); - FC.GPS_CONFIG.ublox_use_galileo = data.readU8(); - } + // Introduced in API version 1.43 + FC.GPS_CONFIG.home_point_once = data.readU8(); + FC.GPS_CONFIG.ublox_use_galileo = data.readU8(); break; case MSPCodes.MSP_GPS_RESCUE: FC.GPS_RESCUE.angle = data.readU16(); @@ -528,18 +523,18 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.GPS_RESCUE.throttleHover = data.readU16(); FC.GPS_RESCUE.sanityChecks = data.readU8(); FC.GPS_RESCUE.minSats = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - FC.GPS_RESCUE.ascendRate = data.readU16(); - FC.GPS_RESCUE.descendRate = data.readU16(); - FC.GPS_RESCUE.allowArmingWithoutFix = data.readU8(); - FC.GPS_RESCUE.altitudeMode = data.readU8(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - FC.GPS_RESCUE.minStartDistM = data.readU16(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) { - FC.GPS_RESCUE.initialClimbM = data.readU16(); - } + + // Introduced in API version 1.43 + FC.GPS_RESCUE.ascendRate = data.readU16(); + FC.GPS_RESCUE.descendRate = data.readU16(); + FC.GPS_RESCUE.allowArmingWithoutFix = data.readU8(); + FC.GPS_RESCUE.altitudeMode = data.readU8(); + + // Introduced in API version 1.44 + FC.GPS_RESCUE.minStartDistM = data.readU16(); + + // Introduced in API version 1.46 + FC.GPS_RESCUE.initialClimbM = data.readU16(); break; case MSPCodes.MSP_RSSI_CONFIG: FC.RSSI_CONFIG.channel = data.readU8(); @@ -831,17 +826,12 @@ MspHelper.prototype.process_data = function(dataHandler) { } FC.CONFIG.mcuTypeId = data.readU8(); + // Introduced in API version 1.42 + FC.CONFIG.configurationState = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - FC.CONFIG.configurationState = data.readU8(); - } - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - FC.CONFIG.sampleRateHz = data.readU16(); - FC.CONFIG.configurationProblems = data.readU32(); - } else { - FC.CONFIG.configurationProblems = 0; - } + // Introduced in API version 1.43 + FC.CONFIG.sampleRateHz = data.readU16(); + FC.CONFIG.configurationProblems = data.readU32(); break; @@ -1011,13 +1001,10 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.RX_CONFIG.rcSmoothingFeedforwardCutoff = data.readU8(); FC.RX_CONFIG.rcSmoothingInputType = data.readU8(); FC.RX_CONFIG.rcSmoothingDerivativeType = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - FC.RX_CONFIG.usbCdcHidType = data.readU8(); - FC.RX_CONFIG.rcSmoothingAutoFactor = data.readU8(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - FC.RX_CONFIG.rcSmoothingMode = data.readU8(); - } + FC.RX_CONFIG.usbCdcHidType = data.readU8(); + FC.RX_CONFIG.rcSmoothingAutoFactor = data.readU8(); + FC.RX_CONFIG.rcSmoothingMode = data.readU8(); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { const elrsUidLength = 6; FC.RX_CONFIG.elrsUid = []; @@ -1058,17 +1045,16 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.PID_ADVANCED_CONFIG.motor_pwm_rate = data.readU16(); FC.PID_ADVANCED_CONFIG.digitalIdlePercent = data.readU16() / 100; data.readU8(); // gyroUse32Khz is not supported - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - FC.PID_ADVANCED_CONFIG.motorPwmInversion = data.readU8(); - FC.SENSOR_ALIGNMENT.gyro_to_use = data.readU8(); // We don't want to double up on storing this state - FC.PID_ADVANCED_CONFIG.gyroHighFsr = data.readU8(); - FC.PID_ADVANCED_CONFIG.gyroMovementCalibThreshold = data.readU8(); - FC.PID_ADVANCED_CONFIG.gyroCalibDuration = data.readU16(); - FC.PID_ADVANCED_CONFIG.gyroOffsetYaw = data.readU16(); - FC.PID_ADVANCED_CONFIG.gyroCheckOverflow = data.readU8(); - FC.PID_ADVANCED_CONFIG.debugMode = data.readU8(); - FC.PID_ADVANCED_CONFIG.debugModeCount = data.readU8(); - } + // Introduced in 1.42 + FC.PID_ADVANCED_CONFIG.motorPwmInversion = data.readU8(); + FC.SENSOR_ALIGNMENT.gyro_to_use = data.readU8(); // We don't want to double up on storing this state + FC.PID_ADVANCED_CONFIG.gyroHighFsr = data.readU8(); + FC.PID_ADVANCED_CONFIG.gyroMovementCalibThreshold = data.readU8(); + FC.PID_ADVANCED_CONFIG.gyroCalibDuration = data.readU16(); + FC.PID_ADVANCED_CONFIG.gyroOffsetYaw = data.readU16(); + FC.PID_ADVANCED_CONFIG.gyroCheckOverflow = data.readU8(); + FC.PID_ADVANCED_CONFIG.debugMode = data.readU8(); + FC.PID_ADVANCED_CONFIG.debugModeCount = data.readU8(); break; case MSPCodes.MSP_FILTER_CONFIG: FC.FILTER_CONFIG.gyro_lowpass_hz = data.readU8(); @@ -1094,22 +1080,19 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.FILTER_CONFIG.gyro_lowpass_dyn_max_hz = data.readU16(); FC.FILTER_CONFIG.dterm_lowpass_dyn_min_hz = data.readU16(); FC.FILTER_CONFIG.dterm_lowpass_dyn_max_hz = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - FC.FILTER_CONFIG.dyn_notch_range = data.readU8(); - FC.FILTER_CONFIG.dyn_notch_width_percent = data.readU8(); - FC.FILTER_CONFIG.dyn_notch_q = data.readU16(); - FC.FILTER_CONFIG.dyn_notch_min_hz = data.readU16(); - - FC.FILTER_CONFIG.gyro_rpm_notch_harmonics = data.readU8(); - FC.FILTER_CONFIG.gyro_rpm_notch_min_hz = data.readU8(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - FC.FILTER_CONFIG.dyn_notch_max_hz = data.readU16(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - FC.FILTER_CONFIG.dyn_lpf_curve_expo = data.readU8(); - FC.FILTER_CONFIG.dyn_notch_count = data.readU8(); - } + // Introduced in 1.42 + FC.FILTER_CONFIG.dyn_notch_range = data.readU8(); + FC.FILTER_CONFIG.dyn_notch_width_percent = data.readU8(); + FC.FILTER_CONFIG.dyn_notch_q = data.readU16(); + FC.FILTER_CONFIG.dyn_notch_min_hz = data.readU16(); + + FC.FILTER_CONFIG.gyro_rpm_notch_harmonics = data.readU8(); + FC.FILTER_CONFIG.gyro_rpm_notch_min_hz = data.readU8(); + // Introduced in 1.43 + FC.FILTER_CONFIG.dyn_notch_max_hz = data.readU16(); + // Introduced in 1.44 + FC.FILTER_CONFIG.dyn_lpf_curve_expo = data.readU8(); + FC.FILTER_CONFIG.dyn_notch_count = data.readU8(); break; case MSPCodes.MSP_SET_PID_ADVANCED: console.log("Advanced PID settings saved"); @@ -1158,28 +1141,28 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.ADVANCED_TUNING.useIntegratedYaw = data.readU8(); FC.ADVANCED_TUNING.integratedYawRelax = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - FC.ADVANCED_TUNING.itermRelaxCutoff = data.readU8(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - FC.ADVANCED_TUNING.motorOutputLimit = data.readU8(); - FC.ADVANCED_TUNING.autoProfileCellCount = data.read8(); - FC.ADVANCED_TUNING.idleMinRpm = data.readU8(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - FC.ADVANCED_TUNING.feedforward_averaging = data.readU8(); - FC.ADVANCED_TUNING.feedforward_smooth_factor = data.readU8(); - FC.ADVANCED_TUNING.feedforward_boost = data.readU8(); - FC.ADVANCED_TUNING.feedforward_max_rate_limit = data.readU8(); - FC.ADVANCED_TUNING.feedforward_jitter_factor = data.readU8(); - FC.ADVANCED_TUNING.vbat_sag_compensation = data.readU8(); - FC.ADVANCED_TUNING.thrustLinearization = data.readU8(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - FC.ADVANCED_TUNING.tpaMode = data.readU8(); - FC.ADVANCED_TUNING.tpaRate = parseFloat((data.readU8() / 100).toFixed(2)); - FC.ADVANCED_TUNING.tpaBreakpoint = data.readU16(); - } + // Introduced in 1.42 + FC.ADVANCED_TUNING.itermRelaxCutoff = data.readU8(); + + // Introduced in 1.43 + FC.ADVANCED_TUNING.motorOutputLimit = data.readU8(); + FC.ADVANCED_TUNING.autoProfileCellCount = data.read8(); + FC.ADVANCED_TUNING.idleMinRpm = data.readU8(); + + // Introduced in 1.44 + FC.ADVANCED_TUNING.feedforward_averaging = data.readU8(); + FC.ADVANCED_TUNING.feedforward_smooth_factor = data.readU8(); + FC.ADVANCED_TUNING.feedforward_boost = data.readU8(); + FC.ADVANCED_TUNING.feedforward_max_rate_limit = data.readU8(); + FC.ADVANCED_TUNING.feedforward_jitter_factor = data.readU8(); + FC.ADVANCED_TUNING.vbat_sag_compensation = data.readU8(); + FC.ADVANCED_TUNING.thrustLinearization = data.readU8(); + + // Introduced in 1.45 + FC.ADVANCED_TUNING.tpaMode = data.readU8(); + FC.ADVANCED_TUNING.tpaRate = parseFloat((data.readU8() / 100).toFixed(2)); + FC.ADVANCED_TUNING.tpaBreakpoint = data.readU16(); + FC.ADVANCED_TUNING_ACTIVE = { ...FC.ADVANCED_TUNING }; break; case MSPCodes.MSP_SENSOR_CONFIG: @@ -1380,9 +1363,11 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.BLACKBOX.blackboxRateNum = data.readU8(); FC.BLACKBOX.blackboxRateDenom = data.readU8(); FC.BLACKBOX.blackboxPDenom = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - FC.BLACKBOX.blackboxSampleRate = data.readU8(); - } + + // Introduced in API version 1.44 + FC.BLACKBOX.blackboxSampleRate = data.readU8(); + + // Introduced in API version 1.45 if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { FC.BLACKBOX.blackboxDisabledMask = data.readU32(); } @@ -1432,14 +1417,13 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.VTX_CONFIG.vtx_device_ready = data.readU8() != 0; FC.VTX_CONFIG.vtx_low_power_disarm = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - FC.VTX_CONFIG.vtx_pit_mode_frequency = data.readU16(); - FC.VTX_CONFIG.vtx_table_available = data.readU8() != 0; - FC.VTX_CONFIG.vtx_table_bands = data.readU8(); - FC.VTX_CONFIG.vtx_table_channels = data.readU8(); - FC.VTX_CONFIG.vtx_table_powerlevels = data.readU8(); - FC.VTX_CONFIG.vtx_table_clear = false; - } + // Introduced in API version 1.42 + FC.VTX_CONFIG.vtx_pit_mode_frequency = data.readU16(); + FC.VTX_CONFIG.vtx_table_available = data.readU8() != 0; + FC.VTX_CONFIG.vtx_table_bands = data.readU8(); + FC.VTX_CONFIG.vtx_table_channels = data.readU8(); + FC.VTX_CONFIG.vtx_table_powerlevels = data.readU8(); + FC.VTX_CONFIG.vtx_table_clear = false; break; case MSPCodes.MSP_SET_VTX_CONFIG: @@ -1775,14 +1759,14 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { buffer.push8(Math.round(FC.RC_TUNING.RC_PITCH_EXPO * 100)); buffer.push8(FC.RC_TUNING.throttleLimitType); buffer.push8(FC.RC_TUNING.throttleLimitPercent); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - buffer.push16(FC.RC_TUNING.roll_rate_limit); - buffer.push16(FC.RC_TUNING.pitch_rate_limit); - buffer.push16(FC.RC_TUNING.yaw_rate_limit); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - buffer.push8(FC.RC_TUNING.rates_type); - } + + // Introduced in 1.42 + buffer.push16(FC.RC_TUNING.roll_rate_limit); + buffer.push16(FC.RC_TUNING.pitch_rate_limit); + buffer.push16(FC.RC_TUNING.yaw_rate_limit); + + // Introduced in 1.43 + buffer.push8(FC.RC_TUNING.rates_type); break; case MSPCodes.MSP_SET_RX_MAP: for (let i = 0; i < FC.RC_MAP.length; i++) { @@ -1826,10 +1810,10 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { buffer.push16(FC.MOTOR_CONFIG.minthrottle) .push16(FC.MOTOR_CONFIG.maxthrottle) .push16(FC.MOTOR_CONFIG.mincommand); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - buffer.push8(FC.MOTOR_CONFIG.motor_poles); - buffer.push8(FC.MOTOR_CONFIG.use_dshot_telemetry ? 1 : 0); - } + + // Introduced in 1.42 + buffer.push8(FC.MOTOR_CONFIG.motor_poles); + buffer.push8(FC.MOTOR_CONFIG.use_dshot_telemetry ? 1 : 0); break; case MSPCodes.MSP_SET_GPS_CONFIG: buffer.push8(FC.GPS_CONFIG.provider) @@ -1837,34 +1821,32 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { .push8(FC.GPS_CONFIG.auto_config) .push8(FC.GPS_CONFIG.auto_baud); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - buffer.push8(FC.GPS_CONFIG.home_point_once) - .push8(FC.GPS_CONFIG.ublox_use_galileo); - } + // Introduced in 1.43 + buffer.push8(FC.GPS_CONFIG.home_point_once) + .push8(FC.GPS_CONFIG.ublox_use_galileo); break; case MSPCodes.MSP_SET_GPS_RESCUE: buffer.push16(FC.GPS_RESCUE.angle) - .push16(FC.GPS_RESCUE.returnAltitudeM) - .push16(FC.GPS_RESCUE.descentDistanceM) - .push16(FC.GPS_RESCUE.groundSpeed) - .push16(FC.GPS_RESCUE.throttleMin) - .push16(FC.GPS_RESCUE.throttleMax) - .push16(FC.GPS_RESCUE.throttleHover) - .push8(FC.GPS_RESCUE.sanityChecks) - .push8(FC.GPS_RESCUE.minSats); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - buffer.push16(FC.GPS_RESCUE.ascendRate) - .push16(FC.GPS_RESCUE.descendRate) - .push8(FC.GPS_RESCUE.allowArmingWithoutFix) - .push8(FC.GPS_RESCUE.altitudeMode); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - buffer.push16(FC.GPS_RESCUE.minStartDistM); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) { - buffer.push16(FC.GPS_RESCUE.initialClimbM); - } + .push16(FC.GPS_RESCUE.returnAltitudeM) + .push16(FC.GPS_RESCUE.descentDistanceM) + .push16(FC.GPS_RESCUE.groundSpeed) + .push16(FC.GPS_RESCUE.throttleMin) + .push16(FC.GPS_RESCUE.throttleMax) + .push16(FC.GPS_RESCUE.throttleHover) + .push8(FC.GPS_RESCUE.sanityChecks) + .push8(FC.GPS_RESCUE.minSats); + + // Introduced in 1.43 + buffer.push16(FC.GPS_RESCUE.ascendRate) + .push16(FC.GPS_RESCUE.descendRate) + .push8(FC.GPS_RESCUE.allowArmingWithoutFix) + .push8(FC.GPS_RESCUE.altitudeMode); + + // Introduced in 1.44 + buffer.push16(FC.GPS_RESCUE.minStartDistM); + + // Introduced in 1.46 + buffer.push16(FC.GPS_RESCUE.initialClimbM); break; case MSPCodes.MSP_SET_COMPASS_CONFIG: buffer.push16(Math.round(10.0 * parseFloat(FC.COMPASS_CONFIG.mag_declination))); @@ -1911,16 +1893,17 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { .push8(FC.RX_CONFIG.rcSmoothingInputType) .push8(FC.RX_CONFIG.rcSmoothingDerivativeType); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - buffer.push8(FC.RX_CONFIG.usbCdcHidType) - .push8(FC.RX_CONFIG.rcSmoothingAutoFactor); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - buffer.push8(FC.RX_CONFIG.rcSmoothingMode); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - FC.RX_CONFIG.elrsUid.forEach(b => buffer.push8(b)); - } + // Introduced in 1.42 + buffer.push8(FC.RX_CONFIG.usbCdcHidType) + .push8(FC.RX_CONFIG.rcSmoothingAutoFactor); + + // Introduced in 1.44 + buffer.push8(FC.RX_CONFIG.rcSmoothingMode); + + // Introduced in 1.45 + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + FC.RX_CONFIG.elrsUid.forEach(b => buffer.push8(b)); + } break; @@ -2011,17 +1994,18 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { .push16(FC.PID_ADVANCED_CONFIG.motor_pwm_rate) .push16(FC.PID_ADVANCED_CONFIG.digitalIdlePercent * 100) .push8(0); // gyroUse32kHz not used - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - buffer.push8(FC.PID_ADVANCED_CONFIG.motorPwmInversion) - .push8(FC.SENSOR_ALIGNMENT.gyro_to_use) // We don't want to double up on storing this state - .push8(FC.PID_ADVANCED_CONFIG.gyroHighFsr) - .push8(FC.PID_ADVANCED_CONFIG.gyroMovementCalibThreshold) - .push16(FC.PID_ADVANCED_CONFIG.gyroCalibDuration) - .push16(FC.PID_ADVANCED_CONFIG.gyroOffsetYaw) - .push8(FC.PID_ADVANCED_CONFIG.gyroCheckOverflow) - .push8(FC.PID_ADVANCED_CONFIG.debugMode); - } - break; + + // Introduced in 1.42 + buffer.push8(FC.PID_ADVANCED_CONFIG.motorPwmInversion) + .push8(FC.SENSOR_ALIGNMENT.gyro_to_use) // We don't want to double up on storing this state + .push8(FC.PID_ADVANCED_CONFIG.gyroHighFsr) + .push8(FC.PID_ADVANCED_CONFIG.gyroMovementCalibThreshold) + .push16(FC.PID_ADVANCED_CONFIG.gyroCalibDuration) + .push16(FC.PID_ADVANCED_CONFIG.gyroOffsetYaw) + .push8(FC.PID_ADVANCED_CONFIG.gyroCheckOverflow) + .push8(FC.PID_ADVANCED_CONFIG.debugMode); + + break; case MSPCodes.MSP_SET_FILTER_CONFIG: buffer.push8(FC.FILTER_CONFIG.gyro_lowpass_hz) .push16(FC.FILTER_CONFIG.dterm_lowpass_hz) @@ -2045,21 +2029,21 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { .push16(FC.FILTER_CONFIG.gyro_lowpass_dyn_max_hz) .push16(FC.FILTER_CONFIG.dterm_lowpass_dyn_min_hz) .push16(FC.FILTER_CONFIG.dterm_lowpass_dyn_max_hz); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - buffer.push8(FC.FILTER_CONFIG.dyn_notch_range) - .push8(FC.FILTER_CONFIG.dyn_notch_width_percent) - .push16(FC.FILTER_CONFIG.dyn_notch_q) - .push16(FC.FILTER_CONFIG.dyn_notch_min_hz) - .push8(FC.FILTER_CONFIG.gyro_rpm_notch_harmonics) - .push8(FC.FILTER_CONFIG.gyro_rpm_notch_min_hz); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - buffer.push16(FC.FILTER_CONFIG.dyn_notch_max_hz); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - buffer.push8(FC.FILTER_CONFIG.dyn_lpf_curve_expo) + + // Introduced in 1.42 + buffer.push8(FC.FILTER_CONFIG.dyn_notch_range) + .push8(FC.FILTER_CONFIG.dyn_notch_width_percent) + .push16(FC.FILTER_CONFIG.dyn_notch_q) + .push16(FC.FILTER_CONFIG.dyn_notch_min_hz) + .push8(FC.FILTER_CONFIG.gyro_rpm_notch_harmonics) + .push8(FC.FILTER_CONFIG.gyro_rpm_notch_min_hz); + + // Introduced in 1.43 + buffer.push16(FC.FILTER_CONFIG.dyn_notch_max_hz); + + // Introduced in 1.44 + buffer.push8(FC.FILTER_CONFIG.dyn_lpf_curve_expo) .push8(FC.FILTER_CONFIG.dyn_notch_count); - } break; case MSPCodes.MSP_SET_PID_ADVANCED: buffer.push16(FC.ADVANCED_TUNING.rollPitchItermIgnoreRate) @@ -2104,28 +2088,27 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { .push8(FC.ADVANCED_TUNING.useIntegratedYaw) .push8(FC.ADVANCED_TUNING.integratedYawRelax); - if(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - buffer.push8(FC.ADVANCED_TUNING.itermRelaxCutoff); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - buffer.push8(FC.ADVANCED_TUNING.motorOutputLimit) - .push8(FC.ADVANCED_TUNING.autoProfileCellCount) - .push8(FC.ADVANCED_TUNING.idleMinRpm); - } - if(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - buffer.push8(FC.ADVANCED_TUNING.feedforward_averaging) - .push8(FC.ADVANCED_TUNING.feedforward_smooth_factor) - .push8(FC.ADVANCED_TUNING.feedforward_boost) - .push8(FC.ADVANCED_TUNING.feedforward_max_rate_limit) - .push8(FC.ADVANCED_TUNING.feedforward_jitter_factor) - .push8(FC.ADVANCED_TUNING.vbat_sag_compensation) - .push8(FC.ADVANCED_TUNING.thrustLinearization); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - buffer.push8(FC.ADVANCED_TUNING.tpaMode); - buffer.push8(Math.round(FC.ADVANCED_TUNING.tpaRate * 100)); - buffer.push16(FC.ADVANCED_TUNING.tpaBreakpoint); - } + // Introduced in 1.42 + buffer.push8(FC.ADVANCED_TUNING.itermRelaxCutoff); + + // Introduced in 1.43 + buffer.push8(FC.ADVANCED_TUNING.motorOutputLimit) + .push8(FC.ADVANCED_TUNING.autoProfileCellCount) + .push8(FC.ADVANCED_TUNING.idleMinRpm); + + // Introduced in 1.44 + buffer.push8(FC.ADVANCED_TUNING.feedforward_averaging) + .push8(FC.ADVANCED_TUNING.feedforward_smooth_factor) + .push8(FC.ADVANCED_TUNING.feedforward_boost) + .push8(FC.ADVANCED_TUNING.feedforward_max_rate_limit) + .push8(FC.ADVANCED_TUNING.feedforward_jitter_factor) + .push8(FC.ADVANCED_TUNING.vbat_sag_compensation) + .push8(FC.ADVANCED_TUNING.thrustLinearization); + + // Introduced in 1.45 + buffer.push8(FC.ADVANCED_TUNING.tpaMode); + buffer.push8(Math.round(FC.ADVANCED_TUNING.tpaRate * 100)); + buffer.push16(FC.ADVANCED_TUNING.tpaBreakpoint); break; case MSPCodes.MSP_SET_SENSOR_CONFIG: buffer.push8(FC.SENSOR_CONFIG.acc_hardware) @@ -2172,9 +2155,11 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { .push8(FC.BLACKBOX.blackboxRateNum) .push8(FC.BLACKBOX.blackboxRateDenom) .push16(FC.BLACKBOX.blackboxPDenom); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - buffer.push8(FC.BLACKBOX.blackboxSampleRate); - } + + // Introduced in 1.44 + buffer.push8(FC.BLACKBOX.blackboxSampleRate); + + // Introduced in 1.45 if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { buffer.push32(FC.BLACKBOX.blackboxDisabledMask); } @@ -2212,6 +2197,7 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { const millis = timestamp % 1000; buffer.push32(secs); buffer.push16(millis); + break; case MSPCodes.MSP_SET_VTX_CONFIG: @@ -2221,25 +2207,24 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { .push8(FC.VTX_CONFIG.vtx_pit_mode ? 1 : 0) .push8(FC.VTX_CONFIG.vtx_low_power_disarm); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - buffer.push16(FC.VTX_CONFIG.vtx_pit_mode_frequency) - .push8(FC.VTX_CONFIG.vtx_band) - .push8(FC.VTX_CONFIG.vtx_channel) - .push16(FC.VTX_CONFIG.vtx_frequency) - .push8(FC.VTX_CONFIG.vtx_table_bands) - .push8(FC.VTX_CONFIG.vtx_table_channels) - .push8(FC.VTX_CONFIG.vtx_table_powerlevels) - .push8(FC.VTX_CONFIG.vtx_table_clear ? 1 : 0); - } + // Introduced in 1.42 + buffer.push16(FC.VTX_CONFIG.vtx_pit_mode_frequency) + .push8(FC.VTX_CONFIG.vtx_band) + .push8(FC.VTX_CONFIG.vtx_channel) + .push16(FC.VTX_CONFIG.vtx_frequency) + .push8(FC.VTX_CONFIG.vtx_table_bands) + .push8(FC.VTX_CONFIG.vtx_table_channels) + .push8(FC.VTX_CONFIG.vtx_table_powerlevels) + .push8(FC.VTX_CONFIG.vtx_table_clear ? 1 : 0); break; case MSPCodes.MSP_SET_VTXTABLE_POWERLEVEL: buffer.push8(FC.VTXTABLE_POWERLEVEL.vtxtable_powerlevel_number) - .push16(FC.VTXTABLE_POWERLEVEL.vtxtable_powerlevel_value); + .push16(FC.VTXTABLE_POWERLEVEL.vtxtable_powerlevel_value) + .push8(FC.VTXTABLE_POWERLEVEL.vtxtable_powerlevel_label.length); - buffer.push8(FC.VTXTABLE_POWERLEVEL.vtxtable_powerlevel_label.length); for (let i = 0; i < FC.VTXTABLE_POWERLEVEL.vtxtable_powerlevel_label.length; i++) { buffer.push8(FC.VTXTABLE_POWERLEVEL.vtxtable_powerlevel_label.charCodeAt(i)); } @@ -2785,12 +2770,12 @@ MspHelper.prototype.setArmingEnabled = function(doEnable, disableRunawayTakeoffP }; MspHelper.prototype.loadSerialConfig = function(callback) { - const mspCode = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43) ? MSPCodes.MSP2_COMMON_SERIAL_CONFIG : MSPCodes.MSP_CF_SERIAL_CONFIG; + const mspCode = MSPCodes.MSP2_COMMON_SERIAL_CONFIG; MSP.send_message(mspCode, false, false, callback); }; MspHelper.prototype.sendSerialConfig = function(callback) { - const mspCode = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43) ? MSPCodes.MSP2_COMMON_SET_SERIAL_CONFIG : MSPCodes.MSP_SET_CF_SERIAL_CONFIG; + const mspCode = MSPCodes.MSP2_COMMON_SET_SERIAL_CONFIG; MSP.send_message(mspCode, mspHelper.crunch(mspCode), false, callback); }; diff --git a/src/js/protocols/webstm32.js b/src/js/protocols/webstm32.js index c75f44ff09..b3d9faa121 100644 --- a/src/js/protocols/webstm32.js +++ b/src/js/protocols/webstm32.js @@ -15,8 +15,6 @@ import { gui_log } from "../gui_log"; import MSPCodes from "../msp/MSPCodes"; import PortUsage from "../port_usage"; import PortHandler from "../port_handler"; -import { API_VERSION_1_42 } from "../data_storage"; -import semver from "semver"; import $ from 'jquery'; import serial from "../webSerial"; import DFU from "../protocols/webusbdfu"; @@ -177,30 +175,6 @@ class STM32Protocol { serial.addEventListener('disconnect', (event) => this.handleDisconnect(event.detail) , { once: true }); } - // TODO: remove this method once all devices are updated to use the new method - legacyRebootAndFlash() { - this.prepareSerialPort(); - serial.connect(this.port, { bitrate: this.options.reboot_baud }, (openInfo) => { - if (!openInfo) { - GUI.connect_lock = false; - gui_log(i18n.getMessage('serialPortOpenFail')); - return; - } - - console.log('Using legacy reboot method'); - - console.log('Sending ascii "R" to reboot'); - const bufferOut = new ArrayBuffer(1); - const bufferView = new Uint8Array(bufferOut); - - bufferView[0] = 0x52; - - serial.send(bufferOut, () => { - serial.disconnect(disconnectionResult => this.handleDisconnect(disconnectionResult)); - }); - }); - } - reboot() { const buffer = []; buffer.push8(this.rebootMode); @@ -260,14 +234,7 @@ class STM32Protocol { handleMSPConnect() { gui_log(i18n.getMessage('apiVersionReceived', [FC.CONFIG.apiVersion])); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - this.mspConnector.disconnect((disconnectionResult) => { - // need some time for the port to be closed, serial port does not open if tried immediately - setTimeout(this.legacyRebootAndFlash, 500); - }); - } else { - this.lookingForCapabilitiesViaMSP(); - } + this.lookingForCapabilitiesViaMSP(); } // no input parameters diff --git a/src/js/tabs/failsafe.js b/src/js/tabs/failsafe.js index 0805929d89..54679d04f9 100644 --- a/src/js/tabs/failsafe.js +++ b/src/js/tabs/failsafe.js @@ -5,7 +5,7 @@ import MSP from "../msp"; import FC from "../fc"; import MSPCodes from "../msp/MSPCodes"; import adjustBoxNameIfPeripheralWithModeID from "../peripherals"; -import { API_VERSION_1_43, API_VERSION_1_44, API_VERSION_1_45, API_VERSION_1_46 } from "../data_storage"; +import { API_VERSION_1_45, API_VERSION_1_46 } from "../data_storage"; import semver from 'semver'; import $ from 'jquery'; @@ -301,24 +301,16 @@ failsafe.initialize = function (callback) { // Sort the element, if need to group, do it by lexical sort, ie. by naming of (the translated) selection text $('#failsafeGpsRescueItemAltitudeSelect').sortSelect(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - $('input[name="gps_rescue_ascend_rate"]').val((FC.GPS_RESCUE.ascendRate / 100).toFixed(1)); - $('input[name="gps_rescue_descend_rate"]').val((FC.GPS_RESCUE.descendRate / 100).toFixed(1)); - $('input[name="gps_rescue_allow_arming_without_fix"]').prop('checked', FC.GPS_RESCUE.allowArmingWithoutFix > 0); - $('select[name="gps_rescue_altitude_mode"]').val(FC.GPS_RESCUE.altitudeMode); - } else { - $('input[name="gps_rescue_ascend_rate"]').closest('.number').hide(); - $('input[name="gps_rescue_descend_rate"]').closest('.number').hide(); - $('input[name="gps_rescue_allow_arming_without_fix"]').closest('.number').hide(); - $('select[name="gps_rescue_altitude_mode"]').closest('.number').hide(); - } + // Introduced in 1.43 + $('input[name="gps_rescue_ascend_rate"]').val((FC.GPS_RESCUE.ascendRate / 100).toFixed(1)); + $('input[name="gps_rescue_descend_rate"]').val((FC.GPS_RESCUE.descendRate / 100).toFixed(1)); + $('input[name="gps_rescue_allow_arming_without_fix"]').prop('checked', FC.GPS_RESCUE.allowArmingWithoutFix > 0); + $('select[name="gps_rescue_altitude_mode"]').val(FC.GPS_RESCUE.altitudeMode); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - $('input[name="gps_rescue_min_start_dist"]').val(FC.GPS_RESCUE.minStartDistM); - } else { - $('input[name="gps_rescue_min_start_dist"]').closest('.number').hide(); - } + // Introduced in 1.44 + $('input[name="gps_rescue_min_start_dist"]').val(FC.GPS_RESCUE.minStartDistM); + // Introduced in 1.45 if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { $('input[name="gps_rescue_angle"]').attr("max", 80); $('input[name="gps_rescue_return_altitude"]').attr({"min": 2, "max": 255}); @@ -329,6 +321,7 @@ failsafe.initialize = function (callback) { $('input[name="gps_rescue_descend_rate"]').attr("min", 0.3); } + // Introduced in 1.46 if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) { $('input[name="gps_rescue_initial_climb"]').val(FC.GPS_RESCUE.initialClimbM); } else { @@ -379,17 +372,16 @@ failsafe.initialize = function (callback) { FC.GPS_RESCUE.minSats = $('input[name="gps_rescue_min_sats"]').val(); FC.GPS_RESCUE.sanityChecks = $('select[name="gps_rescue_sanity_checks"]').val(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - FC.GPS_RESCUE.ascendRate = $('input[name="gps_rescue_ascend_rate"]').val() * 100; - FC.GPS_RESCUE.descendRate = $('input[name="gps_rescue_descend_rate"]').val() * 100; - FC.GPS_RESCUE.allowArmingWithoutFix = $('input[name="gps_rescue_allow_arming_without_fix"]').prop('checked') ? 1 : 0; - FC.GPS_RESCUE.altitudeMode = parseInt($('select[name="gps_rescue_altitude_mode"]').val()); - } + // Introduced in 1.43 + FC.GPS_RESCUE.ascendRate = $('input[name="gps_rescue_ascend_rate"]').val() * 100; + FC.GPS_RESCUE.descendRate = $('input[name="gps_rescue_descend_rate"]').val() * 100; + FC.GPS_RESCUE.allowArmingWithoutFix = $('input[name="gps_rescue_allow_arming_without_fix"]').prop('checked') ? 1 : 0; + FC.GPS_RESCUE.altitudeMode = parseInt($('select[name="gps_rescue_altitude_mode"]').val()); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - FC.GPS_RESCUE.minStartDistM = $('input[name="gps_rescue_min_start_dist"]').val(); - } + // Introduced in 1.44 + FC.GPS_RESCUE.minStartDistM = $('input[name="gps_rescue_min_start_dist"]').val(); + // Introduced in 1.46 if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) { FC.GPS_RESCUE.initialClimbM = $('input[name="gps_rescue_initial_climb"]').val(); } diff --git a/src/js/tabs/gps.js b/src/js/tabs/gps.js index 14d7c2c989..b6d8058eb7 100644 --- a/src/js/tabs/gps.js +++ b/src/js/tabs/gps.js @@ -1,6 +1,6 @@ import { i18n } from "../localization"; import semver from 'semver'; -import { API_VERSION_1_43, API_VERSION_1_46 } from '../data_storage'; +import { API_VERSION_1_46 } from '../data_storage'; import GUI, { TABS } from '../gui'; import FC from '../fc'; import MSP from "../msp"; @@ -122,9 +122,8 @@ gps.initialize = async function (callback) { i18n.getMessage('gpsSbasIndianGAGAN'), ]; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - gpsSbas.push(i18n.getMessage('gpsSbasNone')); - } + // Introduced in API 1.43 + gpsSbas.push(i18n.getMessage('gpsSbasNone')); const gpsProtocolElement = $('select.gps_protocol'); const gpsAutoBaudElement = $('input[name="gps_auto_baud"]'); @@ -161,7 +160,7 @@ gps.initialize = async function (callback) { const ubloxSelected = FC.GPS_CONFIG.provider === gpsProtocols.indexOf('UBLOX'); const mspSelected = FC.GPS_CONFIG.provider === gpsProtocols.indexOf('MSP'); - const enableGalileoVisible = checked && ubloxSelected && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43); + const enableGalileoVisible = checked && ubloxSelected; gpsUbloxGalileoGroup.toggle(enableGalileoVisible); const enableSbasVisible = checked && ubloxSelected; @@ -184,7 +183,6 @@ gps.initialize = async function (callback) { FC.GPS_CONFIG.ublox_sbas = parseInt($(this).val()); }).val(FC.GPS_CONFIG.ublox_sbas); - $('.gps_home_once').toggle(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)); gpsHomeOnceElement.change(function() { FC.GPS_CONFIG.home_point_once = $(this).is(':checked') ? 1 : 0; }).prop('checked', FC.GPS_CONFIG.home_point_once > 0).change(); diff --git a/src/js/tabs/setup.js b/src/js/tabs/setup.js index 34672a7193..7a5b795fea 100644 --- a/src/js/tabs/setup.js +++ b/src/js/tabs/setup.js @@ -211,7 +211,7 @@ setup.initialize = function (callback) { 'BAD_RX_RECOVERY', 'BOXFAILSAFE', 'RUNAWAY_TAKEOFF', - 'CRASH_DETECTED', + 'CRASH_DETECTED', // THROTTLE before 1.42 'ANGLE', 'BOOT_GRACE_TIME', 'NOPREARM', @@ -225,11 +225,13 @@ setup.initialize = function (callback) { 'GPS', 'RESC', 'RPMFILTER', + // Introduced in 1.42 'REBOOT_REQUIRED', 'DSHOT_BITBANG', + // Introduced in 1.43 'ACC_CALIBRATION', 'MOTOR_PROTOCOL', - 'ARM_SWITCH', // Needs to be the last element, since it's always activated if one of the others is active when arming + // 'ARM_SWITCH', // Needs to be the last element, since it's always activated if one of the others is active when arming ]; if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) { diff --git a/src/js/utils/AutoDetect.js b/src/js/utils/AutoDetect.js index 7704bc135e..268a33999b 100644 --- a/src/js/utils/AutoDetect.js +++ b/src/js/utils/AutoDetect.js @@ -7,7 +7,7 @@ import FC from '../fc'; import MSP from '../msp'; import MSPCodes from '../msp/MSPCodes'; import semver from 'semver'; -import { API_VERSION_1_39, API_VERSION_1_45, API_VERSION_1_46 } from '../data_storage'; +import { API_VERSION_1_45, API_VERSION_1_46 } from '../data_storage'; import serial from '../webSerial'; /** @@ -150,7 +150,7 @@ class AutoDetect { await MSP.promise(MSPCodes.MSP_API_VERSION); gui_log(i18n.getMessage('apiVersionReceived', FC.CONFIG.apiVersion)); - if (FC.CONFIG.apiVersion.includes('null') || semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_39)) { + if (FC.CONFIG.apiVersion.includes('null') || semver.lt(FC.CONFIG.apiVersion, "1.39.0")) { // auto-detect is not supported this.onFinishClose(); } else { diff --git a/src/js/utils/EscProtocols.js b/src/js/utils/EscProtocols.js index a72a5df984..ef6e8033f7 100644 --- a/src/js/utils/EscProtocols.js +++ b/src/js/utils/EscProtocols.js @@ -1,6 +1,3 @@ -import semver from 'semver'; -import { API_VERSION_1_42, API_VERSION_1_43 } from '../data_storage'; - class EscProtocols { static get PROTOCOL_PWM() { return "PWM"; } @@ -11,7 +8,6 @@ class EscProtocols static get PROTOCOL_DSHOT150() { return "DSHOT150"; } static get PROTOCOL_DSHOT300() { return "DSHOT300"; } static get PROTOCOL_DSHOT600() { return "DSHOT600"; } - static get PROTOCOL_DSHOT1200() { return "DSHOT1200"; } static get PROTOCOL_PROSHOT1000() { return "PROSHOT1000"; } static get PROTOCOL_DISABLED() { return "DISABLED"; } @@ -21,7 +17,6 @@ class EscProtocols EscProtocols.PROTOCOL_DSHOT150, EscProtocols.PROTOCOL_DSHOT300, EscProtocols.PROTOCOL_DSHOT600, - EscProtocols.PROTOCOL_DSHOT1200, EscProtocols.PROTOCOL_PROSHOT1000, ]; } @@ -49,19 +44,10 @@ class EscProtocols EscProtocols.PROTOCOL_DSHOT150, EscProtocols.PROTOCOL_DSHOT300, EscProtocols.PROTOCOL_DSHOT600, + EscProtocols.PROTOCOL_PROSHOT1000, + EscProtocols.PROTOCOL_DISABLED, ]; - - if (semver.lt(apiVersion, API_VERSION_1_42)) { - escProtocols.push(EscProtocols.PROTOCOL_DSHOT1200); - } - - escProtocols.push(EscProtocols.PROTOCOL_PROSHOT1000); - - if (semver.gte(apiVersion, API_VERSION_1_43)) { - escProtocols.push(EscProtocols.PROTOCOL_DISABLED); - } - return escProtocols; } @@ -69,8 +55,6 @@ class EscProtocols { return protocolIndex; } - - } export default EscProtocols;