-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
111 lines (86 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var usb = require('usb');
var Luxafor;
Luxafor = function () {
this.pid = 0xf372;
this.vid = 0x04d8;
this.endpoint = undefined;
this.colors = {
"red": 82,
"green": 71,
"blue": 66,
"cyan": 67,
"magenta": 77,
"yellow": 89,
"white": 87,
"off": 79
};
}
Luxafor.prototype.init = function (cb) {
var device = undefined,
interface = undefined;
device = usb.findByIds(this.vid, this.pid);
device.open();
interface = device.interface(0);
if (interface.isKernelDriverActive()) {
interface.detachKernelDriver();
}
interface.claim();
this.endpoint = interface.endpoint(1);
//Dummy data
var buff = new Buffer([0, 0]);
this.endpoint.transfer(buff, function () {
if (cb) {
cb();
}
});
};
Luxafor.prototype.setLuxaforColor = function (color, cb) {
var buff = new Buffer(2);
//Padding
buff.writeUInt8(0, 0);
buff.writeUInt8(color, 1);
this.endpoint.transfer(buff, function () {
if (cb) {
cb();
}
});
};
Luxafor.prototype.flashColor = function (r, g, b, cb) {
var buff = new Buffer(8);
//Strobe
buff.writeUInt8(3, 0);
//"Both Sides"
buff.writeUInt8(255, 1);
buff.writeUInt8(r, 2);
buff.writeUInt8(g, 3);
buff.writeUInt8(b, 4);
//"t" 10. Time?
buff.writeUInt8(10, 5);
//"d" ?
buff.writeUInt8(0, 6);
//"Re" 3. Repeat?
buff.writeUInt8(3, 7);
this.endpoint.transfer(buff, function () {
if (cb) {
cb();
}
});
};
Luxafor.prototype.setColor = function (r, g, b, cb) {
var buff = new Buffer(5);
//Jump
buff.writeUInt8(1, 0);
//"Both Sides"
buff.writeUInt8(255, 1);
buff.writeUInt8(r, 2);
buff.writeUInt8(g, 3);
buff.writeUInt8(b, 4);
this.endpoint.transfer(buff, function () {
if (cb) {
cb();
}
});
};
module.exports = function () {
return new Luxafor();
}