Represents a Pixels die. Most of its methods require the instance to be connected to the Pixel device. 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)

Constructors

Properties

_disposeFunc: (() => void)

Type declaration

    • (): void
    • Returns void

_evEmitter: TypedEventEmitter<PixelEventMap> = ...
_logData: boolean = false
_logFunc: undefined | null | ((msg) => void)

Type declaration

    • (msg): void
    • Parameters

      • msg: string

      Returns void

_logMessages: boolean = false
_msgEvEmitter: EventEmitter = ...
_session: PixelSession
_status: PixelStatus
_versions: Omit<VersionInfoChunk, "chunkSize" | "buildTimestamp">
MutablePropsList: readonly (keyof PixelInfo)[] = ...

Accessors

  • get batteryLevel(): number
  • Get the Pixel battery level (percentage).

    Returns number

    Remarks

    This value is automatically updated when the die is connected.

  • get colorway(): "custom" | "clear" | "unknown" | "onyxBlack" | "hematiteGrey" | "midnightGalaxy" | "auroraSky"
  • Gets the color of the Pixel.

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

  • get currentFace(): number
  • Get the die face value that is currently facing up.

    Returns number

    Remarks

    Fudge die returns +1, 0 and -1. This value is automatically updated when the die is connected.

  • get dieType(): "unknown" | "d4" | "d6" | "d8" | "d10" | "d00" | "d12" | "d20" | "d6pipped" | "d6fudge"
  • Gets the die type of the Pixel.

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

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

    Returns boolean

    Remarks

    This value is automatically updated when the die is connected.

  • get rollState(): "unknown" | "handling" | "rolling" | "crooked" | "onFace"
  • Get the Pixel roll state.

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

    Remarks

    This value is automatically updated when the die is connected.

Methods

  • Parameters

    • state: "unknown" | "handling" | "rolling" | "crooked" | "onFace"
    • faceIndex: number
    • Optional opt: {
          skipEvents?: boolean;
      }
      • Optional skipEvents?: boolean

    Returns void

  • Parameters

    • data: ArrayBuffer
    • Optional progressCallback: ((progress) => void)
        • (progress): void
        • Parameters

          • progress: number

          Returns void

    • progressMode: "percent" | "bytes" = "percent"

    Returns Promise<void>

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

    Parameters

    • msgType: "blink" | "none" | "playAnimation" | "whoAreYou" | "iAmADie" | "rollState" | "telemetry" | "bulkSetup" | "bulkSetupAck" | "bulkData" | "bulkDataAck" | "transferAnimationSet" | "transferAnimationSetAck" | "transferAnimationSetFinished" | "transferSettings" | "transferSettingsAck" | "transferSettingsFinished" | "transferTestAnimationSet" | "transferTestAnimationSetAck" | "transferTestAnimationSetFinished" | "debugLog" | "playAnimationEvent" | "stopAnimation" | "remoteAction" | "requestRollState" | "requestAnimationSet" | "requestSettings" | "requestTelemetry" | "programDefaultAnimationSet" | "programDefaultAnimationSetFinished" | "blinkAck" | "requestDefaultAnimationSetColor" | "defaultAnimationSetColor" | "requestBatteryLevel" | "batteryLevel" | "requestRssi" | "rssi" | "calibrate" | "calibrateFace" | "notifyUser" | "notifyUserAck" | "testHardware" | "storeValue" | "storeValueAck" | "setTopLevelState" | "programDefaultParameters" | "programDefaultParametersFinished" | "setDesignAndColor" | "setDesignAndColorAck" | "setCurrentBehavior" | "setCurrentBehaviorAck" | "setName" | "setNameAck" | "powerOperation" | "exitValidation" | "transferInstantAnimationSet" | "transferInstantAnimationSetAck" | "transferInstantAnimationSetFinished" | "playInstantAnimation" | "stopAllAnimations" | "requestTemperature" | "temperature" | "setBatteryControllerMode" | "_unused" | "discharge" | "blinkId" | "blinkIdAck" | "transferTest" | "transferTestAck" | "transferTestFinished" | "clearSettings" | "clearSettingsAck" | "testBulkSend" | "testBulkReceive" | "setAllLEDsToColor" | "attractMode" | "printNormals" | "printA2DReadings" | "lightUpFace" | "setLEDToColor" | "debugAnimationController"

      The type of message to watch for.

    • listener: ((this, message) => void)

      The callback function.

    Returns void

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

    Parameters

    • color: Color

      Blink color.

    • Optional opt: {
          count?: number;
          duration?: number;
          faceMask?: number;
          fade?: number;
          loopCount?: number;
      }
      • Optional count?: number

        Number of blinks.

      • Optional duration?: number

        Total duration of the animation in milliseconds.

      • Optional faceMask?: number

        Select which faces to light up.

      • Optional fade?: number

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

      • Optional loopCount?: 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<Pixel>

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

    Throws

    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" | "rollState" | "batteryLevel" | "rssi" | "pixelId" | "dieType" | "ledCount" | "colorway" | "currentFaceIndex" | "systemId" | "firmwareDate" | "isCharging" | "currentFace"

    Parameters

    • propertyName: K

      Event name.

    Returns void

  • Plays the instant animation at the given index. See

    Parameters

    • animIndex: number

      The index of the instant animation to play.

    Returns Promise<void>

    A promise that resolves once the message has been send.

    See

    transferInstantAnimations().

  • Plays the (single) LEDs animation included in the given data set.

    Parameters

    • dataSet: DataSet

      The data set containing just one animation to play.

    • Optional progressCallback: ((progress) => void)

      An optional callback that is called as the operation progresses with the progress in percent..

        • (progress): void
        • Parameters

          • progress: number

          Returns void

    Returns Promise<void>

    A promise that resolves once the transfer has completed.

  • Asynchronously gets the battery state.

    Returns Promise<number>

    A promise revolving to an object with the batter level in percentage and flag indicating whether it is charging or not.

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

    Parameters

    • msgType: "blink" | "none" | "playAnimation" | "whoAreYou" | "iAmADie" | "rollState" | "telemetry" | "bulkSetup" | "bulkSetupAck" | "bulkData" | "bulkDataAck" | "transferAnimationSet" | "transferAnimationSetAck" | "transferAnimationSetFinished" | "transferSettings" | "transferSettingsAck" | "transferSettingsFinished" | "transferTestAnimationSet" | "transferTestAnimationSetAck" | "transferTestAnimationSetFinished" | "debugLog" | "playAnimationEvent" | "stopAnimation" | "remoteAction" | "requestRollState" | "requestAnimationSet" | "requestSettings" | "requestTelemetry" | "programDefaultAnimationSet" | "programDefaultAnimationSetFinished" | "blinkAck" | "requestDefaultAnimationSetColor" | "defaultAnimationSetColor" | "requestBatteryLevel" | "batteryLevel" | "requestRssi" | "rssi" | "calibrate" | "calibrateFace" | "notifyUser" | "notifyUserAck" | "testHardware" | "storeValue" | "storeValueAck" | "setTopLevelState" | "programDefaultParameters" | "programDefaultParametersFinished" | "setDesignAndColor" | "setDesignAndColorAck" | "setCurrentBehavior" | "setCurrentBehaviorAck" | "setName" | "setNameAck" | "powerOperation" | "exitValidation" | "transferInstantAnimationSet" | "transferInstantAnimationSetAck" | "transferInstantAnimationSetFinished" | "playInstantAnimation" | "stopAllAnimations" | "requestTemperature" | "temperature" | "setBatteryControllerMode" | "_unused" | "discharge" | "blinkId" | "blinkIdAck" | "transferTest" | "transferTestAck" | "transferTestFinished" | "clearSettings" | "clearSettingsAck" | "testBulkSend" | "testBulkReceive" | "setAllLEDsToColor" | "attractMode" | "printNormals" | "printA2DReadings" | "lightUpFace" | "setLEDToColor" | "debugAnimationController"

      The type of message to watch for.

    • listener: ((this, msg) => void)

      The callback function to unregister.

    Returns void

  • Requests the Pixel to change its name.

    Parameters

    • name: string

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

    Returns Promise<void>

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

  • Requests the Pixel 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 Pixel and wait for a specific response.

    Parameters

    • msgOrTypeToSend: MessageOrType

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

    • responseType: "blink" | "none" | "playAnimation" | "whoAreYou" | "iAmADie" | "rollState" | "telemetry" | "bulkSetup" | "bulkSetupAck" | "bulkData" | "bulkDataAck" | "transferAnimationSet" | "transferAnimationSetAck" | "transferAnimationSetFinished" | "transferSettings" | "transferSettingsAck" | "transferSettingsFinished" | "transferTestAnimationSet" | "transferTestAnimationSetAck" | "transferTestAnimationSetFinished" | "debugLog" | "playAnimationEvent" | "stopAnimation" | "remoteAction" | "requestRollState" | "requestAnimationSet" | "requestSettings" | "requestTelemetry" | "programDefaultAnimationSet" | "programDefaultAnimationSetFinished" | "blinkAck" | "requestDefaultAnimationSetColor" | "defaultAnimationSetColor" | "requestBatteryLevel" | "batteryLevel" | "requestRssi" | "rssi" | "calibrate" | "calibrateFace" | "notifyUser" | "notifyUserAck" | "testHardware" | "storeValue" | "storeValueAck" | "setTopLevelState" | "programDefaultParameters" | "programDefaultParametersFinished" | "setDesignAndColor" | "setDesignAndColorAck" | "setCurrentBehavior" | "setCurrentBehaviorAck" | "setName" | "setNameAck" | "powerOperation" | "exitValidation" | "transferInstantAnimationSet" | "transferInstantAnimationSetAck" | "transferInstantAnimationSetFinished" | "playInstantAnimation" | "stopAllAnimations" | "requestTemperature" | "temperature" | "setBatteryControllerMode" | "_unused" | "discharge" | "blinkId" | "blinkIdAck" | "transferTest" | "transferTestAck" | "transferTestFinished" | "clearSettings" | "clearSettingsAck" | "testBulkSend" | "testBulkReceive" | "setAllLEDsToColor" | "attractMode" | "printNormals" | "printA2DReadings" | "lightUpFace" | "setLEDToColor" | "debugAnimationController"

      Expected response type.

    • timeoutMs: number = Constants.ackMessageTimeout

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

    Returns Promise<MessageOrType>

    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

    Parameters

    • msgOrTypeToSend: MessageOrType

      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: MessageOrType

      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.

  • Uploads the given data set of animations to the Pixel flash memory.

    Parameters

    • dataSet: DataSet

      The data set to upload.

    • Optional progressCallback: ((progress) => void)

      An optional callback that is called as the operation progresses with the progress in percent..

        • (progress): void
        • Parameters

          • progress: number

          Returns void

    Returns Promise<void>

    A promise that resolves once the transfer has completed.

  • 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.

    Parameters

    • dataSet: DataSet

      The data set to upload.

    • Optional progressCallback: ((progress) => void)

      An optional callback that is called as the operation progresses with the progress in percent..

        • (progress): void
        • Parameters

          • progress: number

          Returns void

    Returns Promise<void>

    A promise that resolves once the transfer has completed.

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

    Parameters

    • info: Partial<Omit<PixelInfo, "currentFace">>

      The updated info.

    Returns void

    Remarks

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

  • Upload the given data to the Pixel.

    Parameters

    • ackType: "blink" | "none" | "playAnimation" | "whoAreYou" | "iAmADie" | "rollState" | "telemetry" | "bulkSetup" | "bulkSetupAck" | "bulkData" | "bulkDataAck" | "transferAnimationSet" | "transferAnimationSetAck" | "transferAnimationSetFinished" | "transferSettings" | "transferSettingsAck" | "transferSettingsFinished" | "transferTestAnimationSet" | "transferTestAnimationSetAck" | "transferTestAnimationSetFinished" | "debugLog" | "playAnimationEvent" | "stopAnimation" | "remoteAction" | "requestRollState" | "requestAnimationSet" | "requestSettings" | "requestTelemetry" | "programDefaultAnimationSet" | "programDefaultAnimationSetFinished" | "blinkAck" | "requestDefaultAnimationSetColor" | "defaultAnimationSetColor" | "requestBatteryLevel" | "batteryLevel" | "requestRssi" | "rssi" | "calibrate" | "calibrateFace" | "notifyUser" | "notifyUserAck" | "testHardware" | "storeValue" | "storeValueAck" | "setTopLevelState" | "programDefaultParameters" | "programDefaultParametersFinished" | "setDesignAndColor" | "setDesignAndColorAck" | "setCurrentBehavior" | "setCurrentBehaviorAck" | "setName" | "setNameAck" | "powerOperation" | "exitValidation" | "transferInstantAnimationSet" | "transferInstantAnimationSetAck" | "transferInstantAnimationSetFinished" | "playInstantAnimation" | "stopAllAnimations" | "requestTemperature" | "temperature" | "setBatteryControllerMode" | "_unused" | "discharge" | "blinkId" | "blinkIdAck" | "transferTest" | "transferTestAck" | "transferTestFinished" | "clearSettings" | "clearSettingsAck" | "testBulkSend" | "testBulkReceive" | "setAllLEDsToColor" | "attractMode" | "printNormals" | "printA2DReadings" | "lightUpFace" | "setLEDToColor" | "debugAnimationController"

      The expected confirmation message type.

    • data: ArrayBuffer

      The data to send.

    • Optional progressCallback: ((progress) => void)

      An optional callback that is called as the operation progresses with the progress in percent..

        • (progress): void
        • Parameters

          • progress: number

          Returns void

    • progressMode: "percent" | "bytes" = "percent"

      Whether to notify progress in percent or bytes.

    Returns Promise<void>

    A promise that resolves once the transfer has completed.

  • Waits for a message from the Pixel.

    Parameters

    • expectedMsgType: "blink" | "none" | "playAnimation" | "whoAreYou" | "iAmADie" | "rollState" | "telemetry" | "bulkSetup" | "bulkSetupAck" | "bulkData" | "bulkDataAck" | "transferAnimationSet" | "transferAnimationSetAck" | "transferAnimationSetFinished" | "transferSettings" | "transferSettingsAck" | "transferSettingsFinished" | "transferTestAnimationSet" | "transferTestAnimationSetAck" | "transferTestAnimationSetFinished" | "debugLog" | "playAnimationEvent" | "stopAnimation" | "remoteAction" | "requestRollState" | "requestAnimationSet" | "requestSettings" | "requestTelemetry" | "programDefaultAnimationSet" | "programDefaultAnimationSetFinished" | "blinkAck" | "requestDefaultAnimationSetColor" | "defaultAnimationSetColor" | "requestBatteryLevel" | "batteryLevel" | "requestRssi" | "rssi" | "calibrate" | "calibrateFace" | "notifyUser" | "notifyUserAck" | "testHardware" | "storeValue" | "storeValueAck" | "setTopLevelState" | "programDefaultParameters" | "programDefaultParametersFinished" | "setDesignAndColor" | "setDesignAndColorAck" | "setCurrentBehavior" | "setCurrentBehaviorAck" | "setName" | "setNameAck" | "powerOperation" | "exitValidation" | "transferInstantAnimationSet" | "transferInstantAnimationSetAck" | "transferInstantAnimationSetFinished" | "playInstantAnimation" | "stopAllAnimations" | "requestTemperature" | "temperature" | "setBatteryControllerMode" | "_unused" | "discharge" | "blinkId" | "blinkIdAck" | "transferTest" | "transferTestAck" | "transferTestFinished" | "clearSettings" | "clearSettingsAck" | "testBulkSend" | "testBulkReceive" | "setAllLEDsToColor" | "attractMode" | "printNormals" | "printA2DReadings" | "lightUpFace" | "setLEDToColor" | "debugAnimationController"

      Type of the message to expect.

    • timeoutMs: number = Constants.ackMessageTimeout

      Timeout before aborting the wait.

    Returns Promise<MessageOrType>

    A promise with the received message of the expected type.

Generated using TypeDoc