UNPKG

witmotion-react-native

Version:

React Native SDK for WitMotion BLE IMU sensors (WT901, WT901BLECL, etc.)

58 lines (57 loc) 1.88 kB
/** * WitMotion BLE Manager for React Native * * Provides: * - Bluetooth permission handling * - Device scanning * - Connection management * - Subscription to notifications * - Command sending to WitMotion devices * * Uses react-native-ble-plx for BLE operations. */ import { BleManager, Device, Subscription } from 'react-native-ble-plx'; import { WitData } from './witParser'; export declare const manager: BleManager; /** * Ensure required BLE permissions are granted. * - Android 12+ requires BLUETOOTH_SCAN + BLUETOOTH_CONNECT * - Android <12 requires ACCESS_FINE_LOCATION */ export declare function ensureBlePermissions(): Promise<void>; /** Minimal device info returned during scanning */ export type FoundDevice = { id: string; name?: string | null; rssi?: number | null; }; /** * Scan for nearby devices. * @param onDevice callback fired for each device found * @param ms duration of scan in milliseconds */ export declare function scanForDevices(onDevice: (d: FoundDevice) => void, ms?: number): Promise<void>; /** * Connect to a device by ID, subscribe to data, and get send() helper. * @param deviceId target BLE device id * @param onData callback invoked with parsed WitData * @returns device instance, subscriptions, and send() helper */ export declare function connectById(deviceId: string, onData: (d: WitData) => void): Promise<{ readonly device: Device; readonly subs: Subscription[]; readonly send: ((bytes: number[]) => Promise<void>) | undefined; }>; /** * Predefined WitMotion commands (mirroring the official SDK). */ export declare const WitCmd: { /** Start magnetometer calibration */ startMagCalib: number[]; /** Save current settings */ save: number[]; /** Reset yaw angle */ resetYaw: number[]; /** Set output rate in Hz */ setRateHz: (hz: number) => number[]; };