add callback to flashing protocols (no status yet)
parent
3312bf5df2
commit
8fb24b3fa4
|
@ -8,7 +8,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var STM32_protocol = function () {
|
var STM32_protocol = function () {
|
||||||
|
this.baud;
|
||||||
this.options = {};
|
this.options = {};
|
||||||
|
this.callback; // ref
|
||||||
this.hex; // ref
|
this.hex; // ref
|
||||||
this.verify_hex;
|
this.verify_hex;
|
||||||
|
|
||||||
|
@ -47,9 +49,11 @@ var STM32_protocol = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
// no input parameters
|
// 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;
|
var self = this;
|
||||||
self.hex = hex;
|
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
|
// we will crunch the options here since doing it inside initialization routine would be too late
|
||||||
self.options = {
|
self.options = {
|
||||||
|
@ -71,10 +75,11 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options) {
|
||||||
|
|
||||||
if (options.flash_slowly) {
|
if (options.flash_slowly) {
|
||||||
self.options.flash_slowly = true;
|
self.options.flash_slowly = true;
|
||||||
|
self.baud = 115200;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.options.no_reboot) {
|
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) {
|
if (openInfo) {
|
||||||
// we are connected, disabling connect button in the UI
|
// we are connected, disabling connect button in the UI
|
||||||
GUI.connect_lock = true;
|
GUI.connect_lock = true;
|
||||||
|
@ -100,7 +105,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options) {
|
||||||
serial.send(bufferOut, function () {
|
serial.send(bufferOut, function () {
|
||||||
serial.disconnect(function (result) {
|
serial.disconnect(function (result) {
|
||||||
if (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) {
|
if (openInfo) {
|
||||||
self.initialize();
|
self.initialize();
|
||||||
} else {
|
} else {
|
||||||
|
@ -128,7 +133,7 @@ STM32_protocol.prototype.initialize = function () {
|
||||||
self.receive_buffer = [];
|
self.receive_buffer = [];
|
||||||
self.verify_hex = [];
|
self.verify_hex = [];
|
||||||
|
|
||||||
self.upload_time_start = millitime();
|
self.upload_time_start = new Date().getTime();
|
||||||
self.upload_process_alive = false;
|
self.upload_process_alive = false;
|
||||||
|
|
||||||
// reset progress bar to initial state
|
// reset progress bar to initial state
|
||||||
|
@ -655,8 +660,6 @@ STM32_protocol.prototype.upload_procedure = function (step) {
|
||||||
// disconnect
|
// disconnect
|
||||||
GUI.interval_remove('STM32_timeout'); // stop STM32 timeout timer (everything is finished now)
|
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
|
// close connection
|
||||||
serial.disconnect(function (result) {
|
serial.disconnect(function (result) {
|
||||||
if (result) { // All went as expected
|
if (result) { // All went as expected
|
||||||
|
@ -667,6 +670,13 @@ STM32_protocol.prototype.upload_procedure = function (step) {
|
||||||
|
|
||||||
// unlocking connect button
|
// unlocking connect button
|
||||||
GUI.connect_lock = false;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var STM32DFU_protocol = function () {
|
var STM32DFU_protocol = function () {
|
||||||
|
this.callback; // ref
|
||||||
this.hex; // ref
|
this.hex; // ref
|
||||||
this.verify_hex;
|
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;
|
var self = this;
|
||||||
self.hex = hex;
|
self.hex = hex;
|
||||||
|
self.callback = callback;
|
||||||
|
|
||||||
// reset and set some variables before we start
|
// reset and set some variables before we start
|
||||||
self.upload_time_start = millitime();
|
self.upload_time_start = new Date().getTime();
|
||||||
self.verify_hex = [];
|
self.verify_hex = [];
|
||||||
|
|
||||||
// reset progress bar to initial state
|
// reset progress bar to initial state
|
||||||
|
@ -466,9 +468,13 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
||||||
break;
|
break;
|
||||||
case 99:
|
case 99:
|
||||||
// cleanup
|
// cleanup
|
||||||
console.log('Script finished after: ' + ((millitime() - self.upload_time_start) / 1000) + ' seconds');
|
|
||||||
|
|
||||||
self.releaseInterface(0);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue