1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-26 01:35:28 +03:00

Merge pull request #3061 from haslinghuis/enforce-msp

Enable MSP configuration on MSP peripherals
This commit is contained in:
ctzsnooze 2022-10-31 20:38:09 +11:00 committed by GitHub
commit 35ca9fc2aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,7 +17,7 @@ ports.initialize = function (callback) {
{ name: 'TELEMETRY_HOTT', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['peripherals'], maxPorts: 1 }, { name: 'TELEMETRY_HOTT', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['peripherals'], maxPorts: 1 },
{ name: 'TELEMETRY_SMARTPORT', groups: ['telemetry'], maxPorts: 1 }, { name: 'TELEMETRY_SMARTPORT', groups: ['telemetry'], maxPorts: 1 },
{ name: 'RX_SERIAL', groups: ['rx'], maxPorts: 1 }, { name: 'RX_SERIAL', groups: ['rx'], maxPorts: 1 },
{ name: 'BLACKBOX', groups: ['peripherals'], sharableWith: ['msp'], notSharableWith: ['telemetry'], maxPorts: 1 }, { name: 'BLACKBOX', groups: ['peripherals'], sharableWith: ['msp'], notSharableWith: ['telemetry'], maxPorts: 1 },
]; ];
if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) {
@ -33,15 +33,15 @@ ports.initialize = function (callback) {
functionRules.push(mavlinkFunctionRule); functionRules.push(mavlinkFunctionRule);
} }
if (semver.gte(FC.CONFIG.apiVersion, "1.27.0")) {
functionRules.push({ name: 'IRC_TRAMP', groups: ['peripherals'], maxPorts: 1 });
}
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) { if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) {
functionRules.push({ name: 'ESC_SENSOR', groups: ['sensors'], maxPorts: 1 }); functionRules.push({ name: 'ESC_SENSOR', groups: ['sensors'], maxPorts: 1 });
functionRules.push({ name: 'TBS_SMARTAUDIO', groups: ['peripherals'], maxPorts: 1 }); functionRules.push({ name: 'TBS_SMARTAUDIO', groups: ['peripherals'], maxPorts: 1 });
} }
if (semver.gte(FC.CONFIG.apiVersion, "1.27.0")) {
functionRules.push({ name: 'IRC_TRAMP', groups: ['peripherals'], maxPorts: 1 });
}
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_32)) { if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_32)) {
functionRules.push({ name: 'TELEMETRY_IBUS', groups: ['telemetry'], maxPorts: 1 }); functionRules.push({ name: 'TELEMETRY_IBUS', groups: ['telemetry'], maxPorts: 1 });
} }
@ -59,11 +59,8 @@ ports.initialize = function (callback) {
} }
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
functionRules.push({ name: 'VTX_MSP', groups: ['peripherals'], maxPorts: 1 }); functionRules.push({ name: 'VTX_MSP', groups: ['peripherals'], sharableWith: ['msp'], maxPorts: 1 });
} functionRules.push({ name: 'MSP_DISPLAYPORT', groups: ['peripherals'], sharableWith: ['msp'], maxPorts: 1 });
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
functionRules.push({ name: 'MSP_DISPLAYPORT', groups: ['peripherals'], maxPorts: 1 });
} }
for (const rule of functionRules) { for (const rule of functionRules) {
@ -117,15 +114,13 @@ ports.initialize = function (callback) {
const columns = ['configuration', 'peripherals', 'sensors', 'telemetry', 'rx']; const columns = ['configuration', 'peripherals', 'sensors', 'telemetry', 'rx'];
if (GUI.active_tab != 'ports') { GUI.active_tab = 'ports';
GUI.active_tab = 'ports';
}
load_configuration_from_fc(); load_configuration_from_fc();
function load_configuration_from_fc() { function load_configuration_from_fc() {
let promise; let promise;
if(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) {
promise = MSP.promise(MSPCodes.MSP_VTX_CONFIG); promise = MSP.promise(MSPCodes.MSP_VTX_CONFIG);
} else { } else {
promise = Promise.resolve(); promise = Promise.resolve();
@ -193,6 +188,8 @@ ports.initialize = function (callback) {
} }
let lastVtxControlSelected; let lastVtxControlSelected;
let lastMspSelected;
const portsElement = $('.tab-ports .ports'); const portsElement = $('.tab-ports .ports');
const portIdentifierTemplateElement = $('#tab-ports-templates .portIdentifier'); const portIdentifierTemplateElement = $('#tab-ports-templates .portIdentifier');
const portConfigurationTemplateElement = $('#tab-ports-templates .portConfiguration'); const portConfigurationTemplateElement = $('#tab-ports-templates .portConfiguration');
@ -234,7 +231,6 @@ ports.initialize = function (callback) {
portConfigurationElement.data('index', portIndex); portConfigurationElement.data('index', portIndex);
portConfigurationElement.data('port', serialPort); portConfigurationElement.data('port', serialPort);
for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) { for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
const column = columns[columnIndex]; const column = columns[columnIndex];
@ -285,11 +281,15 @@ ports.initialize = function (callback) {
if (column === 'peripherals' && (functionName === "TBS_SMARTAUDIO" || functionName === "IRC_TRAMP")) { if (column === 'peripherals' && (functionName === "TBS_SMARTAUDIO" || functionName === "IRC_TRAMP")) {
lastVtxControlSelected = functionName; lastVtxControlSelected = functionName;
} }
if (column === 'peripherals' && functionName.includes("MSP")) {
lastMspSelected = functionName;
}
} }
if (column === 'telemetry') { if (column === 'telemetry') {
const initialValue = functionName; const initialValue = functionName;
selectElement.change(function () { selectElement.on('change', function () {
const telemetryValue = $(this).val(); const telemetryValue = $(this).val();
let newValue; let newValue;
@ -318,12 +318,28 @@ ports.initialize = function (callback) {
} }
const pheripheralsSelectElement = $('select[name="function-peripherals"]'); const pheripheralsSelectElement = $('select[name="function-peripherals"]');
pheripheralsSelectElement.change(function() { pheripheralsSelectElement.on('change', function() {
let vtxControlSelected = undefined; let vtxControlSelected = undefined;
pheripheralsSelectElement.each(function() { let mspControlSelected = undefined;
const el = $(this);
if (el.val() === "TBS_SMARTAUDIO" || el.val() === "IRC_TRAMP") { pheripheralsSelectElement.each(function(index, element) {
vtxControlSelected = el.val(); const value = $(element).val();
if (value === "TBS_SMARTAUDIO" || value === "IRC_TRAMP") {
vtxControlSelected = value;
}
if (value.includes("MSP")) {
mspControlSelected = value;
// Enable MSP Configuration for MSP function
$('.tab-ports .portConfiguration').each(function (port, portConfig) {
const peripheralFunction = $(portConfig).find('select[name=function-peripherals]').val();
if (peripheralFunction.includes("MSP") && index === port) {
$(`#functionCheckbox-${port}-0-0`).prop("checked", true).trigger('change');
}
});
} }
}); });
@ -333,15 +349,18 @@ ports.initialize = function (callback) {
lastVtxControlSelected = vtxControlSelected; lastVtxControlSelected = vtxControlSelected;
} }
if (lastMspSelected !== mspControlSelected) {
self.analyticsChanges['MspControl'] = mspControlSelected;
lastMspSelected = mspControlSelected;
}
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) {
if (vtxControlSelected && vtxTableNotConfigured) { $('.vtxTableNotSet').toggle(vtxControlSelected && vtxTableNotConfigured);
$('.vtxTableNotSet').show();
} else {
$('.vtxTableNotSet').hide();
}
} }
}); });
pheripheralsSelectElement.change();
pheripheralsSelectElement.trigger('change');
} }
function on_tab_loaded_handler() { function on_tab_loaded_handler() {
@ -350,7 +369,7 @@ ports.initialize = function (callback) {
update_ui(); update_ui();
$('a.save').click(on_save_handler); $('a.save').on('click', on_save_handler);
// status data pulled via separate timer with static speed // status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function status_pull() { GUI.interval_add('status_pull', function status_pull() {
@ -362,7 +381,7 @@ ports.initialize = function (callback) {
function on_save_handler() { function on_save_handler() {
analytics.sendSaveAndChangeEvents(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'ports'); analytics.sendSaveAndChangeEvents(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'ports');
self.analyticsChanges = {}; self.analyticsChanges = {};
// update configuration based on current ui state // update configuration based on current ui state
FC.SERIAL_CONFIG.ports = []; FC.SERIAL_CONFIG.ports = [];