diff options
author | cTn <ctndesigner@gmail.com> | 2014-07-01 14:48:20 +0400 |
---|---|---|
committer | cTn <ctndesigner@gmail.com> | 2014-07-01 14:48:20 +0400 |
commit | 343cb15e6183a0406a847f2c60c93d56de1fe8c3 (patch) | |
tree | 42e5fcb57a265ced5a4e361a61469c0b069272ef | |
parent | 0baad912376d998b72c1594dca5f2adc5e26b034 (diff) |
another experimental fix for serial "system_error"v0.44.4
-rw-r--r-- | js/serial.js | 57 | ||||
-rw-r--r-- | manifest.json | 2 |
2 files changed, 38 insertions, 21 deletions
diff --git a/js/serial.js b/js/serial.js index 5ed4cac2..ba2c1eb4 100644 --- a/js/serial.js +++ b/js/serial.js @@ -3,7 +3,6 @@ var serial = { bitrate: 0, bytes_received: 0, bytes_sent: 0, - connectionRecovered: 0, transmitting: false, output_buffer: [], @@ -26,24 +25,40 @@ var serial = { console.error(info); ga_tracker.sendEvent('Error', 'Serial', info.error); - // valid conditions are 'disconnected', 'timeout', 'device_lost', 'system_error' - if (info.error == 'system_error') { - // 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 <span style="color: red">failure</span> of serial connection, disconnecting...'); - - if ($('a.connect').hasClass('active')) { - $('a.connect').click(); - } else { - self.disconnect(); - } + switch (info.error) { + case 'system_error': // we might be able to recover from this one + chrome.serial.setPaused(self.connectionId, false, get_status); + + function get_status() { + self.getInfo(crunch_status); + } + + function crunch_status(info) { + if (!info.paused) { + console.log('SERIAL: Connection recovered from last onReceiveError'); + ga_tracker.sendEvent('Error', 'Serial', 'recovered'); + } else { + console.log('SERIAL: Connection did not recover from last onReceiveError, disconnecting'); + GUI.log('Unrecoverable <span style="color: red">failure</span> of serial connection, disconnecting...'); + ga_tracker.sendEvent('Error', 'Serial', 'unrecoverable'); + + if ($('a.connect').hasClass('active')) { + $('a.connect').click(); + } else { + self.disconnect(); + } + } + } + break; + case 'timeout': + // TODO + break; + case 'device_lost': + // TODO + break; + case 'disconnected': + // TODO + break; } }); @@ -83,7 +98,6 @@ var serial = { self.connectionId = -1; self.bitrate = 0; - self.connectionRecovered = 0; if (callback) callback(result); }); @@ -98,6 +112,9 @@ var serial = { callback(devices); }); }, + getInfo: function(callback) { + chrome.serial.getInfo(this.connectionId, callback); + }, setControlSignals: function(signals, callback) { chrome.serial.setControlSignals(this.connectionId, signals, callback); }, diff --git a/manifest.json b/manifest.json index 7b1d2594..741cb7c3 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "minimum_chrome_version": "33", - "version": "0.44.3", + "version": "0.44.4", "author": "cTn", "name": "Baseflight - Configurator", |