UNPKG

react-native-bluetooth-obd-manager

Version:

A React Native hook library to manage Bluetooth Low Energy connections and communication with ELM327 OBD-II adapters.

76 lines 2.54 kB
import React, { FC } from 'react'; import type { ChunkedResponse } from '../types'; import type { DeferredPromise } from '../types'; /** * Represents the state of a command being executed over Bluetooth. * This interface tracks the promise, timeout, and response data for each command. */ interface CommandExecutionState { /** Promise that will resolve with the command's response */ promise: DeferredPromise<string | Uint8Array | ChunkedResponse>; /** Timeout ID for command expiration */ timeoutId: NodeJS.Timeout | null; /** Buffer storing incoming response bytes */ responseBuffer: number[]; /** Array storing each chunk of response data as it arrives */ responseChunks: number[][]; /** Expected format of the command's response */ expectedReturnType: 'string' | 'bytes' | 'chunked'; } /** * Props for the BluetoothProvider component */ interface BluetoothProviderProps { /** Child components that will have access to Bluetooth context */ children: React.ReactNode; } /** * BluetoothProvider Component * * A React Context Provider that manages Bluetooth LE communication state and operations * for OBD-II vehicle diagnostics. This provider handles: * * - BLE device scanning and discovery * - Connection management * - Command execution and response handling * - Automatic error recovery * * @example * ```tsx * function App() { * return ( * <BluetoothProvider> * <VehicleDiagnostics /> * </BluetoothProvider> * ); * } * ``` * * @param props - Component props * @returns A provider component that makes Bluetooth functionality available to children */ export declare const BluetoothProvider: FC<BluetoothProviderProps>; /** * Internal hook for accessing the command control context. * This hook provides access to the internal command execution state * and is only meant to be used by the library's internal components. * * @internal * @throws {Error} When used outside of a BluetoothProvider * @returns Command control context object containing the current command reference * * @example * ```typescript * // Internal usage only * function InternalComponent() { * const { currentCommandRef } = useInternalCommandControl(); * // Access command state... * } * ``` */ export declare const useInternalCommandControl: () => { /** Reference to the currently executing command */ currentCommandRef: React.MutableRefObject<CommandExecutionState | null>; }; export {}; //# sourceMappingURL=BluetoothProvider.d.ts.map