Constructor
new Boost()
Members
(private) _ble :BLE
The Bluetooth connection socket for reading/writing peripheral data.
Type:
(private) _colorSamples :Array
An array of values from the Boost Vision Sensor.
Type:
- Array
_extensionId
The id of the extension this peripheral belongs to.
(private) _motors :Array.<BoostMotor>
A list of motors registered by the Boost hardware.
Type:
- Array.<BoostMotor>
(private) _pingDeviceId :number
An interval id for the battery check interval.
Type:
- number
(private) _ports :Array.<string>
A list of the ids of the physical or virtual sensors.
Type:
- Array.<string>
(private) _rateLimiter :RateLimiter
A rate limiter utility, to help limit the rate at which we send BLE messages over the socket to Scratch Link to a maximum number of sends per second.
Type:
(private) _runtime :Runtime
The Scratch 3.0 runtime used to trigger the green flag button.
Type:
(private) _sensors :Object.<string, number>
The most recently received value for each sensor.
Type:
- Object.<string, number>
color
previousColor
tiltX
tiltY
Methods
(private) _clearPort(portID)
Clear the sensors or motors present on the ports.
Parameters:
Name | Type | Description |
---|---|---|
portID |
number | the port to clear. |
(private) _onConnect()
Starts reading data from peripheral after BLE has connected.
(private) _onMessage(base64)
Process the sensor data from the incoming BLE characteristic.
Parameters:
Name | Type | Description |
---|---|---|
base64 |
object | the incoming BLE data. |
(private) _pingDevice()
Ping the Boost hub. If the Boost hub has disconnected for some reason, the BLE socket will get an error back and automatically close the socket.
(private) _registerSensorOrMotor(portID, type)
Register a new sensor or motor connected at a port. Store the type of sensor or motor internally, and then register for notifications on input values if it is a sensor.
Parameters:
Name | Type | Description |
---|---|---|
portID |
number | the port to register a sensor or motor on. |
type |
number | the type ID of the sensor or motor |
boostColorForIndex(index) → {BoostColor}
Look up the color id for an index received from the vision sensor.
Parameters:
Name | Type | Description |
---|---|---|
index |
number | the color index to look up. |
Returns:
the color id for this index.
- Type
- BoostColor
connect(id)
Called by the runtime when user wants to connect to a certain Boost peripheral.
Parameters:
Name | Type | Description |
---|---|---|
id |
number | the id of the peripheral to connect to. |
disconnect()
Disconnects from the current BLE socket and resets state.
generateInputCommand(portID, mode, delta, enableNotifications) → {array}
Generate a Boost 'Input Command' in the byte array format (COMMAND ID, COMMAND TYPE, CONNECT ID, TYPE ID, MODE, DELTA INTERVAL (4 BYTES), UNIT, NOTIFICATIONS ENABLED).
This sends a command to the Boost that sets that input format of the specified inputs and sets value change notifications.
Parameters:
Name | Type | Description |
---|---|---|
portID |
number | the port (Connect ID) to send a command to. |
mode |
number | the mode of the input sensor. |
delta |
number | the delta change needed to trigger notification. |
enableNotifications |
boolean | whether to enable notifications. |
Returns:
- a generated input command.
- Type
- array
generateOutputCommand(portID, execution, subCommand, payload) → {array}
Generate a Boost 'Output Command' in the byte array format (COMMON HEADER, PORT ID, EXECUTION BYTE, SUBCOMMAND ID, PAYLOAD).
Payload is accepted as an array since these vary across different subcommands.
Parameters:
Name | Type | Description |
---|---|---|
portID |
number | the port (Connect ID) to send a command to. |
execution |
number | Byte containing startup/completion information |
subCommand |
number | the id of the subcommand byte. |
payload |
array | the list of bytes to send as subcommand payload |
Returns:
- a generated output command.
- Type
- array
isConnected() → {boolean}
Called by the runtime to detect whether the Boost peripheral is connected.
Returns:
- the connected state.
- Type
- boolean
motor(index) → {BoostMotor}
Access a particular motor on this peripheral.
Parameters:
Name | Type | Description |
---|---|---|
index |
int | the index of the desired motor. |
Returns:
- the BoostMotor instance, if any, at that index.
- Type
- BoostMotor
reset()
Reset all the state and timeout/interval ids.
scan()
Called by the runtime when user wants to scan for a Boost peripheral.
send(uuid, message, useLimiteropt) → {Promise}
Write a message to the Boost peripheral BLE socket.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
uuid |
number | the UUID of the characteristic to write to |
||
message |
Array | the message to write. |
||
useLimiter |
boolean |
<optional> |
true
|
if true, use the rate limiter |
Returns:
- a promise result of the write operation
- Type
- Promise
setLED(inputRGB) → {Promise}
Set the Boost peripheral's LED to a specific color.
Parameters:
Name | Type | Description |
---|---|---|
inputRGB |
int | a 24-bit RGB color in 0xRRGGBB format. |
Returns:
- a promise of the completion of the set led send operation.
- Type
- Promise
setLEDMode() → {Promise}
Sets the input mode of the LED to RGB.
Returns:
- a promise returned by the send operation.
- Type
- Promise
stopAll()
Stop the motors on the Boost peripheral.
stopAllMotors()
Stop all the motors that are currently running.