diff --git a/HID/ia32/0.10/HID.node b/HID/ia32/0.10/HID.node new file mode 100644 index 00000000..1971558d Binary files /dev/null and b/HID/ia32/0.10/HID.node differ diff --git a/HID/ia32/0.11/HID.node b/HID/ia32/0.11/HID.node new file mode 100644 index 00000000..09a6a544 Binary files /dev/null and b/HID/ia32/0.11/HID.node differ diff --git a/HID/ia32/0.8/HID.node b/HID/ia32/0.8/HID.node new file mode 100644 index 00000000..135914e1 Binary files /dev/null and b/HID/ia32/0.8/HID.node differ diff --git a/HID/ia32/0.9/HID.node b/HID/ia32/0.9/HID.node new file mode 100644 index 00000000..fa384d46 Binary files /dev/null and b/HID/ia32/0.9/HID.node differ diff --git a/HID/index.js b/HID/index.js new file mode 100644 index 00000000..0b7267c6 --- /dev/null +++ b/HID/index.js @@ -0,0 +1,14 @@ +// Attempt to load each of the available .node files for the current processor +// architecture until one succeeds, or throw an exception if none do. +var versions = require("fs").readdirSync(__dirname + "\\" + process.arch); +if (!versions.some(function (version) { + try { + module.exports = require("./" + process.arch + "/" + version + "/HID.node"); + return true; + } catch (e) { + return false; + } +})) { + throw new Error("Your processor architecture and node version are not supported"); +}; + diff --git a/HID/x64/0.10/HID.node b/HID/x64/0.10/HID.node new file mode 100644 index 00000000..be7bd14e Binary files /dev/null and b/HID/x64/0.10/HID.node differ diff --git a/HID/x64/0.11/HID.node b/HID/x64/0.11/HID.node new file mode 100644 index 00000000..6a2adbda Binary files /dev/null and b/HID/x64/0.11/HID.node differ diff --git a/HID/x64/0.8/HID.node b/HID/x64/0.8/HID.node new file mode 100644 index 00000000..19dc83e2 Binary files /dev/null and b/HID/x64/0.8/HID.node differ diff --git a/HID/x64/0.9/HID.node b/HID/x64/0.9/HID.node new file mode 100644 index 00000000..bbc3d71e Binary files /dev/null and b/HID/x64/0.9/HID.node differ diff --git a/blinkstick.js b/blinkstick.js index 688c03de..e5e2e74f 100644 --- a/blinkstick.js +++ b/blinkstick.js @@ -5,19 +5,7 @@ */ var isWin = /^win/.test(process.platform), - usb; - -if (isWin) { - //v0.11.13 of Node.js introduced changes to the API which require - //a new version of precompiled HID.node for Windows platforms - if (compareVersions(process.version, '0.11.13')) { - usb = require('./platform/windows/HID_0.3.2-patched.node'); - } else { - usb = require('./platform/windows/HID.node'); - } -} else { - usb = require('usb'); -} + usb = isWin ? require('./HID') : require('usb'); var VENDOR_ID = 0x20a0, PRODUCT_ID = 0x41e5, @@ -244,10 +232,12 @@ function BlinkStick (device, serialNumber, manufacturer, product) { * @param {function} callback Callback to receive serial number */ BlinkStick.prototype.getSerial = function (callback) { + var self = this; if (isWin) { - if (callback) callback(undefined, this.serial); + if (callback) process.nextTick(function() { + callback(undefined, self.serial); + }); } else { - var self = this; this.device.getStringDescriptor(3, function(err, result) { self.serial = result; if (callback) callback(err, result); @@ -269,11 +259,15 @@ BlinkStick.prototype.close = function (callback) { try { this.device.close(); } catch (ex) { - if (callback) callback(ex); + if (callback) process.nextTick(function() { + callback(ex); + }); return; } - if (callback) callback(); + if (callback) process.nextTick(function() { + callback(); + }); }; @@ -332,7 +326,10 @@ BlinkStick.prototype.getVersionMinor = function () { */ BlinkStick.prototype.getManufacturer = function (callback) { if (isWin) { - if (callback) callback(undefined, this.manufacturer); + var self = this; + if (callback) process.nextTick(function() { + callback(undefined, self.manufacturer); + }); } else { this.device.getStringDescriptor(1, function(err, result) { if (callback) callback(err, result); @@ -358,7 +355,10 @@ BlinkStick.prototype.getManufacturer = function (callback) { */ BlinkStick.prototype.getDescription = function (callback) { if (isWin) { - if (callback) callback(undefined, this.product); + var self = this; + if (callback) process.nextTick(function() { + callback(undefined, self.product); + }); } else { this.device.getStringDescriptor(2, function(err, result) { if (callback) callback(err, result); @@ -434,7 +434,9 @@ BlinkStick.prototype.setColor = function (red, green, blue, options, callback) { self.setFeatureReport(5, [5, params.options.channel, params.options.index, r, g, b], callback); } } catch (ex) { - if (callback) callback(ex); + if (callback) process.nextTick(function() { + callback(ex); + }); } }; @@ -563,7 +565,9 @@ BlinkStick.prototype.getMode = function (callback) { } catch (err) { - if (callback) callback(err, 0); + if (callback) process.nextTick(function() { + callback(err, 0); + }); } }; @@ -1308,14 +1312,18 @@ BlinkStick.prototype.setFeatureReport = function (reportId, data, callback) { retries = retries + 1; if (retries > 5) { - if (callback) callback(error); + if (callback) process.nextTick(function() { + callback(error); + }); return; } try { if (isWin) { self.device.sendFeatureReport(data); - if (callback) { callback(); } + if (callback) process.nextTick(function() { + callback(); + }); } else { self.device.controlTransfer(0x20, 0x9, reportId, 0, new Buffer(data), function (err) { if (typeof(err) === 'undefined') { @@ -1363,14 +1371,18 @@ BlinkStick.prototype.getFeatureReport = function (reportId, length, callback) { retries = retries + 1; if (retries > 5) { - if (callback) callback(error); + if (callback) process.nextTick(function() { + callback(error); + }); return; } try { if (isWin) { var buffer = self.device.getFeatureReport(reportId, length); - if (callback) callback(undefined, buffer); + if (callback) process.nextTick(function() { + callback(undefined, buffer); + }); } else { self.device.controlTransfer(0x80 | 0x20, 0x1, reportId, 0, length, function (err, data) { if (typeof(err) === 'undefined') { @@ -1466,7 +1478,9 @@ module.exports = { var finder = function() { if (i == devices.length) { - if (callback) callback(result); + if (callback) process.nextTick(function() { + callback(result); + }); } else { devices[i].getSerial(function (err, serial) { result.push(serial); @@ -1499,7 +1513,9 @@ module.exports = { var finder = function() { if (i == devices.length) { - if (callback) callback(); + if (callback) process.nextTick(function() { + callback(); + }); } else { devices[i].getSerial(function (err, serialNumber) { if (serialNumber == serial) { diff --git a/package.json b/package.json index 3d388e21..db794f30 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "url": "http://paulcuth.me.uk" } ], - "version": "1.1.1", + "version": "1.1.1-multi-hid", "engines": { "node": ">=0.8.x" }, diff --git a/platform/windows/HID.node b/platform/windows/HID.node deleted file mode 100644 index a50ced1f..00000000 Binary files a/platform/windows/HID.node and /dev/null differ diff --git a/platform/windows/HID_0.3.2-patched.node b/platform/windows/HID_0.3.2-patched.node deleted file mode 100644 index fcb7fd4f..00000000 Binary files a/platform/windows/HID_0.3.2-patched.node and /dev/null differ