Documentation
    Preparing search index...

    Class PixelConnect<MutableProps, Type, MessageType, EventMap>Abstract

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

    Type Parameters

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

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

    Accessors

    • get batteryLevel(): number

      The Pixel battery level (percentage).

      Returns number

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

      The Pixel color.

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

    • 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 firmwareDate(): Date

      The Pixel firmware build date.

      Returns Date

    • get isCharging(): boolean

      Whether the Pixel battery is charging or not. Set to 'true' if fully charged but still on charger.

      Returns boolean

    • get ledCount(): number

      The number of LEDs of the Pixel.

      Returns number

    • get logger(): ((msg: string) => void) | null | undefined

      Set logger to use by this instance.

      Returns ((msg: string) => void) | null | undefined

    • set logger(logger: ((msg: string) => void) | null | undefined): void

      Parameters

      • logger: ((msg: string) => void) | null | undefined

      Returns void

    • get logMessages(): boolean

      Toggle logging information about each send and received message.

      Returns boolean

    • set logMessages(enabled: boolean): void

      Parameters

      • enabled: boolean

      Returns void

    • get logMessagesSerializedData(): boolean

      Toggle logging the serialized (binary) data for each send and received message.

      Returns boolean

    • set logMessagesSerializedData(enabled: boolean): void

      Parameters

      • enabled: boolean

      Returns void

    • get name(): string

      The Pixels die name.

      Returns string

    • get pixelId(): number

      The unique Pixel id of the device.

      Returns number

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

      The Pixel roll state.

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

    • get rssi(): number

      The last RSSI value measured by the Pixel.

      Returns number

    • get sessionDeviceName(): string | undefined

      Returns string | undefined

    • get status(): PixelStatus

      Gets the Pixel last known connection status.

      Returns PixelStatus

    • get systemId(): string

      The unique id assigned by the system to the Pixel Bluetooth peripheral.

      Returns string

    Methods

    • Type Parameters

      • K extends string

      Parameters

      Returns void

    • Parameters

      • dataView: DataView

      Returns MessageType | PixelMessage

    • Returns void

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

      Parameters

      • msgOrTypeToSend: MessageType | PixelMessage

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

      • responseType: MessageType

        Expected response type.

      • OptionaltimeoutMs: number

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

      Returns Promise<MessageType | PixelMessage>

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

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

      • responseType: new () => T

        Expected response class type.

      • OptionaltimeoutMs: number

      Returns Promise<T>

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

    • Sends a message to the Pixel.

      Parameters

      • msgOrType: MessageType | PixelMessage

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

      • OptionalwithoutAck: boolean

        Whether to request a confirmation that the message was received.

      Returns Promise<void>

      A promise that resolves once the message has been send.

    • Returns Promise<void>

    • Waits for a message from the Pixel.

      Parameters

      • expectedMsgType: MessageType

        Type of the message to expect.

      • OptionaltimeoutMs: number

        Timeout before aborting the wait.

      Returns Promise<MessageType | PixelMessage>

      A promise with the received message of the expected type.

    • Parameters

      • msg: unknown

      Returns void

    • Parameters

      • arr: ArrayBufferLike

      Returns void

    • Parameters

      • str: string

      Returns string

    • Parameters

      • msg: unknown

      Returns void

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

      Type Parameters

      • K extends string

      Parameters

      • type: K

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

      • listener: EventReceiver<EventMap[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

      Returns void

    • Adds the given listener function for the specified property.

      Type Parameters

      • K extends string

      Parameters

      • propertyName: K

        The name of the property.

      • listener: EventReceiver<Type>

        The callback function.

      Returns void

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

      Parameters

      • OptionaltimeoutMs: number

        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<
          PixelConnect<
              PixelConnectMutableProps,
              PixelInfoWithStatus,
              string,
              PixelConnectEventMap,
          >,
      >

      A promise that resoles to this instance once the connection has been established.

      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 string

      Parameters

      • propertyName: K

        Event name.

      Returns void

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

      Type Parameters

      • K extends string

      Parameters

      • type: K

        A case-sensitive string representing the event type.

      • listener: EventReceiver<EventMap[K]>

        The callback function to unregister.

      Returns void

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

      Parameters

      Returns void

    • Removes the given listener function for the specified property.

      Type Parameters

      • K extends string

      Parameters

      • propertyName: K

        The name of the property.

      • listener: EventReceiver<Type>

        The callback function to unregister.

      Returns void