web serial cleanup (#928)

* updated ticks

* fix enable and compile

* add debug mode

* don't try to change UI while downloading

* cleanup

* don't double open

* use cu

* add delay before reconnecting

* support for 200 ragne in field turn ratio

* updated docs

* fix docs
This commit is contained in:
Peli de Halleux
2019-09-30 11:13:28 -07:00
committed by GitHub
parent d85b5c5129
commit 8ca4558fc2
6 changed files with 43 additions and 25 deletions

View File

@ -64,7 +64,6 @@ class WebSerialPackageIO implements pxt.HF2.PacketIO {
private _writer: any;
constructor(private port: SerialPort, private options: SerialOptions) {
this.openAsync();
}
async readSerialAsync() {
@ -173,7 +172,7 @@ export function initAsync(): Promise<void> {
}
if (WebSerialPackageIO.isSupported())
pxt.tickEvent("bluetooth.supported");
pxt.tickEvent("webserial.supported");
return Promise.resolve();
}
@ -274,7 +273,7 @@ export function deployCoreAsync(resp: pxtc.CompileResult) {
if (!useHID) return saveUF2Async()
pxt.tickEvent("bluetooth.flash");
pxt.tickEvent("webserial.flash");
let w: Ev3Wrapper;
return initHidAsync()
.then(w_ => {
@ -291,12 +290,14 @@ export function deployCoreAsync(resp: pxtc.CompileResult) {
`<ul>
<li>${lf("Make sure to stop your program or exit portview on the EV3.")}</li>
<li>${lf("Check your battery level.")}</li>
<li>${lf("Close EV3 LabView or other MakeCode editor tabs.")}
</ul>`,
hasCloseIcon: true,
hideCancel: true,
hideAgree: false,
agreeLbl: lf("Try again"),
}).then(() => w.disconnectAsync())
.then(() => Promise.delay(1000))
.then(() => w.reconnectAsync());
// nothing we can do
@ -309,11 +310,11 @@ export function deployCoreAsync(resp: pxtc.CompileResult) {
.then(() => w.flashAsync(rbfPath, rbfBIN))
.then(() => w.runAsync(rbfPath))
.then(() => {
pxt.tickEvent("bluetooth.success");
pxt.tickEvent("webserial.success");
return w.disconnectAsync()
//return Promise.delay(1000).then(() => w.dmesgAsync())
}).catch(e => {
pxt.tickEvent("bluetooth.fail");
pxt.tickEvent("webserial.fail");
useHID = false;
useWebSerial = false;
// if we failed to initalize, tell the user to retry