0.1.11 • Published 29 days ago

react-native-synchronysdk v0.1.11

Weekly downloads
-
License
MIT
Repository
github
Last release
29 days ago

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>
0.1.10

29 days ago

0.1.11

29 days ago

0.1.9

29 days ago

0.1.8

1 month ago

0.1.7

1 month ago

0.1.6

1 month ago

0.1.5

1 month ago

0.1.4

2 months ago

0.1.3

2 months ago

0.1.2

2 months ago

0.1.1

2 months ago