Skip to content

Commit da27f22

Browse files
Cleanup serial (#4670)
* Cleanup serial * CR review * Revert non working CR suggestion :( * Some Sonar * CR review II * CR review III * Sonar II * Fix setMask intermittent race condition * Fix more * Coderabbitai fix (protocolType is a getter, not a method) Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Improve error message * CR nitpick * CR suggestion * Revert CR suggestion :( * Rename protocolType getter * Nitpicks * Update CR previous suggestion --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 292093a commit da27f22

File tree

6 files changed

+87
-287
lines changed

6 files changed

+87
-287
lines changed

src/js/main.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import "./jqueryPlugins";
22
import $ from "jquery";
33
import "../components/init.js";
44
import { gui_log } from "./gui_log.js";
5-
// same, msp seems to be everywhere used from global scope
6-
import "./msp/MSPHelper.js";
75
import { i18n } from "./localization.js";
86
import GUI, { TABS } from "./gui.js";
97
import { get as getConfig, set as setConfig } from "./ConfigStorage.js";
@@ -184,13 +182,18 @@ function startProcess() {
184182
return;
185183
}
186184

187-
if (GUI.allowedTabs.indexOf(tab) < 0 && tab === "firmware_flasher") {
188-
if (GUI.connected_to || GUI.connecting_to) {
189-
$("a.connection_button__link").click();
185+
if (!GUI.allowedTabs.includes(tab)) {
186+
if (tab === "firmware_flasher") {
187+
// Special handling for firmware flasher tab
188+
if (GUI.connected_to || GUI.connecting_to) {
189+
$("a.connection_button__link").trigger("click");
190+
}
191+
// This line is required but it triggers opening the firmware flasher tab again
192+
$("a.firmware_flasher_button__link").trigger("click");
193+
} else {
194+
gui_log(i18n.getMessage("tabSwitchUpgradeRequired", [tabName]));
195+
return;
190196
}
191-
} else if (GUI.allowedTabs.indexOf(tab) < 0) {
192-
gui_log(i18n.getMessage("tabSwitchUpgradeRequired", [tabName]));
193-
return;
194197
}
195198

196199
GUI.tab_switch_in_progress = true;

src/js/msp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ const MSP = {
263263
if (this.message_checksum === expectedChecksum) {
264264
// message received, store dataview
265265
this.dataView = new DataView(this.message_buffer, 0, this.message_length_expected);
266-
} else if (serial._webBluetooth.shouldBypassCrc(expectedChecksum)) {
266+
} else if (serial.protocol === "bluetooth" && serial._protocol?.shouldBypassCrc?.(expectedChecksum)) {
267267
this.dataView = new DataView(this.message_buffer, 0, this.message_length_expected);
268268
this.crcError = false; // Override the CRC error for this specific case
269269
} else {

src/js/protocols/WebSerial.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,6 @@ class WebSerial extends EventTarget {
378378
return { bytesSent: 0 };
379379
}
380380
}
381-
382-
/**
383-
* Clean up resources when the protocol is no longer needed
384-
*/
385-
cleanup() {
386-
if (this.connected) {
387-
this.disconnect();
388-
}
389-
}
390381
}
391382

392383
// Export the class itself, not an instance

0 commit comments

Comments
 (0)