From 46b3151e37896714be11331e0b7ec8a1f4bc13fe Mon Sep 17 00:00:00 2001 From: cTn Date: Tue, 9 Sep 2014 13:55:58 +0200 Subject: [PATCH] initial cleanup on the lowest level of serial layer, "system_error" bug is still unknown --- js/serial.js | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/js/serial.js b/js/serial.js index 2a4092bd..d7c4ac85 100644 --- a/js/serial.js +++ b/js/serial.js @@ -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; }