import { Color, DataSet, PixelColorway, PixelDieType } from "@systemic-games/pixels-core-animation"; import { EventReceiver } from "@systemic-games/pixels-core-utils"; import { MessageOrType, MessageType } from "./DieMessages"; import { PixelConnect, PixelConnectMutableProps, PixelStatusEvent } from "./PixelConnect"; import { PixelInfo } from "./PixelInfo"; import { PixelMessage } from "./PixelMessage"; import { PixelRollState } from "./PixelRollState"; import { PixelSession } from "./PixelSession"; /** * Data structure for {@link Pixel} roll state events, * see {@link PixelEventMap}. * @category Pixels */ export type RollEvent = Readonly<{ /** The roll state of the Pixels die when this event was raised. */ state: PixelRollState; /** * The value of the die face that is currently facing up. * @remarks Fudge die will return -1, 0 or 1. **/ face: number; /** * The 0-based index of the die face that is currently facing up. * @see {@link PixelInfo.currentFaceIndex} for more details. **/ faceIndex: number; }>; /** * Data structure for {@link Pixel} battery events, * see {@link PixelEventMap}. * @category Pixels */ export type BatteryEvent = Readonly<{ level: number; isCharging: boolean; }>; /** * Data structure for {@link Pixel} user message events, * see {@link PixelEventMap}. * @category Pixels */ export type UserMessageEvent = Readonly<{ message: string; withCancel: boolean; response: (okCancel: boolean) => Promise; }>; /** * Data structure for {@link Pixel} data transfer events, * and for {@link Pixel.dataTransferProgress}. * see {@link PixelEventMap}. * @category Pixels */ export type DataTransferProgress = Readonly<{ progressPercent: number; transferredBytes: number; totalBytes: number; }>; /** * Event map for {@link Pixel} 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 Pixel.addEventListener} to subscribe to an event. * @category Pixels */ export type PixelEventMap = Readonly<{ /** Pixel status changed notification. */ statusChanged: PixelStatusEvent; /** Message received notification. */ messageReceived: MessageOrType; /** Message send notification. */ messageSend: MessageOrType; /** Roll state changed notification. */ rollState: RollEvent; /** Roll result notification. */ roll: number; /** Battery state changed notification. */ battery: BatteryEvent; /** User message request. */ userMessage: UserMessageEvent; /** Remote action request. */ remoteAction: number; /** Data transfer. */ dataTransfer: Readonly<{ type: "preparing" | "starting" | "completed"; totalBytes: number; } | { type: "failed"; error: "timeout" | "outOfMemory" | "disconnected" | "unknown"; } | ({ type: "progress"; } & DataTransferProgress)>; }>; /** * The mutable properties of {@link Pixel} not inherited from parent * class {@link PixelConnect}. * @category Pixels */ export type PixelOwnMutableProps = { /** On-die profile hash value. */ profileHash: number; /** Whether data is being transferred from or to the die. */ isTransferring: boolean; }; /** * The mutable properties of {@link Pixel}. * @category Pixels */ export type PixelMutableProps = PixelConnectMutableProps & PixelOwnMutableProps; /** * Represents a Pixels die. * Most of its methods require the instance to be connected to the Pixel device. * 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 Pixel extends PixelConnect implements PixelOwnMutableProps { private readonly _evEmitter; private readonly _info; private readonly _versions; private _profileHash; private _isTransferring; private _disposeFunc; /** Device type is Pixels die. */ readonly type = "die"; /** Gets the unique id assigned by the system to the Pixel Bluetooth peripheral. */ get systemId(): string; /** Gets the unique Pixel id of the device, may be 0 until connected. */ get pixelId(): number; /** Gets the Pixel name, may be empty until connected to device. */ get name(): string; /** Gets the number of LEDs for the Pixel, may be 0 until connected to device. */ get ledCount(): number; /** Gets the color of the Pixel. */ get colorway(): PixelColorway; /** Gets the die type of the Pixel. */ get dieType(): PixelDieType; /** Gets the number of faces of the Pixel. */ get dieFaceCount(): number; /** Gets the Pixel firmware build date. */ get firmwareDate(): Date; /** * Gets the last RSSI value notified by the Pixel. * @remarks Call {@link reportRssi()} to automatically update the RSSI value. */ get rssi(): number; /** * Gets the Pixel battery level (percentage). * @remarks This value is automatically updated when the die is connected. */ get batteryLevel(): number; /** * Gets whether the Pixel 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; /** * Gets the Pixel roll state. * @remarks This value is automatically updated when the die is connected. */ get rollState(): PixelRollState; /** * Gets the die face value that is currently facing up. * @remarks * Fudge die returns +1, 0 and -1. * This value is automatically updated when the die is connected. */ get currentFace(): number; /** * Gets the 0-based index of the die face that is currently facing up. * @remarks * This value is automatically updated when the die is connected. * @see {@link PixelInfo.currentFaceIndex} for more details. */ get currentFaceIndex(): number; /** * Gets the on-die profile hash value. * This can be used as an identifier for the current profile. */ get profileHash(): number; /** Whether data is being transferred from or to the die. */ get isTransferring(): boolean; /** * Instantiates a Pixel. * @param session The session used to communicate with the Pixel. */ constructor(session: PixelSession, info?: Partial>); protected _internalDispose(): void; /** * Update Pixel 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 PixelEventMap} 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 PixelEventMap} 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 Pixel. * @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: MessageOrType, withoutAck?: boolean): Promise; /** * Sends a message to the Pixel 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: MessageOrType, responseType: MessageType, timeoutMs?: number): Promise; /** * Sends a message to the Pixel 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: MessageOrType, responseType: { new (): T; }, timeoutMs?: number): Promise; /** * Requests the Pixel to change its name. * @param name New name to assign to the Pixel. Must have at least one character. * @returns A promise that resolves once the die has confirmed being renamed. */ rename(name: string): Promise; /** * Requests the Pixel to start faces calibration sequence. * @returns A promise that resolves once the message has been send. */ startCalibration(): Promise; /** * Requests the Pixel 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 Pixel RSSI value. * @returns A promise revolving to a negative number representing the RSSI value. */ queryRssi(): Promise; /** * Requests the Pixel to completely turn off. * @returns A promise that resolves once the message has been send. */ turnOff(): Promise; /** * Requests the Pixel 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; /** * Requests the Pixel to stop all currently playing animations. * @returns A promise. */ stopAllAnimations(): Promise; /** * Uploads the given data set of animations to the Pixel flash memory. * @param dataSet The data set to upload. * @returns A promise that resolves once the transfer has completed. */ transferDataSet(dataSet: Readonly): Promise; /** * Plays the (single) LEDs animation included in the given data set. * @param dataSet The data set containing just one animation to play. * @returns A promise that resolves once the transfer has completed. */ playTestAnimation(dataSet: Readonly): Promise; /** * Uploads the given data set of animations to the Pixel RAM memory. * Those animations are lost when the Pixel goes to sleep, is turned off or is restarted. * @param dataSet The data set to upload. * @returns A promise that resolves once the transfer has completed. */ transferInstantAnimations(dataSet: Readonly): Promise; /** * Plays the instant animation at the given index. * See @see transferInstantAnimations(). * @param animIndex The index of the instant animation to play. * @returns A promise that resolves once the message has been send. */ playInstantAnimation(animIndex: number): Promise; protected _onStatusChanged(ev: PixelStatusEvent): void; protected _internalSetup(): Promise; protected _internalDeserializeMessage(dataView: DataView): MessageOrType; private _emitEvent; private _updateName; private _updateLedCount; private _updateColorway; private _updateDieType; private _updateFirmwareDate; private _updateRssi; private _updateBattery; private _updateRoll; private _updateHash; private _programDataSet; private _updateTransferProgress; /** * Upload the given data to the Pixel. * @param ackType The expected confirmation message type. * @param data The data to send. * @returns A promise that resolves once the transfer has completed. */ private _uploadBulkDataWithAck; private _uploadBulkData; } //# sourceMappingURL=Pixel.d.ts.map