1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 18:45:49 +01:00

Set the time during initialization. Necessary for steps tracking.

Also see #31
This commit is contained in:
cpfeiffer 2015-04-27 21:43:57 +02:00
parent 8e25c03350
commit 5a458611e2

View File

@ -1,9 +1,5 @@
package nodomain.freeyourgadget.gadgetbridge.miband; package nodomain.freeyourgadget.gadgetbridge.miband;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.util.Log;
import java.io.IOException; import java.io.IOException;
import java.util.Calendar; import java.util.Calendar;
import java.util.UUID; import java.util.UUID;
@ -12,6 +8,9 @@ import nodomain.freeyourgadget.gadgetbridge.GBCommand;
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State; import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
import nodomain.freeyourgadget.gadgetbridge.btle.AbstractBTLEDeviceSupport; import nodomain.freeyourgadget.gadgetbridge.btle.AbstractBTLEDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.btle.TransactionBuilder;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.util.Log;
public class MiBandSupport extends AbstractBTLEDeviceSupport { public class MiBandSupport extends AbstractBTLEDeviceSupport {
@ -23,7 +22,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
@Override @Override
protected TransactionBuilder initializeDevice(TransactionBuilder builder) { protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
pair(builder).sendUserInfo(builder); pair(builder).sendUserInfo(builder).setCurrentTime(builder);
return builder; return builder;
} }
@ -124,7 +123,20 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
@Override @Override
public void onSetTime(long ts) { public void onSetTime(long ts) {
// TODO Not sure about the ts value try {
TransactionBuilder builder = performInitialized("Set date and time");
setCurrentTime(builder);
builder.queue(getQueue());
} catch (IOException ex) {
Log.e(TAG, "Unable to set time on MI device", ex);
}
}
/**
* Sets the current time to the Mi device using the given builder.
* @param builder
*/
private MiBandSupport setCurrentTime(TransactionBuilder builder) {
Calendar now = Calendar.getInstance(); Calendar now = Calendar.getInstance();
byte[] time = new byte[]{ byte[] time = new byte[]{
(byte) (now.get(Calendar.YEAR) - 2000), (byte) (now.get(Calendar.YEAR) - 2000),
@ -140,18 +152,13 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
(byte) 0x0f, (byte) 0x0f,
(byte) 0x0f (byte) 0x0f
}; };
try { BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DATE_TIME);
TransactionBuilder builder = performInitialized("Set date and time"); if (characteristic != null) {
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DATE_TIME); builder.write(characteristic, time);
if (characteristic != null) { } else {
builder.write(characteristic, time); Log.i(TAG, "Unable to set time -- characteristic not available");
} else {
Log.i(TAG, "Unable to set time -- characteristic not available");
}
} catch (IOException ex) {
Log.e(TAG, "Unable to set time on MI device", ex);
} }
return this;
} }
@Override @Override