diff --git a/js/serial.js b/js/serial.js index 8c50f0b70b..5ed4cac209 100644 --- a/js/serial.js +++ b/js/serial.js @@ -1,8 +1,9 @@ var serial = { - connectionId: -1, - bitrate: 0, - bytes_received: 0, - bytes_sent: 0, + connectionId: -1, + bitrate: 0, + bytes_received: 0, + bytes_sent: 0, + connectionRecovered: 0, transmitting: false, output_buffer: [], @@ -30,17 +31,29 @@ var serial = { // we might be able to recover from this one chrome.serial.setPaused(self.connectionId, false, function() { console.log('SERIAL: Connection unpause after onReceiveError triggered'); + self.connectionRecovered++; }); } + + if (self.connectionRecovered >= 10) { + console.log('SERIAL: Connection recovery failed, disconnecting'); + GUI.log('Unrecoverable failure of serial connection, disconnecting...'); + + if ($('a.connect').hasClass('active')) { + $('a.connect').click(); + } else { + self.disconnect(); + } + } }); console.log('SERIAL: Connection opened with ID: ' + connectionInfo.connectionId + ', Baud: ' + connectionInfo.bitrate); - callback(connectionInfo); + if (callback) callback(connectionInfo); } else { console.log('SERIAL: Failed to open serial port'); ga_tracker.sendEvent('Error', 'Serial', 'FailedToOpen'); - callback(false); + if (callback) callback(false); } }); }, @@ -70,8 +83,9 @@ var serial = { self.connectionId = -1; self.bitrate = 0; + self.connectionRecovered = 0; - callback(result); + if (callback) callback(result); }); }, getDevices: function(callback) { diff --git a/manifest.json b/manifest.json index 935ce72c78..7b1d259428 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "minimum_chrome_version": "33", - "version": "0.44.2", + "version": "0.44.3", "author": "cTn", "name": "Baseflight - Configurator",