Skip to content

Latest commit

 

History

History
165 lines (121 loc) · 3.41 KB

README.md

File metadata and controls

165 lines (121 loc) · 3.41 KB

Synchroni SDK + swift demo

Brief

Synchroni SDK is the software development kit for developers to access OYMotion Synchroni products.

1. Permission

Application will obtain bluetooth permission by itself.

2. Import SDK

please add sensor.xcframework to project

import sensor

3. Initalize

//ViewController.swift

class SensorDataContext : SensorProfileDelegate{
    public var profile: SensorProfile
    public var lastEEG: SensorData?
    public var lastECG: SensorData?
    public var lastBRTH: SensorData?
    public var lastACC: SensorData?
    public var lastGYRO: SensorData?
    public var lastError: Error?
}

class ViewController: UIViewController , SensorControllerDelegate {
    private var controller: SensorController?
    private var sensorDataCtxs: [String : SensorDataContext] = [:]
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        controller = SensorController.getInstance()
        controller?.delegate = self
    }
}

4. Start scan

SensorController.startScan(TIMEOUT)
//returns array of BLEPeripheral
onSensorScanResult(_ bleDevices: [BLEPeripheral]){
    for bleDevice in bleDevices {
        if (bleDevice.name.hasPrefix("SYNC")){
            if (sensorDataCtxs[bleDevice.macAddress] == nil){
                let sensorProfile = controller.getSensor(bleDevice.macAddress);
                let sensorDataCtx = SensorDataContext(profile : sensorProfile)
                sensorDataCtxs[bleDevice.macAddress] = sensorDataCtx;
                print("Found: " + bleDevice.name + " : " + String(bleDevice.rssi.intValue))
            }
        }
    }
}

5. Stop scan

SensorController.stopScan()

6. Connect device

SensorProfile.connect()

7. Disconnect

SensorProfile.disconnect()

8. Device status

8.1 Get device status

SensorProfile.state;

Please send command in 'BLEState.ready'

typedef NS_ENUM(NSInteger, BLEState)
{
    BLEStateUnConnected,
    BLEStateConnecting,
    BLEStateConnected,
    BLEStateReady,
    BLEStateInvalid,
};

8.2 Get device status change

func onSensorStateChange(_ newState: BLEState) {
    print("Device: " + profile.device.name + " state: " + profile.stateString)
    if (newState == BLEState.unConnected || newState == BLEState.invalid){
        print("Reset device: " + profile.device.name);
    }else if (newState == BLEState.ready && !profile.hasInit){
        
    }
}

9. DataNotify

9.1 init data notify

SensorProfile.initAll(PACKAGE_COUNT, timeout: TIMEOUT)

9.2 Start data transfer

For start data transfer, use -(BOOL)startDataNotification to start. Process data in onSensorNotify.

SensorProfile.startDataNotification()

func onSensorNotify(_ rawData: SensorData!) {
    if (rawData.dataType == NotifyDataType.NTF_EEG){
        lastEEG = rawData
    } else if (rawData.dataType == NotifyDataType.NTF_ECG){

    }else if (rawData.dataType == NotifyDataType.NTF_ACC_DATA){

    }else if (rawData.dataType == NotifyDataType.NTF_GYO_DATA){

    }else if (rawData.dataType == NotifyDataType.NTF_BRTH){

    }
}

data type:

typedef NS_ENUM(NSInteger, NotifyDataType)  {
    NTF_ACC_DATA,
    NTF_GYO_DATA,
    NTF_EEG,
    NTF_ECG,
    NTF_BRTH,
};

9.3 Stop data transfer

SensorProfile.stopDataNotification;