Skip to content

Commit

Permalink
Return device information only while connected
Browse files Browse the repository at this point in the history
  • Loading branch information
Eko Mirhard committed Apr 30, 2017
1 parent 8eb2368 commit 71c95ad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,18 @@ public void onIntCallBack(int level) {
Timber.d("Found battery %d", level);
hasPendingCallback = false;

WritableMap wm = Arguments.createMap();
wm.putInt("deviceMode", bluetoothService.getCurrentDeviceMode());
wm.putString("identifier", bluetoothService.getCurrentDeviceIdentifier());
wm.putString("firmwareVersion", version);
wm.putInt("batteryLevel", level);

callback.invoke(null, wm);
if (bluetoothService.isDeviceReady()) {
WritableMap wm = Arguments.createMap();
wm.putInt("deviceMode", bluetoothService.getCurrentDeviceMode());
wm.putString("identifier", bluetoothService.getCurrentDeviceIdentifier());
wm.putString("firmwareVersion", version);
wm.putInt("batteryLevel", level);

callback.invoke(null, wm);
}
else {
callback.invoke(JSError.make("Not connected to a device"));
}
}
});
}
Expand Down
9 changes: 8 additions & 1 deletion ios/backbone/DeviceInformationService.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ - (id)init {
[self retrieveFirmwareVersion:^(NSString * _Nonnull str) {
[self retrieveBatteryLevel:^(int value) {
hasPendingCallback = NO;
callback(@[[NSNull null], @{@"deviceMode" : @(BluetoothServiceInstance.currentDeviceMode), @"firmwareVersion" : str, @"batteryLevel" : @(value), @"identifier" : BluetoothServiceInstance.currentDeviceIdentifier }]);

if ([BluetoothServiceInstance isDeviceReady]) {
callback(@[[NSNull null], @{@"deviceMode" : @(BluetoothServiceInstance.currentDeviceMode), @"firmwareVersion" : str, @"batteryLevel" : @(value), @"identifier" : BluetoothServiceInstance.currentDeviceIdentifier }]);
}
else {
NSDictionary *makeError = RCTMakeError(@"Not connected to a device", nil, nil);
callback(@[makeError]);
}
}];
}];
}
Expand Down

0 comments on commit 71c95ad

Please sign in to comment.