From aa49e8c375b6488f475d7e5c7193fec43562418e Mon Sep 17 00:00:00 2001 From: cTn Date: Sat, 25 Jan 2014 13:48:31 +0100 Subject: [PATCH] different approach to serial API logging --- js/serial.js | 12 ++++++++++++ js/serial_backend.js | 5 ----- js/stm32.js | 17 +++-------------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/js/serial.js b/js/serial.js index 553c45fc..44d1c990 100644 --- a/js/serial.js +++ b/js/serial.js @@ -6,6 +6,11 @@ var serial = { chrome.serial.connect(path, options, function(connectionInfo) { self.connectionId = connectionInfo.connectionId; + + if (connectionInfo.connectionId > 0) { + console.log('SERIAL: Connection opened with ID: ' + connectionInfo.connectionId + ', Baud: ' + connectionInfo.bitrate); + } + callback(connectionInfo); }); }, @@ -13,7 +18,14 @@ var serial = { var self = this; chrome.serial.disconnect(this.connectionId, function(result) { + if (result) { + console.log('SERIAL: Connection with ID: ' + self.connectionId + ' closed'); + } else { + console.log('SERIAL: Failed to close connection with ID: ' + self.connectionId + ' closed'); + } + self.connectionId = -1; + callback(result); }); }, diff --git a/js/serial_backend.js b/js/serial_backend.js index 2028198b..4eb7ff16 100644 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -214,8 +214,6 @@ function onOpen(openInfo) { // reset connecting_to GUI.connecting_to = false; - console.log('Connection was opened with ID: ' + openInfo.connectionId + ', Baud: ' + openInfo.bitrate); - // save selected port with chrome.storage if the port differs chrome.storage.local.get('last_used_port', function(result) { if (typeof result.last_used_port != 'undefined') { @@ -280,10 +278,7 @@ function onClosed(result) { sensor_status(sensors_detected = 0); // reset active sensor indicators $('#tabs > ul li').removeClass('active'); // de-select any selected tabs tab_initialize_default(); - - console.log('Connection closed successfully.'); } else { // Something went wrong - console.log('There was an error that happened during "connection-close" procedure.'); notify('Failed to close serial port', 'red'); } } diff --git a/js/stm32.js b/js/stm32.js index 41cca984..0b30eca9 100644 --- a/js/stm32.js +++ b/js/stm32.js @@ -83,7 +83,6 @@ STM32_protocol.prototype.connect = function(hex) { if (!$('input.updating').is(':checked')) { serial.connect(selected_port, {bitrate: baud}, function(openInfo) { if (openInfo.connectionId > 0) { - console.log('Connection was opened with ID: ' + openInfo.connectionId + ' Baud: ' + baud); console.log('Sending ascii "R" to reboot'); // we are connected, disabling connect button in the UI @@ -93,19 +92,13 @@ STM32_protocol.prototype.connect = function(hex) { GUI.timeout_add('reboot_into_bootloader', function() { serial.disconnect(function(result) { - if (result) { - console.log('Connection closed successfully.'); - + if (result) { serial.connect(selected_port, {bitrate: flashing_bitrate, parityBit: 'even', stopBits: 'one'}, function(openInfo) { - if (openInfo.connectionId > 0) { - console.log('Connection was opened with ID: ' + openInfo.connectionId + ' Baud: ' + flashing_bitrate); - + if (openInfo.connectionId > 0) { self.initialize(); } }); } else { - console.log('There was an error that happened during "connection-close" procedure'); - GUI.connect_lock = false; } }); @@ -114,9 +107,7 @@ STM32_protocol.prototype.connect = function(hex) { }); } else { serial.connect(selected_port, {bitrate: flashing_bitrate, parityBit: 'even', stopBits: 'one'}, function(openInfo) { - if (openInfo.connectionId > 0) { - console.log('Connection was opened with ID: ' + openInfo.connectionId + ' Baud: ' + flashing_bitrate); - + if (openInfo.connectionId > 0) { // we are connected, disabling connect button in the UI GUI.connect_lock = true; @@ -591,9 +582,7 @@ STM32_protocol.prototype.upload_procedure = function(step) { // close connection serial.disconnect(function(result) { if (result) { // All went as expected - console.log('Connection closed successfully.'); } else { // Something went wrong - console.log('There was an error that happened during "connection-close" procedure'); } // unlocking connect button