# **node-lpf2** - A Node.js module to interface with LEGO Power Functions 2.0 components. ### Installation Node.js v8.0+ required. ```javascript npm install node-lpf2 --save ``` node-lpf2 uses the Noble BLE library by Sandeep Mistry. On macOS everything should function out of the box. On Linux and Windows there are [certain dependencies which may need installed first](https://github.com/noble/noble#prerequisites). Note: node-lpf2 has been tested on macOS 10.13 and Debian/Raspbian on the Raspberry Pi 3 Model B. ### Compatibility While most LPF2 components and Hubs are compatible with each other, there are exceptions. There is limited backwards compatibility between newer components and the WeDo 2.0 Smart Hub. However WeDo 2.0 components are fully forwards compatible with newer Hubs. | Name | Type | WeDo 2.0 Smart Hub | Boost Move Hub | Powered Up Hub | Availability | | ------------------------------- | ------------- | ------------------ | -------------- | -------------- | ------------ | | WeDo 2.0 Tilt Sensor | Sensor | Yes | Yes | Yes | 45300 | | WeDo 2.0 Motion Sensor | Sensor | Yes | Yes | Yes | 45300 | | WeDo 2.0 Medium Motor | Motor | Yes | Yes | Yes | 45300
76112 | | Boost Color and Distance Sensor | Sensor | *Partial* | Yes | Yes | 17101 | | Boost Interactive Motor | Motor/Sensor | *Partial* | Yes | *Partial* | 17101 | | Powered Up Train Motor | Motor | Yes | Yes | Yes | 60197
60198 | | Powered Up LED Lights | Light | Unknown | Unknown | Unknown | 88005 | ### Known Issues and Limitations * The Boost Color and Distance sensor only works in color mode with the WeDo 2.0 Smart Hub. * When used with the WeDo 2.0 Smart Hub, the Boost Interactive Motor does not support rotating the motor by angle. * When used with the Powered Up Hub, the Boost Interactive Motor does not support rotating the motor by angle. It also does not support rotation detection. * Plugging two Boost Interactive Motors into the Powered Up Hub will crash the Hub (This requires a firmware update from LEGO to fix). ### Usage ```javascript const LPF2 = require("node-lpf2").LPF2; const lpf2 = new LPF2(); ``` Examples are available in the "examples" directory. ### Credits Thanks go to Jorge Pereira ([@JorgePe](https://github.com/JorgePe)), Sebastian Raff ([@hobbyquaker](https://github.com/hobbyquaker)), Valentin Heun ([@vheun](https://github.com/vheun)), Johan Korten ([@jakorten](https://github.com/jakorten)), and Andrey Pokhilko ([@undera](https://github.com/undera)) for their various works, contributions, and assistance on figuring out the LEGO Boost, WeDo 2.0, and Powered Up protocols. ## Classes
LPF2EventEmitter
WeDo2SmartHubHub
BoostMoveHubLPF2Hub
PUPHubLPF2Hub
PUPRemoteLPF2Hub
## LPF2 ⇐ EventEmitter **Kind**: global class **Extends**: EventEmitter * [LPF2](#LPF2) ⇐ EventEmitter * [.scan()](#LPF2+scan) * [.stop()](#LPF2+stop) * [.getConnectedHubByUUID(uuid)](#LPF2+getConnectedHubByUUID) ⇒ Hub \| null * [.getConnectedHubs()](#LPF2+getConnectedHubs) ⇒ Array.<Hub> * ["discover" (hub)](#LPF2+event_discover) ### lpF2.scan() Begin scanning for LPF2 Hub devices. **Kind**: instance method of [LPF2](#LPF2) ### lpF2.stop() Stop scanning for LPF2 Hub devices. **Kind**: instance method of [LPF2](#LPF2) ### lpF2.getConnectedHubByUUID(uuid) ⇒ Hub \| null Retrieve a LPF2 Hub by UUID. **Kind**: instance method of [LPF2](#LPF2) | Param | Type | | --- | --- | | uuid | string | ### lpF2.getConnectedHubs() ⇒ Array.<Hub> Retrieve a list of LPF2 Hubs. **Kind**: instance method of [LPF2](#LPF2) ### "discover" (hub) Emits when a LPF2 Hub device is found. **Kind**: event emitted by [LPF2](#LPF2) | Param | Type | | --- | --- | | hub | [WeDo2SmartHub](#WeDo2SmartHub) \| [BoostMoveHub](#BoostMoveHub) \| [PUPHub](#PUPHub) \| [PUPRemote](#PUPRemote) | ## WeDo2SmartHub ⇐ Hub **Kind**: global class **Extends**: Hub * [WeDo2SmartHub](#WeDo2SmartHub) ⇐ Hub * [new WeDo2SmartHub()](#new_WeDo2SmartHub_new) * [.name](#Hub+name) * [.uuid](#Hub+uuid) * [.rssi](#Hub+rssi) * [.batteryLevel](#Hub+batteryLevel) * [.setName(name)](#WeDo2SmartHub+setName) ⇒ Promise * [.setLEDColor(color)](#WeDo2SmartHub+setLEDColor) ⇒ Promise * [.setLEDRGB(red, green, blue)](#WeDo2SmartHub+setLEDRGB) ⇒ Promise * [.setMotorSpeed(port, speed, [time])](#WeDo2SmartHub+setMotorSpeed) ⇒ Promise * [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#WeDo2SmartHub+rampMotorSpeed) ⇒ Promise * [.playSound(frequency, time)](#WeDo2SmartHub+playSound) ⇒ 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)](#WeDo2SmartHub+event_button) * ["distance" (port, distance)](#WeDo2SmartHub+event_distance) * ["color" (port, color)](#WeDo2SmartHub+event_color) * ["tilt" (port, x, y)](#WeDo2SmartHub+event_tilt) * ["rotate" (port, rotation)](#WeDo2SmartHub+event_rotate) * ["attach" (port, type)](#Hub+event_attach) * ["detach" (port)](#Hub+event_detach) ### new WeDo2SmartHub() The WeDo2SmartHub is emitted if the discovered device is a WeDo 2.0 Smart Hub. ### weDo2SmartHub.name **Kind**: instance property of [WeDo2SmartHub](#WeDo2SmartHub) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | name | string | Name of the hub | ### weDo2SmartHub.uuid **Kind**: instance property of [WeDo2SmartHub](#WeDo2SmartHub) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | uuid | string | UUID of the hub | ### weDo2SmartHub.rssi **Kind**: instance property of [WeDo2SmartHub](#WeDo2SmartHub) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | rssi | number | Signal strength of the hub | ### weDo2SmartHub.batteryLevel **Kind**: instance property of [WeDo2SmartHub](#WeDo2SmartHub) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | batteryLevel | number | Battery level of the hub (Percentage between 0-100) | ### weDo2SmartHub.setName(name) ⇒ Promise Set the name of the Hub. **Kind**: instance method of [WeDo2SmartHub](#WeDo2SmartHub) **Returns**: Promise - Resolved upon successful issuance of command. | Param | Type | Description | | --- | --- | --- | | name | string | New name of the hub (14 characters or less, ASCII only). | ### weDo2SmartHub.setLEDColor(color) ⇒ Promise Set the color of the LED on the Hub via a color value. **Kind**: instance method of [WeDo2SmartHub](#WeDo2SmartHub) **Returns**: Promise - Resolved upon successful issuance of command. | Param | Type | Description | | --- | --- | --- | | color | number | A number representing one of the LED color consts. | ### weDo2SmartHub.setLEDRGB(red, green, blue) ⇒ Promise Set the color of the LED on the Hub via RGB values. **Kind**: instance method of [WeDo2SmartHub](#WeDo2SmartHub) **Returns**: Promise - Resolved upon successful issuance of command. | Param | Type | | --- | --- | | red | number | | green | number | | blue | number | ### weDo2SmartHub.setMotorSpeed(port, speed, [time]) ⇒ Promise Set the motor speed on a given port. **Kind**: instance method of [WeDo2SmartHub](#WeDo2SmartHub) **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 | 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 to activate the motor for (in milliseconds). Leave empty to turn the motor on indefinitely. | ### weDo2SmartHub.rampMotorSpeed(port, fromSpeed, toSpeed, time) ⇒ Promise Ramp the motor speed on a given port. **Kind**: instance method of [WeDo2SmartHub](#WeDo2SmartHub) **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). | ### weDo2SmartHub.playSound(frequency, time) ⇒ Promise Play a sound on the Hub's in-built buzzer **Kind**: instance method of [WeDo2SmartHub](#WeDo2SmartHub) **Returns**: Promise - Resolved upon successful completion of command (ie. once the sound has finished playing). | Param | Type | Description | | --- | --- | --- | | frequency | number | | | time | number | How long the sound should play for (in milliseconds). | ### weDo2SmartHub.connect() ⇒ Promise Connect to the Hub. **Kind**: instance method of [WeDo2SmartHub](#WeDo2SmartHub) **Overrides**: [connect](#Hub+connect) **Returns**: Promise - Resolved upon successful connect. ### weDo2SmartHub.disconnect() ⇒ Promise Disconnect the Hub. **Kind**: instance method of [WeDo2SmartHub](#WeDo2SmartHub) **Returns**: Promise - Resolved upon successful disconnect. ### weDo2SmartHub.subscribe(port, [mode]) ⇒ Promise Subscribe to sensor notifications on a given port. **Kind**: instance method of [WeDo2SmartHub](#WeDo2SmartHub) **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. | ### weDo2SmartHub.unsubscribe(port) ⇒ Promise Unsubscribe to sensor notifications on a given port. **Kind**: instance method of [WeDo2SmartHub](#WeDo2SmartHub) **Returns**: Promise - Resolved upon successful issuance of command. | Param | Type | | --- | --- | | port | string | ### weDo2SmartHub.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 [WeDo2SmartHub](#WeDo2SmartHub) **Returns**: Promise - Resolved after the delay is finished. | Param | Type | Description | | --- | --- | --- | | delay | number | How long to sleep (in milliseconds). | ### weDo2SmartHub.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 [WeDo2SmartHub](#WeDo2SmartHub) **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 [WeDo2SmartHub](#WeDo2SmartHub) | Param | Type | Description | | --- | --- | --- | | button | string | | | state | number | A number representing one of the button state consts. | ### "distance" (port, distance) Emits when a distance sensor is activated. **Kind**: event emitted by [WeDo2SmartHub](#WeDo2SmartHub) | Param | Type | Description | | --- | --- | --- | | port | string | | | distance | number | Distance, in millimeters. | ### "color" (port, color) Emits when a color sensor is activated. **Kind**: event emitted by [WeDo2SmartHub](#WeDo2SmartHub) | Param | Type | Description | | --- | --- | --- | | port | string | | | color | number | A number representing one of the LED color consts. | ### "tilt" (port, x, y) Emits when a tilt sensor is activated. **Kind**: event emitted by [WeDo2SmartHub](#WeDo2SmartHub) | Param | Type | | --- | --- | | port | string | | x | number | | y | number | ### "rotate" (port, rotation) Emits when a rotation sensor is activated. **Kind**: event emitted by [WeDo2SmartHub](#WeDo2SmartHub) | Param | Type | | --- | --- | | port | string | | rotation | number | ### "attach" (port, type) Emits when a motor or sensor is attached to the Hub. **Kind**: event emitted by [WeDo2SmartHub](#WeDo2SmartHub) | Param | Type | Description | | --- | --- | --- | | port | string | | | type | number | A number representing one of the peripheral consts. | ### "detach" (port) Emits when an attached motor or sensor is detached from the Hub. **Kind**: event emitted by [WeDo2SmartHub](#WeDo2SmartHub) | Param | Type | | --- | --- | | port | string | ## BoostMoveHub ⇐ LPF2Hub **Kind**: global class **Extends**: LPF2Hub, Hub * [BoostMoveHub](#BoostMoveHub) ⇐ LPF2Hub * [new BoostMoveHub()](#new_BoostMoveHub_new) * [.current](#LPF2Hub+current) * [.name](#Hub+name) * [.uuid](#Hub+uuid) * [.rssi](#Hub+rssi) * [.batteryLevel](#Hub+batteryLevel) * [.setLEDColor(color)](#BoostMoveHub+setLEDColor) ⇒ Promise * [.setMotorSpeed(port, speed, [time])](#BoostMoveHub+setMotorSpeed) ⇒ Promise * [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#BoostMoveHub+rampMotorSpeed) ⇒ Promise * [.setMotorAngle(port, angle, [speed])](#BoostMoveHub+setMotorAngle) ⇒ Promise * [.setName(name)](#LPF2Hub+setName) ⇒ 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) * ["distance" (port, distance)](#LPF2Hub+event_distance) * ["color" (port, color)](#LPF2Hub+event_color) * ["tilt" (port, x, y)](#LPF2Hub+event_tilt) * ["rotate" (port, rotation)](#LPF2Hub+event_rotate) * ["attach" (port, type)](#Hub+event_attach) * ["detach" (port)](#Hub+event_detach) ### new BoostMoveHub() The BoostMoveHub is emitted if the discovered device is a Boost Move Hub. ### boostMoveHub.current **Kind**: instance property of [BoostMoveHub](#BoostMoveHub) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | current | number | Current usage of the hub (Amps) | ### boostMoveHub.name **Kind**: instance property of [BoostMoveHub](#BoostMoveHub) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | name | string | Name of the hub | ### boostMoveHub.uuid **Kind**: instance property of [BoostMoveHub](#BoostMoveHub) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | uuid | string | UUID of the hub | ### boostMoveHub.rssi **Kind**: instance property of [BoostMoveHub](#BoostMoveHub) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | rssi | number | Signal strength of the hub | ### boostMoveHub.batteryLevel **Kind**: instance property of [BoostMoveHub](#BoostMoveHub) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | batteryLevel | number | Battery level of the hub (Percentage between 0-100) | ### boostMoveHub.setLEDColor(color) ⇒ Promise Set the color of the LED on the Hub via a color value. **Kind**: instance method of [BoostMoveHub](#BoostMoveHub) **Returns**: Promise - Resolved upon successful issuance of command. | Param | Type | Description | | --- | --- | --- | | color | number | A number representing one of the LED color consts. | ### boostMoveHub.setMotorSpeed(port, speed, [time]) ⇒ Promise Set the motor speed on a given port. **Kind**: instance method of [BoostMoveHub](#BoostMoveHub) **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. | ### boostMoveHub.rampMotorSpeed(port, fromSpeed, toSpeed, time) ⇒ Promise Ramp the motor speed on a given port. **Kind**: instance method of [BoostMoveHub](#BoostMoveHub) **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). | ### boostMoveHub.setMotorAngle(port, angle, [speed]) ⇒ Promise Rotate a motor by a given angle. **Kind**: instance method of [BoostMoveHub](#BoostMoveHub) **Returns**: Promise - Resolved upon successful completion of command (ie. once the motor is finished). | Param | Type | Default | Description | | --- | --- | --- | --- | | port | string | | | | angle | number | | How much the motor should be rotated (in degrees). | | [speed] | number \| Array.<number> | 100 | 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. | ### boostMoveHub.setName(name) ⇒ Promise Set the name of the Hub. **Kind**: instance method of [BoostMoveHub](#BoostMoveHub) **Returns**: Promise - Resolved upon successful issuance of command. | Param | Type | Description | | --- | --- | --- | | name | string | New name of the hub (14 characters or less, ASCII only). | ### boostMoveHub.connect() ⇒ Promise Connect to the Hub. **Kind**: instance method of [BoostMoveHub](#BoostMoveHub) **Overrides**: [connect](#Hub+connect) **Returns**: Promise - Resolved upon successful connect. ### boostMoveHub.disconnect() ⇒ Promise Disconnect the Hub. **Kind**: instance method of [BoostMoveHub](#BoostMoveHub) **Returns**: Promise - Resolved upon successful disconnect. ### boostMoveHub.subscribe(port, [mode]) ⇒ Promise Subscribe to sensor notifications on a given port. **Kind**: instance method of [BoostMoveHub](#BoostMoveHub) **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. | ### boostMoveHub.unsubscribe(port) ⇒ Promise Unsubscribe to sensor notifications on a given port. **Kind**: instance method of [BoostMoveHub](#BoostMoveHub) **Returns**: Promise - Resolved upon successful issuance of command. | Param | Type | | --- | --- | | port | string | ### boostMoveHub.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 [BoostMoveHub](#BoostMoveHub) **Returns**: Promise - Resolved after the delay is finished. | Param | Type | Description | | --- | --- | --- | | delay | number | How long to sleep (in milliseconds). | ### boostMoveHub.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 [BoostMoveHub](#BoostMoveHub) **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 [BoostMoveHub](#BoostMoveHub) | Param | Type | Description | | --- | --- | --- | | button | string | | | state | number | A number representing one of the button state consts. | ### "distance" (port, distance) Emits when a distance sensor is activated. **Kind**: event emitted by [BoostMoveHub](#BoostMoveHub) | Param | Type | Description | | --- | --- | --- | | port | string | | | distance | number | Distance, in millimeters. | ### "color" (port, color) Emits when a color sensor is activated. **Kind**: event emitted by [BoostMoveHub](#BoostMoveHub) | Param | Type | Description | | --- | --- | --- | | port | string | | | color | number | A number representing one of the LED color consts. | ### "tilt" (port, x, y) Emits when a tilt sensor is activated. **Kind**: event emitted by [BoostMoveHub](#BoostMoveHub) | Param | Type | Description | | --- | --- | --- | | port | string | If the event is fired from the Move Hub's in-built tilt sensor, the special port "TILT" is used. | | x | number | | | y | number | | ### "rotate" (port, rotation) Emits when a rotation sensor is activated. **Kind**: event emitted by [BoostMoveHub](#BoostMoveHub) | Param | Type | | --- | --- | | port | string | | rotation | number | ### "attach" (port, type) Emits when a motor or sensor is attached to the Hub. **Kind**: event emitted by [BoostMoveHub](#BoostMoveHub) | Param | Type | Description | | --- | --- | --- | | port | string | | | type | number | A number representing one of the peripheral consts. | ### "detach" (port) Emits when an attached motor or sensor is detached from the Hub. **Kind**: event emitted by [BoostMoveHub](#BoostMoveHub) | Param | Type | | --- | --- | | port | string | ## PUPHub ⇐ LPF2Hub **Kind**: global class **Extends**: LPF2Hub, Hub * [PUPHub](#PUPHub) ⇐ LPF2Hub * [new PUPHub()](#new_PUPHub_new) * [.current](#LPF2Hub+current) * [.name](#Hub+name) * [.uuid](#Hub+uuid) * [.rssi](#Hub+rssi) * [.batteryLevel](#Hub+batteryLevel) * [.setLEDColor(color)](#PUPHub+setLEDColor) ⇒ Promise * [.setMotorSpeed(port, speed, [time])](#PUPHub+setMotorSpeed) ⇒ Promise * [.rampMotorSpeed(port, fromSpeed, toSpeed, time)](#PUPHub+rampMotorSpeed) ⇒ Promise * [.setName(name)](#LPF2Hub+setName) ⇒ 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) * ["distance" (port, distance)](#LPF2Hub+event_distance) * ["color" (port, color)](#LPF2Hub+event_color) * ["tilt" (port, x, y)](#LPF2Hub+event_tilt) * ["attach" (port, type)](#Hub+event_attach) * ["detach" (port)](#Hub+event_detach) ### new PUPHub() The PUPHub is emitted if the discovered device is a Powered Up Hub. ### pupHub.current **Kind**: instance property of [PUPHub](#PUPHub) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | current | number | Current usage of the hub (Amps) | ### pupHub.name **Kind**: instance property of [PUPHub](#PUPHub) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | name | string | Name of the hub | ### pupHub.uuid **Kind**: instance property of [PUPHub](#PUPHub) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | uuid | string | UUID of the hub | ### pupHub.rssi **Kind**: instance property of [PUPHub](#PUPHub) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | rssi | number | Signal strength of the hub | ### pupHub.batteryLevel **Kind**: instance property of [PUPHub](#PUPHub) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | batteryLevel | number | Battery level of the hub (Percentage between 0-100) | ### pupHub.setLEDColor(color) ⇒ Promise Set the color of the LED on the Hub via a color value. **Kind**: instance method of [PUPHub](#PUPHub) **Returns**: Promise - Resolved upon successful issuance of command. | Param | Type | Description | | --- | --- | --- | | color | number | A number representing one of the LED color consts. | ### pupHub.setMotorSpeed(port, speed, [time]) ⇒ Promise Set the motor speed on a given port. **Kind**: instance method of [PUPHub](#PUPHub) **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. | ### pupHub.rampMotorSpeed(port, fromSpeed, toSpeed, time) ⇒ Promise Ramp the motor speed on a given port. **Kind**: instance method of [PUPHub](#PUPHub) **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). | ### pupHub.setName(name) ⇒ Promise Set the name of the Hub. **Kind**: instance method of [PUPHub](#PUPHub) **Returns**: Promise - Resolved upon successful issuance of command. | Param | Type | Description | | --- | --- | --- | | name | string | New name of the hub (14 characters or less, ASCII only). | ### pupHub.connect() ⇒ Promise Connect to the Hub. **Kind**: instance method of [PUPHub](#PUPHub) **Overrides**: [connect](#Hub+connect) **Returns**: Promise - Resolved upon successful connect. ### pupHub.disconnect() ⇒ Promise Disconnect the Hub. **Kind**: instance method of [PUPHub](#PUPHub) **Returns**: Promise - Resolved upon successful disconnect. ### pupHub.subscribe(port, [mode]) ⇒ Promise Subscribe to sensor notifications on a given port. **Kind**: instance method of [PUPHub](#PUPHub) **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. | ### pupHub.unsubscribe(port) ⇒ Promise Unsubscribe to sensor notifications on a given port. **Kind**: instance method of [PUPHub](#PUPHub) **Returns**: Promise - Resolved upon successful issuance of command. | Param | Type | | --- | --- | | port | string | ### pupHub.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 [PUPHub](#PUPHub) **Returns**: Promise - Resolved after the delay is finished. | Param | Type | Description | | --- | --- | --- | | delay | number | How long to sleep (in milliseconds). | ### pupHub.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 [PUPHub](#PUPHub) **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 [PUPHub](#PUPHub) | Param | Type | Description | | --- | --- | --- | | button | string | | | state | number | A number representing one of the button state consts. | ### "distance" (port, distance) Emits when a distance sensor is activated. **Kind**: event emitted by [PUPHub](#PUPHub) | Param | Type | Description | | --- | --- | --- | | port | string | | | distance | number | Distance, in millimeters. | ### "color" (port, color) Emits when a color sensor is activated. **Kind**: event emitted by [PUPHub](#PUPHub) | Param | Type | Description | | --- | --- | --- | | port | string | | | color | number | A number representing one of the LED color consts. | ### "tilt" (port, x, y) Emits when a tilt sensor is activated. **Kind**: event emitted by [PUPHub](#PUPHub) | Param | Type | Description | | --- | --- | --- | | port | string | If the event is fired from the Move Hub's in-built tilt sensor, the special port "TILT" is used. | | x | number | | | y | number | | ### "attach" (port, type) Emits when a motor or sensor is attached to the Hub. **Kind**: event emitted by [PUPHub](#PUPHub) | Param | Type | Description | | --- | --- | --- | | port | string | | | type | number | A number representing one of the peripheral consts. | ### "detach" (port) Emits when an attached motor or sensor is detached from the Hub. **Kind**: event emitted by [PUPHub](#PUPHub) | Param | Type | | --- | --- | | port | string | ## PUPRemote ⇐ LPF2Hub **Kind**: global class **Extends**: LPF2Hub, Hub * [PUPRemote](#PUPRemote) ⇐ LPF2Hub * [new PUPRemote()](#new_PUPRemote_new) * [.current](#LPF2Hub+current) * [.name](#Hub+name) * [.uuid](#Hub+uuid) * [.rssi](#Hub+rssi) * [.batteryLevel](#Hub+batteryLevel) * [.setLEDColor(color)](#PUPRemote+setLEDColor) ⇒ Promise * [.setName(name)](#LPF2Hub+setName) ⇒ 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) ### new PUPRemote() The PUPRemote is emitted if the discovered device is a Powered Up Remote. ### pupRemote.current **Kind**: instance property of [PUPRemote](#PUPRemote) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | current | number | Current usage of the hub (Amps) | ### pupRemote.name **Kind**: instance property of [PUPRemote](#PUPRemote) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | name | string | Name of the hub | ### pupRemote.uuid **Kind**: instance property of [PUPRemote](#PUPRemote) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | uuid | string | UUID of the hub | ### pupRemote.rssi **Kind**: instance property of [PUPRemote](#PUPRemote) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | rssi | number | Signal strength of the hub | ### pupRemote.batteryLevel **Kind**: instance property of [PUPRemote](#PUPRemote) **Read only**: true **Properties** | Name | Type | Description | | --- | --- | --- | | batteryLevel | number | Battery level of the hub (Percentage between 0-100) | ### pupRemote.setLEDColor(color) ⇒ Promise Set the color of the LED on the Remote via a color value. **Kind**: instance method of [PUPRemote](#PUPRemote) **Returns**: Promise - Resolved upon successful issuance of command. | Param | Type | Description | | --- | --- | --- | | color | number | A number representing one of the LED color consts. | ### pupRemote.setName(name) ⇒ Promise Set the name of the Hub. **Kind**: instance method of [PUPRemote](#PUPRemote) **Returns**: Promise - Resolved upon successful issuance of command. | Param | Type | Description | | --- | --- | --- | | name | string | New name of the hub (14 characters or less, ASCII only). | ### pupRemote.connect() ⇒ Promise Connect to the Hub. **Kind**: instance method of [PUPRemote](#PUPRemote) **Overrides**: [connect](#Hub+connect) **Returns**: Promise - Resolved upon successful connect. ### pupRemote.disconnect() ⇒ Promise Disconnect the Hub. **Kind**: instance method of [PUPRemote](#PUPRemote) **Returns**: Promise - Resolved upon successful disconnect. ### pupRemote.subscribe(port, [mode]) ⇒ Promise Subscribe to sensor notifications on a given port. **Kind**: instance method of [PUPRemote](#PUPRemote) **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. | ### pupRemote.unsubscribe(port) ⇒ Promise Unsubscribe to sensor notifications on a given port. **Kind**: instance method of [PUPRemote](#PUPRemote) **Returns**: Promise - Resolved upon successful issuance of command. | Param | Type | | --- | --- | | port | string | ### pupRemote.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 [PUPRemote](#PUPRemote) **Returns**: Promise - Resolved after the delay is finished. | Param | Type | Description | | --- | --- | --- | | delay | number | How long to sleep (in milliseconds). | ### pupRemote.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 [PUPRemote](#PUPRemote) **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 [PUPRemote](#PUPRemote) | Param | Type | Description | | --- | --- | --- | | button | string | | | state | number | A number representing one of the button state consts. |