-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from iamthefox/v3
Re-write to be more up to date with the current js
- Loading branch information
Showing
15 changed files
with
3,449 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["@babel/preset-env"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# https://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
max_line_length = 80 | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
max_line_length = 0 | ||
trim_trailing_whitespace = false | ||
|
||
[COMMIT_EDITMSG] | ||
max_line_length = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
/node_modules | ||
/.idea | ||
debug.js | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import babel from "rollup-plugin-babel"; | ||
import { terser } from "rollup-plugin-terser"; | ||
import resolve from "@rollup/plugin-node-resolve"; | ||
import commonjs from "@rollup/plugin-commonjs"; | ||
import pkg from "./package.json"; | ||
|
||
export default { | ||
input: "src/Luxafor.js", | ||
output: [ | ||
{ | ||
file: pkg.main, | ||
format: "cjs", | ||
}, | ||
{ | ||
file: pkg.module, | ||
format: "es", | ||
}, | ||
], | ||
plugins: [resolve(), commonjs(), babel(), terser()], | ||
external: ["node-hid"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import os from "os"; | ||
import hex2rgb from "hex-rgb"; | ||
import colors from "color-name"; | ||
import { WAVE_SHORT } from "./util/constants"; | ||
|
||
class Device { | ||
constructor(hidDevice) { | ||
this._hidDevice = hidDevice; | ||
this._hidDevice.pause(); | ||
} | ||
|
||
/** | ||
* Set device color | ||
* @param color string | ||
* @param target Number | ||
*/ | ||
color(color, target = 0xff) { | ||
this._write(0x01, target, color, [0x00, 0x00, 0x00]); | ||
} | ||
|
||
/** | ||
* Fade to color | ||
* @param color string | ||
* @param target Number | ||
* @param speed Number | ||
*/ | ||
fadeTo(color, speed = 20, target = 0xff) { | ||
this._write(0x02, target, color, [speed, 0x00, 0x00]); | ||
} | ||
|
||
/** | ||
* Flash color given number of times | ||
* @param color string | ||
* @param target Number | ||
* @param speed Number | ||
* @param repeat Number | ||
*/ | ||
flash(color, speed = 20, repeat = 5, target = 0xff) { | ||
this._write(0x03, target, color, [speed, 0x00, repeat]); | ||
} | ||
|
||
/** | ||
* Start a wave with a given parameters | ||
* @param color | ||
* @param type | ||
* @param speed | ||
* @param repeat | ||
*/ | ||
wave(color, type = WAVE_SHORT, speed = 5, repeat = 5) { | ||
this._write(0x04, type, color, [0x00, repeat, speed]); | ||
} | ||
|
||
/** | ||
* Start a police pattern | ||
* @param repeat | ||
*/ | ||
police(repeat = 5) { | ||
this._writeRaw([0x06, 0x05, repeat]); | ||
} | ||
|
||
/** | ||
* Start a rainbow pattern | ||
* @param repeat | ||
*/ | ||
rainbow(repeat = 5) { | ||
this._writeRaw([0x06, 0x08, repeat]); | ||
} | ||
|
||
/** | ||
* Turn off all the LEDs | ||
*/ | ||
off() { | ||
this.color("#000"); | ||
} | ||
|
||
_resolveColor(color) { | ||
if (color && color.startsWith("#")) { | ||
return hex2rgb(color); | ||
} | ||
|
||
if (color && colors[color]) { | ||
return { | ||
red: colors[color][0], | ||
green: colors[color][1], | ||
blue: colors[color][2], | ||
}; | ||
} | ||
|
||
return { red: 0x00, green: 0x00, blue: 0x00 }; | ||
} | ||
|
||
_write(command, target, color, options = []) { | ||
const { red, green, blue } = this._resolveColor(color); | ||
|
||
const data = [command, target, red, green, blue, ...options]; | ||
|
||
this._writeRaw(data); | ||
} | ||
|
||
_writeRaw(data) { | ||
if (os.platform() === "win32") { | ||
data.unshift(0); | ||
} | ||
|
||
this._hidDevice.resume(); | ||
this._hidDevice.write(data); | ||
this._hidDevice.pause(); | ||
} | ||
} | ||
|
||
export default Device; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import resolveDevices from "./util/resolveDevices"; | ||
import * as constants from "./util/constants"; | ||
|
||
export default { | ||
devices: resolveDevices, | ||
device: () => resolveDevices().shift(), | ||
constants, | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.