mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 00:35:39 +03:00
onReceiverError handle implementation
This commit is contained in:
parent
844b211ea6
commit
959edc85e7
1 changed files with 35 additions and 0 deletions
35
js/serial.js
35
js/serial.js
|
@ -21,6 +21,18 @@ var serial = {
|
|||
self.bytes_received += info.data.byteLength;
|
||||
});
|
||||
|
||||
self.onReceiveError.addListener(function watch_for_on_receive_errors(info) {
|
||||
console.error(info);
|
||||
|
||||
// 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');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
console.log('SERIAL: Connection opened with ID: ' + connectionInfo.connectionId + ', Baud: ' + connectionInfo.bitrate);
|
||||
|
||||
callback(connectionInfo);
|
||||
|
@ -40,6 +52,10 @@ var serial = {
|
|||
self.onReceive.removeListener(self.onReceive.listeners[i]);
|
||||
}
|
||||
|
||||
for (var i = (self.onReceiveError.listeners.length - 1); i >= 0; i--) {
|
||||
self.onReceiveError.removeListener(self.onReceiveError.listeners[i]);
|
||||
}
|
||||
|
||||
chrome.serial.disconnect(this.connectionId, function(result) {
|
||||
if (result) {
|
||||
console.log('SERIAL: Connection with ID: ' + self.connectionId + ' closed');
|
||||
|
@ -124,6 +140,25 @@ var serial = {
|
|||
}
|
||||
}
|
||||
},
|
||||
onReceiveError: {
|
||||
listeners: [],
|
||||
|
||||
addListener: function(function_reference) {
|
||||
var listener = chrome.serial.onReceiveError.addListener(function_reference);
|
||||
|
||||
this.listeners.push(function_reference);
|
||||
},
|
||||
removeListener: function(function_reference) {
|
||||
for (var i = (this.listeners.length - 1); i >= 0; i--) {
|
||||
if (this.listeners[i] == function_reference) {
|
||||
chrome.serial.onReceiveError.removeListener(function_reference);
|
||||
|
||||
this.listeners.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
empty_output_buffer: function() {
|
||||
this.output_buffer = [];
|
||||
this.transmitting = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue