mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-24 08:37:32 +01:00
TLW64: Support setting date
This commit is contained in:
parent
7c5a2d0e58
commit
0ed7c385fb
@ -25,6 +25,7 @@ public final class TLW64Constants {
|
||||
public static final UUID UUID_CHARACTERISTIC_CONTROL = UUID.fromString("000033f1-0000-1000-8000-00805f9b34fb");
|
||||
|
||||
// Command bytes
|
||||
public static final byte CMD_DATETIME = (byte) 0xa3;
|
||||
public static final byte CMD_ALARM = (byte) 0xab;
|
||||
|
||||
}
|
||||
|
@ -21,12 +21,15 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.tlw64;
|
||||
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.net.Uri;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.tlw64.TLW64Constants;
|
||||
@ -42,6 +45,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
public class TLW64Support extends AbstractBTLEDeviceSupport {
|
||||
|
||||
@ -62,6 +66,8 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
|
||||
|
||||
ctrlCharacteristic = getCharacteristic(TLW64Constants.UUID_CHARACTERISTIC_CONTROL);
|
||||
|
||||
setTime(builder);
|
||||
|
||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
|
||||
|
||||
LOG.info("Initialization Done");
|
||||
@ -86,7 +92,13 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
|
||||
|
||||
@Override
|
||||
public void onSetTime() {
|
||||
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("setTime");
|
||||
setTime(builder);
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException e) {
|
||||
GB.toast(getContext(), "Error setting time: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -245,4 +257,19 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
|
||||
LOG.warn("Unable to set vibration", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void setTime(TransactionBuilder transaction) {
|
||||
Calendar c = GregorianCalendar.getInstance();
|
||||
byte[] datetimeBytes = new byte[]{
|
||||
TLW64Constants.CMD_DATETIME,
|
||||
(byte) (c.get(Calendar.YEAR) / 256),
|
||||
(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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user