diff --git a/locales/en/messages.json b/locales/en/messages.json index c8f9f439..693bf4ae 100644 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -276,25 +276,6 @@ "deviceReady": { "message": "Device - Betaflight devs on slack" }, - - "initialSetupBackupAndRestoreApiVersion": { - "message": " You have firmware with API version , backup and restore requires . Please backup your settings via the CLI, see Betaflight documentation for procedure." - }, "initialSetupButtonCalibrateAccel": { "message": "Calibrate Accelerometer" }, @@ -793,30 +770,12 @@ "initialSetupResetText": { "message": "Restore settings to default" }, - "initialSetupButtonBackup": { - "message": "Backup JSON" - }, - "initialSetupButtonRestore": { - "message": "Restore JSON" - }, "initialSetupButtonRebootBootloader": { "message": "Activate Boot Loader / DFU" }, - "initialSetupBackupRestoreHeader": { - "message": "Experimental Backup and Restore" - }, - "initialSetupBackupRestoreText": { - "message": "Backup your configuration in case of an accident, CLI settings are included - use the command 'diff all' in CLI for this." - }, "initialSetupRebootBootloaderText": { "message": "Reboot into boot loader / DFU mode." }, - "initialSetupBackupSuccess": { - "message": "Backup saved " - }, - "initialSetupRestoreSuccess": { - "message": "Configuration restored " - }, "initialSetupButtonResetZaxis": { "message": "Reset Z axis, offset: 0 deg" }, diff --git a/src/css/tabs/setup.less b/src/css/tabs/setup.less index 236c8215..78a65008 100644 --- a/src/css/tabs/setup.less +++ b/src/css/tabs/setup.less @@ -171,9 +171,6 @@ float: left; } } -.backupRestore { - margin-bottom: 0; -} .block.info { .fields { padding: 5px 5px 3px 5px; diff --git a/src/js/Beepers.js b/src/js/Beepers.js index b31c9b36..cba055b0 100644 --- a/src/js/Beepers.js +++ b/src/js/Beepers.js @@ -24,22 +24,12 @@ class Beepers { { bit: 16, name: 'SYSTEM_INIT', visible: true }, { bit: 17, name: 'USB', visible: true }, { bit: 18, name: 'BLACKBOX_ERASE', visible: true }, + { bit: 19, name: 'CRASH_FLIP', visible: true }, + { bit: 20, name: 'CAM_CONNECTION_OPEN', visible: true }, + { bit: 21, name: 'CAM_CONNECTION_CLOSE', visible: true }, + { bit: 22, name: 'RC_SMOOTHING_INIT_FAIL', visible: true }, ]; - if (semver.gte(config.apiVersion, API_VERSION_1_37)) { - beepers.push( - { bit: 19, name: 'CRASH_FLIP', visible: true }, - { bit: 20, name: 'CAM_CONNECTION_OPEN', visible: true }, - { bit: 21, name: 'CAM_CONNECTION_CLOSE', visible: true }, - ); - } - - if (semver.gte(config.apiVersion, API_VERSION_1_39)) { - beepers.push( - { bit: 22, name: 'RC_SMOOTHING_INIT_FAIL', visible: true }, - ); - } - if (supportedConditions) { self._beepers = []; beepers.forEach(function (beeper) { diff --git a/src/js/CliAutoComplete.js b/src/js/CliAutoComplete.js index 93abfd15..fff2866f 100644 --- a/src/js/CliAutoComplete.js +++ b/src/js/CliAutoComplete.js @@ -532,34 +532,25 @@ CliAutoComplete._initTextcomplete = function() { }), ]); - if (semver.gte(FC.CONFIG.flightControllerVersion, "4.0.0")) { - $textarea.textcomplete('register', [ - strategy({ // "resource show all", from BF 4.0.0 onwards - match: /^(\s*resource\s+show\s+)(\w*)$/i, - search: function(term, callback) { - sendOnEnter = true; - searcher(term, callback, ['all'], 1, true); - }, - template: highlighterPrefix, - }), - ]); - } - + $textarea.textcomplete('register', [ + strategy({ // "resource show all", from BF 4.0.0 onwards + match: /^(\s*resource\s+show\s+)(\w*)$/i, + search: function(term, callback) { + sendOnEnter = true; + searcher(term, callback, ['all'], 1, true); + }, + template: highlighterPrefix, + }), + ]); // diff command const diffArgs1 = ["master", "profile", "rates", "all"]; const diffArgs2 = []; - if (semver.lt(FC.CONFIG.flightControllerVersion, "3.4.0")) { - diffArgs2.push("showdefaults"); - } else { - // above 3.4.0 - diffArgs2.push("defaults"); - if (semver.gte(FC.CONFIG.flightControllerVersion, "4.0.0")) { - diffArgs1.push("hardware"); - diffArgs2.push("bare"); - } - } + // above 3.4.0 + diffArgs2.push("defaults"); + diffArgs1.push("hardware"); + diffArgs2.push("bare"); diffArgs1.sort(); diffArgs2.sort(); diff --git a/src/js/Features.js b/src/js/Features.js index 06d00585..40bca380 100644 --- a/src/js/Features.js +++ b/src/js/Features.js @@ -5,6 +5,7 @@ const Features = function (config) { const features = [ {bit: 0, group: 'rxMode', mode: 'select', name: 'RX_PPM'}, + {bit: 1, group: 'batteryVoltage', name: 'VBAT'}, {bit: 2, group: 'other', name: 'INFLIGHT_ACC_CAL'}, {bit: 3, group: 'rxMode', mode: 'select', name: 'RX_SERIAL'}, {bit: 4, group: 'escMotorStop', name: 'MOTOR_STOP'}, @@ -13,94 +14,29 @@ const Features = function (config) { {bit: 7, group: 'gps', name: 'GPS', haveTip: true}, {bit: 9, group: 'other', name: 'SONAR'}, {bit: 10, group: 'telemetry', name: 'TELEMETRY'}, + {bit: 11, group: 'batteryCurrent', name: 'CURRENT_METER'}, {bit: 12, group: '3D', name: '3D'}, {bit: 13, group: 'rxMode', mode: 'select', name: 'RX_PARALLEL_PWM'}, {bit: 14, group: 'rxMode', mode: 'select', name: 'RX_MSP'}, {bit: 15, group: 'rssi', name: 'RSSI_ADC'}, {bit: 16, group: 'other', name: 'LED_STRIP'}, {bit: 17, group: 'other', name: 'DISPLAY', haveTip: true}, + {bit: 18, group: 'other', name: 'OSD'}, + {bit: 19, group: 'other', name: 'BLACKBOX', haveTip: true}, + {bit: 20, group: 'other', name: 'CHANNEL_FORWARDING'}, + {bit: 21, group: 'other', name: 'TRANSPONDER', haveTip: true}, + {bit: 22, group: 'other', name: 'AIRMODE'}, + {bit: 25, group: 'rxMode', mode: 'select', name: 'RX_SPI'}, + {bit: 27, group: 'escSensor', name: 'ESC_SENSOR'}, + {bit: 28, group: 'antiGravity', name: 'ANTI_GRAVITY', haveTip: true, hideName: true}, ]; - if (!semver.gte(config.apiVersion, API_VERSION_1_33)) { + 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: 19, group: 'other', name: 'BLACKBOX', haveTip: true}, + {bit: 29, group: 'other', name: 'DYNAMIC_FILTER'}, ); } - if (semver.gte(config.apiVersion, "1.12.0")) { - features.push( - {bit: 20, group: 'other', name: 'CHANNEL_FORWARDING'}, - ); - } - - if (semver.gte(config.apiVersion, "1.15.0") && !semver.gte(config.apiVersion, API_VERSION_1_36)) { - features.push( - {bit: 8, group: 'rxFailsafe', name: 'FAILSAFE', haveTip: true}, - ); - } - - if (semver.gte(config.apiVersion, "1.16.0")) { - features.push( - {bit: 21, group: 'other', name: 'TRANSPONDER', haveTip: true}, - ); - } - - if (config.flightControllerVersion !== '') { - if (semver.gte(config.apiVersion, "1.16.0")) { - features.push( - {bit: 22, group: 'other', name: 'AIRMODE'}, - ); - } - - if (semver.gte(config.apiVersion, "1.16.0")) { - if (semver.lt(config.apiVersion, "1.20.0")) { - features.push( - {bit: 23, group: 'superexpoRates', name: 'SUPEREXPO_RATES'}, - ); - } else if (!semver.gte(config.apiVersion, API_VERSION_1_33)) { - features.push( - {bit: 23, group: 'other', name: 'SDCARD'}, - ); - } - } - - if (semver.gte(config.apiVersion, "1.20.0")) { - features.push( - {bit: 18, group: 'other', name: 'OSD'}, - ); - if (!semver.gte(config.apiVersion, API_VERSION_1_35)) { - features.push( - {bit: 24, group: 'other', name: 'VTX'}, - ); - } - } - - if (semver.gte(config.apiVersion, API_VERSION_1_31)) { - features.push( - {bit: 25, group: 'rxMode', mode: 'select', name: 'RX_SPI'}, - {bit: 27, group: 'escSensor', name: 'ESC_SENSOR'}, - ); - } - - if (semver.gte(config.apiVersion, API_VERSION_1_36)) { - features.push( - {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'}, - ); - } - } - - if (!semver.gte(config.apiVersion, API_VERSION_1_36)) { - features.push( - {bit: 1, group: 'batteryVoltage', name: 'VBAT'}, - {bit: 11, group: 'batteryCurrent', name: 'CURRENT_METER'}, - ); - } - } - self._features = features; self._featureMask = 0; diff --git a/src/js/RateCurve.js b/src/js/RateCurve.js index 19e7d68f..c509ac09 100644 --- a/src/js/RateCurve.js +++ b/src/js/RateCurve.js @@ -87,13 +87,8 @@ const RateCurve = function (useLegacyCurve) { let expoPower; let rcRateConstant; - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - expoPower = 3; - rcRateConstant = 200; - } else { - expoPower = 2; - rcRateConstant = 205.85; - } + expoPower = 3; + rcRateConstant = 200; if (rcExpo > 0) { rcCommandf = rcCommandf * Math.pow(rcCommandfAbs, expoPower) * rcExpo + rcCommandf * (1-rcExpo); @@ -169,23 +164,7 @@ const RateCurve = function (useLegacyCurve) { yaw_rate_limit: FC.RC_TUNING.yaw_rate_limit, }; - if (semver.lt(FC.CONFIG.apiVersion, "1.7.0")) { - currentRates.roll_rate = FC.RC_TUNING.roll_pitch_rate; - currentRates.pitch_rate = FC.RC_TUNING.roll_pitch_rate; - } - - if (semver.lt(FC.CONFIG.apiVersion, "1.16.0")) { - currentRates.rc_rate_yaw = currentRates.rc_rate; - } - - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - currentRates.superexpo = true; - } - - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - currentRates.rc_rate_pitch = currentRates.rc_rate; - currentRates.rc_expo_pitch = currentRates.rc_expo; - } + currentRates.superexpo = true; if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { switch (FC.RC_TUNING.rates_type) { diff --git a/src/js/backup_restore.js b/src/js/backup_restore.js deleted file mode 100644 index f0d26725..00000000 --- a/src/js/backup_restore.js +++ /dev/null @@ -1,956 +0,0 @@ -'use strict'; - -// code below is highly experimental, although it runs fine on latest firmware -// the data inside nested objects needs to be verified if deep copy works properly -function configuration_backup(callback) { - let activeProfile = null; - - let version = CONFIGURATOR.version; - - if (version.indexOf(".") === -1) { - version = `${version}.0.0`; - } - - const configuration = { - 'generatedBy': version, - 'apiVersion': FC.CONFIG.apiVersion, - 'profiles': [], - }; - - const profileSpecificData = [ - MSPCodes.MSP_PID_CONTROLLER, - MSPCodes.MSP_PID, - MSPCodes.MSP_RC_TUNING, - MSPCodes.MSP_ACC_TRIM, - MSPCodes.MSP_SERVO_CONFIGURATIONS, - MSPCodes.MSP_MODE_RANGES, - MSPCodes.MSP_ADJUSTMENT_RANGES, - ]; - - function update_profile_specific_data_list() { - if (semver.gt(FC.CONFIG.apiVersion, "1.12.0")) { - profileSpecificData.push(MSPCodes.MSP_SERVO_MIX_RULES); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - profileSpecificData.push(MSPCodes.MSP_RC_DEADBAND); - } - } - - update_profile_specific_data_list(); - - MSP.send_message(MSPCodes.MSP_STATUS, false, false, function () { - activeProfile = FC.CONFIG.profile; - select_profile(); - }); - - function select_profile() { - if (activeProfile > 0) { - MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [0], false, fetch_specific_data); - } else { - fetch_specific_data(); - } - } - - function fetch_specific_data() { - let fetchingProfile = 0; - let codeKey = 0; - - function fetch_specific_data_item() { - if (fetchingProfile < FC.CONFIG.numProfiles) { - MSP.send_message(profileSpecificData[codeKey], false, false, function () { - codeKey++; - - if (codeKey < profileSpecificData.length) { - fetch_specific_data_item(); - } else { - configuration.profiles.push({ - 'PID': jQuery.extend(true, {}, FC.PID), - 'PIDs': jQuery.extend(true, [], FC.PIDS), - 'RC': jQuery.extend(true, {}, FC.RC_TUNING), - 'AccTrim': jQuery.extend(true, [], FC.CONFIG.accelerometerTrims), - 'ServoConfig': jQuery.extend(true, [], FC.SERVO_CONFIG), - 'ServoRules': jQuery.extend(true, [], FC.SERVO_RULES), - 'ModeRanges': jQuery.extend(true, [], FC.MODE_RANGES), - 'AdjustmentRanges': jQuery.extend(true, [], FC.ADJUSTMENT_RANGES), - }); - - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - configuration.profiles[fetchingProfile].RCdeadband = jQuery.extend(true, {}, FC.RC_DEADBAND_CONFIG); - } - codeKey = 0; - fetchingProfile++; - - MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [fetchingProfile], false, fetch_specific_data_item); - } - }); - } else { - MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [activeProfile], false, fetch_unique_data); - } - } - - // start fetching - fetch_specific_data_item(); - } - - const uniqueData = [ - MSPCodes.MSP_RX_MAP, - MSPCodes.MSP_CF_SERIAL_CONFIG, - MSPCodes.MSP_LED_STRIP_CONFIG, - MSPCodes.MSP_LED_COLORS, - ]; - - function update_unique_data_list() { - if (semver.gte(FC.CONFIG.apiVersion, "1.8.0")) { - uniqueData.push(MSPCodes.MSP_LOOP_TIME); - uniqueData.push(MSPCodes.MSP_ARMING_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.14.0")) { - uniqueData.push(MSPCodes.MSP_MOTOR_3D_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - uniqueData.push(MSPCodes.MSP_SENSOR_ALIGNMENT); - uniqueData.push(MSPCodes.MSP_RX_CONFIG); - uniqueData.push(MSPCodes.MSP_FAILSAFE_CONFIG); - uniqueData.push(MSPCodes.MSP_RXFAIL_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) { - uniqueData.push(MSPCodes.MSP_LED_STRIP_MODECOLOR); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33)) { - uniqueData.push(MSPCodes.MSP_MOTOR_CONFIG); - uniqueData.push(MSPCodes.MSP_RSSI_CONFIG); - uniqueData.push(MSPCodes.MSP_GPS_CONFIG); - uniqueData.push(MSPCodes.MSP_FEATURE_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - uniqueData.push(MSPCodes.MSP_MODE_RANGES_EXTRA); - } - } - - update_unique_data_list(); - - function fetch_unique_data() { - let codeKey = 0; - - function fetch_unique_data_item() { - if (codeKey < uniqueData.length) { - MSP.send_message(uniqueData[codeKey], false, false, function () { - codeKey++; - fetch_unique_data_item(); - }); - } else { - configuration.RCMAP = jQuery.extend(true, [], FC.RC_MAP); - configuration.SERIAL_CONFIG = jQuery.extend(true, {}, FC.SERIAL_CONFIG); - configuration.LED_STRIP = jQuery.extend(true, [], FC.LED_STRIP); - configuration.LED_COLORS = jQuery.extend(true, [], FC.LED_COLORS); - configuration.BOARD_ALIGNMENT_CONFIG = jQuery.extend(true, {}, FC.BOARD_ALIGNMENT_CONFIG); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - configuration.CRAFT_NAME = FC.CONFIG.craftName; - configuration.PILOT_NAME = FC.CONFIG.pilotName; - } else { - configuration.CRAFT_NAME = FC.CONFIG.name; - configuration.DISPLAY_NAME = FC.CONFIG.displayName; - } - configuration.MIXER_CONFIG = jQuery.extend(true, {}, FC.MIXER_CONFIG); - configuration.SENSOR_CONFIG = jQuery.extend(true, {}, FC.SENSOR_CONFIG); - configuration.PID_ADVANCED_CONFIG = jQuery.extend(true, {}, FC.PID_ADVANCED_CONFIG); - - if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) { - configuration.LED_MODE_COLORS = jQuery.extend(true, [], FC.LED_MODE_COLORS); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.8.0")) { - configuration.FC_CONFIG = jQuery.extend(true, {}, FC.FC_CONFIG); - configuration.ARMING_CONFIG = jQuery.extend(true, {}, FC.ARMING_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.14.0")) { - configuration.MOTOR_3D_CONFIG = jQuery.extend(true, {}, FC.MOTOR_3D_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - configuration.SENSOR_ALIGNMENT = jQuery.extend(true, {}, FC.SENSOR_ALIGNMENT); - configuration.RX_CONFIG = jQuery.extend(true, {}, FC.RX_CONFIG); - configuration.FAILSAFE_CONFIG = jQuery.extend(true, {}, FC.FAILSAFE_CONFIG); - configuration.RXFAIL_CONFIG = jQuery.extend(true, [], FC.RXFAIL_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33)) { - configuration.RSSI_CONFIG = jQuery.extend(true, {}, FC.RSSI_CONFIG); - configuration.FEATURE_CONFIG = jQuery.extend(true, {}, FC.FEATURE_CONFIG); - configuration.MOTOR_CONFIG = jQuery.extend(true, {}, FC.MOTOR_CONFIG); - configuration.GPS_CONFIG = jQuery.extend(true, {}, FC.GPS_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - configuration.BEEPER_CONFIG = jQuery.extend(true, {}, FC.BEEPER_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - configuration.MODE_RANGES_EXTRA = jQuery.extend(true, [], FC.MODE_RANGES_EXTRA); - } - - save(); - } - } - - if (GUI.configuration_loaded === true) { - return fetch_unique_data_item(); - } - - MSP.promise(MSPCodes.MSP_ADVANCED_CONFIG).then(function() { - return MSP.promise(MSPCodes.MSP_SENSOR_CONFIG); - }).then(function() { - return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) - ? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.CRAFT_NAME)) - : MSP.promise(MSPCodes.MSP_NAME); - }).then(function() { - return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) - ? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.PILOT_NAME)) : Promise.resolve(true); - }).then(function() { - return MSP.promise(MSPCodes.MSP_BOARD_ALIGNMENT_CONFIG); - }).then(function() { - return MSP.promise(MSPCodes.MSP_MIXER_CONFIG); - }).then(function() { - return MSP.promise(MSPCodes.MSP_BEEPER_CONFIG); - }).then(function() { - return fetch_unique_data_item(); - }); - } - - function save() { - let chosenFileEntry = null; - - const prefix = 'backup'; - const suffix = 'json'; - - const filename = generateFilename(prefix, suffix); - - const accepts = [{ - description: `${suffix.toUpperCase()} files`, extensions: [suffix], - }]; - - // create or load the file - chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: filename, accepts: accepts}, function (fileEntry) { - if (checkChromeRuntimeError()) { - return; - } - - if (!fileEntry) { - console.log('No file selected, backup aborted.'); - return; - } - - chosenFileEntry = fileEntry; - - // echo/console log path specified - chrome.fileSystem.getDisplayPath(chosenFileEntry, function (path) { - console.log(`Backup file path: ${path}`); - }); - - // change file entry from read only to read/write - chrome.fileSystem.getWritableEntry(chosenFileEntry, function (fileEntryWritable) { - // check if file is writable - chrome.fileSystem.isWritableEntry(fileEntryWritable, function (isWritable) { - if (isWritable) { - chosenFileEntry = fileEntryWritable; - - // crunch the config object - const serializedConfigObject = JSON.stringify(configuration, null, '\t'); - const blob = new Blob([serializedConfigObject], {type: 'text/plain'}); // first parameter for Blob needs to be an array - - chosenFileEntry.createWriter(function (writer) { - writer.onerror = function (e) { - console.error(e); - }; - - let truncated = false; - writer.onwriteend = function () { - if (!truncated) { - // onwriteend will be fired again when truncation is finished - truncated = true; - writer.truncate(blob.size); - - return; - } - - analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Backup'); - console.log('Write SUCCESSFUL'); - if (callback) callback(); - }; - - writer.write(blob); - }, function (e) { - console.error(e); - }); - } else { - // Something went wrong or file is set to read only and cannot be changed - console.log('File appears to be read only, sorry.'); - } - }); - }); - }); - } - -} - -function configuration_restore(callback) { - let chosenFileEntry = null; - - const accepts = [{ - description: 'JSON files', extensions: ['json'], - }]; - - // load up the file - chrome.fileSystem.chooseEntry({type: 'openFile', accepts: accepts}, function (fileEntry) { - if (checkChromeRuntimeError()) { - return; - } - - if (!fileEntry) { - console.log('No file selected, restore aborted.'); - return; - } - - chosenFileEntry = fileEntry; - - // echo/console log path specified - chrome.fileSystem.getDisplayPath(chosenFileEntry, function (path) { - console.log(`Restore file path: ${path}`); - }); - - // read contents into variable - chosenFileEntry.file(function (file) { - const reader = new FileReader(); - - reader.onprogress = function (e) { - if (e.total > 1048576) { // 1 MB - // dont allow reading files bigger then 1 MB - console.log('File limit (1 MB) exceeded, aborting'); - reader.abort(); - } - }; - - reader.onloadend = function (e) { - if ((e.total != 0 && e.total == e.loaded) || GUI.isCordova()) { - // Cordova: Ignore verification : seem to have a bug with progressEvent returned - console.log('Read SUCCESSFUL'); - let configuration; - try { // check if string provided is a valid JSON - configuration = JSON.parse(e.target.result); - } catch (err) { - // data provided != valid json object - console.log(`Data provided != valid JSON string, restore aborted: ${err}`); - - return; - } - - // validate - if (typeof configuration.generatedBy !== 'undefined' && compareVersions(configuration.generatedBy, CONFIGURATOR.BACKUP_FILE_VERSION_MIN_SUPPORTED)) { - if (!compareVersions(configuration.generatedBy, "1.14.0") && !migrate(configuration)) { - GUI.log(i18n.getMessage('backupFileUnmigratable')); - return; - } - if (configuration.FEATURE_CONFIG.features._featureMask) { - const features = new Features(FC.CONFIG); - features.setMask(configuration.FEATURE_CONFIG.features._featureMask); - configuration.FEATURE_CONFIG.features = features; - } - - analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Restore'); - - configuration_upload(configuration, callback); - } else { - GUI.log(i18n.getMessage('backupFileIncompatible')); - } - } - }; - - reader.readAsText(file); - }); - }); - - function compareVersions(generated, required) { - if (generated == undefined) { - return false; - } - return semver.gte(generated, required); - } - - - function migrate(configuration) { - let appliedMigrationsCount = 0; - let migratedVersion = configuration.generatedBy; - GUI.log(i18n.getMessage('configMigrationFrom', [migratedVersion])); - - if (!compareVersions(migratedVersion, '0.59.1')) { - - // variable was renamed - configuration.RSSI_CONFIG.channel = configuration.MISC.rssi_aux_channel; - configuration.MISC.rssi_aux_channel = undefined; - - migratedVersion = '0.59.1'; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (!compareVersions(migratedVersion, '0.60.1')) { - - // LED_STRIP support was added. - if (!configuration.LED_STRIP) { - configuration.LED_STRIP = []; - } - - migratedVersion = '0.60.1'; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (!compareVersions(migratedVersion, '0.61.0')) { - - // Changing PID controller via UI was added. - if (!configuration.PIDs && configuration.PID) { - configuration.PIDs = configuration.PID; - configuration.PID = { - controller: 0, // assume pid controller 0 was used. - }; - } - - migratedVersion = '0.61.0'; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (!compareVersions(migratedVersion, '0.63.0')) { - - // LED Strip was saved as object instead of array. - if (typeof(configuration.LED_STRIP) == 'object') { - const fixedLedStrip = []; - - let index = 0; - while (configuration.LED_STRIP[index]) { - fixedLedStrip.push(configuration.LED_STRIP[index++]); - } - configuration.LED_STRIP = fixedLedStrip; - } - - for (let profileIndex = 0; profileIndex < 3; profileIndex++) { - const RC = configuration.profiles[profileIndex].RC; - // TPA breakpoint was added - if (!RC.dynamic_THR_breakpoint) { - RC.dynamic_THR_breakpoint = 1500; // firmware default - } - - // Roll and pitch rates were split - RC.roll_rate = RC.roll_pitch_rate; - RC.pitch_rate = RC.roll_pitch_rate; - } - - migratedVersion = '0.63.0'; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (configuration.apiVersion == undefined) { - configuration.apiVersion = "1.0.0"; // a guess that will satisfy the rest of the code - } - // apiVersion previously stored without patchlevel - if (!semver.parse(configuration.apiVersion)) { - configuration.apiVersion += ".0"; - if (!semver.parse(configuration.apiVersion)) { - return false; - } - } - if (compareVersions(migratedVersion, '0.63.0') && !compareVersions(configuration.apiVersion, '1.7.0')) { - // Serial configuation redesigned, 0.63.0 saves old and new configurations. - const ports = []; - for (const port of configuration.SERIAL_CONFIG.ports) { - const oldPort = port; - - const newPort = { - identifier: oldPort.identifier, - functions: [], - msp_baudrate: String(configuration.SERIAL_CONFIG.mspBaudRate), - gps_baudrate: String(configuration.SERIAL_CONFIG.gpsBaudRate), - telemetry_baudrate: 'AUTO', - blackbox_baudrate: '115200', - }; - - switch(oldPort.scenario) { - case 1: // MSP, CLI, TELEMETRY, SMARTPORT TELEMETRY, GPS-PASSTHROUGH - case 5: // MSP, CLI, GPS-PASSTHROUGH - case 8: // MSP ONLY - newPort.functions.push('MSP'); - break; - case 2: // GPS - newPort.functions.push('GPS'); - break; - case 3: // RX_SERIAL - newPort.functions.push('RX_SERIAL'); - break; - case 10: // BLACKBOX ONLY - newPort.functions.push('BLACKBOX'); - break; - case 11: // MSP, CLI, BLACKBOX, GPS-PASSTHROUGH - newPort.functions.push('MSP'); - newPort.functions.push('BLACKBOX'); - break; - } - - ports.push(newPort); - } - configuration.SERIAL_CONFIG = { - ports: ports, - }; - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (compareVersions(migratedVersion, '0.63.0') && !compareVersions(configuration.apiVersion, '1.8.0')) { - // api 1.8 exposes looptime and arming config - - if (configuration.FC_CONFIG == undefined) { - configuration.FC_CONFIG = { - loopTime: 3500, - }; - } - - if (configuration.ARMING_CONFIG == undefined) { - configuration.ARMING_CONFIG = { - auto_disarm_delay: 5, - disarm_kill_switch: 1, - }; - } - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (compareVersions(migratedVersion, '0.63.0')) { - // backups created with 0.63.0 for firmwares with api < 1.8 were saved with incorrect looptime - if (configuration.FC_CONFIG.loopTime == 0) { - //reset it to the default - configuration.FC_CONFIG.loopTime = 3500; - } - } - - if (semver.lt(migratedVersion, '0.66.0')) { - // api 1.12 updated servo configuration protocol and added servo mixer rules - for (let profileIndex = 0; profileIndex < configuration.profiles.length; profileIndex++) { - if (semver.eq(configuration.apiVersion, '1.10.0')) { - // drop two unused servo configurations - while (configuration.profiles[profileIndex].ServoConfig.length > 8) { - configuration.profiles[profileIndex].ServoConfig.pop(); - } - } - - for (let i = 0; i < configuration.profiles[profileIndex].ServoConfig.length; i++) { - const servoConfig = profiles[profileIndex].ServoConfig; - - servoConfig[i].angleAtMin = 45; - servoConfig[i].angleAtMax = 45; - servoConfig[i].reversedInputSources = 0; - - // set the rate to 0 if an invalid value is detected. - if (servoConfig[i].rate < -100 || servoConfig[i].rate > 100) { - servoConfig[i].rate = 0; - } - } - - configuration.profiles[profileIndex].ServoRules = []; - } - - migratedVersion = '0.66.0'; - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (semver.lt(configuration.apiVersion, '1.14.0') && semver.gte(FC.CONFIG.apiVersion, "1.14.0")) { - // api 1.14 removed old pid controllers - for (let profileIndex = 0; profileIndex < configuration.profiles.length; profileIndex++) { - let newPidControllerIndex = configuration.profiles[profileIndex].PID.controller; - switch (newPidControllerIndex) { - case 3: - case 4: - case 5: - newPidControllerIndex = 0; - break; - } - configuration.profiles[profileIndex].PID.controller = newPidControllerIndex; - } - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - - if (compareVersions(migratedVersion, '0.66.0') && !compareVersions(configuration.apiVersion, '1.14.0')) { - // api 1.14 exposes 3D configuration - - if (configuration.MOTOR_3D_CONFIG == undefined) { - configuration.MOTOR_3D_CONFIG = { - deadband3d_low: 1406, - deadband3d_high: 1514, - neutral: 1460, - deadband3d_throttle: 50, - }; - } - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - - if (compareVersions(migratedVersion, '0.66.0') && !compareVersions(configuration.apiVersion, '1.15.0')) { - // api 1.15 exposes RCdeadband and sensor alignment - - for (let profileIndex = 0; profileIndex < configuration.profiles.length; profileIndex++) { - if (configuration.profiles[profileIndex].RCdeadband == undefined) { - configuration.profiles[profileIndex].RCdeadband = { - deadband: 0, - yaw_deadband: 0, - alt_hold_deadband: 40, - }; - } - } - if (configuration.SENSOR_ALIGNMENT == undefined) { - configuration.SENSOR_ALIGNMENT = { - align_gyro: 0, - align_acc: 0, - align_mag: 0, - }; - } - - // api 1.15 exposes RX_CONFIG, FAILSAFE_CONFIG and RXFAIL_CONFIG configuration - - if (configuration.RX_CONFIG == undefined) { - configuration.RX_CONFIG = { - serialrx_provider: 0, - spektrum_sat_bind: 0, - stick_center: 1500, - stick_min: 1100, - stick_max: 1900, - rx_min_usec: 885, - rx_max_usec: 2115, - }; - } - - if (configuration.FAILSAFE_CONFIG == undefined) { - configuration.FAILSAFE_CONFIG = { - failsafe_delay: 10, - failsafe_off_delay: 200, - failsafe_throttle: 1000, - failsafe_switch_mode: 0, - failsafe_throttle_low_delay: 100, - failsafe_procedure: 0, - }; - } - - if (configuration.RXFAIL_CONFIG == undefined) { - configuration.RXFAIL_CONFIG = [ - {mode: 0, value: 1500}, - {mode: 0, value: 1500}, - {mode: 0, value: 1500}, - {mode: 0, value: 875}, - ]; - - for (let i = 0; i < 14; i++) { - const rxfailChannel = { - mode: 1, - value: 1500, - }; - configuration.RXFAIL_CONFIG.push(rxfailChannel); - } - } - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (compareVersions(migratedVersion, '1.2.0')) { - // old version of the configurator incorrectly had a 'disabled' option for GPS SBAS mode. - if (FC.GPS_CONFIG.ublox_sbas < 0) { - FC.GPS_CONFIG.ublox_sbas = 0; - } - migratedVersion = '1.2.0'; - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (compareVersions(migratedVersion, '1.3.1')) { - - // LED_COLORS & LED_MODE_COLORS support was added. - if (!configuration.LED_COLORS) { - configuration.LED_COLORS = []; - } - if (!configuration.LED_MODE_COLORS) { - configuration.LED_MODE_COLORS = []; - } - - migratedVersion = '1.3.1'; - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (appliedMigrationsCount > 0) { - GUI.log(i18n.getMessage('configMigrationSuccessful', [appliedMigrationsCount])); - } - return true; - } - - function configuration_upload(configuration, _callback) { - function upload() { - let activeProfile = null; - let numProfiles = FC.CONFIG.numProfiles; - if (configuration.profiles.length < numProfiles) { - numProfiles = configuration.profiles.length; - } - - const profileSpecificData = [ - MSPCodes.MSP_SET_PID_CONTROLLER, - MSPCodes.MSP_SET_PID, - MSPCodes.MSP_SET_RC_TUNING, - MSPCodes.MSP_SET_ACC_TRIM, - ]; - - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - profileSpecificData.push(MSPCodes.MSP_SET_RC_DEADBAND); - } - - MSP.send_message(MSPCodes.MSP_STATUS, false, false, function () { - activeProfile = FC.CONFIG.profile; - select_profile(); - }); - - function select_profile() { - if (activeProfile > 0) { - MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [0], false, upload_specific_data); - } else { - upload_specific_data(); - } - } - - function upload_specific_data() { - let savingProfile = 0; - let codeKey = 0; - - function load_objects(profile) { - FC.PID = configuration.profiles[profile].PID; - FC.PIDS = configuration.profiles[profile].PIDs; - FC.RC_TUNING = configuration.profiles[profile].RC; - FC.CONFIG.accelerometerTrims = configuration.profiles[profile].AccTrim; - FC.SERVO_CONFIG = configuration.profiles[profile].ServoConfig; - FC.SERVO_RULES = configuration.profiles[profile].ServoRules; - FC.MODE_RANGES = configuration.profiles[profile].ModeRanges; - FC.ADJUSTMENT_RANGES = configuration.profiles[profile].AdjustmentRanges; - FC.RC_DEADBAND_CONFIG = configuration.profiles[profile].RCdeadband; - } - - function upload_using_specific_commands() { - MSP.send_message(profileSpecificData[codeKey], mspHelper.crunch(profileSpecificData[codeKey]), false, function () { - codeKey++; - - if (codeKey < profileSpecificData.length) { - upload_using_specific_commands(); - } else { - codeKey = 0; - savingProfile++; - - if (savingProfile < numProfiles) { - load_objects(savingProfile); - - MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () { - MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [savingProfile], false, upload_using_specific_commands); - }); - } else { - MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () { - MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [activeProfile], false, upload_unique_data); - }); - } - } - }); - } - - function upload_servo_configuration() { - mspHelper.sendServoConfigurations(upload_mode_ranges); - } - - function upload_mode_ranges() { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - if (configuration.MODE_RANGES_EXTRA == undefined) { - FC.MODE_RANGES_EXTRA = []; - - for (let modeIndex = 0; modeIndex < FC.MODE_RANGES.length; modeIndex++) { - const defaultModeRangeExtra = { - modeId: FC.MODE_RANGES[modeIndex].modeId, - modeLogic: 0, - linkedTo: 0, - }; - FC.MODE_RANGES_EXTRA.push(defaultModeRangeExtra); - } - } else { - FC.MODE_RANGES_EXTRA = configuration.MODE_RANGES_EXTRA; - } - } - - mspHelper.sendModeRanges(upload_adjustment_ranges); - } - - function upload_adjustment_ranges() { - mspHelper.sendAdjustmentRanges(upload_using_specific_commands); - } - // start uploading - load_objects(0); - upload_servo_configuration(); - } - - function upload_unique_data() { - let codeKey = 0; - - const uniqueData = [ - MSPCodes.MSP_SET_RX_MAP, - MSPCodes.MSP_SET_CF_SERIAL_CONFIG, - ]; - - function update_unique_data_list() { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - uniqueData.push([MSPCodes.MSP2_SET_TEXT, MSPCodes.CRAFT_NAME]); - uniqueData.push([MSPCodes.MSP2_SET_TEXT, MSPCodes.PILOT_NAME]); - } else { - uniqueData.push(MSPCodes.MSP_SET_NAME); - } - - uniqueData.push(MSPCodes.MSP_SET_SENSOR_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_MIXER_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_BEEPER_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_BOARD_ALIGNMENT_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_ADVANCED_CONFIG); - - if (semver.gte(FC.CONFIG.apiVersion, "1.8.0")) { - uniqueData.push(MSPCodes.MSP_SET_LOOP_TIME); - uniqueData.push(MSPCodes.MSP_SET_ARMING_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.14.0")) { - uniqueData.push(MSPCodes.MSP_SET_MOTOR_3D_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - uniqueData.push(MSPCodes.MSP_SET_SENSOR_ALIGNMENT); - uniqueData.push(MSPCodes.MSP_SET_RX_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_FAILSAFE_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33)) { - uniqueData.push(MSPCodes.MSP_SET_FEATURE_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_MOTOR_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_GPS_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_RSSI_CONFIG); - } - } - - function load_objects() { - FC.MISC = configuration.MISC; - FC.RC_MAP = configuration.RCMAP; - FC.SERIAL_CONFIG = configuration.SERIAL_CONFIG; - FC.LED_STRIP = configuration.LED_STRIP; - FC.LED_COLORS = configuration.LED_COLORS; - FC.LED_MODE_COLORS = configuration.LED_MODE_COLORS; - FC.ARMING_CONFIG = configuration.ARMING_CONFIG; - FC.FC_CONFIG = configuration.FC_CONFIG; - FC.MOTOR_3D_CONFIG = configuration.MOTOR_3D_CONFIG; - FC.SENSOR_ALIGNMENT = configuration.SENSOR_ALIGNMENT; - FC.RX_CONFIG = configuration.RX_CONFIG; - FC.FAILSAFE_CONFIG = configuration.FAILSAFE_CONFIG; - FC.RXFAIL_CONFIG = configuration.RXFAIL_CONFIG; - FC.FEATURE_CONFIG = configuration.FEATURE_CONFIG; - FC.MOTOR_CONFIG = configuration.MOTOR_CONFIG; - FC.GPS_CONFIG = configuration.GPS_CONFIG; - FC.RSSI_CONFIG = configuration.RSSI_CONFIG; - FC.BOARD_ALIGNMENT_CONFIG = configuration.BOARD_ALIGNMENT_CONFIG; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - FC.CONFIG.craftName = configuration.CRAFT_NAME; - FC.CONFIG.pilotName = configuration.PILOT_NAME; - } else { - FC.CONFIG.name = configuration.CRAFT_NAME; - FC.CONFIG.displayName = configuration.DISPLAY_NAME; - } - FC.MIXER_CONFIG = configuration.MIXER_CONFIG; - FC.SENSOR_CONFIG = configuration.SENSOR_CONFIG; - FC.PID_ADVANCED_CONFIG = configuration.PID_ADVANCED_CONFIG; - - FC.BEEPER_CONFIG.beepers = new Beepers(FC.CONFIG); - FC.BEEPER_CONFIG.beepers.setDisabledMask(configuration.BEEPER_CONFIG.beepers._beeperDisabledMask); - FC.BEEPER_CONFIG.dshotBeaconTone = configuration.BEEPER_CONFIG.dshotBeaconTone; - FC.BEEPER_CONFIG.dshotBeaconConditions = new Beepers(FC.CONFIG, [ "RX_LOST", "RX_SET" ]); - FC.BEEPER_CONFIG.dshotBeaconConditions.setDisabledMask(configuration.BEEPER_CONFIG.dshotBeaconConditions._beeperDisabledMask); - } - - function send_unique_data_item() { - if (codeKey < uniqueData.length) { - const callback = () => { - codeKey++; - send_unique_data_item(); - }; - - if (Array.isArray(uniqueData[codeKey])) { - MSP.send_message(uniqueData[codeKey][0], mspHelper.crunch(...uniqueData[codeKey]), false, callback); - } else { - MSP.send_message(uniqueData[codeKey], mspHelper.crunch(uniqueData[codeKey]), false, callback); - } - } else { - send_led_strip_config(); - } - } - - load_objects(); - - update_unique_data_list(); - - // start uploading - send_unique_data_item(); - } - - function send_led_strip_config() { - mspHelper.sendLedStripConfig(send_led_strip_colors); - } - - function send_led_strip_colors() { - mspHelper.sendLedStripColors(send_led_strip_mode_colors); - } - - function send_led_strip_mode_colors() { - if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) { - mspHelper.sendLedStripModeColors(send_rxfail_config); - } else { - send_rxfail_config(); - } - } - - function send_rxfail_config() { - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - mspHelper.sendRxFailConfig(save_to_eeprom); - } else { - save_to_eeprom(); - } - } - - function save_to_eeprom() { - MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, reboot); - } - - function reboot() { - GUI.log(i18n.getMessage('eeprom_saved_ok')); - - GUI.tab_switch_cleanup(function() { - MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(_callback)); - }); - } - } - - if (CONFIGURATOR.virtualMode) { - FC.resetState(); - FC.CONFIG.apiVersion = CONFIGURATOR.virtualApiVersion; - - sensor_status(FC.CONFIG.activeSensors); - update_dataflash_global(); - } - - upload(); - } -} diff --git a/src/js/data_storage.js b/src/js/data_storage.js index 759eb550..301cf864 100644 --- a/src/js/data_storage.js +++ b/src/js/data_storage.js @@ -18,10 +18,7 @@ const API_VERSION_1_45 = '1.45.0'; const CONFIGURATOR = { // all versions are specified and compared using semantic versioning http://semver.org/ - API_VERSION_ACCEPTED: '1.2.1', - API_VERSION_MIN_SUPPORTED_BACKUP_RESTORE: '1.5.0', - API_VERSION_MIN_SUPPORTED_PID_CONTROLLER_CHANGE: '1.5.0', - BACKUP_FILE_VERSION_MIN_SUPPORTED: '0.55.0', // chrome.runtime.getManifest().version is stored as string, so does this one + API_VERSION_ACCEPTED: API_VERSION_1_41, API_VERSION_MAX_SUPPORTED: API_VERSION_1_45, connectionValid: false, diff --git a/src/js/fc.js b/src/js/fc.js index 574c0237..492dba6a 100644 --- a/src/js/fc.js +++ b/src/js/fc.js @@ -643,7 +643,7 @@ const FC = { dterm_lowpass_dyn_max_hz: 250, dyn_lpf_curve_expo: 5, dterm_lowpass_type: this.FILTER_TYPE_FLAGS.PT1, - dterm_lowpass2_hz: 150, + dterm_lowpass2_hz: 200, dterm_lowpass2_type: this.FILTER_TYPE_FLAGS.BIQUAD, dterm_notch_cutoff: 160, dterm_notch_hz: 260, @@ -712,8 +712,6 @@ const FC = { getSerialRxTypes: () => { const apiVersion = FC.CONFIG.apiVersion; - const flightControllerIdentifier = FC.CONFIG.flightControllerIdentifier; - const flightControllerVersion = FC.CONFIG.flightControllerVersion; // defaults const serialRxTypes = [ @@ -724,33 +722,14 @@ const FC = { 'SUMH', 'XBUS_MODE_B', 'XBUS_MODE_B_RJ01', + 'IBUS', + 'CRSF', + 'JETIEXBUS', + 'SPEKTRUM2048/SRXL', + 'TARGET_CUSTOM', + 'FrSky FPort', ]; - if (semver.gte(apiVersion, "1.15.0")) { - serialRxTypes.push('IBUS'); - } - - if ((flightControllerIdentifier === 'BTFL' && semver.gte(flightControllerVersion, "2.6.0")) || - (flightControllerIdentifier === 'CLFL' && semver.gte(apiVersion, API_VERSION_1_31))) { - serialRxTypes.push('JETIEXBUS'); - } - - if (semver.gte(apiVersion, API_VERSION_1_31)) { - serialRxTypes.push('CRSF'); - } - - if (semver.gte(apiVersion, "1.24.0")) { - serialRxTypes.push('SPEKTRUM2048/SRXL'); - } - - if (semver.gte(apiVersion, API_VERSION_1_35)) { - serialRxTypes.push('TARGET_CUSTOM'); - } - - if (semver.gte(apiVersion, API_VERSION_1_37)) { - serialRxTypes.push('FrSky FPort'); - } - if (semver.gte(apiVersion, API_VERSION_1_42)) { serialRxTypes.push('SPEKTRUM SRXL2'); } @@ -822,14 +801,7 @@ const FC = { }, boardHasVcp() { - let hasVcp = false; - if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_37)) { - hasVcp = bit_check(this.CONFIG.targetCapabilities, this.TARGET_CAPABILITIES_FLAGS.HAS_VCP); - } else { - hasVcp = BOARD.find_board_definition(this.CONFIG.boardIdentifier).vcp; - } - - return hasVcp; + return bit_check(this.CONFIG.targetCapabilities, this.TARGET_CAPABILITIES_FLAGS.HAS_VCP); }, boardHasFlashBootloader() { @@ -849,44 +821,44 @@ const FC = { getFilterDefaults() { const versionFilterDefaults = this.DEFAULT; // Change filter defaults depending on API version here - if (semver.eq(this.CONFIG.apiVersion, API_VERSION_1_40)) { - versionFilterDefaults.dterm_lowpass2_hz = 200; - } else if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_41)) { - versionFilterDefaults.gyro_lowpass_hz = 150; - versionFilterDefaults.gyro_lowpass_type = this.FILTER_TYPE_FLAGS.BIQUAD; - versionFilterDefaults.gyro_lowpass2_hz = 0; - versionFilterDefaults.gyro_lowpass2_type = this.FILTER_TYPE_FLAGS.BIQUAD; + versionFilterDefaults.gyro_lowpass_hz = 150; + versionFilterDefaults.gyro_lowpass_type = this.FILTER_TYPE_FLAGS.BIQUAD; + versionFilterDefaults.gyro_lowpass2_hz = 0; + versionFilterDefaults.gyro_lowpass2_type = this.FILTER_TYPE_FLAGS.BIQUAD; + versionFilterDefaults.dterm_lowpass_hz = 150; + versionFilterDefaults.dterm_lowpass_type = this.FILTER_TYPE_FLAGS.BIQUAD; + 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_type = this.FILTER_TYPE_FLAGS.BIQUAD; + 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.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; - } - if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_45)) { - versionFilterDefaults.dyn_notch_min_hz = 100; - } + 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; + } + + if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_45)) { + versionFilterDefaults.dyn_notch_min_hz = 100; + } + return versionFilterDefaults; }, diff --git a/src/js/main.js b/src/js/main.js index 2f755bef..bf072d40 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -730,11 +730,7 @@ function updateTabList(features) { $('#tabs ul.mode-connected li.tab_osd').hide(); } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - $('#tabs ul.mode-connected li.tab_power').show(); - } else { - $('#tabs ul.mode-connected li.tab_power').hide(); - } + $('#tabs ul.mode-connected li.tab_power').show(); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { $('#tabs ul.mode-connected li.tab_vtx').show(); diff --git a/src/js/msp/MSPHelper.js b/src/js/msp/MSPHelper.js index fe4ac2cd..bb39a6c2 100644 --- a/src/js/msp/MSPHelper.js +++ b/src/js/msp/MSPHelper.js @@ -181,23 +181,19 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.CONFIG.mode = data.readU32(); FC.CONFIG.profile = data.readU8(); FC.CONFIG.cpuload = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - FC.CONFIG.numProfiles = data.readU8(); - FC.CONFIG.rateProfile = data.readU8(); + FC.CONFIG.numProfiles = data.readU8(); + FC.CONFIG.rateProfile = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - // Read flight mode flags - const byteCount = data.readU8(); - for (let i = 0; i < byteCount; i++) { - data.readU8(); - } - - // Read arming disable flags - FC.CONFIG.armingDisableCount = data.readU8(); // Flag count - FC.CONFIG.armingDisableFlags = data.readU32(); - } + // Read flight mode flags + const byteCount = data.readU8(); + for (let i = 0; i < byteCount; i++) { + data.readU8(); } + // Read arming disable flags + FC.CONFIG.armingDisableCount = data.readU8(); // Flag count + FC.CONFIG.armingDisableFlags = data.readU32(); + sensor_status(FC.CONFIG.activeSensors); break; @@ -295,9 +291,7 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.ANALOG.mAhdrawn = data.readU16(); FC.ANALOG.rssi = data.readU16(); // 0-1023 FC.ANALOG.amperage = data.read16() / 100; // A - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.ANALOG.voltage = data.readU16() / 100; - } + FC.ANALOG.voltage = data.readU16() / 100; FC.ANALOG.last_received_timestamp = Date.now(); break; case MSPCodes.MSP_VOLTAGE_METERS: @@ -333,70 +327,51 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.BATTERY_STATE.voltage = data.readU8() / 10.0; // V FC.BATTERY_STATE.mAhDrawn = data.readU16(); // mAh FC.BATTERY_STATE.amperage = data.readU16() / 100; // A - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.BATTERY_STATE.batteryState = data.readU8(); - FC.BATTERY_STATE.voltage = data.readU16() / 100; - } + FC.BATTERY_STATE.batteryState = data.readU8(); + FC.BATTERY_STATE.voltage = data.readU16() / 100; break; case MSPCodes.MSP_VOLTAGE_METER_CONFIG: - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.MISC.vbatscale = data.readU8(); // 10-200 - FC.MISC.vbatmincellvoltage = data.readU8() / 10; // 10-50 - FC.MISC.vbatmaxcellvoltage = data.readU8() / 10; // 10-50 - FC.MISC.vbatwarningcellvoltage = data.readU8() / 10; // 10-50 - if (semver.gte(FC.CONFIG.apiVersion, "1.23.0")) { - FC.MISC.batterymetertype = data.readU8(); - } - } else { - FC.VOLTAGE_METER_CONFIGS = []; - const voltageMeterCount = data.readU8(); + FC.VOLTAGE_METER_CONFIGS = []; + const voltageMeterCount = data.readU8(); - for (let i = 0; i < voltageMeterCount; i++) { - const subframeLength = data.readU8(); - if (subframeLength !== 5) { - for (let j = 0; j < subframeLength; j++) { - data.readU8(); - } - } else { - const voltageMeterConfig = { - id: data.readU8(), - sensorType: data.readU8(), - vbatscale: data.readU8(), - vbatresdivval: data.readU8(), - vbatresdivmultiplier: data.readU8(), - }; - - FC.VOLTAGE_METER_CONFIGS.push(voltageMeterConfig); + for (let i = 0; i < voltageMeterCount; i++) { + const subframeLength = data.readU8(); + if (subframeLength !== 5) { + for (let j = 0; j < subframeLength; j++) { + data.readU8(); } + } else { + const voltageMeterConfig = { + id: data.readU8(), + sensorType: data.readU8(), + vbatscale: data.readU8(), + vbatresdivval: data.readU8(), + vbatresdivmultiplier: data.readU8(), + }; + + FC.VOLTAGE_METER_CONFIGS.push(voltageMeterConfig); } } break; case MSPCodes.MSP_CURRENT_METER_CONFIG: - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.BF_CONFIG.currentscale = data.read16(); - FC.BF_CONFIG.currentoffset = data.read16(); - FC.BF_CONFIG.currentmetertype = data.readU8(); - FC.BF_CONFIG.batterycapacity = data.readU16(); - } else { - FC.CURRENT_METER_CONFIGS = []; - const currentMeterCount = data.readU8(); - for (let i = 0; i < currentMeterCount; i++) { - const currentMeterConfig = {}; - const subframeLength = data.readU8(); + FC.CURRENT_METER_CONFIGS = []; + const currentMeterCount = data.readU8(); + for (let i = 0; i < currentMeterCount; i++) { + const currentMeterConfig = {}; + const subframeLength = data.readU8(); - if (subframeLength !== 6) { - for (let j = 0; j < subframeLength; j++) { - data.readU8(); - } - } else { - currentMeterConfig.id = data.readU8(); - currentMeterConfig.sensorType = data.readU8(); - currentMeterConfig.scale = data.read16(); - currentMeterConfig.offset = data.read16(); - - FC.CURRENT_METER_CONFIGS.push(currentMeterConfig); + if (subframeLength !== 6) { + for (let j = 0; j < subframeLength; j++) { + data.readU8(); } + } else { + currentMeterConfig.id = data.readU8(); + currentMeterConfig.sensorType = data.readU8(); + currentMeterConfig.scale = data.read16(); + currentMeterConfig.offset = data.read16(); + + FC.CURRENT_METER_CONFIGS.push(currentMeterConfig); } } break; @@ -408,11 +383,9 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.BATTERY_CONFIG.capacity = data.readU16(); FC.BATTERY_CONFIG.voltageMeterSource = data.readU8(); FC.BATTERY_CONFIG.currentMeterSource = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.BATTERY_CONFIG.vbatmincellvoltage = data.readU16() / 100; - FC.BATTERY_CONFIG.vbatmaxcellvoltage = data.readU16() / 100; - FC.BATTERY_CONFIG.vbatwarningcellvoltage = data.readU16() / 100; - } + FC.BATTERY_CONFIG.vbatmincellvoltage = data.readU16() / 100; + FC.BATTERY_CONFIG.vbatmaxcellvoltage = data.readU16() / 100; + FC.BATTERY_CONFIG.vbatwarningcellvoltage = data.readU16() / 100; break; case MSPCodes.MSP_SET_BATTERY_CONFIG: console.log('Battery configuration saved'); @@ -420,15 +393,9 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_RC_TUNING: FC.RC_TUNING.RC_RATE = parseFloat((data.readU8() / 100).toFixed(2)); FC.RC_TUNING.RC_EXPO = parseFloat((data.readU8() / 100).toFixed(2)); - if (semver.lt(FC.CONFIG.apiVersion, "1.7.0")) { - FC.RC_TUNING.roll_pitch_rate = parseFloat((data.readU8() / 100).toFixed(2)); - FC.RC_TUNING.pitch_rate = 0; - FC.RC_TUNING.roll_rate = 0; - } else { - FC.RC_TUNING.roll_pitch_rate = 0; - FC.RC_TUNING.roll_rate = parseFloat((data.readU8() / 100).toFixed(2)); - FC.RC_TUNING.pitch_rate = parseFloat((data.readU8() / 100).toFixed(2)); - } + FC.RC_TUNING.roll_pitch_rate = 0; + FC.RC_TUNING.roll_rate = parseFloat((data.readU8() / 100).toFixed(2)); + FC.RC_TUNING.pitch_rate = parseFloat((data.readU8() / 100).toFixed(2)); FC.RC_TUNING.yaw_rate = parseFloat((data.readU8() / 100).toFixed(2)); if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)) { FC.RC_TUNING.dynamic_THR_PID = parseFloat((data.readU8() / 100).toFixed(2)); @@ -437,36 +404,17 @@ MspHelper.prototype.process_data = function(dataHandler) { } FC.RC_TUNING.throttle_MID = parseFloat((data.readU8() / 100).toFixed(2)); FC.RC_TUNING.throttle_EXPO = parseFloat((data.readU8() / 100).toFixed(2)); - if (semver.gte(FC.CONFIG.apiVersion, "1.7.0")) { - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - FC.RC_TUNING.dynamic_THR_breakpoint = data.readU16(); - } else { - data.readU16(); - } + if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + FC.RC_TUNING.dynamic_THR_breakpoint = data.readU16(); } else { - FC.RC_TUNING.dynamic_THR_breakpoint = 0; - } - if (semver.gte(FC.CONFIG.apiVersion, "1.10.0")) { - FC.RC_TUNING.RC_YAW_EXPO = parseFloat((data.readU8() / 100).toFixed(2)); - if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - FC.RC_TUNING.rcYawRate = parseFloat((data.readU8() / 100).toFixed(2)); - } else { - FC.RC_TUNING.rcYawRate = 0; - } - } else { - FC.RC_TUNING.RC_YAW_EXPO = 0; - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - FC.RC_TUNING.rcPitchRate = parseFloat((data.readU8() / 100).toFixed(2)); - FC.RC_TUNING.RC_PITCH_EXPO = parseFloat((data.readU8() / 100).toFixed(2)); - } else { - FC.RC_TUNING.rcPitchRate = 0; - FC.RC_TUNING.RC_PITCH_EXPO = 0; - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.RC_TUNING.throttleLimitType = data.readU8(); - FC.RC_TUNING.throttleLimitPercent = data.readU8(); + data.readU16(); } + FC.RC_TUNING.RC_YAW_EXPO = parseFloat((data.readU8() / 100).toFixed(2)); + FC.RC_TUNING.rcYawRate = parseFloat((data.readU8() / 100).toFixed(2)); + FC.RC_TUNING.rcPitchRate = parseFloat((data.readU8() / 100).toFixed(2)); + 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(); @@ -488,18 +436,12 @@ MspHelper.prototype.process_data = function(dataHandler) { break; case MSPCodes.MSP_ARMING_CONFIG: - if (semver.gte(FC.CONFIG.apiVersion, "1.8.0")) { - FC.ARMING_CONFIG.auto_disarm_delay = data.readU8(); - FC.ARMING_CONFIG.disarm_kill_switch = data.readU8(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - FC.ARMING_CONFIG.small_angle = data.readU8(); - } + FC.ARMING_CONFIG.auto_disarm_delay = data.readU8(); + FC.ARMING_CONFIG.disarm_kill_switch = data.readU8(); + FC.ARMING_CONFIG.small_angle = data.readU8(); break; case MSPCodes.MSP_LOOP_TIME: - if (semver.gte(FC.CONFIG.apiVersion, "1.8.0")) { - FC.FC_CONFIG.loopTime = data.readU16(); - } + FC.FC_CONFIG.loopTime = data.readU16(); break; case MSPCodes.MSP_MISC: // 22 bytes FC.RX_CONFIG.midrc = data.readU16(); @@ -533,14 +475,12 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_GPS_CONFIG: FC.GPS_CONFIG.provider = data.readU8(); FC.GPS_CONFIG.ublox_sbas = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_34)) { - FC.GPS_CONFIG.auto_config = data.readU8(); - FC.GPS_CONFIG.auto_baud = data.readU8(); + 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(); - } + 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(); } break; case MSPCodes.MSP_GPS_RESCUE: @@ -570,9 +510,6 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.MOTOR_3D_CONFIG.deadband3d_low = data.readU16(); FC.MOTOR_3D_CONFIG.deadband3d_high = data.readU16(); FC.MOTOR_3D_CONFIG.neutral = data.readU16(); - if (semver.lt(FC.CONFIG.apiVersion, "1.17.0")) { - FC.RC_DEADBAND_CONFIG.deadband3d_throttle = data.readU16(); - } break; case MSPCodes.MSP_BOXNAMES: FC.AUX_CONFIG = []; // empty the array as new data is coming in @@ -618,61 +555,18 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_SERVO_CONFIGURATIONS: FC.SERVO_CONFIG = []; // empty the array as new data is coming in - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33)) { - if (data.byteLength % 12 == 0) { - for (let i = 0; i < data.byteLength; i += 12) { - const arr = { - 'min': data.readU16(), - 'max': data.readU16(), - 'middle': data.readU16(), - 'rate': data.read8(), - 'indexOfChannelToForward': data.readU8(), - 'reversedInputSources': data.readU32(), - }; + if (data.byteLength % 12 == 0) { + for (let i = 0; i < data.byteLength; i += 12) { + const arr = { + 'min': data.readU16(), + 'max': data.readU16(), + 'middle': data.readU16(), + 'rate': data.read8(), + 'indexOfChannelToForward': data.readU8(), + 'reversedInputSources': data.readU32(), + }; - FC.SERVO_CONFIG.push(arr); - } - } - } else if (semver.gte(FC.CONFIG.apiVersion, "1.12.0")) { - if (data.byteLength % 14 == 0) { - for (let i = 0; i < data.byteLength; i += 14) { - const arr = { - 'min': data.readU16(), - 'max': data.readU16(), - 'middle': data.readU16(), - 'rate': data.read8(), - 'angleAtMin': data.readU8(), - 'angleAtMax': data.readU8(), - 'indexOfChannelToForward': data.readU8(), - 'reversedInputSources': data.readU32(), - }; - - FC.SERVO_CONFIG.push(arr); - } - } - } else { - if (data.byteLength % 7 == 0) { - for (let i = 0; i < data.byteLength; i += 7) { - const arr = { - 'min': data.readU16(), - 'max': data.readU16(), - 'middle': data.readU16(), - 'rate': data.read8(), - 'angleAtMin': 45, - 'angleAtMax': 45, - 'indexOfChannelToForward': undefined, - 'reversedInputSources': 0, - }; - - FC.SERVO_CONFIG.push(arr); - } - } - - if (semver.eq(FC.CONFIG.apiVersion, '1.10.0')) { - // drop two unused servo configurations due to MSP rx buffer to small) - while (FC.SERVO_CONFIG.length > 8) { - FC.SERVO_CONFIG.pop(); - } + FC.SERVO_CONFIG.push(arr); } } break; @@ -681,21 +575,16 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.RC_DEADBAND_CONFIG.yaw_deadband = data.readU8(); FC.RC_DEADBAND_CONFIG.alt_hold_deadband = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, "1.17.0")) { - FC.RC_DEADBAND_CONFIG.deadband3d_throttle = data.readU16(); - } + FC.RC_DEADBAND_CONFIG.deadband3d_throttle = data.readU16(); break; case MSPCodes.MSP_SENSOR_ALIGNMENT: FC.SENSOR_ALIGNMENT.align_gyro = data.readU8(); FC.SENSOR_ALIGNMENT.align_acc = data.readU8(); FC.SENSOR_ALIGNMENT.align_mag = data.readU8(); - - if (semver.gte(FC.CONFIG.apiVersion, '1.41.0')) { - FC.SENSOR_ALIGNMENT.gyro_detection_flags = data.readU8(); - FC.SENSOR_ALIGNMENT.gyro_to_use = data.readU8(); - FC.SENSOR_ALIGNMENT.gyro_1_align = data.readU8(); - FC.SENSOR_ALIGNMENT.gyro_2_align = data.readU8(); - } + FC.SENSOR_ALIGNMENT.gyro_detection_flags = data.readU8(); + FC.SENSOR_ALIGNMENT.gyro_to_use = data.readU8(); + FC.SENSOR_ALIGNMENT.gyro_1_align = data.readU8(); + FC.SENSOR_ALIGNMENT.gyro_2_align = data.readU8(); break; case MSPCodes.MSP_DISPLAYPORT: break; @@ -795,9 +684,7 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_MIXER_CONFIG: FC.MIXER_CONFIG.mixer = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.MIXER_CONFIG.reverseMotorDir = data.readU8(); - } + FC.MIXER_CONFIG.reverseMotorDir = data.readU8(); break; case MSPCodes.MSP_FEATURE_CONFIG: @@ -808,12 +695,8 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_BEEPER_CONFIG: FC.BEEPER_CONFIG.beepers.setDisabledMask(data.readU32()); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - FC.BEEPER_CONFIG.dshotBeaconTone = data.readU8(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - FC.BEEPER_CONFIG.dshotBeaconConditions.setDisabledMask(data.readU32()); - } + FC.BEEPER_CONFIG.dshotBeaconTone = data.readU8(); + FC.BEEPER_CONFIG.dshotBeaconConditions.setDisabledMask(data.readU32()); break; case MSPCodes.MSP_BOARD_ALIGNMENT_CONFIG: @@ -823,15 +706,13 @@ MspHelper.prototype.process_data = function(dataHandler) { break; case MSPCodes.MSP_SET_REBOOT: - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - const rebootType = data.read8(); - if ((rebootType === self.REBOOT_TYPES.MSC) || (rebootType === self.REBOOT_TYPES.MSC_UTC)) { - if (data.read8() === 0) { - console.log('Storage device not ready.'); + const rebootType = data.read8(); + if ((rebootType === self.REBOOT_TYPES.MSC) || (rebootType === self.REBOOT_TYPES.MSC_UTC)) { + if (data.read8() === 0) { + console.log('Storage device not ready.'); - showErrorDialog(i18n.getMessage('storageDeviceNotReady')); - break; - } + showErrorDialog(i18n.getMessage('storageDeviceNotReady')); + break; } } console.log('Reboot request accepted'); @@ -880,49 +761,39 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.CONFIG.boardVersion = data.readU16(); FC.CONFIG.boardType = 0; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_35)) { - FC.CONFIG.boardType = data.readU8(); - } + FC.CONFIG.boardType = data.readU8(); FC.CONFIG.targetCapabilities = 0; FC.CONFIG.targetName = ''; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - FC.CONFIG.targetCapabilities = data.readU8(); - const length = data.readU8(); - for (let i = 0; i < length; i++) { - FC.CONFIG.targetName += String.fromCharCode(data.readU8()); - } + FC.CONFIG.targetCapabilities = data.readU8(); + let length = data.readU8(); + for (let i = 0; i < length; i++) { + FC.CONFIG.targetName += String.fromCharCode(data.readU8()); } FC.CONFIG.boardName = ''; FC.CONFIG.manufacturerId = ''; FC.CONFIG.signature = []; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - let length = data.readU8(); + length = data.readU8(); - for (let i = 0; i < length; i++) { - FC.CONFIG.boardName += String.fromCharCode(data.readU8()); - } - - length = data.readU8(); - - for (let i = 0; i < length; i++) { - FC.CONFIG.manufacturerId += String.fromCharCode(data.readU8()); - } - - for (let i = 0; i < self.SIGNATURE_LENGTH; i++) { - FC.CONFIG.signature.push(data.readU8()); - } + for (let i = 0; i < length; i++) { + FC.CONFIG.boardName += String.fromCharCode(data.readU8()); } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.CONFIG.mcuTypeId = data.readU8(); - } else { - FC.CONFIG.mcuTypeId = 255; + length = data.readU8(); + + for (let i = 0; i < length; i++) { + FC.CONFIG.manufacturerId += String.fromCharCode(data.readU8()); } + for (let i = 0; i < self.SIGNATURE_LENGTH; i++) { + FC.CONFIG.signature.push(data.readU8()); + } + + FC.CONFIG.mcuTypeId = data.readU8(); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { FC.CONFIG.configurationState = data.readU8(); } @@ -973,35 +844,20 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_CF_SERIAL_CONFIG: FC.SERIAL_CONFIG.ports = []; - if (semver.lt(FC.CONFIG.apiVersion, "1.6.0")) { - const serialPortCount = (data.byteLength - (4 * 4)) / 2; - for (let i = 0; i < serialPortCount; i++) { - const serialPort = { - identifier: data.readU8(), - scenario: data.readU8(), - }; - FC.SERIAL_CONFIG.ports.push(serialPort); - } - FC.SERIAL_CONFIG.mspBaudRate = data.readU32(); - FC.SERIAL_CONFIG.cliBaudRate = data.readU32(); - FC.SERIAL_CONFIG.gpsBaudRate = data.readU32(); - FC.SERIAL_CONFIG.gpsPassthroughBaudRate = data.readU32(); - } else { - const bytesPerPort = 1 + 2 + (1 * 4); + const bytesPerPort = 1 + 2 + (1 * 4); - const serialPortCount = data.byteLength / bytesPerPort; - for (let i = 0; i < serialPortCount; i++) { - const serialPort = { - identifier: data.readU8(), - functions: self.serialPortFunctionMaskToFunctions(data.readU16()), - msp_baudrate: self.BAUD_RATES[data.readU8()], - gps_baudrate: self.BAUD_RATES[data.readU8()], - telemetry_baudrate: self.BAUD_RATES[data.readU8()], - blackbox_baudrate: self.BAUD_RATES[data.readU8()], - }; + const serialPortCount = data.byteLength / bytesPerPort; + for (let i = 0; i < serialPortCount; i++) { + const serialPort = { + identifier: data.readU8(), + functions: self.serialPortFunctionMaskToFunctions(data.readU16()), + msp_baudrate: self.BAUD_RATES[data.readU8()], + gps_baudrate: self.BAUD_RATES[data.readU8()], + telemetry_baudrate: self.BAUD_RATES[data.readU8()], + blackbox_baudrate: self.BAUD_RATES[data.readU8()], + }; - FC.SERIAL_CONFIG.ports.push(serialPort); - } + FC.SERIAL_CONFIG.ports.push(serialPort); } break; @@ -1095,49 +951,33 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.RX_CONFIG.spektrum_sat_bind = data.readU8(); FC.RX_CONFIG.rx_min_usec = data.readU16(); FC.RX_CONFIG.rx_max_usec = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - FC.RX_CONFIG.rcInterpolation = data.readU8(); - FC.RX_CONFIG.rcInterpolationInterval = data.readU8(); - FC.RX_CONFIG.airModeActivateThreshold = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) { - FC.RX_CONFIG.rxSpiProtocol = data.readU8(); - FC.RX_CONFIG.rxSpiId = data.readU32(); - FC.RX_CONFIG.rxSpiRfChannelCount = data.readU8(); - FC.RX_CONFIG.fpvCamAngleDegrees = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - FC.RX_CONFIG.rcInterpolationChannels = data.readU8(); - FC.RX_CONFIG.rcSmoothingType = data.readU8(); - FC.RX_CONFIG.rcSmoothingSetpointCutoff = data.readU8(); - 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(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - const elrsUidLength = 6; - FC.RX_CONFIG.elrsUid = []; - for (let i = 0; i < elrsUidLength; i++) { - FC.RX_CONFIG.elrsUid.push(data.readU8()); - } - } - } - } - } - } else { - FC.RX_CONFIG.rxSpiProtocol = 0; - FC.RX_CONFIG.rxSpiId = 0; - FC.RX_CONFIG.rxSpiRfChannelCount = 0; - FC.RX_CONFIG.fpvCamAngleDegrees = 0; - } - } else { - FC.RX_CONFIG.rcInterpolation = 0; - FC.RX_CONFIG.rcInterpolationInterval = 0; - FC.RX_CONFIG.airModeActivateThreshold = 0; + FC.RX_CONFIG.rcInterpolation = data.readU8(); + FC.RX_CONFIG.rcInterpolationInterval = data.readU8(); + FC.RX_CONFIG.airModeActivateThreshold = data.readU16(); + FC.RX_CONFIG.rxSpiProtocol = data.readU8(); + FC.RX_CONFIG.rxSpiId = data.readU32(); + FC.RX_CONFIG.rxSpiRfChannelCount = data.readU8(); + FC.RX_CONFIG.fpvCamAngleDegrees = data.readU8(); + FC.RX_CONFIG.rcInterpolationChannels = data.readU8(); + FC.RX_CONFIG.rcSmoothingType = data.readU8(); + FC.RX_CONFIG.rcSmoothingSetpointCutoff = data.readU8(); + 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(); + } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + const elrsUidLength = 6; + FC.RX_CONFIG.elrsUid = []; + for (let i = 0; i < elrsUidLength; i++) { + FC.RX_CONFIG.elrsUid.push(data.readU8()); + } } - break; @@ -1145,11 +985,9 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.FAILSAFE_CONFIG.failsafe_delay = data.readU8(); FC.FAILSAFE_CONFIG.failsafe_off_delay = data.readU8(); FC.FAILSAFE_CONFIG.failsafe_throttle = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - FC.FAILSAFE_CONFIG.failsafe_switch_mode = data.readU8(); - FC.FAILSAFE_CONFIG.failsafe_throttle_low_delay = data.readU16(); - FC.FAILSAFE_CONFIG.failsafe_procedure = data.readU8(); - } + FC.FAILSAFE_CONFIG.failsafe_switch_mode = data.readU8(); + FC.FAILSAFE_CONFIG.failsafe_throttle_low_delay = data.readU16(); + FC.FAILSAFE_CONFIG.failsafe_procedure = data.readU8(); break; case MSPCodes.MSP_RXFAIL_CONFIG: @@ -1171,80 +1009,59 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.PID_ADVANCED_CONFIG.use_unsyncedPwm = data.readU8(); FC.PID_ADVANCED_CONFIG.fast_pwm_protocol = EscProtocols.ReorderPwmProtocols(FC.CONFIG.apiVersion, data.readU8()); FC.PID_ADVANCED_CONFIG.motor_pwm_rate = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, "1.24.0")) { - FC.PID_ADVANCED_CONFIG.digitalIdlePercent = data.readU16() / 100; - - if (semver.gte(FC.CONFIG.apiVersion, "1.25.0")) { - let gyroUse32kHz = data.readU8(); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.PID_ADVANCED_CONFIG.gyroUse32kHz = gyroUse32kHz; - } - 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(); - } - } + 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(); } break; case MSPCodes.MSP_FILTER_CONFIG: FC.FILTER_CONFIG.gyro_lowpass_hz = data.readU8(); FC.FILTER_CONFIG.dterm_lowpass_hz = data.readU16(); FC.FILTER_CONFIG.yaw_lowpass_hz = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - FC.FILTER_CONFIG.gyro_notch_hz = data.readU16(); - FC.FILTER_CONFIG.gyro_notch_cutoff = data.readU16(); - FC.FILTER_CONFIG.dterm_notch_hz = data.readU16(); - FC.FILTER_CONFIG.dterm_notch_cutoff = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, "1.21.0")) { - FC.FILTER_CONFIG.gyro_notch2_hz = data.readU16(); - FC.FILTER_CONFIG.gyro_notch2_cutoff = data.readU16(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.FILTER_CONFIG.dterm_lowpass_type = data.readU8(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - FC.FILTER_CONFIG.gyro_hardware_lpf = data.readU8(); - let gyro_32khz_hardware_lpf = data.readU8(); - FC.FILTER_CONFIG.gyro_lowpass_hz = data.readU16(); - FC.FILTER_CONFIG.gyro_lowpass2_hz = data.readU16(); - FC.FILTER_CONFIG.gyro_lowpass_type = data.readU8(); - FC.FILTER_CONFIG.gyro_lowpass2_type = data.readU8(); - FC.FILTER_CONFIG.dterm_lowpass2_hz = data.readU16(); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.FILTER_CONFIG.gyro_32khz_hardware_lpf = gyro_32khz_hardware_lpf; - } else { - FC.FILTER_CONFIG.gyro_32khz_hardware_lpf = 0; + FC.FILTER_CONFIG.gyro_notch_hz = data.readU16(); + FC.FILTER_CONFIG.gyro_notch_cutoff = data.readU16(); + FC.FILTER_CONFIG.dterm_notch_hz = data.readU16(); + FC.FILTER_CONFIG.dterm_notch_cutoff = data.readU16(); + FC.FILTER_CONFIG.gyro_notch2_hz = data.readU16(); + FC.FILTER_CONFIG.gyro_notch2_cutoff = data.readU16(); + FC.FILTER_CONFIG.dterm_lowpass_type = data.readU8(); + FC.FILTER_CONFIG.gyro_hardware_lpf = data.readU8(); + data.readU8(); // gyro_32khz_hardware_lpf not used + FC.FILTER_CONFIG.gyro_lowpass_hz = data.readU16(); + FC.FILTER_CONFIG.gyro_lowpass2_hz = data.readU16(); + FC.FILTER_CONFIG.gyro_lowpass_type = data.readU8(); + FC.FILTER_CONFIG.gyro_lowpass2_type = data.readU8(); + FC.FILTER_CONFIG.dterm_lowpass2_hz = data.readU16(); + FC.FILTER_CONFIG.gyro_32khz_hardware_lpf = 0; + FC.FILTER_CONFIG.dterm_lowpass2_type = data.readU8(); + FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz = data.readU16(); + 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.dterm_lowpass2_type = data.readU8(); - FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz = data.readU16(); - 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(); - } - } - } + 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(); } break; case MSPCodes.MSP_SET_PID_ADVANCED: @@ -1252,93 +1069,69 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.ADVANCED_TUNING_ACTIVE = { ...FC.ADVANCED_TUNING }; break; case MSPCodes.MSP_PID_ADVANCED: - if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - FC.ADVANCED_TUNING.rollPitchItermIgnoreRate = data.readU16(); - FC.ADVANCED_TUNING.yawItermIgnoreRate = data.readU16(); - FC.ADVANCED_TUNING.yaw_p_limit = data.readU16(); - FC.ADVANCED_TUNING.deltaMethod = data.readU8(); - FC.ADVANCED_TUNING.vbatPidCompensation = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - FC.ADVANCED_TUNING.feedforwardTransition = data.readU8(); - } else { - FC.ADVANCED_TUNING.dtermSetpointTransition = data.readU8(); - } - FC.ADVANCED_TUNING.dtermSetpointWeight = data.readU8(); - FC.ADVANCED_TUNING.toleranceBand = data.readU8(); - FC.ADVANCED_TUNING.toleranceBandReduction = data.readU8(); - FC.ADVANCED_TUNING.itermThrottleGain = data.readU8(); - FC.ADVANCED_TUNING.pidMaxVelocity = data.readU16(); - FC.ADVANCED_TUNING.pidMaxVelocityYaw = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, "1.24.0")) { - FC.ADVANCED_TUNING.levelAngleLimit = data.readU8(); - FC.ADVANCED_TUNING.levelSensitivity = data.readU8(); + FC.ADVANCED_TUNING.rollPitchItermIgnoreRate = data.readU16(); + FC.ADVANCED_TUNING.yawItermIgnoreRate = data.readU16(); + FC.ADVANCED_TUNING.yaw_p_limit = data.readU16(); + FC.ADVANCED_TUNING.deltaMethod = data.readU8(); + FC.ADVANCED_TUNING.vbatPidCompensation = data.readU8(); + FC.ADVANCED_TUNING.feedforwardTransition = data.readU8(); + FC.ADVANCED_TUNING.dtermSetpointWeight = data.readU8(); + FC.ADVANCED_TUNING.toleranceBand = data.readU8(); + FC.ADVANCED_TUNING.toleranceBandReduction = data.readU8(); + FC.ADVANCED_TUNING.itermThrottleGain = data.readU8(); + FC.ADVANCED_TUNING.pidMaxVelocity = data.readU16(); + FC.ADVANCED_TUNING.pidMaxVelocityYaw = data.readU16(); + FC.ADVANCED_TUNING.levelAngleLimit = data.readU8(); + FC.ADVANCED_TUNING.levelSensitivity = data.readU8(); + FC.ADVANCED_TUNING.itermThrottleThreshold = data.readU16(); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + FC.ADVANCED_TUNING.antiGravityGain = data.readU16(); + } else { + FC.ADVANCED_TUNING.itermAcceleratorGain = data.readU16(); + } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.ADVANCED_TUNING.itermThrottleThreshold = data.readU16(); + FC.ADVANCED_TUNING.dtermSetpointWeight = data.readU16(); + FC.ADVANCED_TUNING.itermRotation = data.readU8(); + FC.ADVANCED_TUNING.smartFeedforward = data.readU8(); + FC.ADVANCED_TUNING.itermRelax = data.readU8(); + FC.ADVANCED_TUNING.itermRelaxType = data.readU8(); + FC.ADVANCED_TUNING.absoluteControlGain = data.readU8(); + FC.ADVANCED_TUNING.throttleBoost = data.readU8(); + FC.ADVANCED_TUNING.acroTrainerAngleLimit = data.readU8(); + FC.ADVANCED_TUNING.feedforwardRoll = data.readU16(); + FC.ADVANCED_TUNING.feedforwardPitch = data.readU16(); + FC.ADVANCED_TUNING.feedforwardYaw = data.readU16(); + FC.ADVANCED_TUNING.antiGravityMode = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - FC.ADVANCED_TUNING.antiGravityGain = data.readU16(); - } else { - FC.ADVANCED_TUNING.itermAcceleratorGain = data.readU16(); - } + FC.ADVANCED_TUNING.dMinRoll = data.readU8(); + FC.ADVANCED_TUNING.dMinPitch = data.readU8(); + FC.ADVANCED_TUNING.dMinYaw = data.readU8(); + FC.ADVANCED_TUNING.dMinGain = data.readU8(); + FC.ADVANCED_TUNING.dMinAdvance = data.readU8(); + FC.ADVANCED_TUNING.useIntegratedYaw = data.readU8(); + FC.ADVANCED_TUNING.integratedYawRelax = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - FC.ADVANCED_TUNING.dtermSetpointWeight = data.readU16(); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - FC.ADVANCED_TUNING.itermRotation = data.readU8(); - FC.ADVANCED_TUNING.smartFeedforward = data.readU8(); - FC.ADVANCED_TUNING.itermRelax = data.readU8(); - FC.ADVANCED_TUNING.itermRelaxType = data.readU8(); - FC.ADVANCED_TUNING.absoluteControlGain = data.readU8(); - FC.ADVANCED_TUNING.throttleBoost = data.readU8(); - FC.ADVANCED_TUNING.acroTrainerAngleLimit = data.readU8(); - FC.ADVANCED_TUNING.feedforwardRoll = data.readU16(); - FC.ADVANCED_TUNING.feedforwardPitch = data.readU16(); - FC.ADVANCED_TUNING.feedforwardYaw = data.readU16(); - FC.ADVANCED_TUNING.antiGravityMode = data.readU8(); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.ADVANCED_TUNING.dMinRoll = data.readU8(); - FC.ADVANCED_TUNING.dMinPitch = data.readU8(); - FC.ADVANCED_TUNING.dMinYaw = data.readU8(); - FC.ADVANCED_TUNING.dMinGain = data.readU8(); - FC.ADVANCED_TUNING.dMinAdvance = data.readU8(); - 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(); - } - } - } - } - } - } - } - } - } - } + 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(); } FC.ADVANCED_TUNING_ACTIVE = { ...FC.ADVANCED_TUNING }; break; @@ -1351,88 +1144,50 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_LED_STRIP_CONFIG: FC.LED_STRIP = []; - let ledCount = data.byteLength / 7; // v1.4.0 and below incorrectly reported 4 bytes per led. - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - ledCount = data.byteLength / 4; - } - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - ledOverlayLetters = ['t', 'o', 'b', 'n', 'i', 'w']; // in LSB bit - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - // According to betaflight/src/main/msp/msp.c - // API 1.41 - add indicator for advanced profile support and the current profile selection - // 0 = basic ledstrip available - // 1 = advanced ledstrip available - // Following byte is the current LED profile - ledCount = (data.byteLength - 2) / 4; - } + // According to betaflight/src/main/msp/msp.c + // API 1.41 - add indicator for advanced profile support and the current profile selection + // 0 = basic ledstrip available + // 1 = advanced ledstrip available + // Following byte is the current LED profile + let ledCount = (data.byteLength - 2) / 4; + for (let i = 0; i < ledCount; i++) { - if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { - const directionMask = data.readU16(); + const mask = data.readU32(); - const directions = []; - for (let directionLetterIndex = 0; directionLetterIndex < ledDirectionLetters.length; directionLetterIndex++) { - if (bit_check(directionMask, directionLetterIndex)) { - directions.push(ledDirectionLetters[directionLetterIndex]); - } + const functionId = (mask >> 8) & 0xF; + const functions = []; + for (let baseFunctionLetterIndex = 0; baseFunctionLetterIndex < ledBaseFunctionLetters.length; baseFunctionLetterIndex++) { + if (functionId == baseFunctionLetterIndex) { + functions.push(ledBaseFunctionLetters[baseFunctionLetterIndex]); + break; } - - const functionMask = data.readU16(); - - const functions = []; - for (let functionLetterIndex = 0; functionLetterIndex < ledFunctionLetters.length; functionLetterIndex++) { - if (bit_check(functionMask, functionLetterIndex)) { - functions.push(ledFunctionLetters[functionLetterIndex]); - } - } - - const led = { - directions: directions, - functions: functions, - x: data.readU8(), - y: data.readU8(), - color: data.readU8(), - }; - - FC.LED_STRIP.push(led); - } else { - const mask = data.readU32(); - - const functionId = (mask >> 8) & 0xF; - const functions = []; - for (let baseFunctionLetterIndex = 0; baseFunctionLetterIndex < ledBaseFunctionLetters.length; baseFunctionLetterIndex++) { - if (functionId == baseFunctionLetterIndex) { - functions.push(ledBaseFunctionLetters[baseFunctionLetterIndex]); - break; - } - } - - const overlayMask = (mask >> 12) & 0x3F; - for (let overlayLetterIndex = 0; overlayLetterIndex < ledOverlayLetters.length; overlayLetterIndex++) { - if (bit_check(overlayMask, overlayLetterIndex)) { - functions.push(ledOverlayLetters[overlayLetterIndex]); - } - } - - const directionMask = (mask >> 22) & 0x3F; - const directions = []; - for (let directionLetterIndex = 0; directionLetterIndex < ledDirectionLetters.length; directionLetterIndex++) { - if (bit_check(directionMask, directionLetterIndex)) { - directions.push(ledDirectionLetters[directionLetterIndex]); - } - } - const led = { - y: (mask) & 0xF, - x: (mask >> 4) & 0xF, - functions: functions, - color: (mask >> 18) & 0xF, - directions: directions, - parameters: (mask >> 28) & 0xF, - }; - - FC.LED_STRIP.push(led); } + + const overlayMask = (mask >> 12) & 0x3F; + for (let overlayLetterIndex = 0; overlayLetterIndex < ledOverlayLetters.length; overlayLetterIndex++) { + if (bit_check(overlayMask, overlayLetterIndex)) { + functions.push(ledOverlayLetters[overlayLetterIndex]); + } + } + + const directionMask = (mask >> 22) & 0x3F; + const directions = []; + for (let directionLetterIndex = 0; directionLetterIndex < ledDirectionLetters.length; directionLetterIndex++) { + if (bit_check(directionMask, directionLetterIndex)) { + directions.push(ledDirectionLetters[directionLetterIndex]); + } + } + const led = { + y: (mask) & 0xF, + x: (mask >> 4) & 0xF, + functions: functions, + color: (mask >> 18) & 0xF, + directions: directions, + parameters: (mask >> 28) & 0xF, + }; + + FC.LED_STRIP.push(led); } break; case MSPCodes.MSP_SET_LED_STRIP_CONFIG: @@ -1459,21 +1214,18 @@ MspHelper.prototype.process_data = function(dataHandler) { console.log('Led strip colors saved'); break; case MSPCodes.MSP_LED_STRIP_MODECOLOR: - if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) { + FC.LED_MODE_COLORS = []; - FC.LED_MODE_COLORS = []; + const colorCount = data.byteLength / 3; - const colorCount = data.byteLength / 3; + for (let i = 0; i < colorCount; i++) { - for (let i = 0; i < colorCount; i++) { - - const modeColor = { - mode: data.readU8(), - direction: data.readU8(), - color: data.readU8(), - }; - FC.LED_MODE_COLORS.push(modeColor); - } + const modeColor = { + mode: data.readU8(), + direction: data.readU8(), + color: data.readU8(), + }; + FC.LED_MODE_COLORS.push(modeColor); } break; case MSPCodes.MSP_SET_LED_STRIP_MODECOLOR: @@ -1518,9 +1270,7 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.BLACKBOX.blackboxDevice = data.readU8(); FC.BLACKBOX.blackboxRateNum = data.readU8(); FC.BLACKBOX.blackboxRateDenom = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.BLACKBOX.blackboxPDenom = data.readU16(); - } + FC.BLACKBOX.blackboxPDenom = data.readU16(); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { FC.BLACKBOX.blackboxSampleRate = data.readU8(); } @@ -1530,37 +1280,26 @@ MspHelper.prototype.process_data = function(dataHandler) { break; case MSPCodes.MSP_TRANSPONDER_CONFIG: let bytesRemaining = data.byteLength; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33)) { - const providerCount = data.readU8(); - bytesRemaining--; + const providerCount = data.readU8(); + bytesRemaining--; - FC.TRANSPONDER.supported = providerCount > 0; - FC.TRANSPONDER.providers = []; + FC.TRANSPONDER.supported = providerCount > 0; + FC.TRANSPONDER.providers = []; - for (let i = 0; i < providerCount; i++) { - const provider = { - id: data.readU8(), - dataLength: data.readU8(), - }; - bytesRemaining -= 2; + for (let i = 0; i < providerCount; i++) { + const provider = { + id: data.readU8(), + dataLength: data.readU8(), + }; + bytesRemaining -= 2; - FC.TRANSPONDER.providers.push(provider); - } - FC.TRANSPONDER.provider = data.readU8(); - bytesRemaining--; - - } else { - FC.TRANSPONDER.supported = (data.readU8() & 1) != 0; - bytesRemaining--; - - // only ILAP was supported prior to 1.33.0 - FC.TRANSPONDER.providers = [{ - id: 1, // ILAP - dataLength: 6, - }]; - FC.TRANSPONDER.provider = FC.TRANSPONDER.providers[0].id; + FC.TRANSPONDER.providers.push(provider); } + FC.TRANSPONDER.provider = data.readU8(); + bytesRemaining--; + FC.TRANSPONDER.data = []; + for (let i = 0; i < bytesRemaining; i++) { FC.TRANSPONDER.data.push(data.readU8()); } @@ -1876,18 +1615,12 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { case MSPCodes.MSP_SET_BEEPER_CONFIG: const beeperDisabledMask = FC.BEEPER_CONFIG.beepers.getDisabledMask(); buffer.push32(beeperDisabledMask); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - buffer.push8(FC.BEEPER_CONFIG.dshotBeaconTone); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - buffer.push32(FC.BEEPER_CONFIG.dshotBeaconConditions.getDisabledMask()); - } + buffer.push8(FC.BEEPER_CONFIG.dshotBeaconTone); + buffer.push32(FC.BEEPER_CONFIG.dshotBeaconConditions.getDisabledMask()); break; case MSPCodes.MSP_SET_MIXER_CONFIG: buffer.push8(FC.MIXER_CONFIG.mixer); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - buffer.push8(FC.MIXER_CONFIG.reverseMotorDir); - } + buffer.push8(FC.MIXER_CONFIG.reverseMotorDir); break; case MSPCodes.MSP_SET_BOARD_ALIGNMENT_CONFIG: buffer.push16(FC.BOARD_ALIGNMENT_CONFIG.roll) @@ -1906,42 +1639,28 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { break; case MSPCodes.MSP_SET_RC_TUNING: buffer.push8(Math.round(FC.RC_TUNING.RC_RATE * 100)) - .push8(Math.round(FC.RC_TUNING.RC_EXPO * 100)); - if (semver.lt(FC.CONFIG.apiVersion, "1.7.0")) { - buffer.push8(Math.round(FC.RC_TUNING.roll_pitch_rate * 100)); - } else { - buffer.push8(Math.round(FC.RC_TUNING.roll_rate * 100)) - .push8(Math.round(FC.RC_TUNING.pitch_rate * 100)); - } - buffer.push8(Math.round(FC.RC_TUNING.yaw_rate * 100)); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - buffer.push8(Math.round(FC.RC_TUNING.dynamic_THR_PID * 100)); - } else { + .push8(Math.round(FC.RC_TUNING.RC_EXPO * 100)) + .push8(Math.round(FC.RC_TUNING.roll_rate * 100)) + .push8(Math.round(FC.RC_TUNING.pitch_rate * 100)) + .push8(Math.round(FC.RC_TUNING.yaw_rate * 100)); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { buffer.push8(0); + } else { + buffer.push8(Math.round(FC.RC_TUNING.dynamic_THR_PID * 100)); } buffer.push8(Math.round(FC.RC_TUNING.throttle_MID * 100)); buffer.push8(Math.round(FC.RC_TUNING.throttle_EXPO * 100)); - if (semver.gte(FC.CONFIG.apiVersion, "1.7.0")) { - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - buffer.push16(FC.RC_TUNING.dynamic_THR_breakpoint); - } else { - buffer.push16(0); - } - } - if (semver.gte(FC.CONFIG.apiVersion, "1.10.0")) { - buffer.push8(Math.round(FC.RC_TUNING.RC_YAW_EXPO * 100)); - if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - buffer.push8(Math.round(FC.RC_TUNING.rcYawRate * 100)); - } - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - buffer.push8(Math.round(FC.RC_TUNING.rcPitchRate * 100)); - buffer.push8(Math.round(FC.RC_TUNING.RC_PITCH_EXPO * 100)); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - buffer.push8(FC.RC_TUNING.throttleLimitType); - buffer.push8(FC.RC_TUNING.throttleLimitPercent); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + buffer.push16(0); + } else { + buffer.push16(FC.RC_TUNING.dynamic_THR_breakpoint); } + buffer.push8(Math.round(FC.RC_TUNING.RC_YAW_EXPO * 100)); + buffer.push8(Math.round(FC.RC_TUNING.rcYawRate * 100)); + buffer.push8(Math.round(FC.RC_TUNING.rcPitchRate * 100)); + 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); @@ -1962,10 +1681,8 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { break; case MSPCodes.MSP_SET_ARMING_CONFIG: buffer.push8(FC.ARMING_CONFIG.auto_disarm_delay) - .push8(FC.ARMING_CONFIG.disarm_kill_switch); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - buffer.push8(FC.ARMING_CONFIG.small_angle); - } + .push8(FC.ARMING_CONFIG.disarm_kill_switch) + .push8(FC.ARMING_CONFIG.small_angle); break; case MSPCodes.MSP_SET_LOOP_TIME: buffer.push16(FC.FC_CONFIG.loopTime); @@ -1999,15 +1716,13 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { break; case MSPCodes.MSP_SET_GPS_CONFIG: buffer.push8(FC.GPS_CONFIG.provider) - .push8(FC.GPS_CONFIG.ublox_sbas); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_34)) { - buffer.push8(FC.GPS_CONFIG.auto_config) - .push8(FC.GPS_CONFIG.auto_baud); + .push8(FC.GPS_CONFIG.ublox_sbas) + .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); - } + 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); } break; case MSPCodes.MSP_SET_GPS_RESCUE: @@ -2021,15 +1736,15 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { .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.minRescueDth); - } + 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.minRescueDth); + } break; case MSPCodes.MSP_SET_RSSI_CONFIG: buffer.push8(FC.RSSI_CONFIG.channel); @@ -2040,33 +1755,17 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { .push8(Math.round(FC.BATTERY_CONFIG.vbatwarningcellvoltage * 10)) .push16(FC.BATTERY_CONFIG.capacity) .push8(FC.BATTERY_CONFIG.voltageMeterSource) - .push8(FC.BATTERY_CONFIG.currentMeterSource); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - buffer.push16(Math.round(FC.BATTERY_CONFIG.vbatmincellvoltage * 100)) - .push16(Math.round(FC.BATTERY_CONFIG.vbatmaxcellvoltage * 100)) - .push16(Math.round(FC.BATTERY_CONFIG.vbatwarningcellvoltage * 100)); - } + .push8(FC.BATTERY_CONFIG.currentMeterSource) + .push16(Math.round(FC.BATTERY_CONFIG.vbatmincellvoltage * 100)) + .push16(Math.round(FC.BATTERY_CONFIG.vbatmaxcellvoltage * 100)) + .push16(Math.round(FC.BATTERY_CONFIG.vbatwarningcellvoltage * 100)); break; case MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG: - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - buffer.push8(FC.MISC.vbatscale) - .push8(Math.round(FC.MISC.vbatmincellvoltage * 10)) - .push8(Math.round(FC.MISC.vbatmaxcellvoltage * 10)) - .push8(Math.round(FC.MISC.vbatwarningcellvoltage * 10)); - if (semver.gte(FC.CONFIG.apiVersion, "1.23.0")) { - buffer.push8(FC.MISC.batterymetertype); - } - } + // not used break; case MSPCodes.MSP_SET_CURRENT_METER_CONFIG: - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - buffer.push16(FC.BF_CONFIG.currentscale) - .push16(FC.BF_CONFIG.currentoffset) - .push8(FC.BF_CONFIG.currentmetertype) - .push16(FC.BF_CONFIG.batterycapacity); - } + // not used break; - case MSPCodes.MSP_SET_RX_CONFIG: buffer.push8(FC.RX_CONFIG.serialrx_provider) .push16(FC.RX_CONFIG.stick_max) @@ -2074,54 +1773,46 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { .push16(FC.RX_CONFIG.stick_min) .push8(FC.RX_CONFIG.spektrum_sat_bind) .push16(FC.RX_CONFIG.rx_min_usec) - .push16(FC.RX_CONFIG.rx_max_usec); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - buffer.push8(FC.RX_CONFIG.rcInterpolation) - .push8(FC.RX_CONFIG.rcInterpolationInterval) - .push16(FC.RX_CONFIG.airModeActivateThreshold); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) { - buffer.push8(FC.RX_CONFIG.rxSpiProtocol) - .push32(FC.RX_CONFIG.rxSpiId) - .push8(FC.RX_CONFIG.rxSpiRfChannelCount) - .push8(FC.RX_CONFIG.fpvCamAngleDegrees); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - buffer.push8(FC.RX_CONFIG.rcInterpolationChannels) - .push8(FC.RX_CONFIG.rcSmoothingType) - .push8(FC.RX_CONFIG.rcSmoothingSetpointCutoff) - .push8(FC.RX_CONFIG.rcSmoothingFeedforwardCutoff) - .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)); - } - } - } - } + .push16(FC.RX_CONFIG.rx_max_usec) + .push8(FC.RX_CONFIG.rcInterpolation) + .push8(FC.RX_CONFIG.rcInterpolationInterval) + .push16(FC.RX_CONFIG.airModeActivateThreshold) + .push8(FC.RX_CONFIG.rxSpiProtocol) + .push32(FC.RX_CONFIG.rxSpiId) + .push8(FC.RX_CONFIG.rxSpiRfChannelCount) + .push8(FC.RX_CONFIG.fpvCamAngleDegrees) + .push8(FC.RX_CONFIG.rcInterpolationChannels) + .push8(FC.RX_CONFIG.rcSmoothingType) + .push8(FC.RX_CONFIG.rcSmoothingSetpointCutoff) + .push8(FC.RX_CONFIG.rcSmoothingFeedforwardCutoff) + .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)); } - } break; case MSPCodes.MSP_SET_FAILSAFE_CONFIG: buffer.push8(FC.FAILSAFE_CONFIG.failsafe_delay) .push8(FC.FAILSAFE_CONFIG.failsafe_off_delay) - .push16(FC.FAILSAFE_CONFIG.failsafe_throttle); - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - buffer.push8(FC.FAILSAFE_CONFIG.failsafe_switch_mode) - .push16(FC.FAILSAFE_CONFIG.failsafe_throttle_low_delay) - .push8(FC.FAILSAFE_CONFIG.failsafe_procedure); - } + .push16(FC.FAILSAFE_CONFIG.failsafe_throttle) + .push8(FC.FAILSAFE_CONFIG.failsafe_switch_mode) + .push16(FC.FAILSAFE_CONFIG.failsafe_throttle_low_delay) + .push8(FC.FAILSAFE_CONFIG.failsafe_procedure); break; case MSPCodes.MSP_SET_TRANSPONDER_CONFIG: - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33)) { - buffer.push8(FC.TRANSPONDER.provider); // - } + buffer.push8(FC.TRANSPONDER.provider); // + for (let i = 0; i < FC.TRANSPONDER.data.length; i++) { buffer.push8(FC.TRANSPONDER.data[i]); } @@ -2137,28 +1828,17 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { } break; case MSPCodes.MSP_SET_CF_SERIAL_CONFIG: - if (semver.lt(FC.CONFIG.apiVersion, "1.6.0")) { + for (let i = 0; i < FC.SERIAL_CONFIG.ports.length; i++) { + const serialPort = FC.SERIAL_CONFIG.ports[i]; - for (let i = 0; i < FC.SERIAL_CONFIG.ports.length; i++) { - buffer.push8(FC.SERIAL_CONFIG.ports[i].scenario); - } - buffer.push32(FC.SERIAL_CONFIG.mspBaudRate) - .push32(FC.SERIAL_CONFIG.cliBaudRate) - .push32(FC.SERIAL_CONFIG.gpsBaudRate) - .push32(FC.SERIAL_CONFIG.gpsPassthroughBaudRate); - } else { - for (let i = 0; i < FC.SERIAL_CONFIG.ports.length; i++) { - const serialPort = FC.SERIAL_CONFIG.ports[i]; + buffer.push8(serialPort.identifier); - buffer.push8(serialPort.identifier); - - const functionMask = self.serialPortFunctionsToMask(serialPort.functions); - buffer.push16(functionMask) - .push8(self.BAUD_RATES.indexOf(serialPort.msp_baudrate)) - .push8(self.BAUD_RATES.indexOf(serialPort.gps_baudrate)) - .push8(self.BAUD_RATES.indexOf(serialPort.telemetry_baudrate)) - .push8(self.BAUD_RATES.indexOf(serialPort.blackbox_baudrate)); - } + const functionMask = self.serialPortFunctionsToMask(serialPort.functions); + buffer.push16(functionMask) + .push8(self.BAUD_RATES.indexOf(serialPort.msp_baudrate)) + .push8(self.BAUD_RATES.indexOf(serialPort.gps_baudrate)) + .push8(self.BAUD_RATES.indexOf(serialPort.telemetry_baudrate)) + .push8(self.BAUD_RATES.indexOf(serialPort.blackbox_baudrate)); } break; @@ -2183,202 +1863,146 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { buffer.push16(FC.MOTOR_3D_CONFIG.deadband3d_low) .push16(FC.MOTOR_3D_CONFIG.deadband3d_high) .push16(FC.MOTOR_3D_CONFIG.neutral); - if (semver.lt(FC.CONFIG.apiVersion, "1.17.0")) { - buffer.push16(FC.RC_DEADBAND_CONFIG.deadband3d_throttle); - } break; case MSPCodes.MSP_SET_RC_DEADBAND: buffer.push8(FC.RC_DEADBAND_CONFIG.deadband) .push8(FC.RC_DEADBAND_CONFIG.yaw_deadband) - .push8(FC.RC_DEADBAND_CONFIG.alt_hold_deadband); - if (semver.gte(FC.CONFIG.apiVersion, "1.17.0")) { - buffer.push16(FC.RC_DEADBAND_CONFIG.deadband3d_throttle); - } + .push8(FC.RC_DEADBAND_CONFIG.alt_hold_deadband) + .push16(FC.RC_DEADBAND_CONFIG.deadband3d_throttle); break; case MSPCodes.MSP_SET_SENSOR_ALIGNMENT: buffer.push8(FC.SENSOR_ALIGNMENT.align_gyro) .push8(FC.SENSOR_ALIGNMENT.align_acc) - .push8(FC.SENSOR_ALIGNMENT.align_mag); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - buffer.push8(FC.SENSOR_ALIGNMENT.gyro_to_use) + .push8(FC.SENSOR_ALIGNMENT.align_mag) + .push8(FC.SENSOR_ALIGNMENT.gyro_to_use) .push8(FC.SENSOR_ALIGNMENT.gyro_1_align) .push8(FC.SENSOR_ALIGNMENT.gyro_2_align); - } break; case MSPCodes.MSP_SET_ADVANCED_CONFIG: buffer.push8(FC.PID_ADVANCED_CONFIG.gyro_sync_denom) .push8(FC.PID_ADVANCED_CONFIG.pid_process_denom) .push8(FC.PID_ADVANCED_CONFIG.use_unsyncedPwm) .push8(EscProtocols.ReorderPwmProtocols(FC.CONFIG.apiVersion, FC.PID_ADVANCED_CONFIG.fast_pwm_protocol)) - .push16(FC.PID_ADVANCED_CONFIG.motor_pwm_rate); - if (semver.gte(FC.CONFIG.apiVersion, "1.24.0")) { - buffer.push16(FC.PID_ADVANCED_CONFIG.digitalIdlePercent * 100); - - if (semver.gte(FC.CONFIG.apiVersion, "1.25.0")) { - let gyroUse32kHz = 0; - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - gyroUse32kHz = FC.PID_ADVANCED_CONFIG.gyroUse32kHz; - } - buffer.push8(gyroUse32kHz); - 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); - } + .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; + break; case MSPCodes.MSP_SET_FILTER_CONFIG: buffer.push8(FC.FILTER_CONFIG.gyro_lowpass_hz) .push16(FC.FILTER_CONFIG.dterm_lowpass_hz) - .push16(FC.FILTER_CONFIG.yaw_lowpass_hz); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - buffer.push16(FC.FILTER_CONFIG.gyro_notch_hz) - .push16(FC.FILTER_CONFIG.gyro_notch_cutoff) - .push16(FC.FILTER_CONFIG.dterm_notch_hz) - .push16(FC.FILTER_CONFIG.dterm_notch_cutoff); - if (semver.gte(FC.CONFIG.apiVersion, "1.21.0")) { - buffer.push16(FC.FILTER_CONFIG.gyro_notch2_hz) - .push16(FC.FILTER_CONFIG.gyro_notch2_cutoff); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - buffer.push8(FC.FILTER_CONFIG.dterm_lowpass_type); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - let gyro_32khz_hardware_lpf = 0; - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - gyro_32khz_hardware_lpf = FC.FILTER_CONFIG.gyro_32khz_hardware_lpf; - } - buffer.push8(FC.FILTER_CONFIG.gyro_hardware_lpf) - .push8(gyro_32khz_hardware_lpf) - .push16(FC.FILTER_CONFIG.gyro_lowpass_hz) - .push16(FC.FILTER_CONFIG.gyro_lowpass2_hz) - .push8(FC.FILTER_CONFIG.gyro_lowpass_type) - .push8(FC.FILTER_CONFIG.gyro_lowpass2_type) - .push16(FC.FILTER_CONFIG.dterm_lowpass2_hz); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - buffer.push8(FC.FILTER_CONFIG.dterm_lowpass2_type) - .push16(FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz) - .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) - .push8(FC.FILTER_CONFIG.dyn_notch_count); - } + .push16(FC.FILTER_CONFIG.yaw_lowpass_hz) + .push16(FC.FILTER_CONFIG.gyro_notch_hz) + .push16(FC.FILTER_CONFIG.gyro_notch_cutoff) + .push16(FC.FILTER_CONFIG.dterm_notch_hz) + .push16(FC.FILTER_CONFIG.dterm_notch_cutoff) + .push16(FC.FILTER_CONFIG.gyro_notch2_hz) + .push16(FC.FILTER_CONFIG.gyro_notch2_cutoff) + .push8(FC.FILTER_CONFIG.dterm_lowpass_type) + .push8(0) // FC.FILTER_CONFIG.gyro_hardware_lpf not used + .push8(0) // gyro_32khz_hardware_lpf not used + .push16(FC.FILTER_CONFIG.gyro_lowpass_hz) + .push16(FC.FILTER_CONFIG.gyro_lowpass2_hz) + .push8(FC.FILTER_CONFIG.gyro_lowpass_type) + .push8(FC.FILTER_CONFIG.gyro_lowpass2_type) + .push16(FC.FILTER_CONFIG.dterm_lowpass2_hz) + .push8(FC.FILTER_CONFIG.dterm_lowpass2_type) + .push16(FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz) + .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) + .push8(FC.FILTER_CONFIG.dyn_notch_count); } break; case MSPCodes.MSP_SET_PID_ADVANCED: - if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - buffer.push16(FC.ADVANCED_TUNING.rollPitchItermIgnoreRate) - .push16(FC.ADVANCED_TUNING.yawItermIgnoreRate) - .push16(FC.ADVANCED_TUNING.yaw_p_limit) - .push8(FC.ADVANCED_TUNING.deltaMethod) - .push8(FC.ADVANCED_TUNING.vbatPidCompensation); + buffer.push16(FC.ADVANCED_TUNING.rollPitchItermIgnoreRate) + .push16(FC.ADVANCED_TUNING.yawItermIgnoreRate) + .push16(FC.ADVANCED_TUNING.yaw_p_limit) + .push8(FC.ADVANCED_TUNING.deltaMethod) + .push8(FC.ADVANCED_TUNING.vbatPidCompensation) + .push8(FC.ADVANCED_TUNING.feedforwardTransition) + .push8(Math.min(FC.ADVANCED_TUNING.dtermSetpointWeight, 254)) + .push8(FC.ADVANCED_TUNING.toleranceBand) + .push8(FC.ADVANCED_TUNING.toleranceBandReduction) + .push8(FC.ADVANCED_TUNING.itermThrottleGain) + .push16(FC.ADVANCED_TUNING.pidMaxVelocity) + .push16(FC.ADVANCED_TUNING.pidMaxVelocityYaw) + .push8(FC.ADVANCED_TUNING.levelAngleLimit) + .push8(FC.ADVANCED_TUNING.levelSensitivity) + .push16(FC.ADVANCED_TUNING.itermThrottleThreshold); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - buffer.push8(FC.ADVANCED_TUNING.feedforwardTransition); - } else { - buffer.push8(FC.ADVANCED_TUNING.dtermSetpointTransition); - } - buffer.push8(Math.min(FC.ADVANCED_TUNING.dtermSetpointWeight, 254)) - .push8(FC.ADVANCED_TUNING.toleranceBand) - .push8(FC.ADVANCED_TUNING.toleranceBandReduction) - .push8(FC.ADVANCED_TUNING.itermThrottleGain) - .push16(FC.ADVANCED_TUNING.pidMaxVelocity) - .push16(FC.ADVANCED_TUNING.pidMaxVelocityYaw); - - if (semver.gte(FC.CONFIG.apiVersion, "1.24.0")) { - buffer.push8(FC.ADVANCED_TUNING.levelAngleLimit) - .push8(FC.ADVANCED_TUNING.levelSensitivity); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - buffer.push16(FC.ADVANCED_TUNING.itermThrottleThreshold); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - buffer.push16(FC.ADVANCED_TUNING.antiGravityGain); - } else { - buffer.push16(FC.ADVANCED_TUNING.itermAcceleratorGain); - } - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - buffer.push16(FC.ADVANCED_TUNING.dtermSetpointWeight); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - buffer.push8(FC.ADVANCED_TUNING.itermRotation) - .push8(FC.ADVANCED_TUNING.smartFeedforward) - .push8(FC.ADVANCED_TUNING.itermRelax) - .push8(FC.ADVANCED_TUNING.itermRelaxType) - .push8(FC.ADVANCED_TUNING.absoluteControlGain) - .push8(FC.ADVANCED_TUNING.throttleBoost) - .push8(FC.ADVANCED_TUNING.acroTrainerAngleLimit) - .push16(FC.ADVANCED_TUNING.feedforwardRoll) - .push16(FC.ADVANCED_TUNING.feedforwardPitch) - .push16(FC.ADVANCED_TUNING.feedforwardYaw) - .push8(FC.ADVANCED_TUNING.antiGravityMode); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - buffer.push8(FC.ADVANCED_TUNING.dMinRoll) - .push8(FC.ADVANCED_TUNING.dMinPitch) - .push8(FC.ADVANCED_TUNING.dMinYaw) - .push8(FC.ADVANCED_TUNING.dMinGain) - .push8(FC.ADVANCED_TUNING.dMinAdvance) - .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); - } - } - } - } - } - } - } - } - } - } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + buffer.push16(FC.ADVANCED_TUNING.antiGravityGain); + } else { + buffer.push16(FC.ADVANCED_TUNING.itermAcceleratorGain); } + + buffer.push16(FC.ADVANCED_TUNING.dtermSetpointWeight) + .push8(FC.ADVANCED_TUNING.itermRotation) + .push8(FC.ADVANCED_TUNING.smartFeedforward) + .push8(FC.ADVANCED_TUNING.itermRelax) + .push8(FC.ADVANCED_TUNING.itermRelaxType) + .push8(FC.ADVANCED_TUNING.absoluteControlGain) + .push8(FC.ADVANCED_TUNING.throttleBoost) + .push8(FC.ADVANCED_TUNING.acroTrainerAngleLimit) + .push16(FC.ADVANCED_TUNING.feedforwardRoll) + .push16(FC.ADVANCED_TUNING.feedforwardPitch) + .push16(FC.ADVANCED_TUNING.feedforwardYaw) + .push8(FC.ADVANCED_TUNING.antiGravityMode) + .push8(FC.ADVANCED_TUNING.dMinRoll) + .push8(FC.ADVANCED_TUNING.dMinPitch) + .push8(FC.ADVANCED_TUNING.dMinYaw) + .push8(FC.ADVANCED_TUNING.dMinGain) + .push8(FC.ADVANCED_TUNING.dMinAdvance) + .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); + } break; case MSPCodes.MSP_SET_SENSOR_CONFIG: buffer.push8(FC.SENSOR_CONFIG.acc_hardware) @@ -2420,10 +2044,8 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { case MSPCodes.MSP_SET_BLACKBOX_CONFIG: buffer.push8(FC.BLACKBOX.blackboxDevice) .push8(FC.BLACKBOX.blackboxRateNum) - .push8(FC.BLACKBOX.blackboxRateDenom); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - buffer.push16(FC.BLACKBOX.blackboxPDenom); - } + .push8(FC.BLACKBOX.blackboxRateDenom) + .push16(FC.BLACKBOX.blackboxPDenom); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { buffer.push8(FC.BLACKBOX.blackboxSampleRate); } @@ -2455,39 +2077,29 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { case MSPCodes.MSP_SET_RTC: const now = new Date(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - const timestamp = now.getTime(); - const secs = timestamp / 1000; - const millis = timestamp % 1000; - buffer.push32(secs); - buffer.push16(millis); - } else { - buffer.push16(now.getUTCFullYear()); - buffer.push8(now.getUTCMonth() + 1); - buffer.push8(now.getUTCDate()); - buffer.push8(now.getUTCHours()); - buffer.push8(now.getUTCMinutes()); - buffer.push8(now.getUTCSeconds()); - } - + const timestamp = now.getTime(); + const secs = timestamp / 1000; + const millis = timestamp % 1000; + buffer.push32(secs); + buffer.push16(millis); break; case MSPCodes.MSP_SET_VTX_CONFIG: buffer.push16(FC.VTX_CONFIG.vtx_frequency) - .push8(FC.VTX_CONFIG.vtx_power) - .push8(FC.VTX_CONFIG.vtx_pit_mode ? 1 : 0) - .push8(FC.VTX_CONFIG.vtx_low_power_disarm); + .push8(FC.VTX_CONFIG.vtx_power) + .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); + .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; @@ -2599,14 +2211,10 @@ MspHelper.prototype.setRawRx = function(channels) { MspHelper.prototype.dataflashRead = function(address, blockSize, onDataCallback) { let outData = [address & 0xFF, (address >> 8) & 0xFF, (address >> 16) & 0xFF, (address >> 24) & 0xFF]; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) { - outData = outData.concat([blockSize & 0xFF, (blockSize >> 8) & 0xFF]); - } + outData = outData.concat([blockSize & 0xFF, (blockSize >> 8) & 0xFF]); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - // Allow compression - outData = outData.concat([1]); - } + // Allow compression + outData = outData.concat([1]); MSP.send_message(MSPCodes.MSP_DATAFLASH_READ, outData, false, function(response) { if (!response.crcError) { @@ -2667,63 +2275,31 @@ MspHelper.prototype.sendServoConfigurations = function(onCompleteCallback) { const buffer = []; - if (semver.lt(FC.CONFIG.apiVersion, "1.12.0")) { - // send all in one go - // 1.9.0 had a bug where the MSP input buffer was too small, limit to 8. - for (let i = 0; i < FC.SERVO_CONFIG.length && i < 8; i++) { - buffer.push16(FC.SERVO_CONFIG[i].min) - .push16(FC.SERVO_CONFIG[i].max) - .push16(FC.SERVO_CONFIG[i].middle) - .push8(FC.SERVO_CONFIG[i].rate); - } - nextFunction = send_channel_forwarding; - } else { - // send one at a time, with index + // send one at a time, with index - const servoConfiguration = FC.SERVO_CONFIG[servoIndex]; + const servoConfiguration = FC.SERVO_CONFIG[servoIndex]; - buffer.push8(servoIndex) - .push16(servoConfiguration.min) - .push16(servoConfiguration.max) - .push16(servoConfiguration.middle) - .push8(servoConfiguration.rate); + buffer.push8(servoIndex) + .push16(servoConfiguration.min) + .push16(servoConfiguration.max) + .push16(servoConfiguration.middle) + .push8(servoConfiguration.rate); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_33)) { - buffer.push8(servoConfiguration.angleAtMin) - .push8(servoConfiguration.angleAtMax); - } - - let out = servoConfiguration.indexOfChannelToForward; - if (out == undefined) { - out = 255; // Cleanflight defines "CHANNEL_FORWARDING_DISABLED" as "(uint8_t)0xFF" - } - buffer.push8(out) - .push32(servoConfiguration.reversedInputSources); - - // prepare for next iteration - servoIndex++; - if (servoIndex == FC.SERVO_CONFIG.length) { - nextFunction = onCompleteCallback; - } + let out = servoConfiguration.indexOfChannelToForward; + if (out == undefined) { + out = 255; // Cleanflight defines "CHANNEL_FORWARDING_DISABLED" as "(uint8_t)0xFF" } + buffer.push8(out) + .push32(servoConfiguration.reversedInputSources); + + // prepare for next iteration + servoIndex++; + if (servoIndex == FC.SERVO_CONFIG.length) { + nextFunction = onCompleteCallback; + } + MSP.send_message(MSPCodes.MSP_SET_SERVO_CONFIGURATION, buffer, false, nextFunction); } - - function send_channel_forwarding() { - const buffer = []; - - for (let i = 0; i < FC.SERVO_CONFIG.length; i++) { - let out = FC.SERVO_CONFIG[i].indexOfChannelToForward; - if (out == undefined) { - out = 255; // Cleanflight defines "CHANNEL_FORWARDING_DISABLED" as "(uint8_t)0xFF" - } - buffer.push8(out); - } - - nextFunction = onCompleteCallback; - - MSP.send_message(MSPCodes.MSP_SET_CHANNEL_FORWARDING, buffer, false, nextFunction); - } }; MspHelper.prototype.sendModeRanges = function(onCompleteCallback) { @@ -2748,12 +2324,10 @@ MspHelper.prototype.sendModeRanges = function(onCompleteCallback) { .push8((modeRange.range.start - 900) / 25) .push8((modeRange.range.end - 900) / 25); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - const modeRangeExtra = FC.MODE_RANGES_EXTRA[modeRangeIndex]; + const modeRangeExtra = FC.MODE_RANGES_EXTRA[modeRangeIndex]; - buffer.push8(modeRangeExtra.modeLogic) - .push8(modeRangeExtra.linkedTo); - } + buffer.push8(modeRangeExtra.modeLogic) + .push8(modeRangeExtra.linkedTo); // prepare for next iteration modeRangeIndex++; @@ -2879,67 +2453,39 @@ MspHelper.prototype.sendLedStripConfig = function(onCompleteCallback) { buffer.push(ledIndex); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - ledOverlayLetters = ['t', 'o', 'b', 'n', 'i', 'w']; // in LSB bit + let mask = 0; + + mask |= (led.y << 0); + mask |= (led.x << 4); + + for (let functionLetterIndex = 0; functionLetterIndex < led.functions.length; functionLetterIndex++) { + const fnIndex = ledBaseFunctionLetters.indexOf(led.functions[functionLetterIndex]); + if (fnIndex >= 0) { + mask |= (fnIndex << 8); + break; + } } - if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { - let directionMask = 0; - for (let directionLetterIndex = 0; directionLetterIndex < led.directions.length; directionLetterIndex++) { - const bitIndex = ledDirectionLetters.indexOf(led.directions[directionLetterIndex]); - if (bitIndex >= 0) { - directionMask = bit_set(directionMask, bitIndex); - } + for (let overlayLetterIndex = 0; overlayLetterIndex < led.functions.length; overlayLetterIndex++) { + const bitIndex = ledOverlayLetters.indexOf(led.functions[overlayLetterIndex]); + if (bitIndex >= 0) { + mask |= bit_set(mask, bitIndex + 12); } - buffer.push16(directionMask); - - let functionMask = 0; - for (let functionLetterIndex = 0; functionLetterIndex < led.functions.length; functionLetterIndex++) { - const bitIndex = ledFunctionLetters.indexOf(led.functions[functionLetterIndex]); - if (bitIndex >= 0) { - functionMask = bit_set(functionMask, bitIndex); - } - } - buffer.push16(functionMask) - - .push8(led.x) - .push8(led.y) - .push8(led.color); - } else { - let mask = 0; - - mask |= (led.y << 0); - mask |= (led.x << 4); - - for (let functionLetterIndex = 0; functionLetterIndex < led.functions.length; functionLetterIndex++) { - const fnIndex = ledBaseFunctionLetters.indexOf(led.functions[functionLetterIndex]); - if (fnIndex >= 0) { - mask |= (fnIndex << 8); - break; - } - } - - for (let overlayLetterIndex = 0; overlayLetterIndex < led.functions.length; overlayLetterIndex++) { - const bitIndex = ledOverlayLetters.indexOf(led.functions[overlayLetterIndex]); - if (bitIndex >= 0) { - mask |= bit_set(mask, bitIndex + 12); - } - } - - mask |= (led.color << 18); - - for (let directionLetterIndex = 0; directionLetterIndex < led.directions.length; directionLetterIndex++) { - const bitIndex = ledDirectionLetters.indexOf(led.directions[directionLetterIndex]); - if (bitIndex >= 0) { - mask |= bit_set(mask, bitIndex + 22); - } - } - - mask |= (0 << 28); // parameters - - buffer.push32(mask); } + mask |= (led.color << 18); + + for (let directionLetterIndex = 0; directionLetterIndex < led.directions.length; directionLetterIndex++) { + const bitIndex = ledDirectionLetters.indexOf(led.directions[directionLetterIndex]); + if (bitIndex >= 0) { + mask |= bit_set(mask, bitIndex + 22); + } + } + + mask |= (0 << 28); // parameters + + buffer.push32(mask); + // prepare for next iteration ledIndex++; if (ledIndex == FC.LED_STRIP.length) { @@ -3056,8 +2602,7 @@ MspHelper.prototype.sendRxFailConfig = function(onCompleteCallback) { }; MspHelper.prototype.setArmingEnabled = function(doEnable, disableRunawayTakeoffPrevention, onCompleteCallback) { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37) - && (FC.CONFIG.armingDisabled === doEnable || FC.CONFIG.runawayTakeoffPreventionDisabled !== disableRunawayTakeoffPrevention)) { + if (FC.CONFIG.armingDisabled === doEnable || FC.CONFIG.runawayTakeoffPreventionDisabled !== disableRunawayTakeoffPrevention) { FC.CONFIG.armingDisabled = !doEnable; FC.CONFIG.runawayTakeoffPreventionDisabled = disableRunawayTakeoffPrevention; diff --git a/src/js/serial_backend.js b/src/js/serial_backend.js index 3bb9fb92..cf848024 100644 --- a/src/js/serial_backend.js +++ b/src/js/serial_backend.js @@ -445,11 +445,7 @@ function processUid() { connectionTimestamp = Date.now(); GUI.log(i18n.getMessage('uniqueDeviceIdReceived', [uniqueDeviceIdentifier])); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - processCraftName(); - } else { - setRtc(); - } + processCraftName(); }); } @@ -471,19 +467,12 @@ async function processCraftName() { } function setRtc() { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - MSP.send_message(MSPCodes.MSP_SET_RTC, mspHelper.crunch(MSPCodes.MSP_SET_RTC), false, finishOpen); - } else { - finishOpen(); - } + MSP.send_message(MSPCodes.MSP_SET_RTC, mspHelper.crunch(MSPCodes.MSP_SET_RTC), false, finishOpen); } function finishOpen() { CONFIGURATOR.connectionValid = true; GUI.allowedTabs = GUI.defaultAllowedFCTabsWhenConnected.slice(); - if (semver.lt(FC.CONFIG.apiVersion, "1.4.0")) { - GUI.allowedTabs.splice(GUI.allowedTabs.indexOf('led_strip'), 1); - } if (GUI.isCordova()) { UI_PHONES.reset(); @@ -689,11 +678,7 @@ function have_sensor(sensors_detected, sensor_code) { case 'sonar': return bit_check(sensors_detected, 4); case 'gyro': - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - return bit_check(sensors_detected, 5); - } else { - return true; - } + return bit_check(sensors_detected, 5); } return false; } @@ -704,11 +689,7 @@ function startLiveDataRefreshTimer() { } async function getStatus() { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_32)) { - return MSP.promise(MSPCodes.MSP_STATUS_EX); - } else { - return MSP.promise(MSPCodes.MSP_STATUS); - } + return MSP.promise(MSPCodes.MSP_STATUS_EX); } async function update_live_status() { diff --git a/src/js/tabs/adjustments.js b/src/js/tabs/adjustments.js index ffb146bd..6b9e7abb 100644 --- a/src/js/tabs/adjustments.js +++ b/src/js/tabs/adjustments.js @@ -289,38 +289,24 @@ adjustments.cleanup = function (callback) { adjustments.adjust_template = function () { const selectFunction = $('#functionSelectionSelect'); - let elementsNumber; - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - elementsNumber = 31; // OSD Profile Select & LED Profile Select - } else if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - elementsNumber = 29; // PID Audio - } else if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - elementsNumber = 26; // PID Audio - } else if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - elementsNumber = 25; // Horizon Strength - } else { - elementsNumber = 24; // Setpoint transition - } + const elementsNumber = 31; // OSD Profile Select & LED Profile Select for (let i = 0; i < elementsNumber; i++) { selectFunction.append(new Option(i18n.getMessage(`adjustmentsFunction${i}`), i)); } // For 1.40, the D Setpoint has been replaced, so we replace it with the correct values - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - const element22 = selectFunction.find("option[value='22']"); - const element23 = selectFunction.find("option[value='23']"); + const element22 = selectFunction.find("option[value='22']"); + const element23 = selectFunction.find("option[value='23']"); - // Change the "text" - element22.text(i18n.getMessage('adjustmentsFunction22_2')); - element23.text(i18n.getMessage('adjustmentsFunction23_2')); + // Change the "text" + element22.text(i18n.getMessage('adjustmentsFunction22_2')); + element23.text(i18n.getMessage('adjustmentsFunction23_2')); - // Reorder, we insert it with the other FF elements to be coherent... - element22.insertAfter(selectFunction.find("option[value='25']")); - element23.insertAfter(selectFunction.find("option[value='28']")); - } + // Reorder, we insert it with the other FF elements to be coherent... + element22.insertAfter(selectFunction.find("option[value='25']")); + element23.insertAfter(selectFunction.find("option[value='28']")); }; window.TABS.adjustments = adjustments; diff --git a/src/js/tabs/auxiliary.js b/src/js/tabs/auxiliary.js index d80ed11a..3d9a1cc5 100644 --- a/src/js/tabs/auxiliary.js +++ b/src/js/tabs/auxiliary.js @@ -8,8 +8,7 @@ auxiliary.initialize = function (callback) { let prevChannelsValues = null; function get_mode_ranges() { - MSP.send_message(MSPCodes.MSP_MODE_RANGES, false, false, - semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41) ? get_mode_ranges_extra : get_box_ids); + MSP.send_message(MSPCodes.MSP_MODE_RANGES, false, false, get_mode_ranges_extra); } function get_mode_ranges_extra() { @@ -57,7 +56,7 @@ auxiliary.initialize = function (callback) { $(newMode).find('a.addLink').data('modeElement', newMode); // hide link button for ARM - if (modeId == 0 || semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { + if (modeId == 0) { $(newMode).find('.addLink').hide(); } @@ -75,12 +74,11 @@ auxiliary.initialize = function (callback) { logicOption.val(0); logicList.append(logicOption); - if(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)){ - logicOption = logicOptionTemplate.clone(); - logicOption.text(i18n.getMessage('auxiliaryModeLogicAND')); - logicOption.val(1); - logicList.append(logicOption); - } + logicOption = logicOptionTemplate.clone(); + logicOption.text(i18n.getMessage('auxiliaryModeLogicAND')); + logicOption.val(1); + logicList.append(logicOption); + logicOptionTemplate.val(0); } @@ -265,15 +263,7 @@ auxiliary.initialize = function (callback) { // skip linked modes for now for (let modeRangeIndex = 0; modeRangeIndex < FC.MODE_RANGES.length; modeRangeIndex++) { const modeRange = FC.MODE_RANGES[modeRangeIndex]; - - let modeRangeExtra = { - id: modeRange.id, - modeLogic: 0, - linkedTo: 0, - }; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - modeRangeExtra = FC.MODE_RANGES_EXTRA[modeRangeIndex]; - } + const modeRangeExtra = FC.MODE_RANGES_EXTRA[modeRangeIndex]; if (modeRange.id != modeId || modeRangeExtra.id != modeId) { continue; @@ -454,13 +444,11 @@ auxiliary.initialize = function (callback) { if (i == 0) { let armSwitchActive = false; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - if (FC.CONFIG.armingDisableCount > 0) { - // check the highest bit of the armingDisableFlags. This will be the ARMING_DISABLED_ARMSWITCH flag. - const armSwitchMask = 1 << (FC.CONFIG.armingDisableCount - 1); - if ((FC.CONFIG.armingDisableFlags & armSwitchMask) > 0) { - armSwitchActive = true; - } + if (FC.CONFIG.armingDisableCount > 0) { + // check the highest bit of the armingDisableFlags. This will be the ARMING_DISABLED_ARMSWITCH flag. + const armSwitchMask = 1 << (FC.CONFIG.armingDisableCount - 1); + if ((FC.CONFIG.armingDisableFlags & armSwitchMask) > 0) { + armSwitchActive = true; } } diff --git a/src/js/tabs/configuration.js b/src/js/tabs/configuration.js index 517bfb89..e74e84c3 100644 --- a/src/js/tabs/configuration.js +++ b/src/js/tabs/configuration.js @@ -20,27 +20,26 @@ configuration.initialize = function (callback) { function load_config() { Promise .resolve(true) - .then(() => { return MSP.promise(MSPCodes.MSP_FEATURE_CONFIG); }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36) ? MSP.promise(MSPCodes.MSP_BEEPER_CONFIG) : true; }) - .then(() => { return MSP.promise(MSPCodes.MSP_BOARD_ALIGNMENT_CONFIG); }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33) ? MSP.promise(MSPCodes.MSP_GPS_CONFIG) : true; }) - .then(() => { return MSP.promise(MSPCodes.MSP_ACC_TRIM); }) - .then(() => { return semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_33) ? MSP.promise(MSPCodes.MSP_MISC) : true; }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, "1.8.0") ? MSP.promise(MSPCodes.MSP_ARMING_CONFIG) : true; }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, "1.17.0") ? MSP.promise(MSPCodes.MSP_RC_DEADBAND) : true; }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, "1.16.0") ? MSP.promise(MSPCodes.MSP_SENSOR_CONFIG) : true; }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, "1.15.0") ? MSP.promise(MSPCodes.MSP_SENSOR_ALIGNMENT) : true; }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, "1.20.0") && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45) + .then(() => MSP.promise(MSPCodes.MSP_FEATURE_CONFIG)) + .then(() => MSP.promise(MSPCodes.MSP_BEEPER_CONFIG)) + .then(() => MSP.promise(MSPCodes.MSP_BOARD_ALIGNMENT_CONFIG)) + .then(() => MSP.promise(MSPCodes.MSP_GPS_CONFIG)) + .then(() => MSP.promise(MSPCodes.MSP_ACC_TRIM)) + .then(() => MSP.promise(MSPCodes.MSP_ARMING_CONFIG)) + .then(() => MSP.promise(MSPCodes.MSP_RC_DEADBAND)) + .then(() => MSP.promise(MSPCodes.MSP_SENSOR_CONFIG)) + .then(() => MSP.promise(MSPCodes.MSP_SENSOR_ALIGNMENT)) + .then(() => semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45) ? MSP.promise(MSPCodes.MSP_NAME) - : Promise.resolve(true); }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) + : Promise.resolve(true)) + .then(() => semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) ? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.CRAFT_NAME)) - : Promise.resolve(true); }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31) ? MSP.promise(MSPCodes.MSP_RX_CONFIG) : true; }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) - ? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.PILOT_NAME)) : Promise.resolve(true); }) - .then(() => { return MSP.promise(MSPCodes.MSP_ADVANCED_CONFIG); }) - .then(() => { load_html(); }); + : Promise.resolve(true)) + .then(() => MSP.promise(MSPCodes.MSP_RX_CONFIG)) + .then(() => semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) + ? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.PILOT_NAME)) : Promise.resolve(true)) + .then(() => MSP.promise(MSPCodes.MSP_ADVANCED_CONFIG)) + .then(() => load_html()); } function load_html() { @@ -58,20 +57,14 @@ configuration.initialize = function (callback) { // Dshot Beeper const dshotBeeper_e = $('.tab-configuration .dshotbeeper'); - const dshotBeacon_e = $('.tab-configuration .dshotbeacon'); - const dshotBeeperSwitch = $('#dshotBeeperSwitch'); const dshotBeeperBeaconTone = $('select.dshotBeeperBeaconTone'); const dshotBeaconCondition_e = $('tbody.dshotBeaconConditions'); const dshotBeaconSwitch_e = $('tr.dshotBeaconSwitch'); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - for (let i = 1; i <= 5; i++) { - dshotBeeperBeaconTone.append(``); - } - dshotBeeper_e.show(); - } else { - dshotBeeper_e.hide(); + for (let i = 1; i <= 5; i++) { + dshotBeeperBeaconTone.append(``); } + dshotBeeper_e.show(); dshotBeeperBeaconTone.change(function() { FC.BEEPER_CONFIG.dshotBeaconTone = dshotBeeperBeaconTone.val(); @@ -80,41 +73,19 @@ configuration.initialize = function (callback) { dshotBeeperBeaconTone.val(FC.BEEPER_CONFIG.dshotBeaconTone); const template = $('.beepers .beeper-template'); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - dshotBeaconSwitch_e.hide(); - FC.BEEPER_CONFIG.dshotBeaconConditions.generateElements(template, dshotBeaconCondition_e); + dshotBeaconSwitch_e.hide(); + FC.BEEPER_CONFIG.dshotBeaconConditions.generateElements(template, dshotBeaconCondition_e); - $('input.condition', dshotBeaconCondition_e).change(function () { - const element = $(this); - FC.BEEPER_CONFIG.dshotBeaconConditions.updateData(element); - }); - } else { - dshotBeaconCondition_e.hide(); - - dshotBeeperSwitch.change(function() { - if ($(this).is(':checked')) { - dshotBeacon_e.show(); - if (dshotBeeperBeaconTone.val() == 0) { - dshotBeeperBeaconTone.val(1).change(); - } - } else { - dshotBeeperBeaconTone.val(0).change(); - dshotBeacon_e.hide(); - } - }); - - dshotBeeperSwitch.prop('checked', FC.BEEPER_CONFIG.dshotBeaconTone !== 0).change(); - } + $('input.condition', dshotBeaconCondition_e).change(function () { + const element = $(this); + FC.BEEPER_CONFIG.dshotBeaconConditions.updateData(element); + }); // Analog Beeper const destination = $('.beepers .beeper-configuration'); const beeper_e = $('.tab-configuration .beepers'); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.BEEPER_CONFIG.beepers.generateElements(template, destination); - } else { - beeper_e.hide(); - } + FC.BEEPER_CONFIG.beepers.generateElements(template, destination); // translate to user-selected language i18n.localizePage(); @@ -147,125 +118,117 @@ configuration.initialize = function (callback) { const orientation_gyro_2_align_e = $('select.gyro_2_align'); gyro_align_content_e.hide(); // default value - if (semver.lt(FC.CONFIG.apiVersion, "1.15.0")) { - $('.tab-configuration .sensoralignment').hide(); - } else { - - for (let i = 0; i < alignments.length; i++) { - orientation_gyro_e.append(``); - orientation_acc_e.append(``); - orientation_mag_e.append(``); - } - - orientation_gyro_e.val(FC.SENSOR_ALIGNMENT.align_gyro); - orientation_acc_e.val(FC.SENSOR_ALIGNMENT.align_acc); - orientation_mag_e.val(FC.SENSOR_ALIGNMENT.align_mag); - - orientation_gyro_e.change(function () { - let value = parseInt($(this).val()); - - let newValue = undefined; - if (value !== FC.SENSOR_ALIGNMENT.align_gyro) { - newValue = $(this).find('option:selected').text(); - } - self.analyticsChanges['GyroAlignment'] = newValue; - - FC.SENSOR_ALIGNMENT.align_gyro = value; - }); - - orientation_acc_e.change(function () { - let value = parseInt($(this).val()); - - let newValue = undefined; - if (value !== FC.SENSOR_ALIGNMENT.align_acc) { - newValue = $(this).find('option:selected').text(); - } - self.analyticsChanges['AccAlignment'] = newValue; - - FC.SENSOR_ALIGNMENT.align_acc = value; - }); - - orientation_mag_e.change(function () { - let value = parseInt($(this).val()); - - let newValue = undefined; - if (value !== FC.SENSOR_ALIGNMENT.align_mag) { - newValue = $(this).find('option:selected').text(); - } - self.analyticsChanges['MagAlignment'] = newValue; - - FC.SENSOR_ALIGNMENT.align_mag = value; - }); - - // Multi gyro config - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - - gyro_align_content_e.show(); - legacy_gyro_alignment_e.hide(); - legacy_accel_alignment_e.hide(); - - const GYRO_DETECTION_FLAGS = { - DETECTED_GYRO_1: (1 << 0), - DETECTED_GYRO_2: (1 << 1), - DETECTED_DUAL_GYROS: (1 << 7), - }; - - const detected_gyro_1 = (FC.SENSOR_ALIGNMENT.gyro_detection_flags & GYRO_DETECTION_FLAGS.DETECTED_GYRO_1) != 0; - const detected_gyro_2 = (FC.SENSOR_ALIGNMENT.gyro_detection_flags & GYRO_DETECTION_FLAGS.DETECTED_GYRO_2) != 0; - const detected_dual_gyros = (FC.SENSOR_ALIGNMENT.gyro_detection_flags & GYRO_DETECTION_FLAGS.DETECTED_DUAL_GYROS) != 0; - - if (detected_gyro_1) { - orientation_gyro_to_use_e.append(``); - } - if (detected_gyro_2) { - orientation_gyro_to_use_e.append(``); - } - if (detected_dual_gyros) { - orientation_gyro_to_use_e.append(``); - } - - for (let i = 0; i < alignments.length; i++) { - orientation_gyro_1_align_e.append(``); - orientation_gyro_2_align_e.append(``); - } - - orientation_gyro_to_use_e.val(FC.SENSOR_ALIGNMENT.gyro_to_use); - orientation_gyro_1_align_e.val(FC.SENSOR_ALIGNMENT.gyro_1_align); - orientation_gyro_2_align_e.val(FC.SENSOR_ALIGNMENT.gyro_2_align); - - $('.gyro_alignment_inputs_first').toggle(detected_gyro_1); - $('.gyro_alignment_inputs_second').toggle(detected_gyro_2); - $('.gyro_alignment_inputs_selection').toggle(detected_gyro_1 || detected_gyro_2); - $('.gyro_alignment_inputs_notfound').toggle(!detected_gyro_1 && !detected_gyro_2); - - orientation_gyro_1_align_e.change(function () { - let value = parseInt($(this).val()); - - let newValue = undefined; - if (value !== FC.SENSOR_ALIGNMENT.gyro_1_align) { - newValue = $(this).find('option:selected').text(); - } - self.analyticsChanges['Gyro1Alignment'] = newValue; - - FC.SENSOR_ALIGNMENT.gyro_1_align = value; - }); - - orientation_gyro_2_align_e.change(function () { - let value = parseInt($(this).val()); - - let newValue = undefined; - if (value !== FC.SENSOR_ALIGNMENT.gyro_2_align) { - newValue = $(this).find('option:selected').text(); - } - self.analyticsChanges['Gyro2Alignment'] = newValue; - - FC.SENSOR_ALIGNMENT.gyro_2_align = value; - }); - } + for (let i = 0; i < alignments.length; i++) { + orientation_gyro_e.append(``); + orientation_acc_e.append(``); + orientation_mag_e.append(``); } + orientation_gyro_e.val(FC.SENSOR_ALIGNMENT.align_gyro); + orientation_acc_e.val(FC.SENSOR_ALIGNMENT.align_acc); + orientation_mag_e.val(FC.SENSOR_ALIGNMENT.align_mag); + + orientation_gyro_e.change(function () { + let value = parseInt($(this).val()); + + let newValue = undefined; + if (value !== FC.SENSOR_ALIGNMENT.align_gyro) { + newValue = $(this).find('option:selected').text(); + } + self.analyticsChanges['GyroAlignment'] = newValue; + + FC.SENSOR_ALIGNMENT.align_gyro = value; + }); + + orientation_acc_e.change(function () { + let value = parseInt($(this).val()); + + let newValue = undefined; + if (value !== FC.SENSOR_ALIGNMENT.align_acc) { + newValue = $(this).find('option:selected').text(); + } + self.analyticsChanges['AccAlignment'] = newValue; + + FC.SENSOR_ALIGNMENT.align_acc = value; + }); + + orientation_mag_e.change(function () { + let value = parseInt($(this).val()); + + let newValue = undefined; + if (value !== FC.SENSOR_ALIGNMENT.align_mag) { + newValue = $(this).find('option:selected').text(); + } + self.analyticsChanges['MagAlignment'] = newValue; + + FC.SENSOR_ALIGNMENT.align_mag = value; + }); + + // Multi gyro config + + gyro_align_content_e.show(); + legacy_gyro_alignment_e.hide(); + legacy_accel_alignment_e.hide(); + + const GYRO_DETECTION_FLAGS = { + DETECTED_GYRO_1: (1 << 0), + DETECTED_GYRO_2: (1 << 1), + DETECTED_DUAL_GYROS: (1 << 7), + }; + + const detected_gyro_1 = (FC.SENSOR_ALIGNMENT.gyro_detection_flags & GYRO_DETECTION_FLAGS.DETECTED_GYRO_1) != 0; + const detected_gyro_2 = (FC.SENSOR_ALIGNMENT.gyro_detection_flags & GYRO_DETECTION_FLAGS.DETECTED_GYRO_2) != 0; + const detected_dual_gyros = (FC.SENSOR_ALIGNMENT.gyro_detection_flags & GYRO_DETECTION_FLAGS.DETECTED_DUAL_GYROS) != 0; + + if (detected_gyro_1) { + orientation_gyro_to_use_e.append(``); + } + if (detected_gyro_2) { + orientation_gyro_to_use_e.append(``); + } + if (detected_dual_gyros) { + orientation_gyro_to_use_e.append(``); + } + + for (let i = 0; i < alignments.length; i++) { + orientation_gyro_1_align_e.append(``); + orientation_gyro_2_align_e.append(``); + } + + orientation_gyro_to_use_e.val(FC.SENSOR_ALIGNMENT.gyro_to_use); + orientation_gyro_1_align_e.val(FC.SENSOR_ALIGNMENT.gyro_1_align); + orientation_gyro_2_align_e.val(FC.SENSOR_ALIGNMENT.gyro_2_align); + + $('.gyro_alignment_inputs_first').toggle(detected_gyro_1); + $('.gyro_alignment_inputs_second').toggle(detected_gyro_2); + $('.gyro_alignment_inputs_selection').toggle(detected_gyro_1 || detected_gyro_2); + $('.gyro_alignment_inputs_notfound').toggle(!detected_gyro_1 && !detected_gyro_2); + + orientation_gyro_1_align_e.change(function () { + let value = parseInt($(this).val()); + + let newValue = undefined; + if (value !== FC.SENSOR_ALIGNMENT.gyro_1_align) { + newValue = $(this).find('option:selected').text(); + } + self.analyticsChanges['Gyro1Alignment'] = newValue; + + FC.SENSOR_ALIGNMENT.gyro_1_align = value; + }); + + orientation_gyro_2_align_e.change(function () { + let value = parseInt($(this).val()); + + let newValue = undefined; + if (value !== FC.SENSOR_ALIGNMENT.gyro_2_align) { + newValue = $(this).find('option:selected').text(); + } + self.analyticsChanges['Gyro2Alignment'] = newValue; + + FC.SENSOR_ALIGNMENT.gyro_2_align = value; + }); + // Gyro and PID update - const gyroUse32kHzElement = $('input[id="gyroUse32kHz"]'); const gyroTextElement = $('input.gyroFrequency'); const gyroSelectElement = $('select.gyroSyncDenom'); const pidSelectElement = $('select.pidProcessDenom'); @@ -288,7 +251,7 @@ configuration.initialize = function (callback) { gyroSelectElement.empty(); - const MAX_DENOM = semver.gte(FC.CONFIG.apiVersion, "1.25.0") && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41) ? 32 : 8; + const MAX_DENOM = 8; for (let denom = 1; denom <= MAX_DENOM; denom++) { addDenomOption(gyroSelectElement, denom, gyroBaseFreq); @@ -311,24 +274,12 @@ configuration.initialize = function (callback) { gyroTextElement.val(gyroContent); }; - if (semver.gte(FC.CONFIG.apiVersion, "1.25.0") && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - gyroUse32kHzElement.prop('checked', FC.PID_ADVANCED_CONFIG.gyroUse32kHz !== 0); + $('div.gyroUse32kHz').hide(); - gyroUse32kHzElement.change(function () { - const gyroBaseFreq = ($(this).is(':checked'))? 32 : 8; - - updateGyroDenom(gyroBaseFreq); - }).change(); - - } else { - - $('div.gyroUse32kHz').hide(); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - updateGyroDenomReadOnly(FC.CONFIG.sampleRateHz); - } else { - updateGyroDenom(8); - } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { + updateGyroDenomReadOnly(FC.CONFIG.sampleRateHz); + } else { + updateGyroDenom(8); } gyroSelectElement.val(FC.PID_ADVANCED_CONFIG.gyro_sync_denom); @@ -343,15 +294,12 @@ configuration.initialize = function (callback) { pidBaseFreq = FC.CONFIG.sampleRateHz / 1000; } else { pidBaseFreq = 8; - if (semver.gte(FC.CONFIG.apiVersion, "1.25.0") && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41) && gyroUse32kHzElement.is(':checked')) { - pidBaseFreq = 32; - } - pidBaseFreq = pidBaseFreq / parseInt($(this).val()); + pidBaseFreq /= parseInt($(this).val()); } pidSelectElement.empty(); - const MAX_DENOM = semver.gte(FC.CONFIG.apiVersion, "1.24.0") ? 16 : 8; + const MAX_DENOM = 8; for (let denom = 1; denom <= MAX_DENOM; denom++) { addDenomOption(pidSelectElement, denom, pidBaseFreq); @@ -367,14 +315,6 @@ configuration.initialize = function (callback) { $('input[id="magHardwareSwitch"]').prop('checked', FC.SENSOR_CONFIG.mag_hardware !== 1); // Only show these sections for supported FW - if (semver.lt(FC.CONFIG.apiVersion, "1.16.0")) { - $('.selectPidProcessDenom').hide(); - } - - if (semver.lt(FC.CONFIG.apiVersion, "1.16.0")) { - $('.hardwareSelection').hide(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { $('input[name="craftName"]').val(FC.CONFIG.craftName); $('input[name="pilotName"]').val(FC.CONFIG.pilotName); @@ -383,27 +323,15 @@ configuration.initialize = function (callback) { $('.pilotName').hide(); } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) { - $('input[name="fpvCamAngleDegrees"]').val(FC.RX_CONFIG.fpvCamAngleDegrees); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - $('input[name="fpvCamAngleDegrees"]').attr("max", 90); - } - } else { - $('div.fpvCamAngleDegrees').hide(); - } - - if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { - $('.miscSettings').hide(); - } + $('input[name="fpvCamAngleDegrees"]').val(FC.RX_CONFIG.fpvCamAngleDegrees); + $('input[name="fpvCamAngleDegrees"]').attr("max", 90); // generate GPS const gpsProtocols = [ 'NMEA', 'UBLOX', + 'MSP', ]; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - gpsProtocols.push('MSP'); - } const gpsBaudRates = [ '115200', @@ -464,13 +392,8 @@ configuration.initialize = function (callback) { }).prop('checked', FC.GPS_CONFIG.auto_config === 1).change(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_34)) { - gpsAutoBaudGroup.show(); - gpsAutoConfigGroup.show(); - } else { - gpsAutoBaudGroup.hide(); - gpsAutoConfigGroup.hide(); - } + gpsAutoBaudGroup.show(); + gpsAutoConfigGroup.show(); gpsUbloxGalileoElement.change(function() { FC.GPS_CONFIG.ublox_use_galileo = $(this).is(':checked') ? 1 : 0; @@ -493,15 +416,8 @@ configuration.initialize = function (callback) { gpsBaudrateElement.append(``); } - if (semver.lt(FC.CONFIG.apiVersion, "1.6.0")) { - gpsBaudrateElement.change(function () { - FC.SERIAL_CONFIG.gpsBaudRate = parseInt($(this).val()); - }); - gpsBaudrateElement.val(FC.SERIAL_CONFIG.gpsBaudRate); - } else { - gpsBaudrateElement.prop("disabled", true); - gpsBaudrateElement.parent().hide(); - } + gpsBaudrateElement.prop("disabled", true); + gpsBaudrateElement.parent().hide(); // fill board alignment $('input[name="board_align_roll"]').val(FC.BOARD_ALIGNMENT_CONFIG.roll); @@ -512,10 +428,8 @@ configuration.initialize = function (callback) { $('input[name="roll"]').val(FC.CONFIG.accelerometerTrims[1]); $('input[name="pitch"]').val(FC.CONFIG.accelerometerTrims[0]); - $('._smallAngle').toggle(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)); - if(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - $('input[id="configurationSmallAngle"]').val(FC.ARMING_CONFIG.small_angle); - } + $('._smallAngle').show(); + $('input[id="configurationSmallAngle"]').val(FC.ARMING_CONFIG.small_angle); // UI hooks @@ -539,10 +453,8 @@ configuration.initialize = function (callback) { }); $('input[id="accHardwareSwitch"]').change(function() { - if(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - const checked = $(this).is(':checked'); - $('.accelNeeded').toggle(checked); - } + const checked = $(this).is(':checked'); + $('.accelNeeded').toggle(checked); }).change(); $(features_e).filter('select').change(function () { @@ -569,13 +481,9 @@ configuration.initialize = function (callback) { FC.CONFIG.accelerometerTrims[0] = parseInt($('input[name="pitch"]').val()); // small angle configuration - if(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - FC.ARMING_CONFIG.small_angle = parseInt($('input[id="configurationSmallAngle"]').val()); - } + FC.ARMING_CONFIG.small_angle = parseInt($('input[id="configurationSmallAngle"]').val()); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.SENSOR_ALIGNMENT.gyro_to_use = parseInt(orientation_gyro_to_use_e.val()); - } + FC.SENSOR_ALIGNMENT.gyro_to_use = parseInt(orientation_gyro_to_use_e.val()); FC.PID_ADVANCED_CONFIG.gyro_sync_denom = parseInt(gyroSelectElement.val()); @@ -589,9 +497,6 @@ configuration.initialize = function (callback) { } FC.PID_ADVANCED_CONFIG.pid_process_denom = value; - if (semver.gte(FC.CONFIG.apiVersion, "1.25.0") && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.PID_ADVANCED_CONFIG.gyroUse32kHz = $('input[id="gyroUse32kHz"]').is(':checked') ? 1 : 0; - } FC.RX_CONFIG.fpvCamAngleDegrees = parseInt($('input[name="fpvCamAngleDegrees"]').val()); @@ -599,10 +504,8 @@ configuration.initialize = function (callback) { self.analyticsChanges = {}; // fill some data - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_34)) { - FC.GPS_CONFIG.auto_baud = $('input[name="gps_auto_baud"]').is(':checked') ? 1 : 0; - FC.GPS_CONFIG.auto_config = $('input[name="gps_auto_config"]').is(':checked') ? 1 : 0; - } + FC.GPS_CONFIG.auto_baud = $('input[name="gps_auto_baud"]').is(':checked') ? 1 : 0; + FC.GPS_CONFIG.auto_config = $('input[name="gps_auto_config"]').is(':checked') ? 1 : 0; FC.SENSOR_CONFIG.acc_hardware = $('input[id="accHardwareSwitch"]').is(':checked') ? 0 : 1; FC.SENSOR_CONFIG.baro_hardware = $('input[id="baroHardwareSwitch"]').is(':checked') ? 0 : 1; @@ -621,28 +524,24 @@ configuration.initialize = function (callback) { function save_config() { Promise .resolve(true) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_FEATURE_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FEATURE_CONFIG)); }) - .then(() => { return (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) ? - MSP.promise(MSPCodes.MSP_SET_BEEPER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_BEEPER_CONFIG)) : true; }) - .then(() => { return (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_33)) ? - MSP.promise(MSPCodes.MSP_SET_MISC, mspHelper.crunch(MSPCodes.MSP_SET_MISC)) : true; }) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_BOARD_ALIGNMENT_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_BOARD_ALIGNMENT_CONFIG)); }) - .then(() => { return (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33)) ? - MSP.promise(MSPCodes.MSP_SET_GPS_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_GPS_CONFIG)) : true; }) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_RC_DEADBAND, mspHelper.crunch(MSPCodes.MSP_SET_RC_DEADBAND)); }) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_SENSOR_ALIGNMENT, mspHelper.crunch(MSPCodes.MSP_SET_SENSOR_ALIGNMENT)); }) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_ADVANCED_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_ADVANCED_CONFIG)); }) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_ACC_TRIM, mspHelper.crunch(MSPCodes.MSP_SET_ACC_TRIM)); }) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_ARMING_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_ARMING_CONFIG)); }) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_SENSOR_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_SENSOR_CONFIG)); }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) + .then(() => MSP.promise(MSPCodes.MSP_SET_FEATURE_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FEATURE_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_SET_BEEPER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_BEEPER_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_SET_BOARD_ALIGNMENT_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_BOARD_ALIGNMENT_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_SET_GPS_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_GPS_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_SET_RC_DEADBAND, mspHelper.crunch(MSPCodes.MSP_SET_RC_DEADBAND))) + .then(() => MSP.promise(MSPCodes.MSP_SET_SENSOR_ALIGNMENT, mspHelper.crunch(MSPCodes.MSP_SET_SENSOR_ALIGNMENT))) + .then(() => MSP.promise(MSPCodes.MSP_SET_ADVANCED_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_ADVANCED_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_SET_ACC_TRIM, mspHelper.crunch(MSPCodes.MSP_SET_ACC_TRIM))) + .then(() => MSP.promise(MSPCodes.MSP_SET_ARMING_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_ARMING_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_SET_SENSOR_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_SENSOR_CONFIG))) + .then(() => semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) ? MSP.promise(MSPCodes.MSP2_SET_TEXT, mspHelper.crunch(MSPCodes.MSP2_SET_TEXT, MSPCodes.CRAFT_NAME)) - : MSP.promise(MSPCodes.MSP_SET_NAME, mspHelper.crunch(MSPCodes.MSP_SET_NAME)); }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) ? - MSP.promise(MSPCodes.MSP2_SET_TEXT, mspHelper.crunch(MSPCodes.MSP2_SET_TEXT, MSPCodes.PILOT_NAME)) : Promise.resolve(true); }) - .then(() => { return (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) ? MSP.promise(MSPCodes.MSP_SET_RX_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_RX_CONFIG)) : true; }) - .then(() => { return MSP.promise(MSPCodes.MSP_EEPROM_WRITE); }) - .then(() => { reboot(); }); + : MSP.promise(MSPCodes.MSP_SET_NAME, mspHelper.crunch(MSPCodes.MSP_SET_NAME))) + .then(() => semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) ? + MSP.promise(MSPCodes.MSP2_SET_TEXT, mspHelper.crunch(MSPCodes.MSP2_SET_TEXT, MSPCodes.PILOT_NAME)) : Promise.resolve(true)) + .then(() => MSP.promise(MSPCodes.MSP_SET_RX_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_RX_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_EEPROM_WRITE)) + .then(() => reboot()); } function reboot() { diff --git a/src/js/tabs/failsafe.js b/src/js/tabs/failsafe.js index 3952f003..02e5f41b 100644 --- a/src/js/tabs/failsafe.js +++ b/src/js/tabs/failsafe.js @@ -17,8 +17,7 @@ failsafe.initialize = function (callback) { } function load_rxfail_config() { - MSP.send_message(MSPCodes.MSP_RXFAIL_CONFIG, false, false, - semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41) ? load_gps_rescue : get_box_names); + MSP.send_message(MSPCodes.MSP_RXFAIL_CONFIG, false, false, load_gps_rescue); } function load_gps_rescue() { @@ -134,37 +133,21 @@ failsafe.initialize = function (callback) { for (let i = 0; i < FC.RXFAIL_CONFIG.length; i++) { if (i < channelNames.length) { - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - fullChannels_e.append(`\ -
" }, - - "backupFileIncompatible": { - "message": "Backup file provided was generated for previous version of the configurator and is incompatible with this version of configurator. Sorry" - }, - - "backupFileUnmigratable": { - "message": "Backup file provided was generated by a previous version of the configurator and is not migratable. Sorry." - }, - - "configMigrationFrom": { - "message": "Migrating configuration file generated by configurator: $1" - }, - "configMigratedTo": { - "message": "Migrated configuration to configurator: $1" - }, - "configMigrationSuccessful": { - "message": "Configuration migration complete, migrations applied: $1" - }, - "tabFirmwareFlasher": { "message": "Firmware Flasher" }, @@ -768,10 +749,6 @@ "defaultSupport5": { "message": "