add callback to flashing protocols (no status yet)

pull/3/head
cTn 10 years ago
parent 3312bf5df2
commit 8fb24b3fa4

@ -8,7 +8,9 @@
'use strict';
var STM32_protocol = function () {
this.baud;
this.options = {};
this.callback; // ref
this.hex; // ref
this.verify_hex;
@ -47,9 +49,11 @@ var STM32_protocol = function () {
};
// no input parameters
STM32_protocol.prototype.connect = function (port, baud, hex, options) {
STM32_protocol.prototype.connect = function (port, baud, hex, options, callback) {
var self = this;
self.hex = hex;
self.baud = baud;
self.callback = callback;
// we will crunch the options here since doing it inside initialization routine would be too late
self.options = {
@ -71,10 +75,11 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options) {
if (options.flash_slowly) {
self.options.flash_slowly = true;
self.baud = 115200;
}
if (self.options.no_reboot) {
serial.connect(port, {bitrate: (!self.options.flash_slowly) ? baud : 115200, parityBit: 'even', stopBits: 'one'}, function (openInfo) {
serial.connect(port, {bitrate: self.baud, parityBit: 'even', stopBits: 'one'}, function (openInfo) {
if (openInfo) {
// we are connected, disabling connect button in the UI
GUI.connect_lock = true;
@ -100,7 +105,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options) {
serial.send(bufferOut, function () {
serial.disconnect(function (result) {
if (result) {
serial.connect(port, {bitrate: (!self.options.flash_slowly) ? baud : 115200, parityBit: 'even', stopBits: 'one'}, function (openInfo) {
serial.connect(port, {bitrate: self.baud, parityBit: 'even', stopBits: 'one'}, function (openInfo) {
if (openInfo) {
self.initialize();
} else {
@ -128,7 +133,7 @@ STM32_protocol.prototype.initialize = function () {
self.receive_buffer = [];
self.verify_hex = [];
self.upload_time_start = millitime();
self.upload_time_start = new Date().getTime();
self.upload_process_alive = false;
// reset progress bar to initial state
@ -655,8 +660,6 @@ STM32_protocol.prototype.upload_procedure = function (step) {
// disconnect
GUI.interval_remove('STM32_timeout'); // stop STM32 timeout timer (everything is finished now)
console.log('Script finished after: ' + ((millitime() - self.upload_time_start) / 1000) + ' seconds');
// close connection
serial.disconnect(function (result) {
if (result) { // All went as expected
@ -667,6 +670,13 @@ STM32_protocol.prototype.upload_procedure = function (step) {
// unlocking connect button
GUI.connect_lock = false;
// handle timing
var timeSpent = new Date().getTime() - self.upload_time_start;
console.log('Script finished after: ' + (timeSpent / 1000) + ' seconds');
if (self.callback) callback();
});
break;
}

@ -13,6 +13,7 @@
'use strict';
var STM32DFU_protocol = function () {
this.callback; // ref
this.hex; // ref
this.verify_hex;
@ -62,12 +63,13 @@ var STM32DFU_protocol = function () {
};
};
STM32DFU_protocol.prototype.connect = function (device, hex) {
STM32DFU_protocol.prototype.connect = function (device, hex, callback) {
var self = this;
self.hex = hex;
self.callback = callback;
// reset and set some variables before we start
self.upload_time_start = millitime();
self.upload_time_start = new Date().getTime();
self.verify_hex = [];
// reset progress bar to initial state
@ -466,9 +468,13 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
break;
case 99:
// cleanup
console.log('Script finished after: ' + ((millitime() - self.upload_time_start) / 1000) + ' seconds');
self.releaseInterface(0);
var timeSpent = new Date().getTime() - self.upload_time_start;
console.log('Script finished after: ' + (timeSpent / 1000) + ' seconds');
if (self.callback) callback();
break;
}
};

Loading…
Cancel
Save