boost-movehub

0.1.0

Boost

The Boost instance scans for Boost devices like your movehub.

Boost

Extends EventEmitter

Parameters
hubAddressOrUuid (string) The UUID or MAC address of the movehub to connect to.
options (Object?) Some options.
Name Description
options.logger Object? Logger implementation when logging is desired.
Instance Members
startScanning()
stopScanning()
onDiscover(peripheral)

Boost#hubConnected

Boost#hubConnected
Parameters
hub (Hub) The hub that just connected.

Hub

Movehub implementation that handles all the sending and receiving of messages between us and the Movehub device.

Hub

Extends EventEmitter

Instance Members
address
uuid
connect()
disconnect()
switchOff()
immediateShutdown()
sendMessage(msg, callback)
activateAlerts(filter = null)
deactivateAlerts(filter = null)
_receiveMessage(msg)

Hub#error

Fires when an error is received when connecting to the Movehub.

Hub#error
Parameters
error (Error)

Hub#disconnect

Fires when a Movehub gets disconnected.

Hub#disconnect

Hub#rssi

Fires when new RSSI value is received from BLE device.

Hub#rssi
Parameters
rssi (number) The received RSSI value.

Hub#connect

Fires when a connection to the Move Hub is established.

Hub#connect

Hub#hubAlert

Fires on received Hub Alert.

Hub#hubAlert
Parameters
value (any) {string} String representation of HubAlert that happened.

R2D2

Interface to work with your R2D2 robot.

R2D2
Instance Members
on(what, cb)

R2D2.rgbLed.setColor

Sets color of RGB to given index color.

R2D2.rgbLed.setColor(color: number): Promise<void>
Parameters
color (number) The index of color to use. (One of RgbLed.COLOR_* )
Returns
Promise<void>:

R2D2.wheels.drive

Starts both wheels synchronous using given speed.

R2D2.wheels.drive(speed: number): Promise<void>
Parameters
speed (number) Speed ranging from 0 to 100 (%).
Returns
Promise<void>:

R2D2.wheels.driveDistance

Starts both wheels synchronous using given speed until the traveled the given distance.

R2D2.wheels.driveDistance(centimeters: number, speed: number): Promise<void>
Parameters
centimeters (number) Number of centimeters until wheels stop.
speed (number) Speed ranging from 0 to 100 (%).
Returns
Promise<void>:

R2D2.wheels.driveTime

Starts both wheels synchronous using given speed for given amount of time.

R2D2.wheels.driveTime(time: number, speed: number): Promise<void>
Parameters
time (number) Number of milliseconds until wheels stop.
speed (number) Speed ranging from 0 to 100 (%).
Returns
Promise<void>:

R2D2.wheels.stop

Stop both wheels.

R2D2.wheels.stop(): Promise<void>
Returns
Promise<void>:

R2D2.chassis.isOpen

Resolves telling if the legs are behind the body of R2D2.

R2D2.chassis.isOpen(): Promise<boolean>
Returns
Promise<boolean>:

R2D2.chassis.open

Speeds up the wheels for a short amount of time, so the force will bring R2D2’s body in front of his legs.

R2D2.chassis.open(): Promise<void>
Returns
Promise<void>: Resolves when the movement is done.

R2D2.chassis.close

TODO: Brings the legs close to R2D2’s body.

R2D2.chassis.close(): Promise<void>
Returns
Promise<void>: Resolves when the movement is done.

R2D2.head.turn

Starts turning the head.

R2D2.head.turn(speed: number): Promise<void>
Parameters
speed (number) The speed ranging from -100 to 100 (%). (Clockwise or counter-clockwise)
Returns
Promise<void>: Resolves immediately.

R2D2.head.stop

Stops turning the head.

R2D2.head.stop(): Promise<void>
Returns
Promise<void>: Resolves immediately.

R2D2.head.turnDegrees

Starts turning the head for given amount of degrees.

R2D2.head.turnDegrees(degrees: number, speed: number): Promise<void>
Parameters
degrees (number) The amount of degrees to turn. Can be positive or negative for clockwise and counter-clockwise movement.
speed (number) The speed ranging from 0 to 100 (%).
Returns
Promise<void>: Resolves after movement finishes.

R2D2.head.turnTime

Starts turning the head for given amount of milliseconds.

R2D2.head.turnTime(time: number, speed: number): Promise<void>
Parameters
time (number) Milliseconds to turn
speed (number) The speed ranging from 0 to 100 (%).
Returns
Promise<void>: Resolves after movement finishes.

create

Creates an instance of a DeviceMessage implementation

create(data: Buffer): (DeviceMessage | UnknownMessage)
Parameters
data (Buffer)
Returns
(DeviceMessage | UnknownMessage): Returns an instance of DeviceMessage subclass, or null if message type is unknown to us

DeviceMessage

Base class for all Messages being send to or received from the MoveHub.

As defined in https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#message-types

new DeviceMessage(data: Buffer)
Parameters
data (Buffer) Received Buffer data.
Instance Members

GenericError

GenericError received from theMoveHub.

As defined in https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#generic-error-messages

new GenericError()

Extends DeviceMessage

HubAction

Up- & Downstream messages for control actions on connected Hub.

As defined in https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#hub-actions

new HubAction()

Extends DeviceMessage

Static Members
build(actionType)

HubAlert

HubAlert Messages from MoveHub.

As defined in https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#hub-alerts

TODO: Test receiving them

new HubAlert()

Extends DeviceMessage

Static Members
build(alertType, alertOp)
Instance Members
alertTypeToString

HubAttachedMessage

As defined in https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#hub-attached-i-o.

Example data: <Buffer 0f 00 04 00 01 27 00 00 00 00 10 00 00 00 10>

new HubAttachedMessage()

Extends DeviceMessage

Instance Members
portId
eventType
ioMembers

PortInputFormat

Upstream message as answer to PortInputFormatSetup message.

As defined in https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#port-input-format-single

new PortInputFormat(args: ...any)

Extends DeviceMessage

Parameters
args (...any)

PortInputFormatSetup

Downstream message to setup receiving single value sensor updates

As defined in https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#port-input-format-setup-single

new PortInputFormatSetup(args: ...any)

Extends PortInputFormat

Parameters
args (...any)
Static Members
build(portId, options = {})

PortOutput

Downstream message to make peripherals do something.

As defined in https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#port-output-command

new PortOutput()

Extends DeviceMessage

Static Members
buildWriteDirectModeData(portId, startupCompletionFlags, subCommand, payload)
build(portId, startupCompletionFlags, subCommand, payload)

PortOutputCommandFeedbackMessage

Message that holds values for multiple ports.

As defined in https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#port-value-single

new PortOutputCommandFeedbackMessage()

Extends DeviceMessage

Instance Members
payload
valuesForPorts

PortValueSingleMessage

As defined in https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#port-value-single

Example: <Buffer 06 00 45 3a 00 a6>

new PortValueSingleMessage()

Extends DeviceMessage

create

Creates an instance of a Peripheral implementation

create(ioType: Number, portId: Number, options: any): (Peripheral | UnknownPeripheral)
Parameters
ioType (Number)
portId (Number)
options (any)
Returns
(Peripheral | UnknownPeripheral): Returns an instance of DeviceMessage subclass, or null if message type is unknown to us

CurrentSensor

This handles the communication with the internal current sensor of Movehub. The values it produces are in milliamperes.

new CurrentSensor(ioType: Number, portId: Number, options: any)

Extends Peripheral

Parameters
ioType (Number) Peripheral Device Type ID (Should be Peripheral.DEV_CURRENT )
portId (Number) Port ID this peripheral is connected to
options (any = undefined)
Instance Members
receiveValue(msg)

Motor

Defines methods for internal and external Methods of a Movehub.

new Motor(ioType: Number, portId: Number, options: any)

Extends Peripheral

Parameters
ioType (Number) Peripheral Device Type ID (Either Peripheral.DEV_MOTOR , Peripheral.DEV_MOTOR_EXTERNAL_TACHO or Peripheral.DEV_MOTOR_INTERNAL_TACHO )
portId (Number) Port ID this peripheral is connected to
options (any = undefined)
Instance Members
startPower(dutyCycle)
startSpeed(dutyCycle, maxSpeed = 100, useProfile)
startSpeedForTime(time, dutyCycle, maxSpeed, endState, useProfile)
startSpeedForDegrees(degrees, dutyCycle, maxSpeed, endState, useProfile)
stop()
combinedStartSpeed(dutyCycleL, dutyCycleR, maxSpeed, useProfile)
combinedStartPower(dutyCycleL, dutyCycleR)
combinedStartSpeedForTime(time, dutyCycleL, dutyCycleR, maxSpeed, endState, useProfile)
combinedStartSpeedForDegrees(degrees, dutyCycleL, dutyCycleR, maxSpeed, endState, useProfile)
combinedStop()
receiveValue(msg)
receiveCommandFeedback(value)

Motor#start

Fires when Motor starts running.

Motor#start

Motor#stop

Fires when Motor finished running.

Motor#stop

Peripheral

This is the base class for all the peripherals of an Movehub.

new Peripheral(ioType: Number, portId: Number, options: any)

Extends EventEmitter

Parameters
ioType (Number) Peripheral Device Type ID (One of Peripheral.DEV_* )
portId (Number) Port ID this peripheral is connected to
options (any = DEFAULT_OPTIONS)
Static Members
Instance Members
subscribe(mode = this.defaultMode)
unsubscribe()
receiveSubscriptionAck(msg)
setValue(value)
getValueAsync()

Peripheral#value

Fires when a new value is set on a Peripheral.

Peripheral#value
Parameters
value (number)

Peripheral#value

Fires when a new value is set on a Peripheral.

Peripheral#value
Parameters
value (number)

RgbLed

Class to set LED colors of the Movehub.

new RgbLed(ioType: Number, portId: Number, options: any)

Extends Peripheral

Parameters
ioType (Number) Peripheral Device Type ID (Should be Peripheral.DEV_RGB_LIGHT )
portId (Number) Port ID this peripheral is connected to
options (any = undefined)
Instance Members
setColor(color)
setRgbColor(red, green, blue)
receiveValue(_msg)

TiltSensor

This handles the communication with the internal tilt sensor of Movehub. There seem to be different modes implemented in the device. We just made the one available that simply gets us the roll and pitch values.

new TiltSensor(ioType: Number, portId: Number, options: any)

Extends Peripheral

Parameters
ioType (Number) Peripheral Device Type ID (Should be Peripheral.DEV_TILT_SENSOR )
portId (Number) Port ID this peripheral is connected to
options (any = undefined)
Instance Members
receiveValue(msg)

UnknownPeripheral

This class represents a peripheral we don't know what we can do with it.

UnknownPeripheral

Extends Peripheral

VisionSensor

This handles the communication and the values we receive from the external vision sensor of the Movehub. That one that measures the distance and the color it sees.

new VisionSensor(ioType: Number, portId: Number, options: any)

Extends Peripheral

Parameters
ioType (Number) Peripheral Device Type ID (Should be Peripheral.DEV_VISON_SENSORT )
portId (Number) Port ID this peripheral is connected to
options (any = undefined)
Instance Members
receiveValue(msg)
setValue(value)

VisionSensor#distance

Fires when a VisionSensor receives a new distance value.

VisionSensor#distance
Parameters
distance (number)

VisionSensor#color

Fires when a VisionSensor receives a new color value.

VisionSensor#color
Parameters
color (number) The index value of the perceived color (One of RgbLed.COLOR_* ).

VisionSensor#color

Fires when a VisionSensor receives a new color value.

VisionSensor#color
Parameters
color (Array<number>) Red, green and blue values of the perceived color.

VoltageSensor

This handles the communication with the internal voltage sensor of Movehub. The values it produces are in volts.

new VoltageSensor(ioType: Number, portId: Number, options: any)

Extends Peripheral

Parameters
ioType (Number) Peripheral Device Type ID (Should be Peripheral.DEV_VOLTAGE )
portId (Number) Port ID this peripheral is connected to
options (any = undefined)
Instance Members
receiveValue(msg)