Creates an instance of FrameBle. The constructor is currently empty as most setup occurs during the connect method.
Connects to a Frame device.
Prompts the user to select a Bluetooth device if one is not already known or connected. Handles connection attempts, retries, and characteristic setup.
Optional configuration for the connection process.
Optional
name?: stringThe exact name of the device to connect to.
Optional
namePrefix?: stringThe prefix of the device name to filter by.
Optional
numAttempts?: numberThe maximum number of connection attempts. Defaults to 5.
Optional
retryDelayMs?: numberThe delay in milliseconds between retry attempts. Defaults to 1000ms.
A promise that resolves with the name or ID of the connected device, or undefined if connection fails.
Disconnects from the currently connected Frame device.
If no device is connected, this method does nothing.
It also triggers the handleDisconnect
cleanup logic if not connected,
or relies on the 'gattserverdisconnected' event if connected.
A promise that resolves once the disconnection process has been initiated, or immediately if already disconnected.
Gets the maximum payload size for a single BLE transmission.
This value is determined after device connection.
For Lua strings, the full maxPayload
can be used.
For data packets (which include a 0x01 prefix byte), the effective payload is maxPayload - 1
.
If true, returns the max payload for Lua strings. Otherwise, for data packets.
The maximum payload size in bytes.
Checks if the Frame device is currently connected.
True if the device is connected, false otherwise.
Sends a break signal (0x03) to the Frame device. This typically interrupts any currently running Lua script on the device.
If true, logs the transmitted signal (hex format) to the console. Defaults to false.
A promise that resolves after a short delay post-transmission.
Sends raw data to the device. The data is prefixed with a 0x01
byte to distinguish it from Lua commands.
The raw application payload to send as a Uint8Array. This is the actual data without the prefix.
Optional configuration for sending data.
Optional
awaitData?: booleanIf true, waits for a data response from the device. Defaults to false.
Optional
showMe?: booleanIf true, logs the transmitted data (including prefix, hex format) to the console. Defaults to false.
Optional
timeout?: numberThe timeout in milliseconds to wait for a data response if awaitData
is true. Defaults to 5000ms.
A promise that resolves with the Uint8Array data response if awaitData
is true, or void otherwise.
Sends a Lua command string to the Frame device.
The Lua command string to send.
Optional configuration for sending the Lua command.
Optional
awaitPrint?: booleanIf true, waits for a print response from the device. Defaults to false.
Optional
showMe?: booleanIf true, logs the transmitted data (hex format) to the console. Defaults to false.
Optional
timeout?: numberThe timeout in milliseconds to wait for a print response if awaitPrint
is true. Defaults to 5000ms.
A promise that resolves with the print response string if awaitPrint
is true, or void otherwise.
Sends a multi-packet message to the device. This method handles chunking the payload and sending it in multiple BLE packets according to a specific protocol (message code, total size header, then data chunks).
A number (0-255) representing the message type or command.
The Uint8Array data to send as the message payload.
If true, logs details of each transmitted packet to the console. Defaults to false.
A promise that resolves when all parts of the message have been sent and acknowledged.
Sends a reset signal (0x04) to the Frame device. This typically causes the device to restart its Lua environment.
If true, logs the transmitted signal (hex format) to the console. Defaults to false.
A promise that resolves after a short delay post-transmission.
Sets or updates the handler for asynchronous data responses from the device.
The function to call when data (as Uint8Array) is received. Pass undefined to remove the current handler.
Sets or updates the handler for disconnection events.
The function to call when the device disconnects. Pass undefined to remove the current handler.
Sets or updates the handler for asynchronous print (string) responses from the device.
The function to call when a print string is received. Pass undefined to remove the current handler.
A convenience method that calls uploadFileFromString
.
Uploads file content to a specified path on the Frame device.
The string content of the file to upload.
The path on the Frame device where the file will be saved. Defaults to "main.lua".
A promise that resolves when the file upload is complete.
Uploads content to a file on the Frame device by sending Lua commands. The content is escaped and chunked to fit within payload limits.
The string content to write to the file.
The path to the file on the Frame device. Defaults to "main.lua".
A promise that resolves when the file upload is complete.
Class for managing a connection to and transferring data to and from the Brilliant Labs Frame device over Bluetooth LE using WebBluetooth