Skip to content
This repository was archived by the owner on Dec 20, 2018. It is now read-only.

Commit f515ad9

Browse files
author
divanvisagie
committed
Added necessary files and references
1 parent d91fc47 commit f515ad9

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

lib/mixins/within.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var mixins = {
2+
3+
within: function(range, unit, callback) {
4+
var upper;
5+
6+
if (typeof range === "number") {
7+
upper = range;
8+
range = [0, upper];
9+
}
10+
11+
if (!Array.isArray(range)) {
12+
this.emit("error", {
13+
message: "range must be an array"
14+
});
15+
return;
16+
}
17+
18+
if (typeof unit === "function") {
19+
callback = unit;
20+
unit = "value";
21+
}
22+
23+
if (typeof this[unit] === "undefined") {
24+
return this;
25+
}
26+
27+
// Use the continuous read event for high resolution
28+
this.on("data", function() {
29+
var value = this[unit] | 0;
30+
if (value >= range[0] && value <= range[1]) {
31+
callback.call(this, null, value);
32+
}
33+
}.bind(this));
34+
35+
return this;
36+
}
37+
};
38+
39+
module.exports = mixins;

lib/xbox.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var HID = require('node-hid'),
66
path = require('path'),
77
triggers = require('./triggers.json'),
88
buttons = require('./buttons.json'),
9+
within = require('./mixins/within'),
910
joysticks = require('./joysticks.json');
1011

1112
var dead = 6000;
@@ -245,10 +246,10 @@ XboxController.configure = function () {
245246
for (i = 0; i < configArray.length; i++) {
246247
fs.writeFile(configArray[i], JSON.stringify(nameArray[i], null, 4), function (err) {
247248
if (err) throw err;
248-
console.log("Saved" + nameArray[i])
249+
console.log('Saved' + nameArray[i])
249250
});
250251
}
251-
console.log("Config complete");
252+
console.log('Config complete');
252253
break;
253254
default:
254255
console.log('error try again');

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
],
3030
"main": "./lib/xbox.js",
3131
"dependencies": {
32+
"lodash": "latest",
3233
"node-hid": "~>0.3.1",
3334
"chalk": "~0.3.0"
3435
},

0 commit comments

Comments
 (0)