From 8fb24b3fa48f7699cec630f43894a65280bd5dfc Mon Sep 17 00:00:00 2001 From: cTn Date: Wed, 1 Oct 2014 15:55:11 +0200 Subject: [PATCH] add callback to flashing protocols (no status yet) --- js/protocols/stm32.js | 22 ++++++++++++++++------ js/protocols/stm32usbdfu.js | 14 ++++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/js/protocols/stm32.js b/js/protocols/stm32.js index a769816b..7e4a1c70 100644 --- a/js/protocols/stm32.js +++ b/js/protocols/stm32.js @@ -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; } diff --git a/js/protocols/stm32usbdfu.js b/js/protocols/stm32usbdfu.js index 7b614168..56c049ae 100644 --- a/js/protocols/stm32usbdfu.js +++ b/js/protocols/stm32usbdfu.js @@ -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; } };