1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-24 15:43:46 +02:00

NO1 F1: Set time during initialization.

This commit is contained in:
protomors 2018-07-17 11:56:36 +03:00 committed by cpfeiffer
parent 343239ff9e
commit fd68700b9a

View File

@ -89,6 +89,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
builder.setGattCallback(this); builder.setGattCallback(this);
builder.notify(measureCharacteristic, true); builder.notify(measureCharacteristic, true);
setTime(builder);
sendSettings(builder); sendSettings(builder);
builder.write(ctrlCharacteristic, new byte[]{No1F1Constants.CMD_FIRMWARE_VERSION}); builder.write(ctrlCharacteristic, new byte[]{No1F1Constants.CMD_FIRMWARE_VERSION});
@ -173,18 +174,8 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
public void onSetTime() { public void onSetTime() {
try { try {
TransactionBuilder builder = performInitialized("setTime"); TransactionBuilder builder = performInitialized("setTime");
Calendar c = GregorianCalendar.getInstance(); setTime(builder);
byte[] datetimeBytes = new byte[]{ performConnected(builder.getTransaction());
No1F1Constants.CMD_DATETIME,
(byte) ((c.get(Calendar.YEAR) / 256) & 0xff),
(byte) (c.get(Calendar.YEAR) % 256),
(byte) (c.get(Calendar.MONTH) + 1),
(byte) c.get(Calendar.DAY_OF_MONTH),
(byte) c.get(Calendar.HOUR_OF_DAY),
(byte) c.get(Calendar.MINUTE),
(byte) c.get(Calendar.SECOND)
};
builder.write(ctrlCharacteristic, datetimeBytes);
} catch (IOException e) { } catch (IOException e) {
GB.toast(getContext(), "Error setting time: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); GB.toast(getContext(), "Error setting time: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
} }
@ -396,6 +387,21 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
return true; return true;
} }
private void setTime(TransactionBuilder transaction) {
Calendar c = GregorianCalendar.getInstance();
byte[] datetimeBytes = new byte[]{
No1F1Constants.CMD_DATETIME,
(byte) ((c.get(Calendar.YEAR) / 256) & 0xff),
(byte) (c.get(Calendar.YEAR) % 256),
(byte) (c.get(Calendar.MONTH) + 1),
(byte) c.get(Calendar.DAY_OF_MONTH),
(byte) c.get(Calendar.HOUR_OF_DAY),
(byte) c.get(Calendar.MINUTE),
(byte) c.get(Calendar.SECOND)
};
transaction.write(ctrlCharacteristic, datetimeBytes);
}
/** /**
* Set display settings (time format and measurement system) * Set display settings (time format and measurement system)
* *