use of com.eveningoutpost.dexdrip.watch.miband.Firmware.WatchFaceGenerator in project xDrip by NightscoutFoundation.
the class MiBandService method installWatchface.
@SuppressLint("CheckResult")
private void installWatchface() {
// TODO decrease display brightness before uploading watchface to minimize battery consumption
RxBleConnection connection = I.connection;
if (d)
UserError.Log.d(TAG, "Install WatchFace");
if (I.connection == null) {
if (d)
UserError.Log.d(TAG, "Cannot enable as connection is null!");
return;
}
try {
WatchFaceGenerator wfGen = new WatchFaceGenerator(getBaseContext().getAssets());
byte[] fwArray = wfGen.genWatchFace();
if (fwArray == null || fwArray.length == 0) {
resetFirmwareState(false, "Empty image");
return;
}
firmware = new FirmwareOperations(fwArray);
} catch (Exception e) {
resetFirmwareState(false, "FirmwareOperations error " + e.getMessage());
return;
}
if (d)
UserError.Log.d(TAG, "Begin uploading Watchface, lenght: " + firmware.getSize());
if (d)
UserError.Log.d(TAG, "Requesting to enable notifications for installWatchface");
watchfaceSubscription = new Subscription(connection.setupNotification(firmware.getFirmwareCharacteristicUUID()).timeout(400, // WARN
TimeUnit.SECONDS).doOnNext(notificationObservable -> {
if (d)
UserError.Log.d(TAG, "Notification for firmware enabled");
firmware.nextSequence();
processFirmwareCommands(null, true);
}).flatMap(notificationObservable -> notificationObservable).subscribe(bytes -> {
// incoming notifications
if (d)
UserError.Log.d(TAG, "Received firmware notification bytes: " + bytesToHex(bytes));
processFirmwareCommands(bytes, false);
}, throwable -> {
UserError.Log.d(TAG, "Throwable in firmware Notification: " + throwable);
if (throwable instanceof BleCharacteristicNotFoundException) {
// maybe legacy - ignore for now but needs better handling
UserError.Log.d(TAG, "Characteristic not found for notification");
} else if (throwable instanceof BleCannotSetCharacteristicNotificationException) {
UserError.Log.e(TAG, "Problems setting notifications - disconnecting");
} else if (throwable instanceof BleDisconnectedException) {
UserError.Log.d(TAG, "Disconnected while enabling notifications");
} else if (throwable instanceof TimeoutException) {
UserError.Log.d(TAG, "Timeout");
}
resetFirmwareState(false);
}));
}
use of com.eveningoutpost.dexdrip.watch.miband.Firmware.WatchFaceGenerator in project xDrip-plus by jamorham.
the class MiBandService method installWatchface.
@SuppressLint("CheckResult")
private void installWatchface() {
// TODO decrease display brightness before uploading watchface to minimize battery consumption
RxBleConnection connection = I.connection;
if (d)
UserError.Log.d(TAG, "Install WatchFace");
if (I.connection == null) {
if (d)
UserError.Log.d(TAG, "Cannot enable as connection is null!");
return;
}
try {
WatchFaceGenerator wfGen = new WatchFaceGenerator(getBaseContext().getAssets());
byte[] fwArray = wfGen.genWatchFace();
if (fwArray == null || fwArray.length == 0) {
resetFirmwareState(false, "Empty image");
return;
}
firmware = new FirmwareOperations(fwArray);
} catch (Exception e) {
resetFirmwareState(false, "FirmwareOperations error " + e.getMessage());
return;
}
if (d)
UserError.Log.d(TAG, "Begin uploading Watchface, lenght: " + firmware.getSize());
if (d)
UserError.Log.d(TAG, "Requesting to enable notifications for installWatchface");
watchfaceSubscription = new Subscription(connection.setupNotification(firmware.getFirmwareCharacteristicUUID()).timeout(400, // WARN
TimeUnit.SECONDS).doOnNext(notificationObservable -> {
if (d)
UserError.Log.d(TAG, "Notification for firmware enabled");
firmware.nextSequence();
processFirmwareCommands(null, true);
}).flatMap(notificationObservable -> notificationObservable).subscribe(bytes -> {
// incoming notifications
if (d)
UserError.Log.d(TAG, "Received firmware notification bytes: " + bytesToHex(bytes));
processFirmwareCommands(bytes, false);
}, throwable -> {
UserError.Log.d(TAG, "Throwable in firmware Notification: " + throwable);
if (throwable instanceof BleCharacteristicNotFoundException) {
// maybe legacy - ignore for now but needs better handling
UserError.Log.d(TAG, "Characteristic not found for notification");
} else if (throwable instanceof BleCannotSetCharacteristicNotificationException) {
UserError.Log.e(TAG, "Problems setting notifications - disconnecting");
} else if (throwable instanceof BleDisconnectedException) {
UserError.Log.d(TAG, "Disconnected while enabling notifications");
} else if (throwable instanceof TimeoutException) {
UserError.Log.d(TAG, "Timeout");
}
resetFirmwareState(false);
}));
}
Aggregations