/** * (c) 2023, Center for Computational Thinking and Design at Aarhus University and contributors * * SPDX-License-Identifier: MIT */ import { BleDevice, TimeoutOptions } from "@capacitor-community/bluetooth-le"; import { BoardVersion, ConnectOptions } from "../device.js"; import { Logging, LoggingEvent } from "../logging.js"; import { ServiceConnectionEventMap, TypedServiceEvent, TypedServiceEventDispatcher } from "../service-events.js"; import { DeviceBondState } from "./device-bond-state.js"; import { AccelerometerService } from "./services/accelerometer-service.js"; import { ButtonService } from "./services/button-service.js"; import { DeviceInformationService } from "./services/device-information-service.js"; import { EventService } from "./services/event-service.js"; import { IoPinService } from "./services/io-pin-service.js"; import { LedService } from "./services/led-service.js"; import { MagnetometerService } from "./services/magnetometer-service.js"; import { TemperatureService } from "./services/temperature-service.js"; import { UARTService } from "./services/uart-service.js"; /** * The @capacitor-community/bluetooth-le plugin throws this message when * a characteristic UUID is not found in the device's GATT table. */ export declare const isCharacteristicNotFoundError: (e: unknown) => boolean; export declare const bondingTimeoutInMs = 40000; export declare const connectTimeoutInMs = 10000; export declare const scanningTimeoutInMs = 10000; export declare const isAndroid: () => boolean; export interface Service { readonly uuid: string; getRelevantEvents(): TypedServiceEvent[]; startNotifications(type: TypedServiceEvent): Promise; stopNotifications(type: TypedServiceEvent): Promise; } interface ConnectCallbacks { onConnecting: () => void; onDisconnect: () => void; onSuccess: () => void; } export declare class BluetoothDeviceWrapper implements Logging { readonly bleDevice: BleDevice; private logging; private deviceBondState; private currentEvents; private callbacks; connected: boolean; private serviceIds; accelerometer: AccelerometerService; buttons: ButtonService; deviceInformation: DeviceInformationService; events: EventService; ioPin: IoPinService; led: LedService; magnetometer: MagnetometerService; temperature: TemperatureService; uart: UARTService; /** * Only defined after connection. */ boardVersion: BoardVersion | undefined; private services; private waitingForDisconnectEventCallbacks; private internalNotificationListeners; constructor(bleDevice: BleDevice, logging: Logging | undefined, deviceBondState: DeviceBondState | undefined, dispatchTypedEvent: TypedServiceEventDispatcher, currentEvents: () => Array, callbacks: ConnectCallbacks); setBonded(isBonded: boolean): void; connect(options?: ConnectOptions): Promise; private connectInternal; disconnect(): Promise; private disconnectInternal; handleDisconnectEvent: () => void; getBoardVersion(): Promise; startNotifications(type: TypedServiceEvent): Promise; stopNotifications(type: TypedServiceEvent): Promise; private getServicesForEvent; startInternalNotifications(serviceId: string, characteristicId: string, options?: TimeoutOptions): Promise; subscribe(serviceId: string, characteristicId: string, callback: (data: Uint8Array) => void): void; unsubscribe(serviceId: string, characteristicId: string, callback: (data: Uint8Array) => void): void; stopInternalNotifications(serviceId: string, characteristicId: string): Promise; /** * Write to characteristic and wait for a notification response. * * It is the responsibility of the caller to have started notifications * for the characteristic. */ writeForNotification(serviceId: string, characteristicId: string, value: DataView, notificationId: number, isFinalNotification?: (p: Uint8Array) => boolean): Promise; waitForDisconnect(timeout: number): Promise; /** * Suitable for running a series of BLE interactions with an overall timeout * and general disconnection */ raceDisconnectAndTimeout(promise: Promise, options?: { actionName?: string; timeout?: number; }): Promise; private disconnectErrorPromise; event(event: LoggingEvent): void; log(message: string): void; error(message: string, e?: unknown): void; private getNotificationKey; /** * Bonds with device and handles the post-bond device state only returning * when we can reattempt a connection with the device. */ private connectHandlingBond; private bondConnectDeviceInternal; /** * On iOS, accessing an encrypted characteristic triggers the pairing dialog. * Try each candidate characteristic in turn until one succeeds. The error is * fast (local GATT cache lookup) so there's no meaningful delay from retries. */ private triggerIosPairing; } export {};