Skip to content

Commit 3873dff

Browse files
committed
cleanup
1 parent 1ff56c4 commit 3873dff

File tree

4 files changed

+8
-47
lines changed

4 files changed

+8
-47
lines changed

src/js/data_storage.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ const CONFIGURATOR = {
1111

1212
connectionValid: false,
1313
connectionValidCliOnly: false,
14-
bluetoothMode: false,
15-
manualMode: false,
1614
virtualMode: false,
1715
virtualApiVersion: "0.0.1",
1816
cliActive: false,

src/js/protocols/WebSerial.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { webSerialDevices, vendorIdNames } from "./devices";
22
import GUI from "../gui";
33

4-
const logHead = "[SERIAL]";
4+
const logHead = "[WEBSERIAL]";
55

66
async function* streamAsyncIterable(reader, keepReadingFlag) {
77
try {

src/js/serial.js

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ class Serial extends EventTarget {
3030
virtual: this._virtual,
3131
};
3232

33-
// Initialize with default protocol
34-
this.selectProtocol(false);
35-
3633
// Forward events from all protocols to the Serial class
3734
this._setupEventForwarding();
3835
}
@@ -114,59 +111,28 @@ class Serial extends EventTarget {
114111
}
115112

116113
/**
117-
* Selects the appropriate protocol based on port path or CONFIGURATOR settings
114+
* Selects the appropriate protocol based on port path
118115
* @param {string|null} portPath - Optional port path to determine protocol
119116
* @param {boolean} forceDisconnect - Whether to force disconnect from current protocol
120117
*/
121118
selectProtocol(portPath = null, forceDisconnect = true) {
122-
// Determine which protocol to use based on port path first, then fall back to CONFIGURATOR
119+
// Determine which protocol to use based on port path
123120
let newProtocol;
124121

125122
if (portPath) {
126123
// Select protocol based on port path
127124
if (portPath === "virtual") {
128125
console.log(`${this.logHead} Using virtual protocol (based on port path)`);
129126
newProtocol = this._virtual;
130-
// Update CONFIGURATOR flags for consistency
131-
CONFIGURATOR.virtualMode = true;
132-
CONFIGURATOR.bluetoothMode = false;
133-
CONFIGURATOR.manualMode = false;
134127
} else if (portPath === "manual") {
135128
console.log(`${this.logHead} Using websocket protocol (based on port path)`);
136129
newProtocol = this._websocket;
137-
// Update CONFIGURATOR flags for consistency
138-
CONFIGURATOR.virtualMode = false;
139-
CONFIGURATOR.bluetoothMode = false;
140-
CONFIGURATOR.manualMode = true;
141130
} else if (portPath.startsWith("bluetooth")) {
142131
console.log(`${this.logHead} Using bluetooth protocol (based on port path: ${portPath})`);
143132
newProtocol = this._bluetooth;
144-
// Update CONFIGURATOR flags for consistency
145-
CONFIGURATOR.virtualMode = false;
146-
CONFIGURATOR.bluetoothMode = true;
147-
CONFIGURATOR.manualMode = false;
148133
} else {
149134
console.log(`${this.logHead} Using web serial protocol (based on port path: ${portPath})`);
150135
newProtocol = this._webSerial;
151-
// Update CONFIGURATOR flags for consistency
152-
CONFIGURATOR.virtualMode = false;
153-
CONFIGURATOR.bluetoothMode = false;
154-
CONFIGURATOR.manualMode = false;
155-
}
156-
} else {
157-
// Fall back to CONFIGURATOR flags if no port path is provided
158-
if (CONFIGURATOR.virtualMode) {
159-
console.log(`${this.logHead} Using virtual protocol (based on CONFIGURATOR flags)`);
160-
newProtocol = this._virtual;
161-
} else if (CONFIGURATOR.manualMode) {
162-
console.log(`${this.logHead} Using websocket protocol (based on CONFIGURATOR flags)`);
163-
newProtocol = this._websocket;
164-
} else if (CONFIGURATOR.bluetoothMode) {
165-
console.log(`${this.logHead} Using bluetooth protocol (based on CONFIGURATOR flags)`);
166-
newProtocol = this._bluetooth;
167-
} else {
168-
console.log(`${this.logHead} Using web serial protocol (based on CONFIGURATOR flags)`);
169-
newProtocol = this._webSerial;
170136
}
171137
}
172138

@@ -184,8 +150,6 @@ class Serial extends EventTarget {
184150
// Set new protocol
185151
this._protocol = newProtocol;
186152
console.log(`${this.logHead} Protocol switched successfully to:`, this._protocol);
187-
} else {
188-
console.log(`${this.logHead} Same protocol selected, no switch needed`);
189153
}
190154

191155
return this._protocol;
@@ -251,8 +215,6 @@ class Serial extends EventTarget {
251215
return false;
252216
}
253217

254-
console.log(`${this.logHead} Disconnecting from current protocol`, this._protocol);
255-
256218
try {
257219
// Handle case where we're already disconnected
258220
if (!this._protocol.connected) {

src/js/serial_backend.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,9 @@ function connectDisconnect() {
125125

126126
// Set configuration flags for consistency with other code
127127
CONFIGURATOR.virtualMode = selectedPort === "virtual";
128-
CONFIGURATOR.bluetoothMode = selectedPort.startsWith("bluetooth");
129-
CONFIGURATOR.manualMode = selectedPort === "manual";
130128

131129
// Select the appropriate protocol based directly on the port path
132130
serial.selectProtocol(selectedPort);
133-
console.log("Serial protocol selected:", serial._protocol, "using port", portName);
134131

135132
if (CONFIGURATOR.virtualMode) {
136133
CONFIGURATOR.virtualApiVersion = PortHandler.portPicker.virtualMspVersion;
@@ -186,7 +183,11 @@ function finishClose(finishedCallback) {
186183
$("#dialogResetToCustomDefaults")[0].close();
187184
}
188185

189-
serial.disconnect(onClosed);
186+
serial.disconnect();
187+
188+
if (CONFIGURATOR.virtualMode) {
189+
onClosed(true);
190+
}
190191

191192
MSP.disconnect_cleanup();
192193
PortUsage.reset();

0 commit comments

Comments
 (0)