UNPKG

flashmagic.js

Version:
37 lines (36 loc) 1.67 kB
"use strict"; var InSystemProgramming_1 = require('./InSystemProgramming'); var ECHO = false; function handshake(isp, count, timeout) { if (count === void 0) { count = Infinity; } if (timeout === void 0) { timeout = 20; } return new Promise(function (resolve, reject) { console.log("Sync'ing..."); (function synchronize() { var ret = isp.write('?') .then(function () { return isp.assert(/^\?*Synchronized/, timeout); }) .then(function (isp) { return isp.writeln('Synchronized'); }) .then(function (isp) { return isp.assert(/Synchronized/); }) .then(function (isp) { return isp.assertOK(); }) .then(function (isp) { return isp.reset(); }) .then(function (isp) { return isp.sendLine(isp.cclk.toString(10)); }) .then(function (isp) { return isp.assertOK(); }); if (!InSystemProgramming_1.InSystemProgramming.VLAB_MODE) { ret = ret.then(function (isp) { return isp.setEcho(ECHO); }) .then(function (isp) { return isp.readPartIdentification(); }) .then(function (partId) { return isp.readBootcodeVersion(); }) .then(function (bootVer) { return isp; }); } ret.then(function (isp) { return resolve(isp); }) .catch(function (error) { if (count-- <= 0) { return reject(error); } else { process.nextTick(synchronize); } }); })(); }); } exports.handshake = handshake;