WebUSB support (#632)

* Enable webusb

* WebUSB reconnects

* bumped pxt
This commit is contained in:
Michał Moskal 2018-03-21 17:11:56 +00:00 committed by Peli de Halleux
parent 30a0d396f1
commit 666186c78c
2 changed files with 24 additions and 5 deletions

View File

@ -57,8 +57,7 @@ namespace pxt.editor {
}
function writeAsync(data: ArrayBuffer) {
h.sendPacketAsync(new Uint8Array(data));
return Promise.resolve();
return h.sendPacketAsync(new Uint8Array(data));
}
function readAsync() {
@ -67,7 +66,11 @@ namespace pxt.editor {
}
reconnectAsync(first: boolean) {
return this.cortexM.init();
if (!first)
return this.packetIo.reconnectAsync()
.then(() => this.cortexM.init())
else
return this.cortexM.init();
}
disconnectAsync() {
@ -97,6 +100,8 @@ namespace pxt.editor {
let previousDapWrapper: DAPWrapper;
function dapAsync() {
if (previousDapWrapper)
return Promise.resolve(previousDapWrapper)
return Promise.resolve()
.then(() => {
if (previousDapWrapper) {
@ -118,7 +123,9 @@ namespace pxt.editor {
function canHID(): boolean {
let r = false
if (U.isNodeJS) {
if (pxt.usb.isEnabled) {
r = true
} else if (U.isNodeJS) {
r = true
} else {
const forceHexDownload = /forceHexDownload/i.test(window.location.href);
@ -288,6 +295,11 @@ namespace pxt.editor {
wrap = w
log("reset")
return wrap.cortexM.reset(true)
.catch(e => {
log("trying re-connect")
return wrap.reconnectAsync(false)
.then(() => wrap.cortexM.reset(true))
})
})
.then(() => wrap.cortexM.memory.readBlock(0x10001014, 1, pageSize))
.then(v => {
@ -405,6 +417,13 @@ namespace pxt.editor {
}]
};
pxt.usb.setFilters([{
vendorId: 0x0D28,
productId: 0x0204,
classCode: 0xff,
subclassCode: 0x03
}])
if (canHID())
pxt.commands.deployCoreAsync = deployCoreAsync;
return Promise.resolve<pxt.editor.ExtensionResult>(res);

View File

@ -41,6 +41,6 @@
"semantic-ui-less": "^2.2.4"
},
"dependencies": {
"pxt-core": "0.17.14"
"pxt-core": "0.17.15"
}
}