import { Color, PixelColorway, PixelDieType } from "@systemic-games/pixels-core-animation"; import { EventReceiver } from "@systemic-games/pixels-core-utils"; import { ChargerMessageOrType, ChargerMessageType } from "./ChargerMessages"; 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 Charger} 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 Charger.addEventListener} to subscribe to an event. * @category Pixels */ export type ChargerEventMap = Readonly<{ /** Charger status changed notification. */ statusChanged: PixelStatusEvent; /** Message received notification. */ messageReceived: ChargerMessageOrType; /** Message send notification. */ messageSend: ChargerMessageOrType; /** Battery state changed notification. */ battery: Readonly<{ level: number; isCharging: boolean; }>; }>; /** * The mutable properties of {@link Charger} not inherited from parent * class {@link PixelConnect}. * @category Pixels */ export type ChargerOwnMutableProps = object; /** * The mutable properties of {@link Charger}. * @category Pixels */ export type ChargerMutableProps = PixelConnectMutableProps & ChargerOwnMutableProps; /** * Represents a Pixels charger. * Most of its methods require the instance to be connected to the charger. * 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 Charger extends PixelConnect implements ChargerOwnMutableProps { private readonly _evEmitter; private readonly _info; private readonly _versions; private _disposeFunc; /** Device type is Pixels charger. */ readonly type = "charger"; /** Gets the unique id assigned by the system to the Charger Bluetooth peripheral. */ get systemId(): string; /** Gets the unique Pixel id of the charger, may be 0 until connected. */ get pixelId(): number; /** Gets the Charger name, may be empty until connected to device. */ get name(): string; /** Gets the number of LEDs for the Charger, may be 0 until connected to device. */ get ledCount(): number; /** Always return "unknown". */ get colorway(): PixelColorway; /** Always return "unknown". */ get dieType(): PixelDieType; /** Gets the Charger firmware build date. */ get firmwareDate(): Date; /** * Gets the last RSSI value notified by the Charger. * @remarks Call {@link reportRssi()} to automatically update the RSSI value. */ get rssi(): number; /** * Gets the Charger battery level (percentage). * @remarks This value is automatically updated when the die is connected. */ get batteryLevel(): number; /** * Gets whether the Charger 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 Charger. * @param session The session used to communicate with the Charger. */ constructor(session: PixelSession, info?: Partial>); protected _internalDispose(): void; /** * Update Charger 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 ChargerEventMap} 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 ChargerEventMap} 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 Charger. * @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: ChargerMessageOrType, withoutAck?: boolean): Promise; /** * Sends a message to the Charger 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: ChargerMessageOrType, responseType: ChargerMessageType, timeoutMs?: number): Promise; /** * Sends a message to the Charger 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: ChargerMessageOrType, responseType: { new (): T; }, timeoutMs?: number): Promise; /** * Requests the Charger to change its name. * @param name New name to assign to the Charger. Must have at least one character. * @returns A promise that resolves once the die has confirmed being renamed. */ rename(name: string): Promise; /** * Requests the Charger 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 Charger RSSI value. * @returns A promise revolving to a negative number representing the RSSI value. */ queryRssi(): Promise; /** * Requests the Charger 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; protected _onStatusChanged(ev: PixelStatusEvent): void; protected _internalSetup(): Promise; protected _internalDeserializeMessage(dataView: DataView): ChargerMessageOrType; private _emitEvent; private _updateName; private _updateLedCount; private _updateFirmwareDate; private _updateRssi; private _updateBattery; } //# sourceMappingURL=Charger.d.ts.map