Appearance
PPG Device Scanner
The SDK provides an API to scan for nearby PPG devices, based on a specified PPGDeviceType
. The results obtained during the scan can be utilized later to create PPG Device sessions with any device from the list.
Creating a PPG Device Scanner
PPGDeviceScanner
can be created using the PPGDeviceScannerFactory
. In the following sample, a scanner searching for PPGDeviceType.polar
is created, and the current class implements PPGDeviceScannerListener
Swift
do {
let ppgDeviceType = PPGDeviceType.polar
let listener: PPGDeviceScannerListener = self
let scanner = try PPGDeviceScannerFactory.create(
ppgDeviceType: ppgDeviceType,
listener: listener
)
}
catch {
let e = error as NSError
print("Received Error. Domain: \(e.domain) Code: \(e.code)")
}
Objective-c
BNHPpgDeviceType ppgDeviceType = BNHPpgDeviceTypePolar;
id<BNHPpgDeviceScannerListener> listener = self;
NSError *error = nil;
id<BNHPpgDeviceScanner> scanner = [BNHPpgDeviceScannerFactory createWithPpgDeviceType:ppgDeviceType
listener:listener
error:&error];
if (error != nil) {
NSLog(@"Received Error. Domain: %@ Code: %ld", error.domain, (long)error.code);
}
Starting a scan for PPG Devices
To initiate a scan, call the start
method. If the method is called without a timeoutDuration
parameter, or with a value of 0 or below, the default timeout of 60 seconds is used. The timeout duration should be specified in seconds.
If a scanner is already performing a scan, calling start
will first stop the current scan before starting a new one.
In the following example, scanner.start
is called with a timeoutDuration
of 30 seconds.
Swift
do {
let timeoutDuration: UInt = 30
try scanner.start(timeout: timeoutDuration)
}
catch {
let e = error as NSError
print("Received Error. Domain: \(e.domain) Code: \(e.code)")
}
Objective-c
NSUInteger timeoutDuration = 30;
NSError *error = nil;
[scanner startWithTimeout:timeoutDuration
error:&error];
if (error != nil) {
NSLog(@"Received Error. Domain: %@ Code: %ld", error.domain, (long)error.code);
}
Receiving results during a scan
To receive PPGDevice
objects, the application should implement the onPPGDeviceDiscovered
method as part of PPGDeviceScannerListener
.
The PPGDevice
objects obtained through this method represent nearby PPG devices found by the scanner during the scan. These devices are potential candidates for establishing a session later, utilizing their deviceID
field.
Swift
func onPPGDeviceDiscovered(ppgDevice: BinahAI.PPGDevice) {
DispatchQueue.main.async {
// ppgDevice.type - The PPGDeviceType of the found device
// ppgDevice.deviceID - The ID to use later when creating a PPG Device Session
}
}
func onPPGDeviceScanFinished() {
DispatchQueue.main.async {
// Called when a scan is finished or stopped
}
}
Objective-c
- (void)onPPGDeviceDiscoveredWithPpgDevice:(BNHPpgDevice *)ppgDevice {
dispatch_async(dispatch_get_main_queue(), ^{
// ppgDevice.type - The PPGDeviceType of the found device
// ppgDevice.deviceID - The ID to use later when creating a PPG Device Session
});
}
- (void)onPPGDeviceScanFinished {
dispatch_async(dispatch_get_main_queue(), ^{
// Called when a scan is finished or stopped
});
}
Note
Please note that devices found during the scan do not guarantee a successful session establishment. Certain factors, such as the device having a version lower than the allowed minimum in the SDK, can cause a session to fail.
For more information on potential errors during session establishment, refer to the Alerts List.
Stopping a scan for PPG Devices
During a scan, it will automatically stop when the timeout period ends. Additionally, the application can manually stop the scan by calling the stop
method.
Swift
scanner.stop()
Objective-c
[scanner stop];
When a scan timeout is finished, the method onPPGDeviceScanFinished
(part of PPGDeviceScannerListener
) is called.
Swift
func onPPGDeviceDiscovered(ppgDevice: BinahAI.PPGDevice) {
DispatchQueue.main.async {
// ppgDevice.type - The PPGDeviceType of the found device
// ppgDevice.deviceID - The ID to use later when creating a PPG Device Session
}
}
func onPPGDeviceScanFinished() {
DispatchQueue.main.async {
// Called when a scan is finished or stopped
}
}
Objective-c
- (void)onPPGDeviceDiscoveredWithPpgDevice:(BNHPpgDevice *)ppgDevice {
dispatch_async(dispatch_get_main_queue(), ^{
// ppgDevice.type - The PPGDeviceType of the found device
// ppgDevice.deviceID - The ID to use later when creating a PPG Device Session
});
}
- (void)onPPGDeviceScanFinished {
dispatch_async(dispatch_get_main_queue(), ^{
// Called when a scan is finished or stopped
});
}
Important
Note that the methods of PPGDeviceScannerListener
are called on a background thread. The application must switch to the UI thread in order to perform UI updates.