@@ -18,21 +18,18 @@ class Serial extends EventTarget {
1818
1919 // Initialize the available protocols
2020 this . _webSerial = new WebSerial ( ) ;
21- this . _bluetooth = new WebBluetooth ( ) ;
22- this . _websocket = new Websocket ( ) ;
21+ this . _webBluetooth = new WebBluetooth ( ) ;
22+ this . _webSocket = new Websocket ( ) ;
2323 this . _virtual = new VirtualSerial ( ) ;
2424
2525 // Update protocol map to use consistent naming
2626 this . _protocolMap = {
27- serial : this . _webSerial , // TODO: should be 'webserial'
28- bluetooth : this . _bluetooth , // TODO: should be 'webbluetooth'
29- websocket : this . _websocket ,
27+ webserial : this . _webSerial ,
28+ webbluetooth : this . _webBluetooth ,
29+ websocket : this . _webSocket ,
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 }
@@ -61,10 +58,10 @@ class Serial extends EventTarget {
6158 if ( protocol === this . _webSerial ) {
6259 return "webserial" ;
6360 }
64- if ( protocol === this . _bluetooth ) {
61+ if ( protocol === this . _webBluetooth ) {
6562 return "webbluetooth" ;
6663 }
67- if ( protocol === this . _websocket ) {
64+ if ( protocol === this . _webSocket ) {
6865 return "websocket" ;
6966 }
7067 if ( protocol === this . _virtual ) {
@@ -77,7 +74,7 @@ class Serial extends EventTarget {
7774 * Set up event forwarding from all protocols to the Serial class
7875 */
7976 _setupEventForwarding ( ) {
80- const protocols = [ this . _webSerial , this . _bluetooth , this . _websocket , this . _virtual ] ;
77+ const protocols = [ this . _webSerial , this . _webBluetooth , this . _webSocket , this . _virtual ] ;
8178 const events = [ "addedDevice" , "removedDevice" , "connect" , "disconnect" , "receive" ] ;
8279
8380 protocols . forEach ( ( protocol ) => {
@@ -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)` ) ;
136- newProtocol = this . _websocket ;
137- // Update CONFIGURATOR flags for consistency
138- CONFIGURATOR . virtualMode = false ;
139- CONFIGURATOR . bluetoothMode = false ;
140- CONFIGURATOR . manualMode = true ;
129+ newProtocol = this . _webSocket ;
141130 } else if ( portPath . startsWith ( "bluetooth" ) ) {
142131 console . log ( `${ this . logHead } Using bluetooth protocol (based on port path: ${ portPath } )` ) ;
143- newProtocol = this . _bluetooth ;
144- // Update CONFIGURATOR flags for consistency
145- CONFIGURATOR . virtualMode = false ;
146- CONFIGURATOR . bluetoothMode = true ;
147- CONFIGURATOR . manualMode = false ;
132+ newProtocol = this . _webBluetooth ;
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 ) {
@@ -292,7 +254,7 @@ class Serial extends EventTarget {
292254
293255 /**
294256 * Get devices from a specific protocol type or current protocol
295- * @param {string } protocolType - Optional protocol type ('serial ', 'bluetooth ', 'websocket', 'virtual')
257+ * @param {string } protocolType - Optional protocol type ('webserial ', 'webbluetooth ', 'websocket', 'virtual')
296258 * @returns {Promise<Array> } - List of devices
297259 */
298260 async getDevices ( protocolType = null ) {
0 commit comments