use of com.eveningoutpost.dexdrip.watch.miband.Const.PREFERRED_MTU_SIZE in project xDrip by NightscoutFoundation.
the class MiBandService method enableNotification.
@SuppressLint("CheckResult")
private void enableNotification() {
if (d)
UserError.Log.d(TAG, "enableNotifications called");
if (I.connection == null) {
if (d)
UserError.Log.d(TAG, "Cannot enable as connection is null!");
return;
}
enableHeartRateNotification();
if (I.isNotificationEnabled) {
if (d)
UserError.Log.d(TAG, "Notifications already enabled");
changeNextState();
return;
}
if (notifSubscriptionDeviceEvent != null) {
notifSubscriptionDeviceEvent.unsubscribe();
}
if (notifSubscriptionHeartRateMeasurement != null) {
notifSubscriptionHeartRateMeasurement.unsubscribe();
}
if (d)
UserError.Log.d(TAG, "Requesting to enable device event notifications");
I.connection.requestMtu(PREFERRED_MTU_SIZE).subscribe();
notifSubscriptionDeviceEvent = new Subscription(I.connection.setupNotification(Const.UUID_CHARACTERISTIC_DEVICEEVENT).doOnNext(notificationObservable -> {
I.isNotificationEnabled = true;
changeNextState();
}).flatMap(notificationObservable -> notificationObservable).observeOn(Schedulers.newThread()).subscribe(bytes -> {
// incoming notifications
if (d)
UserError.Log.d(TAG, "Received device notification bytes: " + bytesToHex(bytes));
handleDeviceEvent(bytes);
}, throwable -> {
UserError.Log.d(TAG, "Throwable in Record Notification: " + throwable);
I.isNotificationEnabled = false;
if (throwable instanceof BleCharacteristicNotFoundException) {
// maybe legacy - ignore for now but needs better handling
UserError.Log.d(TAG, "Characteristic not found for notification");
changeNextState();
} else {
UserError.Log.d(TAG, "Disconnected exception");
isNeedToAuthenticate = true;
messageQueue.clear();
changeState(CLOSE);
}
}));
}
use of com.eveningoutpost.dexdrip.watch.miband.Const.PREFERRED_MTU_SIZE in project xDrip-plus by jamorham.
the class MiBandService method enableNotification.
@SuppressLint("CheckResult")
private void enableNotification() {
if (d)
UserError.Log.d(TAG, "enableNotifications called");
if (I.connection == null) {
if (d)
UserError.Log.d(TAG, "Cannot enable as connection is null!");
return;
}
enableHeartRateNotification();
if (I.isNotificationEnabled) {
if (d)
UserError.Log.d(TAG, "Notifications already enabled");
changeNextState();
return;
}
if (notifSubscriptionDeviceEvent != null) {
notifSubscriptionDeviceEvent.unsubscribe();
}
if (notifSubscriptionHeartRateMeasurement != null) {
notifSubscriptionHeartRateMeasurement.unsubscribe();
}
if (d)
UserError.Log.d(TAG, "Requesting to enable device event notifications");
I.connection.requestMtu(PREFERRED_MTU_SIZE).subscribe();
notifSubscriptionDeviceEvent = new Subscription(I.connection.setupNotification(Const.UUID_CHARACTERISTIC_DEVICEEVENT).doOnNext(notificationObservable -> {
I.isNotificationEnabled = true;
changeNextState();
}).flatMap(notificationObservable -> notificationObservable).observeOn(Schedulers.newThread()).subscribe(bytes -> {
// incoming notifications
if (d)
UserError.Log.d(TAG, "Received device notification bytes: " + bytesToHex(bytes));
handleDeviceEvent(bytes);
}, throwable -> {
UserError.Log.d(TAG, "Throwable in Record Notification: " + throwable);
I.isNotificationEnabled = false;
if (throwable instanceof BleCharacteristicNotFoundException) {
// maybe legacy - ignore for now but needs better handling
UserError.Log.d(TAG, "Characteristic not found for notification");
changeNextState();
} else {
UserError.Log.d(TAG, "Disconnected exception");
isNeedToAuthenticate = true;
messageQueue.clear();
changeState(CLOSE);
}
}));
}
Aggregations