import { Color, PixelColorway, PixelDieType } from "@systemic-games/pixels-core-animation"; import { EventReceiver } from "@systemic-games/pixels-core-utils"; import { MPCMessageOrType, MPCMessageType } from "./MPCMessages"; import { PixelConnect, PixelConnectMutableProps, PixelStatusEvent } from "./PixelConnect"; import { PixelInfo } from "./PixelInfo"; import { PixelMessage } from "./PixelMessage"; import { PixelRollState } from "./PixelRollState"; import { PixelSession } from "./PixelSession"; /** * Event map for {@link MPC} class. * This is the list of supported events where the property name * is the event name and the property type the event data type. * Call {@link MPC.addEventListener} to subscribe to an event. * @category Pixels */ export type MPCEventMap = Readonly<{ /** MPC status changed notification. */ statusChanged: PixelStatusEvent; /** Message received notification. */ messageReceived: MPCMessageOrType; /** Message send notification. */ messageSend: MPCMessageOrType; /** Battery state changed notification. */ battery: Readonly<{ level: number; isCharging: boolean; }>; }>; /** * The mutable properties of {@link MPC} not inherited from parent * class {@link PixelConnect}. * @category Pixels */ export type MPCOwnMutableProps = object; /** * The mutable properties of {@link MPC}. * @category Pixels */ export type MPCMutableProps = PixelConnectMutableProps & MPCOwnMutableProps; /** * Represents a Pixels Multi Purpose Controller (MPC). * Most of its methods require the instance to be connected to the MPC. * Call the {@link connect()} method to initiate a connection. * * Call {@link addEventListener} to get notified for rolls, connection and * disconnection events and more. * * Call {@link addPropertyListener} to get notified on property changes. * * @category Pixels */ export declare class MPC extends PixelConnect implements MPCOwnMutableProps { private readonly _evEmitter; private readonly _info; private readonly _versions; private _disposeFunc; /** Device type is Pixels MPC. */ readonly type = "mpc"; /** Gets the unique id assigned by the system to the MPC Bluetooth peripheral. */ get systemId(): string; /** Gets the unique Pixel id of the MPC, may be 0 until connected. */ get pixelId(): number; /** Gets the MPC name, may be empty until connected to device. */ get name(): string; /** Gets the number of LEDs for the MPC, may be 0 until connected to device. */ get ledCount(): number; /** Always return "unknown". */ get colorway(): PixelColorway; /** Always return "unknown". */ get dieType(): PixelDieType; /** Gets the MPC firmware build date. */ get firmwareDate(): Date; /** * Gets the last RSSI value notified by the MPC. * @remarks Call {@link reportRssi()} to automatically update the RSSI value. */ get rssi(): number; /** * Gets the MPC battery level (percentage). * @remarks This value is automatically updated when the die is connected. */ get batteryLevel(): number; /** * Gets whether the MPC battery is charging or not. * Returns 'true' if fully charged but still on charger. * @remarks This value is automatically updated when the die is connected. */ get isCharging(): boolean; /** Always return "unknown". */ get rollState(): PixelRollState; /** Always return "0". */ get currentFace(): number; /** Always return "0". */ get currentFaceIndex(): number; /** * Instantiates a MPC. * @param session The session used to communicate with the MPC. */ constructor(session: PixelSession, info?: Partial>); protected _internalDispose(): void; /** * Update MPC info from an external source such as scanning data. * @param info The updated info. * @remarks * The info will be updated only if the die is disconnected. * Roll state and face index are updated only if both are provided. */ updateInfo(info: Partial>): void; /** * Asynchronously tries to connect to the die. Throws on connection error. * @param timeoutMs Delay before giving up (may be ignored when having concurrent * calls to connect()). It may take longer than the given timeout * for the function to return. * @returns A promise that resoles to this instance once the connection process * has completed (whether successfully or not). * @throws Will throw a {@link PixelConnectError} if it fails to connect in time. */ connect(timeoutMs?: number): Promise; /** * Immediately disconnects from the die. * @returns A promise that resolves once the disconnect request has been processed. **/ disconnect(): Promise; /** * Registers a listener function that will be called when the specified * event is raised. * See {@link MPCEventMap} for the list of events and their * associated data. * @param type A case-sensitive string representing the event type to listen for. * @param listener The callback function. */ addEventListener(type: K, listener: EventReceiver): void; /** * Unregisters a listener from receiving events identified by * the given event name. * See {@link MPCEventMap} for the list of events and their * associated data. * @param type A case-sensitive string representing the event type. * @param listener The callback function to unregister. */ removeEventListener(type: K, listener: EventReceiver): void; /** * Sends a message to the MPC. * @param msgOrType Message with the data to send or just a message type. * @param withoutAck Whether to request a confirmation that the message was received. * @returns A promise that resolves once the message has been send. */ sendMessage(msgOrType: MPCMessageOrType, withoutAck?: boolean): Promise; /** * Sends a message to the MPC and wait for a specific response. * @param msgOrTypeToSend Message with the data to send or just a message type. * @param responseType Expected response type. * @param timeoutMs Timeout in mill-seconds before aborting waiting for the response. * @returns A promise resolving to the response in the form of a message type or a message object. */ sendAndWaitForResponse(msgOrTypeToSend: MPCMessageOrType, responseType: MPCMessageType, timeoutMs?: number): Promise; /** * Sends a message to the MPC and wait for a specific response * which is returned casted to the expected type. * @param msgOrTypeToSend Message with the data to send or just a message type. * @param responseType Expected response class type. * @param responseType Expected response type. * @returns A promise resolving to a message object of the expected type. */ sendAndWaitForTypedResponse(msgOrTypeToSend: MPCMessageOrType, responseType: { new (): T; }, timeoutMs?: number): Promise; /** * Requests the MPC to change its name. * @param name New name to assign to the MPC. Must have at least one character. * @returns A promise that resolves once the die has confirmed being renamed. */ rename(name: string): Promise; /** * Requests the MPC to regularly send its measured RSSI value. * @param activate Whether to turn or turn off this feature. * @param minInterval The minimum time interval in milliseconds * between two RSSI updates. * @returns A promise that resolves once the message has been send. */ reportRssi(activate?: boolean, minInterval?: number): Promise; /** * Asynchronously gets the MPC RSSI value. * @returns A promise revolving to a negative number representing the RSSI value. */ queryRssi(): Promise; /** * Requests the MPC to blink and wait for a confirmation. * @param color Blink color. * @param opt.count Number of blinks. * @param opt.duration Total duration of the animation in milliseconds. * @param opt.fade Amount of in and out fading, 0: sharp transition, 1: maximum fading. * @param opt.faceMask Select which faces to light up. * @param opt.loopCount How many times to loop the animation. * @returns A promise that resolves once the die has confirmed receiving the message. */ blink(color: Color, opt?: { count?: number; duration?: number; fade?: number; faceMask?: number; loopCount?: number; }): Promise; sync(targetTime: number, referenceTime: number): Promise; playAnim(animIndex: number): Promise; stopAnim(animIndex: number): Promise; protected _onStatusChanged(ev: PixelStatusEvent): void; protected _internalSetup(): Promise; protected _internalDeserializeMessage(dataView: DataView): MPCMessageOrType; private _emitEvent; private _updateName; private _updateLedCount; private _updateFirmwareDate; private _updateRssi; private _updateBattery; } //# sourceMappingURL=MPC.d.ts.map