Represents a Pixels charger. Most of its methods require the instance to be connected to the charger. Call the () method to initiate a connection.

Call addEventListener to get notified for rolls, connection and disconnection events and more.

Call addPropertyListener to get notified on property changes.

Hierarchy (view full)

Implements

Constructors

  • Instantiates a Charger.

    Parameters

    • session: PixelSession

      The session used to communicate with the Charger.

    • Optionalinfo: Partial<Pick<Readonly<{
          batteryLevel: number;
          colorway:
              | "custom"
              | "clear"
              | "unknown"
              | "onyxBlack"
              | "hematiteGrey"
              | "midnightGalaxy"
              | "auroraSky"
              | "whiteAurora";
          currentFace: number;
          currentFaceIndex: number;
          dieType:
              | "unknown"
              | "d4"
              | "d6"
              | "d8"
              | "d10"
              | "d00"
              | "d12"
              | "d20"
              | "d6pipped"
              | "d6fudge";
          firmwareDate: Date;
          isCharging: boolean;
          ledCount: number;
          name: string;
          pixelId: number;
          rollState:
              | "unknown"
              | "handling"
              | "rolling"
              | "crooked"
              | "rolled"
              | "onFace";
          rssi: number;
          systemId: string;
      }>, "pixelId" | "ledCount" | "firmwareDate">>

    Returns Charger

Properties

_msgEvEmitter: EventEmitter = ...
_serializer: MessageSerializer<
    | "blink"
    | "none"
    | "whoAreYou"
    | "iAmALCC"
    | "bulkSetup"
    | "bulkSetupAck"
    | "bulkData"
    | "bulkDataAck"
    | "transferSettings"
    | "transferSettingsAck"
    | "transferSettingsFinished"
    | "debugLog"
    | "requestSettings"
    | "blinkAck"
    | "requestBatteryLevel"
    | "batteryLevel"
    | "requestRssi"
    | "rssi"
    | "notifyUser"
    | "notifyUserAck"
    | "programDefaultParameters"
    | "programDefaultParametersFinished"
    | "setName"
    | "setNameAck"
    | "requestTemperature"
    | "temperature"
    | "testBulkSend"
    | "testBulkReceive"
    | "attractMode"
    | "printA2DReadings"
    | "printAnimationControllerState">
isNotifier = true
type = "charger"

Device type is Pixels charger.

MutablePropsList: readonly (
    | "name"
    | "batteryLevel"
    | "rssi"
    | "pixelId"
    | "ledCount"
    | "systemId"
    | "colorway"
    | "dieType"
    | "firmwareDate"
    | "isCharging"
    | "rollState"
    | "currentFace"
    | "currentFaceIndex")[] = ...

Accessors

  • get batteryLevel(): number
  • Gets the Charger battery level (percentage).

    Returns number

    This value is automatically updated when the die is connected.

  • get colorway():
        | "custom"
        | "clear"
        | "unknown"
        | "onyxBlack"
        | "hematiteGrey"
        | "midnightGalaxy"
        | "auroraSky"
        | "whiteAurora"
  • Always return "unknown".

    Returns
        | "custom"
        | "clear"
        | "unknown"
        | "onyxBlack"
        | "hematiteGrey"
        | "midnightGalaxy"
        | "auroraSky"
        | "whiteAurora"

  • get dieType():
        | "unknown"
        | "d4"
        | "d6"
        | "d8"
        | "d10"
        | "d00"
        | "d12"
        | "d20"
        | "d6pipped"
        | "d6fudge"
  • Always return "unknown".

    Returns
        | "unknown"
        | "d4"
        | "d6"
        | "d8"
        | "d10"
        | "d00"
        | "d12"
        | "d20"
        | "d6pipped"
        | "d6fudge"

  • get isCharging(): boolean
  • Gets whether the Charger battery is charging or not. Returns 'true' if fully charged but still on charger.

    Returns boolean

    This value is automatically updated when the die is connected.

  • get rollState():
        | "unknown"
        | "handling"
        | "rolling"
        | "crooked"
        | "rolled"
        | "onFace"
  • Always return "unknown".

    Returns
        | "unknown"
        | "handling"
        | "rolling"
        | "crooked"
        | "rolled"
        | "onFace"

Methods

  • Sends a message to the Pixel and wait for a specific response.

    Parameters

    • msgOrTypeToSend:
          | "blink"
          | "none"
          | PixelMessage
          | "whoAreYou"
          | "iAmALCC"
          | "bulkSetup"
          | "bulkSetupAck"
          | "bulkData"
          | "bulkDataAck"
          | "transferSettings"
          | "transferSettingsAck"
          | "transferSettingsFinished"
          | "debugLog"
          | "requestSettings"
          | "blinkAck"
          | "requestBatteryLevel"
          | "batteryLevel"
          | "requestRssi"
          | "rssi"
          | "notifyUser"
          | "notifyUserAck"
          | "programDefaultParameters"
          | "programDefaultParametersFinished"
          | "setName"
          | "setNameAck"
          | "requestTemperature"
          | "temperature"
          | "testBulkSend"
          | "testBulkReceive"
          | "attractMode"
          | "printA2DReadings"
          | "printAnimationControllerState"

      Message with the data to send or just a message type.

    • responseType:
          | "blink"
          | "none"
          | "whoAreYou"
          | "iAmALCC"
          | "bulkSetup"
          | "bulkSetupAck"
          | "bulkData"
          | "bulkDataAck"
          | "transferSettings"
          | "transferSettingsAck"
          | "transferSettingsFinished"
          | "debugLog"
          | "requestSettings"
          | "blinkAck"
          | "requestBatteryLevel"
          | "batteryLevel"
          | "requestRssi"
          | "rssi"
          | "notifyUser"
          | "notifyUserAck"
          | "programDefaultParameters"
          | "programDefaultParametersFinished"
          | "setName"
          | "setNameAck"
          | "requestTemperature"
          | "temperature"
          | "testBulkSend"
          | "testBulkReceive"
          | "attractMode"
          | "printA2DReadings"
          | "printAnimationControllerState"

      Expected response type.

    • timeoutMs: number = Constants.ackMessageTimeout

      Timeout in mill-seconds before aborting waiting for the response.

    Returns Promise<
        | "blink"
        | "none"
        | PixelMessage
        | "whoAreYou"
        | "iAmALCC"
        | "bulkSetup"
        | "bulkSetupAck"
        | "bulkData"
        | "bulkDataAck"
        | "transferSettings"
        | "transferSettingsAck"
        | "transferSettingsFinished"
        | "debugLog"
        | "requestSettings"
        | "blinkAck"
        | "requestBatteryLevel"
        | "batteryLevel"
        | "requestRssi"
        | "rssi"
        | "notifyUser"
        | "notifyUserAck"
        | "programDefaultParameters"
        | "programDefaultParametersFinished"
        | "setName"
        | "setNameAck"
        | "requestTemperature"
        | "temperature"
        | "testBulkSend"
        | "testBulkReceive"
        | "attractMode"
        | "printA2DReadings"
        | "printAnimationControllerState">

    A promise resolving to the response in the form of a message type or a message object.

  • Sends a message to the Pixel and wait for a specific response which is returned casted to the expected type.

    Type Parameters

    • T extends PixelMessage

    Parameters

    • msgOrTypeToSend:
          | "blink"
          | "none"
          | PixelMessage
          | "whoAreYou"
          | "iAmALCC"
          | "bulkSetup"
          | "bulkSetupAck"
          | "bulkData"
          | "bulkDataAck"
          | "transferSettings"
          | "transferSettingsAck"
          | "transferSettingsFinished"
          | "debugLog"
          | "requestSettings"
          | "blinkAck"
          | "requestBatteryLevel"
          | "batteryLevel"
          | "requestRssi"
          | "rssi"
          | "notifyUser"
          | "notifyUserAck"
          | "programDefaultParameters"
          | "programDefaultParametersFinished"
          | "setName"
          | "setNameAck"
          | "requestTemperature"
          | "temperature"
          | "testBulkSend"
          | "testBulkReceive"
          | "attractMode"
          | "printA2DReadings"
          | "printAnimationControllerState"

      Message with the data to send or just a message type.

    • responseType: (new () => T)

      Expected response class type.

        • new (): T
        • Returns T

    • timeoutMs: number = Constants.ackMessageTimeout

    Returns Promise<T>

    A promise resolving to a message object of the expected type.

  • Sends a message to the Pixel.

    Parameters

    • msgOrType:
          | "blink"
          | "none"
          | PixelMessage
          | "whoAreYou"
          | "iAmALCC"
          | "bulkSetup"
          | "bulkSetupAck"
          | "bulkData"
          | "bulkDataAck"
          | "transferSettings"
          | "transferSettingsAck"
          | "transferSettingsFinished"
          | "debugLog"
          | "requestSettings"
          | "blinkAck"
          | "requestBatteryLevel"
          | "batteryLevel"
          | "requestRssi"
          | "rssi"
          | "notifyUser"
          | "notifyUserAck"
          | "programDefaultParameters"
          | "programDefaultParametersFinished"
          | "setName"
          | "setNameAck"
          | "requestTemperature"
          | "temperature"
          | "testBulkSend"
          | "testBulkReceive"
          | "attractMode"
          | "printA2DReadings"
          | "printAnimationControllerState"

      Message with the data to send or just a message type.

    • withoutAck: boolean = false

      Whether to request a confirmation that the message was received.

    Returns Promise<void>

    A promise that resolves once the message has been send.

  • Waits for a message from the Pixel.

    Parameters

    • expectedMsgType:
          | "blink"
          | "none"
          | "whoAreYou"
          | "iAmALCC"
          | "bulkSetup"
          | "bulkSetupAck"
          | "bulkData"
          | "bulkDataAck"
          | "transferSettings"
          | "transferSettingsAck"
          | "transferSettingsFinished"
          | "debugLog"
          | "requestSettings"
          | "blinkAck"
          | "requestBatteryLevel"
          | "batteryLevel"
          | "requestRssi"
          | "rssi"
          | "notifyUser"
          | "notifyUserAck"
          | "programDefaultParameters"
          | "programDefaultParametersFinished"
          | "setName"
          | "setNameAck"
          | "requestTemperature"
          | "temperature"
          | "testBulkSend"
          | "testBulkReceive"
          | "attractMode"
          | "printA2DReadings"
          | "printAnimationControllerState"

      Type of the message to expect.

    • timeoutMs: number = Constants.ackMessageTimeout

      Timeout before aborting the wait.

    Returns Promise<
        | "blink"
        | "none"
        | PixelMessage
        | "whoAreYou"
        | "iAmALCC"
        | "bulkSetup"
        | "bulkSetupAck"
        | "bulkData"
        | "bulkDataAck"
        | "transferSettings"
        | "transferSettingsAck"
        | "transferSettingsFinished"
        | "debugLog"
        | "requestSettings"
        | "blinkAck"
        | "requestBatteryLevel"
        | "batteryLevel"
        | "requestRssi"
        | "rssi"
        | "notifyUser"
        | "notifyUserAck"
        | "programDefaultParameters"
        | "programDefaultParametersFinished"
        | "setName"
        | "setNameAck"
        | "requestTemperature"
        | "temperature"
        | "testBulkSend"
        | "testBulkReceive"
        | "attractMode"
        | "printA2DReadings"
        | "printAnimationControllerState">

    A promise with the received message of the expected type.

  • Parameters

    • ev: Readonly<{
          lastStatus: PixelStatus;
          reason?:
              | "canceled"
              | "success"
              | "unknown"
              | "host"
              | "timeout"
              | "notSupported"
              | "linkLoss"
              | "bluetoothOff"
              | "peripheral";
          status: PixelStatus;
      }>

    Returns void

  • Registers a listener function that will be called when the specified event is raised. See ChargerEventMap for the list of events and their associated data.

    Type Parameters

    • K extends
          | "battery"
          | "statusChanged"
          | "messageReceived"
          | "messageSend"

    Parameters

    • type: K

      A case-sensitive string representing the event type to listen for.

    • listener: EventReceiver<Readonly<{
          battery: Readonly<{
              isCharging: boolean;
              level: number;
          }>;
          messageReceived: ChargerMessages.ChargerMessageOrType;
          messageSend: ChargerMessages.ChargerMessageOrType;
          statusChanged: Readonly<{
              lastStatus: PixelStatus;
              reason?:
                  | "canceled"
                  | "success"
                  | "unknown"
                  | "host"
                  | "timeout"
                  | "notSupported"
                  | "linkLoss"
                  | "bluetoothOff"
                  | "peripheral";
              status: PixelStatus;
          }>;
      }>[K]>

      The callback function.

    Returns void

  • Registers a listener function that will be called on receiving raw messages of a given type from the Pixel.

    Parameters

    • msgType:
          | "blink"
          | "none"
          | "whoAreYou"
          | "iAmALCC"
          | "bulkSetup"
          | "bulkSetupAck"
          | "bulkData"
          | "bulkDataAck"
          | "transferSettings"
          | "transferSettingsAck"
          | "transferSettingsFinished"
          | "debugLog"
          | "requestSettings"
          | "blinkAck"
          | "requestBatteryLevel"
          | "batteryLevel"
          | "requestRssi"
          | "rssi"
          | "notifyUser"
          | "notifyUserAck"
          | "programDefaultParameters"
          | "programDefaultParametersFinished"
          | "setName"
          | "setNameAck"
          | "requestTemperature"
          | "temperature"
          | "testBulkSend"
          | "testBulkReceive"
          | "attractMode"
          | "printA2DReadings"
          | "printAnimationControllerState"

      The type of message to watch for.

    • listener: ((this: PixelConnect<PixelConnectMutableProps, PixelInfoWithStatus, string>, message:
          | "blink"
          | "none"
          | PixelMessage
          | "whoAreYou"
          | "iAmALCC"
          | "bulkSetup"
          | "bulkSetupAck"
          | "bulkData"
          | "bulkDataAck"
          | "transferSettings"
          | "transferSettingsAck"
          | "transferSettingsFinished"
          | "debugLog"
          | "requestSettings"
          | "blinkAck"
          | "requestBatteryLevel"
          | "batteryLevel"
          | "requestRssi"
          | "rssi"
          | "notifyUser"
          | "notifyUserAck"
          | "programDefaultParameters"
          | "programDefaultParametersFinished"
          | "setName"
          | "setNameAck"
          | "requestTemperature"
          | "temperature"
          | "testBulkSend"
          | "testBulkReceive"
          | "attractMode"
          | "printA2DReadings"
          | "printAnimationControllerState") => void)

      The callback function.

        • (this, message): void
        • Parameters

          • this: PixelConnect<PixelConnectMutableProps, PixelInfoWithStatus, string>
          • message:
                | "blink"
                | "none"
                | PixelMessage
                | "whoAreYou"
                | "iAmALCC"
                | "bulkSetup"
                | "bulkSetupAck"
                | "bulkData"
                | "bulkDataAck"
                | "transferSettings"
                | "transferSettingsAck"
                | "transferSettingsFinished"
                | "debugLog"
                | "requestSettings"
                | "blinkAck"
                | "requestBatteryLevel"
                | "batteryLevel"
                | "requestRssi"
                | "rssi"
                | "notifyUser"
                | "notifyUserAck"
                | "programDefaultParameters"
                | "programDefaultParametersFinished"
                | "setName"
                | "setNameAck"
                | "requestTemperature"
                | "temperature"
                | "testBulkSend"
                | "testBulkReceive"
                | "attractMode"
                | "printA2DReadings"
                | "printAnimationControllerState"

          Returns void

    Returns void

  • Requests the Charger to blink and wait for a confirmation.

    Parameters

    • color: Color

      Blink color.

    • Optionalopt: {
          count?: number;
          duration?: number;
          faceMask?: number;
          fade?: number;
          loopCount?: number;
      }
      • Optionalcount?: number

        Number of blinks.

      • Optionalduration?: number

        Total duration of the animation in milliseconds.

      • OptionalfaceMask?: number

        Select which faces to light up.

      • Optionalfade?: number

        Amount of in and out fading, 0: sharp transition, 1: maximum fading.

      • OptionalloopCount?: number

        How many times to loop the animation.

    Returns Promise<void>

    A promise that resolves once the die has confirmed receiving the message.

  • Asynchronously tries to connect to the die. Throws on connection error.

    Parameters

    • timeoutMs: number = 0

      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 Promise<Charger>

    A promise that resoles to this instance once the connection process has completed (whether successfully or not).

    Will throw a PixelConnectError if it fails to connect in time.

  • Emit a Pixel event for the specified property. This function should be called by the concrete type whenever the a property's value changes.

    Type Parameters

    • K extends
          | "name"
          | "status"
          | "batteryLevel"
          | "rssi"
          | "pixelId"
          | "ledCount"
          | "systemId"
          | "colorway"
          | "dieType"
          | "firmwareDate"
          | "isCharging"
          | "rollState"
          | "currentFace"
          | "currentFaceIndex"

    Parameters

    • propertyName: K

      Event name.

    Returns void

  • Unregisters a listener from receiving events identified by the given event name. See ChargerEventMap for the list of events and their associated data.

    Type Parameters

    • K extends
          | "battery"
          | "statusChanged"
          | "messageReceived"
          | "messageSend"

    Parameters

    • type: K

      A case-sensitive string representing the event type.

    • listener: EventReceiver<Readonly<{
          battery: Readonly<{
              isCharging: boolean;
              level: number;
          }>;
          messageReceived: ChargerMessages.ChargerMessageOrType;
          messageSend: ChargerMessages.ChargerMessageOrType;
          statusChanged: Readonly<{
              lastStatus: PixelStatus;
              reason?:
                  | "canceled"
                  | "success"
                  | "unknown"
                  | "host"
                  | "timeout"
                  | "notSupported"
                  | "linkLoss"
                  | "bluetoothOff"
                  | "peripheral";
              status: PixelStatus;
          }>;
      }>[K]>

      The callback function to unregister.

    Returns void

  • Unregisters a listener from receiving raw messages of a given type.

    Parameters

    • msgType:
          | "blink"
          | "none"
          | "whoAreYou"
          | "iAmALCC"
          | "bulkSetup"
          | "bulkSetupAck"
          | "bulkData"
          | "bulkDataAck"
          | "transferSettings"
          | "transferSettingsAck"
          | "transferSettingsFinished"
          | "debugLog"
          | "requestSettings"
          | "blinkAck"
          | "requestBatteryLevel"
          | "batteryLevel"
          | "requestRssi"
          | "rssi"
          | "notifyUser"
          | "notifyUserAck"
          | "programDefaultParameters"
          | "programDefaultParametersFinished"
          | "setName"
          | "setNameAck"
          | "requestTemperature"
          | "temperature"
          | "testBulkSend"
          | "testBulkReceive"
          | "attractMode"
          | "printA2DReadings"
          | "printAnimationControllerState"

      The type of message to watch for.

    • listener: ((this: PixelConnect<PixelConnectMutableProps, PixelInfoWithStatus, string>, msg:
          | "blink"
          | "none"
          | PixelMessage
          | "whoAreYou"
          | "iAmALCC"
          | "bulkSetup"
          | "bulkSetupAck"
          | "bulkData"
          | "bulkDataAck"
          | "transferSettings"
          | "transferSettingsAck"
          | "transferSettingsFinished"
          | "debugLog"
          | "requestSettings"
          | "blinkAck"
          | "requestBatteryLevel"
          | "batteryLevel"
          | "requestRssi"
          | "rssi"
          | "notifyUser"
          | "notifyUserAck"
          | "programDefaultParameters"
          | "programDefaultParametersFinished"
          | "setName"
          | "setNameAck"
          | "requestTemperature"
          | "temperature"
          | "testBulkSend"
          | "testBulkReceive"
          | "attractMode"
          | "printA2DReadings"
          | "printAnimationControllerState") => void)

      The callback function to unregister.

        • (this, msg): void
        • Parameters

          • this: PixelConnect<PixelConnectMutableProps, PixelInfoWithStatus, string>
          • msg:
                | "blink"
                | "none"
                | PixelMessage
                | "whoAreYou"
                | "iAmALCC"
                | "bulkSetup"
                | "bulkSetupAck"
                | "bulkData"
                | "bulkDataAck"
                | "transferSettings"
                | "transferSettingsAck"
                | "transferSettingsFinished"
                | "debugLog"
                | "requestSettings"
                | "blinkAck"
                | "requestBatteryLevel"
                | "batteryLevel"
                | "requestRssi"
                | "rssi"
                | "notifyUser"
                | "notifyUserAck"
                | "programDefaultParameters"
                | "programDefaultParametersFinished"
                | "setName"
                | "setNameAck"
                | "requestTemperature"
                | "temperature"
                | "testBulkSend"
                | "testBulkReceive"
                | "attractMode"
                | "printA2DReadings"
                | "printAnimationControllerState"

          Returns void

    Returns void

  • Requests the Charger to change its name.

    Parameters

    • name: string

      New name to assign to the Charger. Must have at least one character.

    Returns Promise<void>

    A promise that resolves once the die has confirmed being renamed.

  • Requests the Charger to regularly send its measured RSSI value.

    Parameters

    • activate: boolean

      Whether to turn or turn off this feature.

    • minInterval: number = 5000

      The minimum time interval in milliseconds between two RSSI updates.

    Returns Promise<void>

    A promise that resolves once the message has been send.

  • Sends a message to the Charger and wait for a specific response.

    Parameters

    • msgOrTypeToSend: ChargerMessages.ChargerMessageOrType

      Message with the data to send or just a message type.

    • responseType:
          | "blink"
          | "none"
          | "whoAreYou"
          | "iAmALCC"
          | "bulkSetup"
          | "bulkSetupAck"
          | "bulkData"
          | "bulkDataAck"
          | "transferSettings"
          | "transferSettingsAck"
          | "transferSettingsFinished"
          | "debugLog"
          | "requestSettings"
          | "blinkAck"
          | "requestBatteryLevel"
          | "batteryLevel"
          | "requestRssi"
          | "rssi"
          | "notifyUser"
          | "notifyUserAck"
          | "programDefaultParameters"
          | "programDefaultParametersFinished"
          | "setName"
          | "setNameAck"
          | "requestTemperature"
          | "temperature"
          | "testBulkSend"
          | "testBulkReceive"
          | "attractMode"
          | "printA2DReadings"
          | "printAnimationControllerState"

      Expected response type.

    • timeoutMs: number = Constants.ackMessageTimeout

      Timeout in mill-seconds before aborting waiting for the response.

    Returns Promise<ChargerMessages.ChargerMessageOrType>

    A promise resolving to the response in the form of a message type or a message object.

  • Sends a message to the Charger and wait for a specific response which is returned casted to the expected type.

    Type Parameters

    • T extends PixelMessage

    Parameters

    • msgOrTypeToSend: ChargerMessages.ChargerMessageOrType

      Message with the data to send or just a message type.

    • responseType: (new () => T)

      Expected response class type.

        • new (): T
        • Returns T

    • timeoutMs: number = Constants.ackMessageTimeout

    Returns Promise<T>

    A promise resolving to a message object of the expected type.

  • Sends a message to the Charger.

    Parameters

    • msgOrType: ChargerMessages.ChargerMessageOrType

      Message with the data to send or just a message type.

    • withoutAck: boolean = false

      Whether to request a confirmation that the message was received.

    Returns Promise<void>

    A promise that resolves once the message has been send.

  • Update Charger info from an external source such as scanning data.

    Parameters

    • info: Partial<Omit<Readonly<{
          batteryLevel: number;
          colorway:
              | "custom"
              | "clear"
              | "unknown"
              | "onyxBlack"
              | "hematiteGrey"
              | "midnightGalaxy"
              | "auroraSky"
              | "whiteAurora";
          currentFace: number;
          currentFaceIndex: number;
          dieType:
              | "unknown"
              | "d4"
              | "d6"
              | "d8"
              | "d10"
              | "d00"
              | "d12"
              | "d20"
              | "d6pipped"
              | "d6fudge";
          firmwareDate: Date;
          isCharging: boolean;
          ledCount: number;
          name: string;
          pixelId: number;
          rollState:
              | "unknown"
              | "handling"
              | "rolling"
              | "crooked"
              | "rolled"
              | "onFace";
          rssi: number;
          systemId: string;
      }>,
          | "systemId"
          | "colorway"
          | "dieType"
          | "rollState"
          | "currentFace"
          | "currentFaceIndex">>

      The updated info.

    Returns void

    The info will be updated only if the die is disconnected. Roll state and face index are updated only if both are provided.