npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@synchroni/synchroni_sdk_react_native

v0.2.30

Published

Synchroni sdk for react native

Downloads

63

Readme

react-native-synchronisdk

Synchroni sdk for react native

Brief

Synchroni SDK is the software development kit for developers to access Synchroni 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  @synchroni/synchroni_sdk_react_native

1. Permission

Application will obtain bluetooth permission by itself. There are builtin code in SensorController for Android.

2. Import SDK

import {
  SensorController,
  SensorProfile,
  DeviceStateEx,
  DataType,
  type BLEDevice,
  type SensorData,
} from '@synchroni/synchroni_sdk_react_native';

SensorController methods:

1. Initalize

const SensorControllerInstance = SensorController.Instance;

//register scan listener
if (!SensorControllerInstance.hasDeviceCallback){
  SensorControllerInstance.onDeviceCallback = (devices: BLEDevice[]) =>{
    //return all devices doesn't connected 
  };
}

2. Start scan

Use public async startScan(periodInMs: number): Promise<boolean> to start scan

const success = await SensorControllerInstance.startScan(6000)

returns true if start scan success, periodInMS means onDeviceCallback will be called every periodInMS, minium is 3000ms for iOS, 6000ms for Android

3. Stop scan

Use public async stopScan(): Promise<void> to stop scan

await SensorControllerInstance.stopScan();

4. Check scaning

Use public get isScaning(): boolean to check scaning status

const isScaning = SensorControllerInstance.isScaning;

5. Check if bluetooth is enabled

Use public get isEnable(): boolean to check if bluetooth is enabled

const isEnable = SensorControllerInstance.isEnable;

6. Create SensorProfile

Use public requireSensor(device: BLEDevice): SensorProfile | undefined to create sensorProfile

If bleDevice is invalid, result is undefined

const sensorProfile = SensorControllerInstance.requireSensor(bleDevice);

7. Get SensorProfile

Use public getSensor(device: BLEDevice): SensorProfile | undefined to get sensorProfile

If SensorProfile didn't created, result is undefined

const sensorProfile = SensorControllerInstance.getSensor(bleDevice);

8. Get Connected SensorProfiles

Use public getConnectedSensors(): SensorProfile[] to get connected SensorProfiles

const sensorProfiles = SensorControllerInstance.getConnectedSensors();

9. Get Connected BLE Devices

Use public getConnectedDevices(): SensorProfile[] to get connected BLE Devices

const bleDevices = SensorControllerInstance.getConnectedDevices();

SensorProfile methods:

1. Initalize

Please register callbacks for SensorProfile

let sensorProfile = SensorControllerInstance.requireSensor(bledevice);
//register callbacks
sensorProfile.onStateChanged = (sensor: SensorProfile, newstate: DeviceStateEx) => {
    //please do logic when device disconnected unexpected
}

sensorProfile.onErrorCallback = (sensor: SensorProfile, reason: string) => {
    //called when error occurs
}

sensorProfile.onPowerChanged = (sensor: SensorProfile, power: number) => {
    //callback for get batter level of device, power from 0 - 100, -1 is invalid
}

sensorProfile.onDataCallback = (sensor: SensorProfile, data: SensorData) => {
    //called after start data transfer
}

2. Connect device

Use public async connect(): Promise<boolean> to connect

const success = await sensorProfile.connect();

3. Disconnect

Use public async disconnect(): Promise<boolean> to disconnect

const success = await sensorProfile.disconnect();

4. Get device status

Use public get connectionState(): DeviceStateEx to get device status

Please send command in 'Ready' state, should be after connect() return true

const deviceStateEx = sensorProfile.connectionState;

# deviceStateEx has define:
export enum DeviceStateEx {
  Disconnected,
  Connecting,
  Connected,
  Ready,
  Disconnecting,
  Invalid,
}

5. Get BLE device of SensorProfile

Use public get BLEDevice(): BLEDevice to BLE device of SensorProfile

const bleDevice = sensorProfile.BLEDevice;

6. Get device info of SensorProfile

Use public async deviceInfo(): Promise<DeviceInfo | undefined> to get device info of SensorProfile.

Please call after device in 'Ready' state, return undefined if it's not connected

const deviceInfo = await sensorProfile.deviceInfo();

# deviceInfo has defines:
export type DeviceInfo = {
  DeviceName: string;
  ModelName: string;
  HardwareVersion: string;
  FirmwareVersion: string;
  EmgChannelCount: number;
  EegChannelCount: number;
  EcgChannelCount: number;
  AccChannelCount: number;
  GyroChannelCount: number;
  BrthChannelCount: number;
  MTUSize: number;
};

7. Init data transfer

Use public async init(packageSampleCount: number, powerRefreshInterval: number): Promise<boolean>.

Please call after device in 'Ready' state, return true if init succeed

const success = await sensorProfile.init(5, 60*1000);

packageSampleCount: set sample counts of SensorData.channelSamples in onDataCallback() powerRefreshInterval: callback period for onPowerChanged()

8. Check if init data transfer succeed

Use public get hasInited(): boolean to check if init data transfer succeed

const hasInited = sensorProfile.hasInited;

9. DataNotify

Use public async startDataNotification(): Promise<boolean> to start data notification.

Please call if hasInited() return true

9.1 Start data transfer

const success = await sensorProfile.startDataNotification();

Data type list:

export enum DataType {
  NTF_ACC = 0x1,    //unit is g
  NTF_GYRO = 0x2,   //unit is degree/s
  NTF_EEG = 0x10,   //unit is uV
  NTF_ECG = 0x11,   //unit is uV
  NTF_BRTH = 0x15,  //unit is uV
}

Process data in onDataCallback.

    sensorProfile.onDataCallback = (sensor: SensorProfile, data: SensorData) => {
      if (data.dataType === DataType.NTF_EEG) {
        
      } else if (data.dataType === DataType.NTF_ECG) {
        
      }

      //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.2 Stop data transfer

Use public async stopDataNotification(): Promise<boolean> to stop data transfer

const success = await sensorProfile.stopDataNotification();

9.3 Check if it's data transfering

Use public get isDataTransfering(): boolean to check if it's data transfering

const isDataTransfering = sensorProfile.isDataTransfering; 

10. Get battery level

Use public async batteryPower(): Promise<number> to get battery level. Please call after device in 'Ready' state

const batteryPower = await sensorProfile.batteryPower();

# batteryPower is battery level returned, value ranges from 0 to 100, 0 means out of battery, while 100 means full.

Please check SimpleTest function in App