Represents a list of scanned Pixels that is updated when scanning. Set a callback to PixelScanner.scanListener to get notified when the list is updated.

When powered on but not yet connected, a Pixels die will periodically emit information which is picked up by the scanner. Typically the information is send a few times per second.

Calls to the async methods of this class are queued and executed in order across all instances.

Even though the roll state and roll face are included in a ScannedPixel instance, this data is not emitted in a reliable way.

To get reliably notified for rolls, first connect to the die and listen for roll events.

Constructors

Accessors

  • get scannedChargers(): Readonly<{
        address: number;
        batteryLevel: number;
        firmwareDate: Date;
        isCharging: boolean;
        ledCount: number;
        name: string;
        pixelId: number;
        rssi: number;
        systemId: string;
        timestamp: Date;
        type: "charger";
    }>[]
  • A copy of the list of scanned chargers (cleared on loosing Bluetooth access if PixelScanner.keepAliveDuration is greater than zero).

    Returns Readonly<{
        address: number;
        batteryLevel: number;
        firmwareDate: Date;
        isCharging: boolean;
        ledCount: number;
        name: string;
        pixelId: number;
        rssi: number;
        systemId: string;
        timestamp: Date;
        type: "charger";
    }>[]

Methods

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

    Type Parameters

    • K extends
          | "status"
          | "isReady"
          | "scannedPixels"
          | "scannedChargers"
          | "scannedBootloaders"
          | "onStatusChange"
          | "onScanListChange"

    Parameters

    • type: K

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

    • listener: EventReceiver<Readonly<{
          isReady: boolean;
          onScanListChange: Readonly<{
              ops: readonly PixelScannerListOperation[];
          }>;
          onStatusChange: Pick<Readonly<{
              context?: unknown;
              startError?: ScanStartErrorCode;
              status: ScanStatus;
              stopReason?: ScanStopReason;
          }>, "status" | "stopReason" | "startError">;
          scannedBootloaders: readonly ScannedBootloader[];
          scannedChargers: readonly Readonly<{
              address: number;
              batteryLevel: number;
              firmwareDate: Date;
              isCharging: boolean;
              ledCount: number;
              name: string;
              pixelId: number;
              rssi: number;
              systemId: string;
              timestamp: Date;
              type: "charger";
          }>[];
          scannedPixels: readonly ScannedPixel[];
          status: ScanStatus;
      }>[K]>

      The callback function.

    Returns void

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

    Type Parameters

    • T extends
          | "status"
          | "isReady"
          | "scannedPixels"
          | "scannedChargers"
          | "scannedBootloaders"
          | "onStatusChange"
          | "onScanListChange"

    Parameters

    • type: T

      A case-sensitive string representing the event type.

    • listener: ((ev: Readonly<{
          isReady: boolean;
          onScanListChange: Readonly<{
              ops: readonly PixelScannerListOperation[];
          }>;
          onStatusChange: Pick<Readonly<{
              context?: unknown;
              startError?: ScanStartErrorCode;
              status: ScanStatus;
              stopReason?: ScanStopReason;
          }>, "status" | "stopReason" | "startError">;
          scannedBootloaders: readonly ScannedBootloader[];
          scannedChargers: readonly Readonly<{
              address: number;
              batteryLevel: number;
              firmwareDate: Date;
              isCharging: boolean;
              ledCount: number;
              name: string;
              pixelId: number;
              rssi: number;
              systemId: string;
              timestamp: Date;
              type: "charger";
          }>[];
          scannedPixels: readonly ScannedPixel[];
          status: ScanStatus;
      }>[T]) => void)

      The callback function to unregister.

        • (ev): void
        • Parameters

          • ev: Readonly<{
                isReady: boolean;
                onScanListChange: Readonly<{
                    ops: readonly PixelScannerListOperation[];
                }>;
                onStatusChange: Pick<Readonly<{
                    context?: unknown;
                    startError?: ScanStartErrorCode;
                    status: ScanStatus;
                    stopReason?: ScanStopReason;
                }>, "status" | "stopReason" | "startError">;
                scannedBootloaders: readonly ScannedBootloader[];
                scannedChargers: readonly Readonly<{
                    address: number;
                    batteryLevel: number;
                    firmwareDate: Date;
                    isCharging: boolean;
                    ledCount: number;
                    name: string;
                    pixelId: number;
                    rssi: number;
                    systemId: string;
                    timestamp: Date;
                    type: "charger";
                }>[];
                scannedPixels: readonly ScannedPixel[];
                status: ScanStatus;
            }>[T]

          Returns void

    Returns void

  • Queues a command to start a Bluetooth scan for Pixels and update the list as advertisement packets are being received. If the instance is already scanning it will just notify of pending list operations or clear the list if clearOnStop is true.

    Returns Promise<void>

    A promise.

    Calls to the async methods of this class are queued and executed in order.

    On Android, BLE scanning will fail without error when started more than 5 times over the last 30 seconds.