Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added HID/ia32/0.10/HID.node
Binary file not shown.
Binary file added HID/ia32/0.11/HID.node
Binary file not shown.
Binary file added HID/ia32/0.8/HID.node
Binary file not shown.
Binary file added HID/ia32/0.9/HID.node
Binary file not shown.
14 changes: 14 additions & 0 deletions HID/index.js
Original file line number Diff line number Diff line change
@@ -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");
};

Binary file added HID/x64/0.10/HID.node
Binary file not shown.
Binary file added HID/x64/0.11/HID.node
Binary file not shown.
Binary file added HID/x64/0.8/HID.node
Binary file not shown.
Binary file added HID/x64/0.9/HID.node
Binary file not shown.
70 changes: 43 additions & 27 deletions blinkstick.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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();
});
};


Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
});
}
};

Expand Down Expand Up @@ -563,7 +565,9 @@ BlinkStick.prototype.getMode = function (callback) {
}
catch (err)
{
if (callback) callback(err, 0);
if (callback) process.nextTick(function() {
callback(err, 0);
});
}
};

Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"url": "http://paulcuth.me.uk"
}
],
"version": "1.1.1",
"version": "1.1.1-multi-hid",
"engines": {
"node": ">=0.8.x"
},
Expand Down
Binary file removed platform/windows/HID.node
Binary file not shown.
Binary file removed platform/windows/HID_0.3.2-patched.node
Binary file not shown.