react-native-synchronysdk
v0.1.12
Published
OYMotion Synchrony sdk for react native
Downloads
14
Readme
react-native-synchronysdk
OYMotion synchrony sdk for react native
Brief
Synchrony SDK is the software development kit for developers to access OYMotion products.
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made with create-react-native-library
Installation
yarn add react-native-synchronisdk
1. Permission
Application will obtain bluetooth permission by itself if use SynchronyProfile. There are builtin code in SynchronyController.
2. Import SDK
import {
SynchronyController,
DeviceStateEx,
type BLEDevice,
type SynchronyData,
DataType,
} from 'react-native-synchronysdk';
3. Initalize
const SyncControllerInstance = SynchronyController.Instance;
SyncControllerInstance.onStateChanged = (newstate: DeviceStateEx) => {
//please do logic when device disconnected unexpected
};
SyncControllerInstance.onErrorCallback = (reason: string) => {
//called when error occurs
};
SyncControllerInstance.onDataCallback = (data: SensorData) => {
//called after start data transfer
};
4. Start scan
public async startSearch(timeoutInMs: number): Promise<Array<BLEDevice>>
returns array of BLEDevice
5. Stop scan
public async stopSearch(): Promise<void>
6. Connect device
public async connect(device: BLEDevice): Promise<boolean>
7. Disconnect
public async disconnect(): Promise<boolean>
8. Get device status
public get connectionState(): DeviceStateEx
Please send command in 'Ready' state
export enum DeviceStateEx {
Disconnected,
Connecting,
Connected,
Ready,
Disconnecting,
}
9. DataNotify
9.1 Init data transfer
public async init(): Promise<boolean>
9.2 Start data transfer
public async startDataNotification(): Promise<boolean>
Data type list:
export enum DataType {
NTF_EEG = 0x10,
NTF_ECG = 0x11,
}
For start data transfer, use startDataNotification
to start. Process data in onDataCallback.
SyncControllerInstance.onDataCallback = (data: SensorData) => {
if (data.dataType === DataType.NTF_EEG) {
lastEEG.current = data;
} else if (data.dataType === DataType.NTF_ECG) {
lastECG.current = data;
}
//process data as you wish
data.channelSamples.forEach((oneChannelSamples) => {
oneChannelSamples.forEach((sample) => {
if (sample.isLost) {
//do some logic
} else {
//draw with sample.data & sample.channelIndex
// console.log(sample.channelIndex + ' | ' + sample.sampleIndex + ' | ' + sample.data + ' | ' + sample.impedance);
}
});
});
};
9.3 Stop data transfer
public async stopDataNotification(): Promise<boolean>