frame-msg
    Preparing search index...

    Class FrameMsg

    FrameMsg class handles communication with the Frame device. It wraps the FrameBle class and provides higher-level methods for uploading standard Lua libraries and Frame applications. It also manages the registration and unregistration of data response handlers for different Rx message types. Subscribers can register their own handlers for specific message codes.

    Index

    Constructors

    • Constructs an instance of the FrameMsg class. Initializes a new FrameBle instance and sets up internal data response handling.

      Returns FrameMsg

    Properties

    ble: FrameBle

    The underlying FrameBle instance used for Bluetooth Low Energy communication.

    Methods

    • Attaches a handler for print responses from the Frame device. This handler will be called with any text data printed by Lua scripts on the device.

      Parameters

      • handler: (data: string) => void | Promise<void> = console.log

        A function to handle the print response string. Defaults to console.log.

      Returns void

    • Connects to the Frame device and optionally runs the initialization sequence. Note: Print and Disconnect handlers should be set directly on the FrameBle instance (e.g., frameMsg.ble.setPrintResponseHandler(...), frameMsg.ble.setDisconnectHandler(...)) or via frameMsg.attachPrintResponseHandler(...) before or after calling connect.

      Parameters

      • initialize: boolean = true

        If true, runs the break/reset/break sequence after connecting. Defaults to true.

      • connectOptions: { name?: string; namePrefix?: string } = {}

        Options including name and namePrefix for device filtering.

      Returns Promise<undefined | string>

      The device ID or name if connection was successful.

      Any exceptions from the underlying FrameBle connection or initialization.

    • Detaches the currently set print response handler. After calling this, print responses from the device will no longer be processed by a custom handler.

      Returns void

    • Disconnects from the Frame device if currently connected.

      Returns Promise<void>

      A Promise that resolves when disconnection is complete.

    • Gets the maximum payload size for sending data to the Frame device. This is a proxy to FrameBle.getMaxPayload().

      Parameters

      • isLua: boolean

        True if the payload is for a Lua command, false for other data types.

      Returns number

      The maximum payload size in bytes.

    • Checks if the Frame device is currently connected.

      Returns boolean

      True if connected, false otherwise.

    • Displays a short string of text on the Frame's display. The text is sanitized to escape single quotes and remove newlines.

      Parameters

      • text: string = ''

        The text to display. Defaults to an empty string.

      Returns Promise<string | void>

      A Promise that resolves with the print response from the device if awaitPrint is true (default), otherwise void.

    • Registers a handler for a subscriber interested in specific message codes from Frame.

      Parameters

      • subscriber: any

        The subscriber object/identifier.

      • msgCodes: number[]

        Array of message codes the subscriber is interested in.

      • handler: FrameMsgDataHandler

        The function to call with the incoming data (Uint8Array).

      Returns void

    • Sends a break signal (Ctrl+C) to the Frame device. This is a proxy to FrameBle.sendBreakSignal().

      Parameters

      • showMe: boolean = false

        If true, prints a message to the console indicating the signal was sent. Defaults to false.

      Returns Promise<void>

      A Promise that resolves when the signal has been sent.

    • Sends raw data to the device.

      Parameters

      • data: Uint8Array

        The Uint8Array payload to send.

      • options: { awaitData?: boolean; showMe?: boolean; timeout?: number } = {}

        Configuration options.

      Returns Promise<void | Uint8Array<ArrayBufferLike>>

      A Promise that resolves with the Uint8Array data response if awaitData is true, or void.

    • Sends a Lua command string to the Frame device. This is a proxy to FrameBle.sendLua().

      Parameters

      • str: string

        The Lua command string to send.

      • options: { awaitPrint?: boolean; showMe?: boolean; timeout?: number } = {}

        Configuration options for sending the Lua command.

      Returns Promise<string | void>

      A Promise that resolves with the print response if awaitPrint is true, otherwise void.

    • Sends a message (msg_code and payload) to the Frame device.

      Parameters

      • msgCode: number

        The message code (an integer identifying the message type).

      • payload: Uint8Array

        The Uint8Array payload for the message.

      • showMe: boolean = false

        If true, prints the message being sent to the console. Defaults to false.

      Returns Promise<void>

      A Promise that resolves when the message has been sent.

    • Sends a reset signal to the Frame device. This is a proxy to FrameBle.sendResetSignal().

      Parameters

      • showMe: boolean = false

        If true, prints a message to the console indicating the signal was sent. Defaults to false.

      Returns Promise<void>

      A Promise that resolves when the signal has been sent.

    • Starts a Frame application on the device by requiring its module name.

      Parameters

      • frameAppName: string = 'frame_app'

        The name of the Frame application module (without .lua extension). Defaults to 'frame_app'.

      • awaitPrint: boolean = true

        Whether to wait for a print response from the device. Defaults to true.

      Returns Promise<string | void>

      A Promise that resolves with the print response if awaitPrint is true, otherwise void.

    • Stops the currently running Frame application by sending a break signal. Optionally, it can also reset the device.

      Parameters

      • reset: boolean = true

        If true, sends a reset signal after the break signal. Defaults to true.

      Returns Promise<void>

      A Promise that resolves when the signals have been sent.

    • Unregisters all data response handlers associated with a specific subscriber.

      Parameters

      • subscriber: any

        The subscriber object/identifier whose handlers should be removed.

      Returns void

    • Uploads a Frame application (Lua script) to the device.

      Parameters

      • fileContent: string

        The content of the Lua application file as a string.

      • frameFileName: string = 'frame_app.lua'

        The target filename on the Frame device. Defaults to 'frame_app.lua'.

      Returns Promise<void>

      A Promise that resolves when the file has been uploaded.

    • Uploads specified standard Lua libraries to the Frame device.

      Parameters

      • libs: StdLua[]

        An array of StdLua enum values indicating which libraries to upload.

      Returns Promise<void>

      A Promise that resolves when all specified libraries have been uploaded.