Block LMS while running and implemnet own USB HID handling

This commit is contained in:
Michal Moskal
2017-07-08 21:18:05 +01:00
parent 0b56acb1b8
commit 672f888663
4 changed files with 150 additions and 36 deletions

View File

@ -9,9 +9,8 @@ eval("if (typeof process === 'object' && process + '' === '[object process]') px
namespace pxt.editor {
// this comes from aux/pxt.lms
const rbfTemplate = `
4c45474f710000006d000100000000001c000000000000000a000000821b028405018130813e8053
74617274696e672e2e2e008400c002802f746d702f73657269616c2e74787400486080XX00448303
83010640414082f5ff8405018130813e80427965210084000a
4c45474f580000006d000100000000001c000000000000000e000000821b038405018130813e8053
74617274696e672e2e2e0084006080XX00448581644886488405018130813e80427965210084000a
`
function hf2Async() {
@ -43,6 +42,7 @@ namespace pxt.editor {
w = w_
if (w.isStreaming)
U.userError("please stop the program first")
return w.rmAsync(elfPath)
}).then(() => {
let f = U.stringToUint8Array(atob(resp.outfiles[pxt.outputName()]))
return w.flashAsync(elfPath, f)
@ -69,6 +69,7 @@ namespace pxt.editor {
deployCoreAsync,
};
initAsync()
/*
.then(w => w.streamFileAsync("/tmp/serial.txt", buf => {
let str = Util.fromUTF8(Util.uint8ArrayToString(buf))
window.postMessage({
@ -77,6 +78,7 @@ namespace pxt.editor {
data: str
}, "*")
}))
*/
return Promise.resolve<pxt.editor.ExtensionResult>(res);
}
}

View File

@ -23,6 +23,15 @@ namespace pxt.editor {
constructor(public io: pxt.HF2.PacketIO) {
io.onData = buf => {
buf = buf.slice(0, HF2.read16(buf, 0) + 2)
if (HF2.read16(buf, 4) == 0x3d3f) {
let code = HF2.read16(buf, 6)
let payload = buf.slice(8)
if (code == 1)
console.log("Serial: " + U.uint8ArrayToString(payload))
else
console.log("Magic: " + code + ": " + U.toHex(payload))
return
}
//log("DATA: " + U.toHex(buf))
this.msgs.push(buf)
}
@ -56,8 +65,9 @@ namespace pxt.editor {
}
talkAsync(buf: Uint8Array, altResponse = 0) {
return this.lock.enqueue("talk", () =>
this.io.sendPacketAsync(buf)
return this.lock.enqueue("talk", () => {
this.msgs.drain()
return this.io.sendPacketAsync(buf)
.then(() => this.msgs.shiftAsync(1000))
.then(resp => {
if (resp[2] != buf[2] || resp[3] != buf[3])
@ -69,7 +79,8 @@ namespace pxt.editor {
U.userError("cmd error: " + resp[6])
}
return resp
}))
})
})
}
flashAsync(path: string, file: Uint8Array) {