initial cleanup on the lowest level of serial layer, "system_error" bug is still unknown

10.3.x-maintenance
cTn 2014-09-09 13:55:58 +02:00
parent 2cbd911653
commit 46b3151e37
1 changed files with 21 additions and 23 deletions

View File

@ -9,10 +9,10 @@ var serial = {
transmitting: false,
output_buffer: [],
connect: function(path, options, callback) {
connect: function (path, options, callback) {
var self = this;
chrome.serial.connect(path, options, function(connectionInfo) {
chrome.serial.connect(path, options, function (connectionInfo) {
if (connectionInfo) {
self.connectionId = connectionInfo.connectionId;
self.bitrate = connectionInfo.bitrate;
@ -78,7 +78,7 @@ var serial = {
}
});
},
disconnect: function(callback) {
disconnect: function (callback) {
var self = this;
self.empty_output_buffer();
@ -92,7 +92,7 @@ var serial = {
self.onReceiveError.removeListener(self.onReceiveError.listeners[i]);
}
chrome.serial.disconnect(this.connectionId, function(result) {
chrome.serial.disconnect(this.connectionId, function (result) {
if (result) {
console.log('SERIAL: Connection with ID: ' + self.connectionId + ' closed');
} else {
@ -108,26 +108,26 @@ var serial = {
if (callback) callback(result);
});
},
getDevices: function(callback) {
chrome.serial.getDevices(function(devices_array) {
getDevices: function (callback) {
chrome.serial.getDevices(function (devices_array) {
var devices = [];
devices_array.forEach(function(device) {
devices_array.forEach(function (device) {
devices.push(device.path);
});
callback(devices);
});
},
getInfo: function(callback) {
getInfo: function (callback) {
chrome.serial.getInfo(this.connectionId, callback);
},
getControlSignals: function(callback) {
getControlSignals: function (callback) {
chrome.serial.getControlSignals(this.connectionId, callback);
},
setControlSignals: function(signals, callback) {
setControlSignals: function (signals, callback) {
chrome.serial.setControlSignals(this.connectionId, signals, callback);
},
send: function(data, callback) {
send: function (data, callback) {
var self = this;
self.output_buffer.push({'data': data, 'callback': callback});
@ -136,10 +136,10 @@ var serial = {
var sending = function () {
// store inside separate variables in case array gets destroyed
var data = self.output_buffer[0].data;
var callback = self.output_buffer[0].callback;
var data = self.output_buffer[0].data,
callback = self.output_buffer[0].callback;
chrome.serial.send(self.connectionId, data, function(sendInfo) {
chrome.serial.send(self.connectionId, data, function (sendInfo) {
callback(sendInfo);
self.output_buffer.shift();
@ -164,12 +164,11 @@ var serial = {
onReceive: {
listeners: [],
addListener: function(function_reference) {
var listener = chrome.serial.onReceive.addListener(function_reference);
addListener: function (function_reference) {
chrome.serial.onReceive.addListener(function_reference);
this.listeners.push(function_reference);
},
removeListener: function(function_reference) {
removeListener: function (function_reference) {
for (var i = (this.listeners.length - 1); i >= 0; i--) {
if (this.listeners[i] == function_reference) {
chrome.serial.onReceive.removeListener(function_reference);
@ -183,12 +182,11 @@ var serial = {
onReceiveError: {
listeners: [],
addListener: function(function_reference) {
var listener = chrome.serial.onReceiveError.addListener(function_reference);
addListener: function (function_reference) {
chrome.serial.onReceiveError.addListener(function_reference);
this.listeners.push(function_reference);
},
removeListener: function(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);
@ -199,7 +197,7 @@ var serial = {
}
}
},
empty_output_buffer: function() {
empty_output_buffer: function () {
this.output_buffer = [];
this.transmitting = false;
}