mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 09:01:55 +01:00
Moyoung: Add support for world clocks
This commit is contained in:
parent
ff865fbc99
commit
938085b5fa
@ -65,4 +65,14 @@ public class ColmiI28UltraCoordinator extends AbstractMoyoungDeviceCoordinator {
|
||||
public int getAlarmSlotCount(GBDevice device) {
|
||||
return 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWorldClocksSlotCount() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWorldClocksLabelLength() {
|
||||
return 30;
|
||||
}
|
||||
}
|
@ -212,7 +212,7 @@ public class MoyoungConstants {
|
||||
public static final byte CMD_SET_ALARM_CLOCK = 17; // (?) {id, enable ? 1 : 0, repeat, hour, minute, i >> 8, i, repeatMode}, repeatMode is 0(SINGLE), 127(EVERYDAY), or bitmask of 1,2,4,8,16,32,64(SUNDAY-SATURDAY) is 0,1,2, i is ((year << 12) + (month << 8) + day) where year is 2015-based, month and day start at 1 for repeatMode=SINGLE and 0 otherwise, repeat is 0(SINGLE),1(EVERYDAY),2(OTHER)
|
||||
|
||||
public static final byte CMD_ADVANCED_QUERY = (byte) 0xb9;
|
||||
public static final byte CMD_DAGPT = (byte) 0xbb;
|
||||
public static final byte CMD_ADVANCED_CMD = (byte) 0xbb;
|
||||
|
||||
public static final byte CMD_QUERY_POWER_SAVING = (byte) 0xa4;
|
||||
public static final byte CMD_SET_POWER_SAVING = (byte) 0x94;
|
||||
|
@ -47,6 +47,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
|
||||
import de.greenrobot.dao.query.QueryBuilder;
|
||||
@ -489,12 +490,6 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (packetType == MoyoungConstants.CMD_DAGPT)
|
||||
{
|
||||
LOG.info("Da GPT started on watch");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (packetType == MoyoungConstants.CMD_FIND_MY_PHONE)
|
||||
{
|
||||
LOG.info("Find my phone started on watch");
|
||||
@ -838,7 +833,36 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
@Override
|
||||
public void onSetWorldClocks(ArrayList<? extends WorldClock> clocks) {
|
||||
// TODO
|
||||
final TimeZone localTZ = Calendar.getInstance().getTimeZone();
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("sendWorldClocks");
|
||||
for (byte i=1; i<getDevice().getDeviceCoordinator().getWorldClocksSlotCount(); i++) {
|
||||
LOG.info("Deleting world clock " + i);
|
||||
ByteBuffer payload = ByteBuffer.allocate(3);
|
||||
payload.put((byte) 0x00);
|
||||
payload.put((byte) 0x03); // Delete clock
|
||||
payload.put(i);
|
||||
sendPacket(builder, MoyoungPacketOut.buildPacket(mtu, MoyoungConstants.CMD_ADVANCED_CMD, payload.array()));
|
||||
}
|
||||
byte currentNr = 1;
|
||||
for (WorldClock clock : clocks) {
|
||||
LOG.info("Sending world clock " + currentNr);
|
||||
TimeZone timezone = TimeZone.getTimeZone(clock.getTimeZoneId());
|
||||
ByteBuffer payload = ByteBuffer.allocate(19 + clock.getLabel().getBytes().length).order(ByteOrder.LITTLE_ENDIAN);
|
||||
payload.put((byte) 0x00);
|
||||
payload.put((byte) 0x02); // Set/edit clock
|
||||
payload.put(currentNr);
|
||||
payload.putInt(timezone.getOffset(System.currentTimeMillis()) / 1000); // Offset in secs vs UTC
|
||||
payload.putLong(0); // 8 unidentified bytes, but using 0x00 works
|
||||
payload.putInt((timezone.getOffset(System.currentTimeMillis()) - localTZ.getOffset(System.currentTimeMillis())) / 1000); // Offset in secs vs local timezone
|
||||
payload.put(clock.getLabel().getBytes());
|
||||
sendPacket(builder, MoyoungPacketOut.buildPacket(mtu, MoyoungConstants.CMD_ADVANCED_CMD, payload.array()));
|
||||
currentNr++;
|
||||
}
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException e) {
|
||||
LOG.error("Error sending world clocks: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user