use of com.eveningoutpost.dexdrip.watch.miband.message.DisplayControllMessageMiband3_4.NightMode.Sheduled in project xDrip-plus by jamorham.
the class MiBandService method processFirmwareCommands.
@SuppressLint("CheckResult")
private void processFirmwareCommands(byte[] value, boolean isSeqCommand) {
RxBleConnection connection = I.connection;
FirmwareOperations.SequenceType seq = firmware.getSequence();
if (d)
UserError.Log.d(TAG, "processFirmwareCommands: " + bytesToHex(value) + ": seq:" + seq.toString());
if (isSeqCommand) {
switch(seq) {
case SET_NIGHTMODE:
{
if (true) {
isNeedToRestoreNightMode = true;
DisplayControllMessageMiband3_4 dispControl = new DisplayControllMessageMiband3_4();
Calendar sheduledCalendar = Calendar.getInstance();
sheduledCalendar.set(Calendar.HOUR_OF_DAY, 0);
sheduledCalendar.set(Calendar.MINUTE, 0);
Date sheduledDate = sheduledCalendar.getTime();
connection.writeCharacteristic(dispControl.getCharacteristicUUID(), dispControl.setNightModeCmd(Sheduled, sheduledDate, sheduledDate)).subscribe(valB -> {
UserError.Log.d(TAG, "Wrote nigntmode, got: " + JoH.bytesToHex(valB));
firmware.nextSequence();
processFirmwareCommands(null, true);
}, throwable -> {
UserError.Log.e(TAG, "Could not write nigntmode: " + throwable);
firmware.nextSequence();
processFirmwareCommands(null, true);
});
} else {
firmware.nextSequence();
processFirmwareCommands(null, true);
}
break;
}
case PREPARE_UPLOAD:
{
connection.writeCharacteristic(firmware.getFirmwareCharacteristicUUID(), firmware.prepareFWUploadInitCommand()).subscribe(valB -> {
UserError.Log.d(TAG, "Wrote prepareFWUploadInitCommand, got: " + JoH.bytesToHex(valB));
}, throwable -> {
UserError.Log.e(TAG, "Could not write prepareFWUploadInitCommand: " + throwable);
resetFirmwareState(false);
});
firmware.nextSequence();
break;
}
}
return;
} else {
if (value.length != 3 && value.length != 11) {
UserError.Log.e(TAG, "Notifications should be 3 or 11 bytes long.");
return;
}
boolean success = value[2] == OperationCodes.SUCCESS;
if (value[0] == OperationCodes.RESPONSE && success) {
try {
switch(value[1]) {
case OperationCodes.COMMAND_FIRMWARE_INIT:
{
if (seq == FirmwareOperations.SequenceType.TRANSFER_FW_START) {
connection.writeCharacteristic(firmware.getFirmwareCharacteristicUUID(), firmware.getFirmwareStartCommand()).subscribe(valB -> {
UserError.Log.d(TAG, "Wrote Start command, got: " + JoH.bytesToHex(valB));
}, throwable -> {
UserError.Log.e(TAG, "Could not write Start command: " + throwable);
resetFirmwareState(false);
});
firmware.nextSequence();
} else if (seq == FirmwareOperations.SequenceType.TRANSFER_SEND_WF_INFO) {
connection.writeCharacteristic(firmware.getFirmwareCharacteristicUUID(), firmware.sendFwInfo()).subscribe(valB -> {
UserError.Log.d(TAG, "Wrote sendFwInfo, got: " + JoH.bytesToHex(valB));
}, throwable -> {
UserError.Log.e(TAG, "Could not write firmware info: " + throwable);
resetFirmwareState(false);
});
firmware.nextSequence();
break;
}
break;
}
case OperationCodes.COMMAND_FIRMWARE_START_DATA:
{
sendFirmwareData();
break;
}
case OperationCodes.COMMAND_FIRMWARE_CHECKSUM:
{
firmware.nextSequence();
if (firmware.getFirmwareType() == FirmwareOperations.FirmwareType.FIRMWARE) {
// send reboot
} else {
UserError.Log.e(TAG, "Watch Face has been installed successfully");
resetFirmwareState(true);
}
break;
}
case OperationCodes.COMMAND_FIRMWARE_REBOOT:
{
UserError.Log.e(TAG, "Reboot command successfully sent.");
resetFirmwareState(true);
break;
}
default:
{
resetFirmwareState(false, "Unexpected response during firmware update");
}
}
} catch (Exception ex) {
resetFirmwareState(false);
}
} else {
String errorMessage = null;
Boolean sendBGNotification = false;
if (value[2] == OperationCodes.LOW_BATTERY_ERROR) {
errorMessage = "Cannot upload watchface, low battery, please charge device";
sendBGNotification = true;
} else if (value[2] == OperationCodes.TIMER_RUNNING) {
errorMessage = "Cannot upload watchface, timer running on band";
} else if (value[2] == OperationCodes.ON_CALL) {
errorMessage = "Cannot upload watchface, call in progress";
} else {
errorMessage = "Unexpected notification during firmware update:" + JoH.bytesToHex(value);
}
resetFirmwareState(false, errorMessage);
if (sendBGNotification) {
emptyQueue();
JoH.startService(MiBandService.class, "function", "update_bg_as_notification");
changeState(SLEEP);
}
}
}
}
use of com.eveningoutpost.dexdrip.watch.miband.message.DisplayControllMessageMiband3_4.NightMode.Sheduled in project xDrip by NightscoutFoundation.
the class MiBandService method processFirmwareCommands.
@SuppressLint("CheckResult")
private void processFirmwareCommands(byte[] value, boolean isSeqCommand) {
RxBleConnection connection = I.connection;
FirmwareOperations.SequenceType seq = firmware.getSequence();
if (d)
UserError.Log.d(TAG, "processFirmwareCommands: " + bytesToHex(value) + ": seq:" + seq.toString());
if (isSeqCommand) {
switch(seq) {
case SET_NIGHTMODE:
{
if (true) {
isNeedToRestoreNightMode = true;
DisplayControllMessageMiband3_4 dispControl = new DisplayControllMessageMiband3_4();
Calendar sheduledCalendar = Calendar.getInstance();
sheduledCalendar.set(Calendar.HOUR_OF_DAY, 0);
sheduledCalendar.set(Calendar.MINUTE, 0);
Date sheduledDate = sheduledCalendar.getTime();
connection.writeCharacteristic(dispControl.getCharacteristicUUID(), dispControl.setNightModeCmd(Sheduled, sheduledDate, sheduledDate)).subscribe(valB -> {
UserError.Log.d(TAG, "Wrote nigntmode, got: " + JoH.bytesToHex(valB));
firmware.nextSequence();
processFirmwareCommands(null, true);
}, throwable -> {
UserError.Log.e(TAG, "Could not write nigntmode: " + throwable);
firmware.nextSequence();
processFirmwareCommands(null, true);
});
} else {
firmware.nextSequence();
processFirmwareCommands(null, true);
}
break;
}
case PREPARE_UPLOAD:
{
connection.writeCharacteristic(firmware.getFirmwareCharacteristicUUID(), firmware.prepareFWUploadInitCommand()).subscribe(valB -> {
UserError.Log.d(TAG, "Wrote prepareFWUploadInitCommand, got: " + JoH.bytesToHex(valB));
}, throwable -> {
UserError.Log.e(TAG, "Could not write prepareFWUploadInitCommand: " + throwable);
resetFirmwareState(false);
});
firmware.nextSequence();
break;
}
}
return;
} else {
if (value.length != 3 && value.length != 11) {
UserError.Log.e(TAG, "Notifications should be 3 or 11 bytes long.");
return;
}
boolean success = value[2] == OperationCodes.SUCCESS;
if (value[0] == OperationCodes.RESPONSE && success) {
try {
switch(value[1]) {
case OperationCodes.COMMAND_FIRMWARE_INIT:
{
if (seq == FirmwareOperations.SequenceType.TRANSFER_FW_START) {
connection.writeCharacteristic(firmware.getFirmwareCharacteristicUUID(), firmware.getFirmwareStartCommand()).subscribe(valB -> {
UserError.Log.d(TAG, "Wrote Start command, got: " + JoH.bytesToHex(valB));
}, throwable -> {
UserError.Log.e(TAG, "Could not write Start command: " + throwable);
resetFirmwareState(false);
});
firmware.nextSequence();
} else if (seq == FirmwareOperations.SequenceType.TRANSFER_SEND_WF_INFO) {
connection.writeCharacteristic(firmware.getFirmwareCharacteristicUUID(), firmware.sendFwInfo()).subscribe(valB -> {
UserError.Log.d(TAG, "Wrote sendFwInfo, got: " + JoH.bytesToHex(valB));
}, throwable -> {
UserError.Log.e(TAG, "Could not write firmware info: " + throwable);
resetFirmwareState(false);
});
firmware.nextSequence();
break;
}
break;
}
case OperationCodes.COMMAND_FIRMWARE_START_DATA:
{
sendFirmwareData();
break;
}
case OperationCodes.COMMAND_FIRMWARE_CHECKSUM:
{
firmware.nextSequence();
if (firmware.getFirmwareType() == FirmwareOperations.FirmwareType.FIRMWARE) {
// send reboot
} else {
UserError.Log.e(TAG, "Watch Face has been installed successfully");
resetFirmwareState(true);
}
break;
}
case OperationCodes.COMMAND_FIRMWARE_REBOOT:
{
UserError.Log.e(TAG, "Reboot command successfully sent.");
resetFirmwareState(true);
break;
}
default:
{
resetFirmwareState(false, "Unexpected response during firmware update");
}
}
} catch (Exception ex) {
resetFirmwareState(false);
}
} else {
String errorMessage = null;
Boolean sendBGNotification = false;
if (value[2] == OperationCodes.LOW_BATTERY_ERROR) {
errorMessage = "Cannot upload watchface, low battery, please charge device";
sendBGNotification = true;
} else if (value[2] == OperationCodes.TIMER_RUNNING) {
errorMessage = "Cannot upload watchface, timer running on band";
} else if (value[2] == OperationCodes.ON_CALL) {
errorMessage = "Cannot upload watchface, call in progress";
} else {
errorMessage = "Unexpected notification during firmware update:" + JoH.bytesToHex(value);
}
resetFirmwareState(false, errorMessage);
if (sendBGNotification) {
emptyQueue();
JoH.startService(MiBandService.class, "function", "update_bg_as_notification");
changeState(SLEEP);
}
}
}
}
Aggregations