Class PixelConnect<MutableProps, Type, MessageType>Abstract

Abstract class that represents a connection to a Pixel device (die, charger, etc.).

Type Parameters

Hierarchy (view full)

Constructors

Properties

_msgEvEmitter: EventEmitter = ...
_serializer: MessageSerializer<MessageType>
isNotifier = true
type: "die" | "charger" | "bootloader"
MutablePropsList: readonly (
    | "name"
    | "batteryLevel"
    | "rssi"
    | "pixelId"
    | "ledCount"
    | "systemId"
    | "colorway"
    | "dieType"
    | "firmwareDate"
    | "isCharging"
    | "rollState"
    | "currentFace"
    | "currentFaceIndex")[] = ...

Accessors

  • get colorway():
        | "custom"
        | "clear"
        | "unknown"
        | "onyxBlack"
        | "hematiteGrey"
        | "midnightGalaxy"
        | "auroraSky"
        | "whiteAurora"
  • The Pixel color.

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

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

    Returns number

    • This value is always an integer number.
    • D10 returns values ranging from 0 to 9 included.
    • D00 returns 0, 10, 20, ..., 90.
    • Fudge die returns +1, 0 and -1.
  • get currentFaceIndex(): number
  • The 0-based index of the die face that is currently facing up.

    Returns number

    Indices are continuous and follow the numerical order of the die faces values.

    A D20 die will have face indices ranging from 0 to 19.
    Index 0 corresponds to face 1 and index 19 to face 20.

    D10 and D00 share the same face indices but have different face values.
    Index 0 corresponds to face 0 of both dice types.
    Index 9 corresponds to face 9 for a D10 and to face 90 for a D00.

    The fudge die returns the following indices:
    - O and 5 for the "+" face .
    - 1 and 4 for the "-" face.
    - 2 and 3 for the "blank" face.
  • get dieType():
        | "unknown"
        | "d4"
        | "d6"
        | "d8"
        | "d10"
        | "d00"
        | "d12"
        | "d20"
        | "d6pipped"
        | "d6fudge"
  • The Pixel die type.

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

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

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

Methods

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

    Parameters

    • msgOrTypeToSend: PixelMessage | MessageType

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

    • responseType: MessageType

      Expected response type.

    • timeoutMs: number = Constants.ackMessageTimeout

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

    Returns Promise<PixelMessage | MessageType>

    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: PixelMessage | MessageType

      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: PixelMessage | MessageType

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

      Type of the message to expect.

    • timeoutMs: number = Constants.ackMessageTimeout

      Timeout before aborting the wait.

    Returns Promise<PixelMessage | MessageType>

    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