Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Commit

Permalink
chore: use vendor id's
Browse files Browse the repository at this point in the history
  • Loading branch information
sverben committed Mar 21, 2024
1 parent 1d844c3 commit d8e849c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/app/modules/components/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ export class HeaderComponent {

public async onChooseRobot() {
if ('serial' in navigator) {
const port = await navigator.serial.requestPort({filters: [{usbVendorId: 0x1a86}, {usbVendorId: 9025}, {usbVendorId: 2341}, {usbVendorId: 0x0403}]})
const port = await navigator.serial.requestPort({
filters: this.robotWiredState.SUPPORTED_VENDORS.map(vendor => ({
usbVendorId: vendor
}))
})
if (port !== this.robotWiredState.getSerialPort()) {
await port.open({baudRate: 115200});
this.robotWiredState.setSerialPort(port);
Expand Down
6 changes: 5 additions & 1 deletion src/app/modules/core/dialogs/upload/upload.dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ export class UploadDialog {

async reconnect() {
try {
const port = await navigator.usb.requestDevice({ filters: [] })
const port = await navigator.usb.requestDevice({
filters: this.robotWiredState.SUPPORTED_VENDORS.map(vendor => ({
vendorId: vendor
}))
})
this.uploadState.connectUSB(port)
} catch (e) {}
}
Expand Down
6 changes: 5 additions & 1 deletion src/app/services/arduino-uploader/ArduinoUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ class Arduino {
const ports = await navigator.serial.getPorts()

if (ports[0]) port = ports[0]
else port = await navigator.serial.requestPort();
else port = await navigator.serial.requestPort({
filters: this.robotWiredState.SUPPORTED_VENDORS.map(vendor => ({
usbVendorId: vendor
}))
})
} catch (error) {
console.log(error)
throw new Error('No device selected')
Expand Down
2 changes: 2 additions & 0 deletions src/app/state/robot.wired.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { filter, map, scan } from 'rxjs/operators';
})
export class RobotWiredState {

public SUPPORTED_VENDORS = [0x1a86, 9025, 2341, 0x0403, 2341]

private serialPortSubject$: BehaviorSubject<SerialPort> = new BehaviorSubject(null);
public serialPort$: Observable<SerialPort> = this.serialPortSubject$.asObservable();

Expand Down

0 comments on commit d8e849c

Please sign in to comment.