Update: 在线版支持对serial/hid/usb设备进行过滤
This commit is contained in:
@@ -170,6 +170,9 @@ Boards.changeTo = (boardName) => {
|
||||
}, {
|
||||
type: 'upload',
|
||||
obj: BOARD.web.upload
|
||||
}, {
|
||||
type: 'devices',
|
||||
obj: BOARD.web.devices
|
||||
}]) {
|
||||
if (!(value.obj instanceof Object)) {
|
||||
continue;
|
||||
|
||||
@@ -1628,6 +1628,7 @@
|
||||
"path": "/web/hid.js",
|
||||
"require": [
|
||||
"Mixly.Serial",
|
||||
"Mixly.Config",
|
||||
"Mixly.Web"
|
||||
],
|
||||
"provide": [
|
||||
@@ -1659,6 +1660,7 @@
|
||||
"require": [
|
||||
"Mixly.Serial",
|
||||
"Mixly.Debug",
|
||||
"Mixly.Config",
|
||||
"Mixly.Web"
|
||||
],
|
||||
"provide": [
|
||||
@@ -1670,6 +1672,7 @@
|
||||
"require": [
|
||||
"Mixly.Serial",
|
||||
"Mixly.Registry",
|
||||
"Mixly.Config",
|
||||
"Mixly.Web"
|
||||
],
|
||||
"provide": [
|
||||
@@ -1682,6 +1685,7 @@
|
||||
"DAPjs",
|
||||
"Mixly.Serial",
|
||||
"Mixly.Registry",
|
||||
"Mixly.Config",
|
||||
"Mixly.Web"
|
||||
],
|
||||
"provide": [
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
goog.loadJs('web', () => {
|
||||
|
||||
goog.require('Mixly.Serial');
|
||||
goog.require('Mixly.Config');
|
||||
goog.require('Mixly.Web');
|
||||
goog.provide('Mixly.Web.HID');
|
||||
|
||||
const {
|
||||
Serial,
|
||||
Config,
|
||||
Web
|
||||
} = Mixly;
|
||||
|
||||
const { SELECTED_BOARD } = Config;
|
||||
|
||||
class WebHID extends Serial {
|
||||
static {
|
||||
@@ -31,9 +34,13 @@ class WebHID extends Serial {
|
||||
}
|
||||
|
||||
this.requestPort = async function () {
|
||||
const devices = await navigator.hid.requestDevice({
|
||||
filters: []
|
||||
});
|
||||
let options = SELECTED_BOARD?.web?.devices?.hid;
|
||||
if (options && typeof(options) !== 'object') {
|
||||
options = {
|
||||
filters: []
|
||||
};
|
||||
}
|
||||
const devices = await navigator.hid.requestDevice(options);
|
||||
if (!devices.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,15 +2,18 @@ goog.loadJs('web', () => {
|
||||
|
||||
goog.require('Mixly.Serial');
|
||||
goog.require('Mixly.Debug');
|
||||
goog.require('Mixly.Config');
|
||||
goog.require('Mixly.Web');
|
||||
goog.provide('Mixly.Web.SerialPort');
|
||||
|
||||
const {
|
||||
Serial,
|
||||
Debug,
|
||||
Config,
|
||||
Web
|
||||
} = Mixly;
|
||||
|
||||
const { SELECTED_BOARD } = Config;
|
||||
|
||||
class WebSerialPort extends Serial {
|
||||
static {
|
||||
@@ -33,7 +36,13 @@ class WebSerialPort extends Serial {
|
||||
}
|
||||
|
||||
this.requestPort = async function () {
|
||||
const serialport = await navigator.serial.requestPort();
|
||||
let options = SELECTED_BOARD?.web?.devices?.serial;
|
||||
if (options && typeof(options) !== 'object') {
|
||||
options = {
|
||||
filters: []
|
||||
};
|
||||
}
|
||||
const serialport = await navigator.serial.requestPort(options);
|
||||
this.addPort(serialport);
|
||||
this.refreshPorts();
|
||||
}
|
||||
|
||||
@@ -2,15 +2,19 @@ goog.loadJs('web', () => {
|
||||
|
||||
goog.require('Mixly.Serial');
|
||||
goog.require('Mixly.Registry');
|
||||
goog.require('Mixly.Config');
|
||||
goog.require('Mixly.Web');
|
||||
goog.provide('Mixly.Web.USBMini');
|
||||
|
||||
const {
|
||||
Serial,
|
||||
Registry,
|
||||
Config,
|
||||
Web
|
||||
} = Mixly;
|
||||
|
||||
const { SELECTED_BOARD } = Config;
|
||||
|
||||
class USBMini extends Serial {
|
||||
static {
|
||||
this.type = 'usb';
|
||||
@@ -33,9 +37,13 @@ class USBMini extends Serial {
|
||||
}
|
||||
|
||||
this.requestPort = async function () {
|
||||
const device = await navigator.usb.requestDevice({
|
||||
filters: []
|
||||
});
|
||||
let options = SELECTED_BOARD?.web?.devices?.usb;
|
||||
if (options && typeof(options) !== 'object') {
|
||||
options = {
|
||||
filters: []
|
||||
};
|
||||
}
|
||||
const device = await navigator.usb.requestDevice(options);
|
||||
this.addPort(device);
|
||||
this.refreshPorts();
|
||||
}
|
||||
|
||||
@@ -3,15 +3,19 @@ goog.loadJs('web', () => {
|
||||
goog.require('DAPjs');
|
||||
goog.require('Mixly.Serial');
|
||||
goog.require('Mixly.Registry');
|
||||
goog.require('Mixly.Config');
|
||||
goog.require('Mixly.Web');
|
||||
goog.provide('Mixly.Web.USB');
|
||||
|
||||
const {
|
||||
Serial,
|
||||
Registry,
|
||||
Config,
|
||||
Web
|
||||
} = Mixly;
|
||||
|
||||
const { SELECTED_BOARD } = Config;
|
||||
|
||||
class USB extends Serial {
|
||||
static {
|
||||
this.type = 'usb';
|
||||
@@ -34,9 +38,13 @@ class USB extends Serial {
|
||||
}
|
||||
|
||||
this.requestPort = async function () {
|
||||
const device = await navigator.usb.requestDevice({
|
||||
filters: []
|
||||
});
|
||||
let options = SELECTED_BOARD?.web?.devices?.usb;
|
||||
if (options && typeof(options) !== 'object') {
|
||||
options = {
|
||||
filters: []
|
||||
};
|
||||
}
|
||||
const device = await navigator.usb.requestDevice(options);
|
||||
this.addPort(device);
|
||||
this.refreshPorts();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user