Skip to content

Commit e8841f9

Browse files
authored
Reduce confusion selecting VTX (#4489)
1 parent b361b00 commit e8841f9

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

src/js/tabs/ports.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,15 @@ ports.initialize = function (callback) {
258258
selectElement = functionsElement.find(selectElementSelector);
259259
selectElement.append(`<option value="">${disabledText}</option>`);
260260
}
261-
const isDisabled = FC.CONFIG.buildOptions.length && functionRule.dependsOn !== undefined && !FC.CONFIG.buildOptions.includes(functionRule.dependsOn) ? "disabled" : "";
262-
selectElement.append(`<option value="${functionName}" ${isDisabled}>${functionRule.displayName}</option>`);
261+
const isDisabled =
262+
FC.CONFIG.buildOptions.length &&
263+
functionRule.dependsOn !== undefined &&
264+
!FC.CONFIG.buildOptions.includes(functionRule.dependsOn)
265+
? "disabled"
266+
: "";
267+
selectElement.append(
268+
`<option value="${functionName}" ${isDisabled}>${functionRule.displayName}</option>`,
269+
);
263270
// sort telemetry, sensors, peripherals select elements. disabledText on top
264271
selectElement.sortSelect(disabledText);
265272

@@ -304,47 +311,44 @@ ports.initialize = function (callback) {
304311
FC.VTX_CONFIG.vtx_table_channels === 0 ||
305312
FC.VTX_CONFIG.vtx_table_powerlevels === 0);
306313

307-
const pheripheralsSelectElement = $('select[name="function-peripherals"]');
308-
pheripheralsSelectElement.on("change", function () {
314+
const peripheralsSelectElement = $('select[name="function-peripherals"]');
315+
316+
peripheralsSelectElement.on("change", function () {
309317
let vtxControlSelected, mspControlSelected;
310318

311-
pheripheralsSelectElement.each(function (index, element) {
312-
const value = $(element).val();
319+
// Handle each port's peripheral selection
320+
peripheralsSelectElement.each(function (portIndex, element) {
321+
const selectedFunction = $(element).val();
322+
const mspCheckbox = $(`#functionCheckbox-${portIndex}-0-0`);
313323

314-
if (value === "TBS_SMARTAUDIO" || value === "IRC_TRAMP") {
315-
vtxControlSelected = value;
324+
// Handle VTX control protocols (SmartAudio/Tramp)
325+
if (selectedFunction === "TBS_SMARTAUDIO" || selectedFunction === "IRC_TRAMP") {
326+
vtxControlSelected = selectedFunction;
327+
mspCheckbox.prop("checked", false).trigger("change");
316328
}
317329

318-
if (value.includes("MSP")) {
319-
mspControlSelected = value;
320-
321-
// Enable MSP Configuration for MSP function
322-
$(".tab-ports .portConfiguration").each(function (port, portConfig) {
323-
const peripheralFunction = $(portConfig).find("select[name=function-peripherals]").val();
324-
325-
if (peripheralFunction.includes("MSP") && index === port) {
326-
$(`#functionCheckbox-${port}-0-0`).prop("checked", true).trigger("change");
327-
}
328-
});
330+
// Handle MSP-based peripheral functions
331+
if (selectedFunction.includes("MSP")) {
332+
mspControlSelected = selectedFunction;
333+
mspCheckbox.prop("checked", true).trigger("change");
329334
}
330335
});
331336

337+
// Update analytics and UI elements
332338
if (lastVtxControlSelected !== vtxControlSelected) {
333339
self.analyticsChanges["VtxControl"] = vtxControlSelected;
334-
335340
lastVtxControlSelected = vtxControlSelected;
336341
}
337342

338343
if (lastMspSelected !== mspControlSelected) {
339344
self.analyticsChanges["MspControl"] = mspControlSelected;
340-
341345
lastMspSelected = mspControlSelected;
342346
}
343347

344348
$(".vtxTableNotSet").toggle(vtxControlSelected && vtxTableNotConfigured);
345349
});
346350

347-
pheripheralsSelectElement.trigger("change");
351+
peripheralsSelectElement.trigger("change");
348352
}
349353

350354
function on_tab_loaded_handler() {

0 commit comments

Comments
 (0)