Run program after flashing

This commit is contained in:
Michal Moskal
2017-07-06 17:58:15 +01:00
parent e6a72ba56a
commit 3010b29a26
4 changed files with 42 additions and 17 deletions

View File

@ -8,8 +8,7 @@ eval("if (typeof process === 'object' && process + '' === '[object process]') px
namespace pxt.editor {
// this comes from aux/pxt.lms
const rbfTemplate = "4c45474f5d0000006d000100000000001c0000000000000008000000821b028405018130813e805374617274696e672e2e2e00840060805858585858585858580044830383010640414082f5ff8405018130813e80427965210084000a";
const rbfTemplate = "4c45474f5d0000006d000100000000001c0000000000000008000000821b028405018130813e805374617274696e672e2e2e0084006080XX0044830383010640414082f5ff8405018130813e80427965210084000a";
function hf2Async() {
return pxt.HF2.mkPacketIOAsync()
@ -38,14 +37,19 @@ namespace pxt.editor {
return initAsync()
.then(w_ => {
w = w_
// run LS to make sure we can talk to device first
// otherwise flashing a file might lock it
return w.lsAsync("/")
}).then(() => {
let f = U.stringToUint8Array(atob(resp.outfiles[pxt.outputName()]))
return w.flashAsync(elfPath, f)
})
.then(() => {
let rbfHex = rbfTemplate.replace(/58585858(58)+/, U.toHex(U.stringToUint8Array(elfPath)))
}).then(() => {
let rbfHex = rbfTemplate.replace("XX", U.toHex(U.stringToUint8Array(elfPath)))
let rbf = U.fromHex(rbfHex)
HF2.write16(rbf, 4, rbf.length)
return w.flashAsync(rbfPath, rbf)
}).then(() => {
return w.runAsync(rbfPath)
}).then(() => {
if (isCli)
return w.disconnectAsync()
@ -61,4 +65,4 @@ namespace pxt.editor {
};
return Promise.resolve<pxt.editor.ExtensionResult>(res);
}
}
}