Skip to content

Commit 9bd2927

Browse files
authored
Enable servo tab for WING define (#4635)
* Enable servo tab for WING define * Per review sonar
1 parent 3947308 commit 9bd2927

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

src/js/serial_backend.js

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,18 @@ function connectDisconnect() {
110110

111111
GUI.configuration_loaded = false;
112112

113-
if (!isConnected) {
113+
if (isConnected) {
114+
// If connected, start disconnection sequence
115+
GUI.timeout_kill_all();
116+
GUI.interval_kill_all();
117+
GUI.tab_switch_cleanup(() => (GUI.tab_switch_in_progress = false));
118+
119+
function onFinishCallback() {
120+
finishClose(toggleStatus);
121+
}
122+
123+
mspHelper?.setArmingEnabled(true, false, onFinishCallback);
124+
} else {
114125
// prevent connection when we do not have permission
115126
if (selectedPort.startsWith("requestpermission")) {
116127
return;
@@ -145,17 +156,6 @@ function connectDisconnect() {
145156
{ baudRate: PortHandler.portPicker.selectedBauds },
146157
selectedPort === "virtual" ? onOpenVirtual : undefined,
147158
);
148-
} else {
149-
// If connected, start disconnection sequence
150-
GUI.timeout_kill_all();
151-
GUI.interval_kill_all();
152-
GUI.tab_switch_cleanup(() => (GUI.tab_switch_in_progress = false));
153-
154-
function onFinishCallback() {
155-
finishClose(toggleStatus);
156-
}
157-
158-
mspHelper?.setArmingEnabled(true, false, onFinishCallback);
159159
}
160160

161161
// show CLI panel on Control+I
@@ -395,8 +395,8 @@ function onOpenVirtual() {
395395
// Set connection timestamp for virtual connections
396396
connectionTimestamp = Date.now();
397397
setTimeout(() => {
398-
if (window.vm?.CONNECTION) {
399-
window.vm.CONNECTION.timestamp = connectionTimestamp;
398+
if (globalThis.vm?.CONNECTION) {
399+
globalThis.vm.CONNECTION.timestamp = connectionTimestamp;
400400
}
401401
}, 100);
402402

@@ -460,17 +460,17 @@ function processBoardInfo() {
460460
}
461461
}
462462

463+
function checkReportProblem(problemName, problems) {
464+
if (bit_check(FC.CONFIG.configurationProblems, FC.CONFIGURATION_PROBLEM_FLAGS[problemName])) {
465+
problems.push({ name: problemName, description: i18n.getMessage(`reportProblemsDialog${problemName}`) });
466+
return true;
467+
}
468+
return false;
469+
}
470+
463471
function checkReportProblems() {
464472
const problemItemTemplate = $("#dialogReportProblems-listItemTemplate");
465473

466-
function checkReportProblem(problemName, problems) {
467-
if (bit_check(FC.CONFIG.configurationProblems, FC.CONFIGURATION_PROBLEM_FLAGS[problemName])) {
468-
problems.push({ name: problemName, description: i18n.getMessage(`reportProblemsDialog${problemName}`) });
469-
return true;
470-
}
471-
return false;
472-
}
473-
474474
MSP.send_message(MSPCodes.MSP_STATUS, false, false, function () {
475475
let needsProblemReportingDialog = false;
476476
const problemDialogList = $("#dialogReportProblems-list");
@@ -509,9 +509,9 @@ function checkReportProblems() {
509509
}
510510

511511
if (needsProblemReportingDialog) {
512-
problems.forEach((problem) => {
512+
for (const problem of problems) {
513513
problemItemTemplate.clone().html(problem.description).appendTo(problemDialogList);
514-
});
514+
}
515515

516516
const problemDialog = $("#dialogReportProblems")[0];
517517
$("#dialogReportProblems-closebtn").click(function () {
@@ -564,8 +564,8 @@ async function processUid() {
564564
// Update the global CONNECTION object for Vue components
565565
// Use a small delay to ensure the Vue app is mounted
566566
setTimeout(() => {
567-
if (window.vm?.CONNECTION) {
568-
window.vm.CONNECTION.timestamp = connectionTimestamp;
567+
if (globalThis.vm?.CONNECTION) {
568+
globalThis.vm.CONNECTION.timestamp = connectionTimestamp;
569569
}
570570
}, 100);
571571

@@ -617,6 +617,11 @@ function finishOpen() {
617617
GUI.allowedTabs.push(tab);
618618
}
619619
}
620+
621+
// Special case: USE_WING includes servo functionality but doesn't expose USE_SERVOS in build options
622+
if (FC.CONFIG.buildOptions.some((opt) => opt.includes("USE_WING")) && !GUI.allowedTabs.includes("servos")) {
623+
GUI.allowedTabs.push("servos");
624+
}
620625
} else {
621626
GUI.allowedTabs = Array.from(GUI.defaultAllowedFCTabsWhenConnected);
622627
}
@@ -665,7 +670,7 @@ function onConnect() {
665670
});
666671

667672
if (FC.CONFIG.boardType == 0) {
668-
if (classes.indexOf("osd-required") >= 0) {
673+
if (classes.includes("osd-required")) {
669674
found = false;
670675
}
671676
}
@@ -704,8 +709,8 @@ function onClosed(result) {
704709
// Clear connection timestamp
705710
connectionTimestamp = null;
706711
setTimeout(() => {
707-
if (window.vm?.CONNECTION) {
708-
window.vm.CONNECTION.timestamp = null;
712+
if (globalThis.vm?.CONNECTION) {
713+
globalThis.vm.CONNECTION.timestamp = null;
709714
}
710715
}, 100);
711716

src/js/utils/updateTabList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function updateTabList(features) {
99
$("#tabs ul.mode-connected li.tab_sensors").toggle(isExpertModeEnabled);
1010
$("#tabs ul.mode-connected li.tab_logging").toggle(isExpertModeEnabled);
1111
$("#tabs ul.mode-connected li.tab_servos").toggle(
12-
isExpertModeEnabled && FC.CONFIG?.buildOptions?.includes("USE_SERVOS"),
12+
["USE_SERVOS", "USE_WING"].some((option) => FC.CONFIG?.buildOptions?.includes(option)),
1313
);
1414

1515
$("#tabs ul.mode-connected li.tab_gps").toggle(FC.CONFIG?.buildOptions?.includes("USE_GPS"));

0 commit comments

Comments
 (0)