NiimBlueLib Docs
    Preparing search index...

    Class Utils

    Utility class for various common operations.

    Index

    Constructors

    Methods

    • Converts a DataView, Uint8Array, or number array to a hexadecimal string with byte separator.

      Parameters

      • buf: DataView<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | number[]
      • separator: string = " "

      Returns string

    • Converts a Uint8Array of length 2 to a 16-bit signed integer (big endian).

      Parameters

      • arr: Uint8Array

      Returns number

    • Converts a Uint8Array of length 2 to a 16-bit signed integer (big endian).

      Parameters

      • arr: Uint8Array

      Returns number

    • Count non-zero bits in the byte array.

      For split mode:

      Data splitted to the three chunks (last chunk sizes can be lesser, base chunk size is printhead size / 8 / 3) and non-zero bit count calculated from each chunk.

      If data size is more than printheadPixels / 8, only total mode can be used.

      For total mode:

      Return total number of pixel in little-endian format: [0, LL, HH]

      For auto mode:

      By default split mode used. If it is not available, total mode used.

      Parameters

      • buf: Uint8Array
      • printheadPixels: number
      • mode: "auto" | "split" | "total" = "auto"

      Returns PixelCountResult

    • Converts a DataView object to an array of numbers.

      Parameters

      • dw: DataView

      Returns number[]

    • Converts a DataView object to a Uint8Array

      Parameters

      • dw: DataView

      Returns Uint8Array

    • Find check array has subarray at index

      Type Parameters

      • T

      Parameters

      • arr: ArrayLike<T>
      • sub: ArrayLike<T>
      • pos: number

      Returns boolean

    • Converts a hexadecimal string to a Uint8Array buffer.

      Parameters

      • str: string

      Returns Uint8Array

    • Checks if the browser supports Bluetooth functionality.

      Returns boolean

      use getAvailableTransports

    • Checks if the browser supports the Web Serial API for serial communication.

      Returns boolean

      use getAvailableTransports

    • Converts a given number to its hexadecimal representation.

      Parameters

      • n: number

      Returns string

    • Asynchronously pauses the execution for the specified amount of time.

      Parameters

      • ms: number

      Returns Promise<undefined>

    • Converts a 16-bit unsigned integer to an array of two bytes (big endian).

      Parameters

      • n: number

      Returns [number, number]

    • Converts a 32-bit unsigned integer to an array of two bytes (big endian).

      Parameters

      • n: number

      Returns [number, number, number, number]

    • Parameters

      • src: Uint8Array
      • data: Uint8Array

      Returns Uint8Array

    • Compares two Uint8Arrays to check if they are equal.

      Parameters

      • a: Uint8Array
      • b: Uint8Array

      Returns boolean

    • Converts a Uint8Array to a string using TextDecoder.

      Parameters

      • arr: Uint8Array

      Returns string