File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ export class MicrobitWebUSBConnection
52
52
? ConnectionStatus . NO_AUTHORIZED_DEVICE
53
53
: ConnectionStatus . NOT_SUPPORTED ;
54
54
55
+ private exclusionFilters : USBDeviceFilter [ ] | undefined ;
55
56
/**
56
57
* The USB device we last connected to.
57
58
* Cleared if it is disconnected.
@@ -175,6 +176,10 @@ export class MicrobitWebUSBConnection
175
176
}
176
177
}
177
178
179
+ setRequestDeviceExclusionFilters ( exclusionFilters : USBDeviceFilter [ ] ) {
180
+ this . exclusionFilters = exclusionFilters ;
181
+ }
182
+
178
183
async connect ( ) : Promise < ConnectionStatus > {
179
184
return this . withEnrichedErrors ( async ( ) => {
180
185
await this . connectInternal ( ) ;
@@ -421,6 +426,7 @@ export class MicrobitWebUSBConnection
421
426
}
422
427
this . dispatchTypedEvent ( "beforerequestdevice" , new BeforeRequestDevice ( ) ) ;
423
428
this . device = await navigator . usb . requestDevice ( {
429
+ exclusionFilters : this . exclusionFilters ,
424
430
filters : [ { vendorId : 0x0d28 , productId : 0x0204 } ] ,
425
431
} ) ;
426
432
this . dispatchTypedEvent ( "afterrequestdevice" , new AfterRequestDevice ( ) ) ;
Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ recreateUi("usb");
83
83
const createConnectSection = ( type : ConnectionType ) : Section => {
84
84
const statusParagraph = crelt ( "p" ) ;
85
85
let name = "" ;
86
+ let exclusionFilters = JSON . stringify ( [ { serialNumber : "XXXX" } ] ) ;
86
87
const dom = crelt (
87
88
"section" ,
88
89
crelt ( "h2" , "Connect" ) ,
@@ -119,10 +120,38 @@ const createConnectSection = (type: ConnectionType): Section => {
119
120
} ,
120
121
} ) ,
121
122
) ,
123
+ type === "usb"
124
+ ? crelt (
125
+ "label" ,
126
+ "Exclusion filters" ,
127
+ crelt ( "input" , {
128
+ type : "text" ,
129
+ value : exclusionFilters ,
130
+ onchange : ( e : Event ) => {
131
+ exclusionFilters = ( e . currentTarget as HTMLInputElement ) . value ;
132
+ } ,
133
+ } ) ,
134
+ )
135
+ : undefined ,
122
136
crelt (
123
137
"button" ,
124
138
{
125
139
onclick : ( ) => {
140
+ if ( type === "usb" ) {
141
+ let parsedExclusionFilters ;
142
+ try {
143
+ if ( exclusionFilters ) {
144
+ parsedExclusionFilters = JSON . parse ( exclusionFilters ) ;
145
+ }
146
+ } catch ( err ) {
147
+ console . error ( "Invalid exclusion filters" ) ;
148
+ }
149
+ (
150
+ connection as MicrobitWebUSBConnection
151
+ ) . setRequestDeviceExclusionFilters ( parsedExclusionFilters ) ;
152
+ } else if ( type === "bluetooth" ) {
153
+ ( connection as MicrobitWebBluetoothConnection ) . setNameFilter ( name ) ;
154
+ }
126
155
void connection . connect ( ) ;
127
156
} ,
128
157
} ,
You can’t perform that action at this time.
0 commit comments