-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
168 lines (149 loc) · 3.89 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
const native = require('bindings')('Chroma')
/**
* Ensures that a color object is sound.
*
* @param {Object} color
* @returns {color}
*
* @typedef color
* @param {number} red
* @param {number} green
* @param {number} blue
*/
function checkColor (color) {
color = color || {}
if (color.red > 255 || color.red < 0) {
throw new Error(`Color red needs to be between 0 and 255! It is: ${color.red}`)
}
if (color.blue > 255 || color.blue < 0) {
throw new Error('Color blue needs to be between 0 and 255!')
}
if (color.green > 255 || color.green < 0) {
throw new Error('Color green needs to be between 0 and 255!')
}
return color
}
module.exports = {
/**
* Initializes the Razer Chroma SDK.
*
* @return {boolean} success - Whether or not the SDK was initialized.
* False means usually that there's no Chroma device.
*/
initialize () {
return native.initialize()
},
/**
* Terminates the Razer Chroma SDK.
*
* @return {boolean} success - Whether or not the SDK was initialized.
* False means usually that it wasn't initialized.
*/
terminate () {
return native.terminate()
},
Keyboard: {
/**
* Show a "wave" effect on the keyboard
*
* @param {string} direction - Either 'leftToRight' or 'rightToLeft'
*
* @returns {void}
*/
setWave (direction) {
return native.Keyboard.setWave(direction || 'leftToRight')
},
/**
* Sets the whole keyboard to a given color.
*
* @param {color} color
*
* @typedef color
* @param {number} red
* @param {number} green
* @param {number} blue
*
* @returns {void}
*/
setStatic (color) {
color = checkColor(color)
return native.Keyboard.setStatic(color)
},
/**
* Set the keyboard to a custom array, allowing you to specify the
* color for each key. The array should contain six arrays (for each row),
* with each array containing 22 keys (for each column).
*
* @param {Array<Array<color>>} customArray
*
* @typedef color
* @param {number} red
* @param {number} green
* @param {number} blue
*
* @returns {void}
*/
setCustom (customArray) {
if (!customArray) {
throw new Error('setCustom must be called with an array as parameter.')
}
return native.Keyboard.setCustom(customArray)
},
/**
* Set the keyboard to a breathing effect, using two given colors.
*
* @param {color} colorOne - A color object
* @param {color} colorTwo - A color object
* @returns {void}
*/
setBreathing (colorOne, colorTwo) {
colorOne = checkColor(colorOne)
colorTwo = checkColor(colorTwo)
return native.Keyboard.setBreathing(colorOne, colorTwo)
},
/**
* Set the keyboard to a random breathing effect.
*
* @returns {void}
*/
setBreathingRandom (colorOne, colorTwo) {
return native.Keyboard.setBreathingRandom()
},
/**
* Set the keyboard to a spectrum cycling effect.
*
* @returns {void}
*/
setSpectrumCycling () {
return native.Keyboard.setSpectrumCycling()
},
/**
* Set the keyboard to a starlight effect, using random colors.
*
* @param {color} colorOne - A color object
* @param {color} colorTwo - A color object
* @returns {void}
*/
setStarlight (colorOne, colorTwo) {
colorOne = checkColor(colorOne)
colorTwo = checkColor(colorTwo)
return native.Keyboard.setStarlight(colorOne, colorTwo)
},
/**
* Sets the whole keyboard to a reactive effect.
*
* @param {color} color
*
* @typedef color
* @param {number} red
* @param {number} green
* @param {number} blue
*
* @returns {void}
*/
setReactive (color) {
color = checkColor(color)
return native.Keyboard.setReactive(color)
}
}
}