From 9caa5e251eb60eea47063bf359f66b688fcda40d Mon Sep 17 00:00:00 2001 From: cTn Date: Sat, 18 Jan 2014 11:44:43 +0100 Subject: [PATCH] adding new serial object utilizing new serial api --- js/serial.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ main.html | 1 + 2 files changed, 47 insertions(+) create mode 100644 js/serial.js diff --git a/js/serial.js b/js/serial.js new file mode 100644 index 0000000000..553c45fc79 --- /dev/null +++ b/js/serial.js @@ -0,0 +1,46 @@ +var serial = { + connectionId: -1, + + connect: function(path, options, callback) { + var self = this; + + chrome.serial.connect(path, options, function(connectionInfo) { + self.connectionId = connectionInfo.connectionId; + callback(connectionInfo); + }); + }, + disconnect: function(callback) { + var self = this; + + chrome.serial.disconnect(this.connectionId, function(result) { + self.connectionId = -1; + callback(result); + }); + }, + getDevices: function(callback) { + chrome.serial.getDevices(function(devices_array) { + var devices = []; + devices_array.forEach(function(device) { + devices.push(device.path); + }); + + callback(devices); + }); + }, + setControlSignals: function(signals, callback) { + chrome.serial.setControlSignals(this.connectionId, signals, callback); + }, + send: function(data, callback) { + chrome.serial.send(this.connectionId, data, callback); + }, + onReceive: { + listeners_: chrome.serial.onReceive.listeners_, + + addListener: function(function_reference) { + chrome.serial.onReceive.addListener(function_reference); + }, + removeListener: function(function_reference) { + chrome.serial.onReceive.removeListener(function_reference); + } + } +}; \ No newline at end of file diff --git a/main.html b/main.html index 73860883a7..401ca5a68f 100644 --- a/main.html +++ b/main.html @@ -11,6 +11,7 @@ +