Synchroni SDK is the software development kit for developers to access OYMotion Synchroni products.
Application will obtain bluetooth permission by itself.
please add sensor.xcframework to project
import sensor
//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
}
}
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))
}
}
}
}
SensorController.stopScan()
SensorProfile.connect()
SensorProfile.disconnect()
SensorProfile.state;
Please send command in 'BLEState.ready'
typedef NS_ENUM(NSInteger, BLEState)
{
BLEStateUnConnected,
BLEStateConnecting,
BLEStateConnected,
BLEStateReady,
BLEStateInvalid,
};
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){
}
}
SensorProfile.initAll(PACKAGE_COUNT, timeout: TIMEOUT)
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,
};
SensorProfile.stopDataNotification;