diff --git a/Wirefile b/Wirefile new file mode 100644 index 0000000..9f8523d --- /dev/null +++ b/Wirefile @@ -0,0 +1,28 @@ +{ + "name": "Lego Dimensions", + "description": "Node.js and Wirething module for interacting with the Lego Dimensions ToyPad", + "author": "Nathan Kunicki ", + "main": "./index.js", + "devices": [{ + "name": "ToyPad", + "type": "toypad", + "outputs": [{ + "name": "Add", + "event": "add", + "params": [{ + "name": "Decoded Payload", + "param": "payload", + "type": "Object" + }] + },{ + "name": "Remove", + "event": "remove", + "params": [{ + "name": "Decoded Payload", + "param": "payload", + "type": "Object" + }] + }], + "inputs": [] + }] +} \ No newline at end of file diff --git a/data/minifigs.json b/data/minifigs.json index 2047e96..6800f0e 100644 --- a/data/minifigs.json +++ b/data/minifigs.json @@ -9,5 +9,7 @@ "54 60 a2 5b 49 81": "Krusty-the-Clown", "87 b8 1a 7f 49 80": "Peter Venkman", "0a 2e aa 5c 49 81": "Kai", - "cc cb 22 55 42 80": "Scooby-Doo" + "cc cb 22 55 42 80": "Scooby-Doo", + "5f 33 9a 58 49 80": "Green Lantern", + "28 9e 32 83 49 80": "Supergirl" } \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..dfd7614 --- /dev/null +++ b/index.js @@ -0,0 +1,31 @@ +const EventEmitter = require("events").EventEmitter, + debugLog = require("debug")("LegoDimensions"), + fs = require("fs"); + + +const ToyPad = require("./src/toypad.js"); + + +class LegoDimensions extends EventEmitter { + + + constructor (config) { + super(); + } + + + wirethingInit () { + let toyPad = new ToyPad(); + this.emit("discover", toyPad); + } + + + static get wirething () { + return JSON.parse(fs.readFileSync(`${__dirname}/Wirefile`)); + } + + +} + + +module.exports = LegoDimensions; \ No newline at end of file diff --git a/package.json b/package.json index f2b7661..7b958cc 100644 --- a/package.json +++ b/package.json @@ -2,13 +2,14 @@ "name": "retrodimensions", "version": "1.0.0", "description": "Retro Dimensions", - "main": "main.js", + "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "Nathan Kunicki ", "license": "MIT", "dependencies": { + "debug": "2.6.0", "node-hid": "0.5.1" } } diff --git a/src/toypad.js b/src/toypad.js index 95a3dd6..db6fd5a 100644 --- a/src/toypad.js +++ b/src/toypad.js @@ -1,5 +1,5 @@ -let EventEmitter = require("events").EventEmitter, - HID = require("node-hid"); +const EventEmitter = require("events").EventEmitter, + HID = require("node-hid"); const minifigData = require("../data/minifigs.json"); @@ -35,6 +35,8 @@ class ToyPad extends EventEmitter { constructor () { super(); + this.uuid = "1"; + this.deviceType = "toypad"; this._device = null; this._requestId = 0; } @@ -123,7 +125,7 @@ class ToyPad extends EventEmitter { }); this._device.on("error", (err) => { - this.emit("error"); + this.emit("error", err); }); this._wake();