Made module Wirething compatible

This commit is contained in:
Nathan Kunicki 2017-01-01 21:58:30 +00:00
parent 38d10719b0
commit 109393c0cf
5 changed files with 69 additions and 5 deletions

28
Wirefile Normal file
View File

@ -0,0 +1,28 @@
{
"name": "Lego Dimensions",
"description": "Node.js and Wirething module for interacting with the Lego Dimensions ToyPad",
"author": "Nathan Kunicki <me@nathankunicki.com>",
"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": []
}]
}

View File

@ -9,5 +9,7 @@
"54 60 a2 5b 49 81": "Krusty-the-Clown", "54 60 a2 5b 49 81": "Krusty-the-Clown",
"87 b8 1a 7f 49 80": "Peter Venkman", "87 b8 1a 7f 49 80": "Peter Venkman",
"0a 2e aa 5c 49 81": "Kai", "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"
} }

31
index.js Normal file
View File

@ -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;

View File

@ -2,13 +2,14 @@
"name": "retrodimensions", "name": "retrodimensions",
"version": "1.0.0", "version": "1.0.0",
"description": "Retro Dimensions", "description": "Retro Dimensions",
"main": "main.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"author": "Nathan Kunicki <me@nathankunicki.com>", "author": "Nathan Kunicki <me@nathankunicki.com>",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"debug": "2.6.0",
"node-hid": "0.5.1" "node-hid": "0.5.1"
} }
} }

View File

@ -1,4 +1,4 @@
let EventEmitter = require("events").EventEmitter, const EventEmitter = require("events").EventEmitter,
HID = require("node-hid"); HID = require("node-hid");
@ -35,6 +35,8 @@ class ToyPad extends EventEmitter {
constructor () { constructor () {
super(); super();
this.uuid = "1";
this.deviceType = "toypad";
this._device = null; this._device = null;
this._requestId = 0; this._requestId = 0;
} }
@ -123,7 +125,7 @@ class ToyPad extends EventEmitter {
}); });
this._device.on("error", (err) => { this._device.on("error", (err) => {
this.emit("error"); this.emit("error", err);
}); });
this._wake(); this._wake();