From 9a3077866c9f452ddfd93b771167f15271d12627 Mon Sep 17 00:00:00 2001 From: Nathan Kellenicki Date: Thu, 23 Aug 2018 16:15:36 +0100 Subject: [PATCH] First pass at Duplo train support --- DOCS.md | 242 +++++++++++++++++++++++++++++++++++++++++++++++ README.md | 242 +++++++++++++++++++++++++++++++++++++++++++++++ consts.ts | 6 +- duplotrainhub.ts | 150 +++++++++++++++++++++++++++++ hub.ts | 1 - package.json | 2 +- poweredup.ts | 3 + puphub.ts | 1 - wedo2smarthub.ts | 1 - 9 files changed, 642 insertions(+), 6 deletions(-) create mode 100644 duplotrainhub.ts diff --git a/DOCS.md b/DOCS.md index 39f00ae..ee96efa 100644 --- a/DOCS.md +++ b/DOCS.md @@ -11,6 +11,8 @@
PUPRemoteLPF2Hub
+
DuploTrainHubLPF2Hub
+
@@ -1206,3 +1208,243 @@ Emits when a button is pressed. | button | string | | | state | number | A number representing one of the button state consts. | + + +## DuploTrainHub ⇐ LPF2Hub +**Kind**: global class +**Extends**: LPF2Hub, Hub + +* [DuploTrainHub](#DuploTrainHub) ⇐ LPF2Hub + * [new DuploTrainHub()](#new_DuploTrainHub_new) + * [.current](#LPF2Hub+current) + * [.name](#Hub+name) + * [.uuid](#Hub+uuid) + * [.rssi](#Hub+rssi) + * [.batteryLevel](#Hub+batteryLevel) + * [.setMotorSpeed(port, speed, [time])](#DuploTrainHub+setMotorSpeed) ⇒ Promise + * [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#DuploTrainHub+rampMotorSpeed) ⇒ Promise + * [.setName(name)](#LPF2Hub+setName) ⇒ Promise + * [.setLEDColor(color)](#LPF2Hub+setLEDColor) ⇒ Promise + * [.connect()](#Hub+connect) ⇒ Promise + * [.disconnect()](#Hub+disconnect) ⇒ Promise + * [.subscribe(port, [mode])](#Hub+subscribe) ⇒ Promise + * [.unsubscribe(port)](#Hub+unsubscribe) ⇒ Promise + * [.sleep(delay)](#Hub+sleep) ⇒ Promise + * [.wait(commands)](#Hub+wait) ⇒ Promise + * ["button" (button, state)](#LPF2Hub+event_button) + * ["color" (port, color)](#LPF2Hub+event_color) + + + +### new DuploTrainHub() +The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub. + + + +### duploTrainHub.current +**Kind**: instance property of [DuploTrainHub](#DuploTrainHub) +**Read only**: true +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| current | number | Current usage of the hub (Amps) | + + + +### duploTrainHub.name +**Kind**: instance property of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [name](#Hub+name) +**Read only**: true +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| name | string | Name of the hub | + + + +### duploTrainHub.uuid +**Kind**: instance property of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [uuid](#Hub+uuid) +**Read only**: true +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| uuid | string | UUID of the hub | + + + +### duploTrainHub.rssi +**Kind**: instance property of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [rssi](#Hub+rssi) +**Read only**: true +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| rssi | number | Signal strength of the hub | + + + +### duploTrainHub.batteryLevel +**Kind**: instance property of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [batteryLevel](#Hub+batteryLevel) +**Read only**: true +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| batteryLevel | number | Battery level of the hub (Percentage between 0-100) | + + + +### duploTrainHub.setMotorSpeed(port, speed, [time]) ⇒ Promise +Set the motor speed on a given port. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Returns**: Promise - Resolved upon successful completion of command. If time is specified, this is once the motor is finished. + +| Param | Type | Description | +| --- | --- | --- | +| port | string | | +| speed | number \| Array.<number> | For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. If you are specifying port AB to control both motors, you can optionally supply a tuple of speeds. | +| [time] | number | How long to activate the motor for (in milliseconds). Leave empty to turn the motor on indefinitely. | + + + +### duploTrainHub.rampMotorSpeed(port, fromSpeed, toSpeed, time) ⇒ Promise +Ramp the motor speed on a given port. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Returns**: Promise - Resolved upon successful completion of command. + +| Param | Type | Description | +| --- | --- | --- | +| port | string | | +| fromSpeed | number | For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. | +| toSpeed | number | For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. | +| time | number | How long the ramp should last (in milliseconds). | + + + +### duploTrainHub.setName(name) ⇒ Promise +Set the name of the Hub. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Returns**: Promise - Resolved upon successful issuance of command. + +| Param | Type | Description | +| --- | --- | --- | +| name | string | New name of the hub (14 characters or less, ASCII only). | + + + +### duploTrainHub.setLEDColor(color) ⇒ Promise +Set the color of the LED on the Hub via a color value. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Returns**: Promise - Resolved upon successful issuance of command. + +| Param | Type | Description | +| --- | --- | --- | +| color | number | A number representing one of the LED color consts. | + + + +### duploTrainHub.connect() ⇒ Promise +Connect to the Hub. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [connect](#Hub+connect) +**Returns**: Promise - Resolved upon successful connect. + + +### duploTrainHub.disconnect() ⇒ Promise +Disconnect the Hub. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [disconnect](#Hub+disconnect) +**Returns**: Promise - Resolved upon successful disconnect. + + +### duploTrainHub.subscribe(port, [mode]) ⇒ Promise +Subscribe to sensor notifications on a given port. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [subscribe](#Hub+subscribe) +**Returns**: Promise - Resolved upon successful issuance of command. + +| Param | Type | Description | +| --- | --- | --- | +| port | string | | +| [mode] | number | The sensor mode to activate. If no mode is provided, the default for that sensor will be chosen. | + + + +### duploTrainHub.unsubscribe(port) ⇒ Promise +Unsubscribe to sensor notifications on a given port. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [unsubscribe](#Hub+unsubscribe) +**Returns**: Promise - Resolved upon successful issuance of command. + +| Param | Type | +| --- | --- | +| port | string | + + + +### duploTrainHub.sleep(delay) ⇒ Promise +Sleep a given amount of time. + +This is a helper method to make it easier to add delays into a chain of commands. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [sleep](#Hub+sleep) +**Returns**: Promise - Resolved after the delay is finished. + +| Param | Type | Description | +| --- | --- | --- | +| delay | number | How long to sleep (in milliseconds). | + + + +### duploTrainHub.wait(commands) ⇒ Promise +Wait until a given list of concurrently running commands are complete. + +This is a helper method to make it easier to wait for concurrent commands to complete. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [wait](#Hub+wait) +**Returns**: Promise - Resolved after the commands are finished. + +| Param | Type | Description | +| --- | --- | --- | +| commands | Array.<Promise.<any>> | Array of executing commands. | + + + +### "button" (button, state) +Emits when a button is pressed. + +**Kind**: event emitted by [DuploTrainHub](#DuploTrainHub) + +| Param | Type | Description | +| --- | --- | --- | +| button | string | | +| state | number | A number representing one of the button state consts. | + + + +### "color" (port, color) +Emits when a color sensor is activated. + +**Kind**: event emitted by [DuploTrainHub](#DuploTrainHub) + +| Param | Type | Description | +| --- | --- | --- | +| port | string | | +| color | number | A number representing one of the LED color consts. | + diff --git a/README.md b/README.md index ea9e36d..4836dc1 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,8 @@ Thanks go to Jorge Pereira ([@JorgePe](https://github.com/JorgePe)), Sebastian R
PUPRemoteLPF2Hub
+
DuploTrainHubLPF2Hub
+
@@ -1285,3 +1287,243 @@ Emits when a button is pressed. | button | string | | | state | number | A number representing one of the button state consts. | + + +## DuploTrainHub ⇐ LPF2Hub +**Kind**: global class +**Extends**: LPF2Hub, Hub + +* [DuploTrainHub](#DuploTrainHub) ⇐ LPF2Hub + * [new DuploTrainHub()](#new_DuploTrainHub_new) + * [.current](#LPF2Hub+current) + * [.name](#Hub+name) + * [.uuid](#Hub+uuid) + * [.rssi](#Hub+rssi) + * [.batteryLevel](#Hub+batteryLevel) + * [.setMotorSpeed(port, speed, [time])](#DuploTrainHub+setMotorSpeed) ⇒ Promise + * [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#DuploTrainHub+rampMotorSpeed) ⇒ Promise + * [.setName(name)](#LPF2Hub+setName) ⇒ Promise + * [.setLEDColor(color)](#LPF2Hub+setLEDColor) ⇒ Promise + * [.connect()](#Hub+connect) ⇒ Promise + * [.disconnect()](#Hub+disconnect) ⇒ Promise + * [.subscribe(port, [mode])](#Hub+subscribe) ⇒ Promise + * [.unsubscribe(port)](#Hub+unsubscribe) ⇒ Promise + * [.sleep(delay)](#Hub+sleep) ⇒ Promise + * [.wait(commands)](#Hub+wait) ⇒ Promise + * ["button" (button, state)](#LPF2Hub+event_button) + * ["color" (port, color)](#LPF2Hub+event_color) + + + +### new DuploTrainHub() +The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub. + + + +### duploTrainHub.current +**Kind**: instance property of [DuploTrainHub](#DuploTrainHub) +**Read only**: true +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| current | number | Current usage of the hub (Amps) | + + + +### duploTrainHub.name +**Kind**: instance property of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [name](#Hub+name) +**Read only**: true +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| name | string | Name of the hub | + + + +### duploTrainHub.uuid +**Kind**: instance property of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [uuid](#Hub+uuid) +**Read only**: true +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| uuid | string | UUID of the hub | + + + +### duploTrainHub.rssi +**Kind**: instance property of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [rssi](#Hub+rssi) +**Read only**: true +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| rssi | number | Signal strength of the hub | + + + +### duploTrainHub.batteryLevel +**Kind**: instance property of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [batteryLevel](#Hub+batteryLevel) +**Read only**: true +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| batteryLevel | number | Battery level of the hub (Percentage between 0-100) | + + + +### duploTrainHub.setMotorSpeed(port, speed, [time]) ⇒ Promise +Set the motor speed on a given port. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Returns**: Promise - Resolved upon successful completion of command. If time is specified, this is once the motor is finished. + +| Param | Type | Description | +| --- | --- | --- | +| port | string | | +| speed | number \| Array.<number> | For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. If you are specifying port AB to control both motors, you can optionally supply a tuple of speeds. | +| [time] | number | How long to activate the motor for (in milliseconds). Leave empty to turn the motor on indefinitely. | + + + +### duploTrainHub.rampMotorSpeed(port, fromSpeed, toSpeed, time) ⇒ Promise +Ramp the motor speed on a given port. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Returns**: Promise - Resolved upon successful completion of command. + +| Param | Type | Description | +| --- | --- | --- | +| port | string | | +| fromSpeed | number | For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. | +| toSpeed | number | For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. | +| time | number | How long the ramp should last (in milliseconds). | + + + +### duploTrainHub.setName(name) ⇒ Promise +Set the name of the Hub. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Returns**: Promise - Resolved upon successful issuance of command. + +| Param | Type | Description | +| --- | --- | --- | +| name | string | New name of the hub (14 characters or less, ASCII only). | + + + +### duploTrainHub.setLEDColor(color) ⇒ Promise +Set the color of the LED on the Hub via a color value. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Returns**: Promise - Resolved upon successful issuance of command. + +| Param | Type | Description | +| --- | --- | --- | +| color | number | A number representing one of the LED color consts. | + + + +### duploTrainHub.connect() ⇒ Promise +Connect to the Hub. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [connect](#Hub+connect) +**Returns**: Promise - Resolved upon successful connect. + + +### duploTrainHub.disconnect() ⇒ Promise +Disconnect the Hub. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [disconnect](#Hub+disconnect) +**Returns**: Promise - Resolved upon successful disconnect. + + +### duploTrainHub.subscribe(port, [mode]) ⇒ Promise +Subscribe to sensor notifications on a given port. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [subscribe](#Hub+subscribe) +**Returns**: Promise - Resolved upon successful issuance of command. + +| Param | Type | Description | +| --- | --- | --- | +| port | string | | +| [mode] | number | The sensor mode to activate. If no mode is provided, the default for that sensor will be chosen. | + + + +### duploTrainHub.unsubscribe(port) ⇒ Promise +Unsubscribe to sensor notifications on a given port. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [unsubscribe](#Hub+unsubscribe) +**Returns**: Promise - Resolved upon successful issuance of command. + +| Param | Type | +| --- | --- | +| port | string | + + + +### duploTrainHub.sleep(delay) ⇒ Promise +Sleep a given amount of time. + +This is a helper method to make it easier to add delays into a chain of commands. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [sleep](#Hub+sleep) +**Returns**: Promise - Resolved after the delay is finished. + +| Param | Type | Description | +| --- | --- | --- | +| delay | number | How long to sleep (in milliseconds). | + + + +### duploTrainHub.wait(commands) ⇒ Promise +Wait until a given list of concurrently running commands are complete. + +This is a helper method to make it easier to wait for concurrent commands to complete. + +**Kind**: instance method of [DuploTrainHub](#DuploTrainHub) +**Overrides**: [wait](#Hub+wait) +**Returns**: Promise - Resolved after the commands are finished. + +| Param | Type | Description | +| --- | --- | --- | +| commands | Array.<Promise.<any>> | Array of executing commands. | + + + +### "button" (button, state) +Emits when a button is pressed. + +**Kind**: event emitted by [DuploTrainHub](#DuploTrainHub) + +| Param | Type | Description | +| --- | --- | --- | +| button | string | | +| state | number | A number representing one of the button state consts. | + + + +### "color" (port, color) +Emits when a color sensor is activated. + +**Kind**: event emitted by [DuploTrainHub](#DuploTrainHub) + +| Param | Type | Description | +| --- | --- | --- | +| port | string | | +| color | number | A number representing one of the LED color consts. | + diff --git a/consts.ts b/consts.ts index 2ed1d74..de220c3 100644 --- a/consts.ts +++ b/consts.ts @@ -3,7 +3,8 @@ export enum Hubs { WEDO2_SMART_HUB = 1, BOOST_MOVE_HUB = 2, POWERED_UP_HUB = 3, - POWERED_UP_REMOTE = 4 + POWERED_UP_REMOTE = 4, + DUPLO_TRAIN_HUB = 5 } export enum Devices { @@ -48,7 +49,8 @@ export enum ButtonStates { export enum BLEManufacturerData { BOOST_MOVE_HUB_ID = 64, POWERED_UP_HUB_ID = 65, - POWERED_UP_REMOTE_ID = 66 + POWERED_UP_REMOTE_ID = 66, + DUPLO_TRAIN_HUB_ID = 66 } export enum BLEServices { diff --git a/duplotrainhub.ts b/duplotrainhub.ts new file mode 100644 index 0000000..064ca6d --- /dev/null +++ b/duplotrainhub.ts @@ -0,0 +1,150 @@ +import { Peripheral } from "noble"; + +import { LPF2Hub } from "./lpf2hub"; +import { Port } from "./port"; + +import * as Consts from "./consts"; + +import Debug = require("debug"); +const debug = Debug("duplotrainhub"); + + +/** + * The DuploTrainHub is emitted if the discovered device is a Duplo Train Hub. + * @class DuploTrainHub + * @extends LPF2Hub + * @extends Hub + */ +export class DuploTrainHub extends LPF2Hub { + + + // We set JSDoc to ignore these events as a Duplo Train Hub will never emit them. + + /** + * @event DuploTrainHub#distance + * @ignore + */ + + /** + * @event DuploTrainHub#tilt + * @ignore + */ + + /** + * @event DuploTrainHub#rotate + * @ignore + */ + + /** + * @event DuploTrainHub#attach + * @ignore + */ + + /** + * @event DuploTrainHub#detach + * @ignore + */ + + + public static IsDuploTrainHub (peripheral: Peripheral) { + return (peripheral.advertisement.serviceUuids.indexOf(Consts.BLEServices.LPF2_HUB) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.DUPLO_TRAIN_HUB_ID); + } + + + constructor (peripheral: Peripheral, autoSubscribe: boolean = true) { + super(peripheral, autoSubscribe); + this.type = Consts.Hubs.DUPLO_TRAIN_HUB; + this._ports = { + "MOTOR": new Port("MOTOR", 0), + "LIGHT": new Port("LIGHT", 1) + }; + debug("Discovered Duplo Train Hub"); + } + + + public connect () { + return new Promise(async (resolve, reject) => { + debug("Connecting to Duplo Train Hub"); + await super.connect(); + debug("Connect completed"); + return resolve(); + }); + } + + + /** + * Set the motor speed on a given port. + * @method DuploTrainHub#setMotorSpeed + * @param {string} port + * @param {number | Array.} speed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. If you are specifying port AB to control both motors, you can optionally supply a tuple of speeds. + * @param {number} [time] How long to activate the motor for (in milliseconds). Leave empty to turn the motor on indefinitely. + * @returns {Promise} Resolved upon successful completion of command. If time is specified, this is once the motor is finished. + */ + public setMotorSpeed (port: string, speed: number | [number, number], time?: number) { + const portObj = this._portLookup(port); + if (portObj.id !== "AB" && speed instanceof Array) { + throw new Error(`Port ${portObj.id} can only accept a single speed`); + } + if (portObj.id === "AB") { + const portObjA = this._portLookup("A"); + const portObjB = this._portLookup("B"); + if (portObjA.type !== portObjB.type) { + throw new Error(`Port ${portObj.id} requires both motors be of the same type`); + } + } + return new Promise((resolve, reject) => { + if (time) { + let data = null; + if (portObj.id === "AB") { + data = Buffer.from([0x81, portObj.value, 0x11, 0x02, this._mapSpeed(speed instanceof Array ? speed[0] : speed), this._mapSpeed(speed instanceof Array ? speed[1] : speed)]); + } else { + // @ts-ignore: The type of speed is properly checked at the start + data = Buffer.from([0x81, portObj.value, 0x11, 0x60, 0x00, this._mapSpeed(speed), 0x00, 0x00]); + } + this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); + setTimeout(() => { + let data = null; + if (portObj.id === "AB") { + data = Buffer.from([0x81, portObj.value, 0x11, 0x02, 0x00, 0x00]); + } else { + data = Buffer.from([0x81, portObj.value, 0x11, 0x60, 0x00, 0x00, 0x00, 0x00]); + } + this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); + return resolve(); + }, time); + } else { + let data = null; + if (portObj.id === "AB") { + data = Buffer.from([0x81, portObj.value, 0x11, 0x02, this._mapSpeed(speed instanceof Array ? speed[0] : speed), this._mapSpeed(speed instanceof Array ? speed[1] : speed)]); + } else { + // @ts-ignore: The type of speed is properly checked at the start + data = Buffer.from([0x81, portObj.value, 0x11, 0x60, 0x00, this._mapSpeed(speed), 0x00, 0x00]); + } + this._writeMessage(Consts.BLECharacteristics.LPF2_ALL, data); + return resolve(); + } + }); + } + + + /** + * Ramp the motor speed on a given port. + * @method DuploTrainHub#rampMotorSpeed + * @param {string} port + * @param {number} fromSpeed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. + * @param {number} toSpeed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. + * @param {number} time How long the ramp should last (in milliseconds). + * @returns {Promise} Resolved upon successful completion of command. + */ + public rampMotorSpeed (port: string, fromSpeed: number, toSpeed: number, time: number) { + return new Promise((resolve, reject) => { + this._calculateRamp(fromSpeed, toSpeed, time) + .on("changeSpeed", (speed) => { + this.setMotorSpeed(port, speed); + }) + .on("finished", resolve); + }); + } + + +} diff --git a/hub.ts b/hub.ts index 23cd983..efff925 100644 --- a/hub.ts +++ b/hub.ts @@ -6,7 +6,6 @@ import { Port } from "./port"; import * as Consts from "./consts"; import Debug = require("debug"); -import { resolve } from "path"; const debug = Debug("hub"); diff --git a/package.json b/package.json index c029ea8..4a78735 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "types": "dist/poweredup.d.ts", "scripts": { "build": "tslint -c tslint.json \"*.ts\" && tsc", - "docs": "jsdoc2md dist/poweredup.js dist/lpf2hub.js dist/wedo2smarthub.js dist/boostmovehub.js dist/puphub.js dist/pupremote.js dist/hub.js dist/consts.js > DOCS.md", + "docs": "jsdoc2md dist/poweredup.js dist/lpf2hub.js dist/wedo2smarthub.js dist/boostmovehub.js dist/puphub.js dist/pupremote.js dist/duplotrainhub.js dist/hub.js dist/consts.js > DOCS.md", "readme": "cat ABOUT.md DOCS.md > README.md", "all": "npm run build && npm run docs && npm run readme", "prepublishOnly": "npm run build" diff --git a/poweredup.ts b/poweredup.ts index d7f07e5..854b9be 100644 --- a/poweredup.ts +++ b/poweredup.ts @@ -1,6 +1,7 @@ import { Peripheral } from "noble"; import { BoostMoveHub } from "./boostmovehub"; +import { DuploTrainHub } from "./duplotrainhub"; import { Hub } from "./hub"; import { PUPHub } from "./puphub"; import { PUPRemote } from "./pupremote"; @@ -66,6 +67,8 @@ export class PoweredUP extends EventEmitter { hub = new PUPHub(peripheral, this.autoSubscribe); } else if (PUPRemote.IsPUPRemote(peripheral)) { hub = new PUPRemote(peripheral, this.autoSubscribe); + } else if (DuploTrainHub.IsDuploTrainHub(peripheral)) { + hub = new DuploTrainHub(peripheral, this.autoSubscribe); } else { return; } diff --git a/puphub.ts b/puphub.ts index 2f29a66..02affb5 100644 --- a/puphub.ts +++ b/puphub.ts @@ -6,7 +6,6 @@ import { Port } from "./port"; import * as Consts from "./consts"; import Debug = require("debug"); -import { resolve } from "path"; const debug = Debug("puphub"); diff --git a/wedo2smarthub.ts b/wedo2smarthub.ts index b50a38d..e38c494 100644 --- a/wedo2smarthub.ts +++ b/wedo2smarthub.ts @@ -6,7 +6,6 @@ import { Port } from "./port"; import * as Consts from "./consts"; import Debug = require("debug"); -import { resolve } from "path"; const debug = Debug("wedo2smarthub");