mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-25 18:15:49 +01:00
Huami: Allow activity fetch timestamps to be sent in seconds
This commit is contained in:
parent
2216b6b76a
commit
2a47dc863a
@ -120,6 +120,7 @@ public class AmazfitBand5Coordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -95,6 +95,7 @@ public class AmazfitBipCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_buttonactions_with_longpress,
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ public class AmazfitBipLiteCoordinator extends AmazfitBipCoordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_relax_firmware_checks,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -111,6 +111,7 @@ public class AmazfitBipSCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -126,6 +126,7 @@ public class AmazfitBipUCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -123,6 +123,7 @@ public class AmazfitBipUProCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -103,6 +103,7 @@ public class AmazfitCorCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_bt_connected_advertisement,
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -105,6 +105,7 @@ public class AmazfitCor2Coordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_bt_connected_advertisement,
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -105,6 +105,7 @@ public class AmazfitGTRCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -103,6 +103,7 @@ public class AmazfitGTRLiteCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_expose_hr_thirdparty,
|
||||
R.xml.devicesettings_bt_connected_advertisement,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -110,6 +110,7 @@ public class AmazfitGTR2Coordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -110,6 +110,7 @@ public class AmazfitGTR2eCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -104,6 +104,7 @@ public class AmazfitGTSCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -110,6 +110,7 @@ public class AmazfitGTS2Coordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ public class AmazfitGTS2MiniCoordinator extends AmazfitGTS2Coordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -110,6 +110,7 @@ public class AmazfitGTS2eCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -109,6 +109,7 @@ public class AmazfitNeoCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -104,6 +104,7 @@ public class AmazfitTRexCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -104,6 +104,7 @@ public class AmazfitTRexProCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -104,6 +104,7 @@ public class AmazfitVergeLCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_bt_connected_advertisement,
|
||||
R.xml.devicesettings_buttonactions_with_longpress,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -110,6 +110,7 @@ public class AmazfitXCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -95,6 +95,7 @@ public class MiBand2Coordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_reserve_alarms_calendar,
|
||||
R.xml.devicesettings_bt_connected_advertisement,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -97,6 +97,7 @@ public class MiBand2HRXCoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_inactivity_dnd,
|
||||
R.xml.devicesettings_rotatewrist_cycleinfo,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -119,6 +119,7 @@ public class MiBand3Coordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_bt_connected_advertisement,
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -115,6 +115,7 @@ public class MiBand4Coordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -129,6 +129,7 @@ public class MiBand5Coordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -110,6 +110,7 @@ public class MiBand6Coordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_expose_hr_thirdparty,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -103,6 +103,7 @@ public class ZeppECoordinator extends HuamiCoordinator {
|
||||
R.xml.devicesettings_device_actions,
|
||||
R.xml.devicesettings_high_mtu,
|
||||
R.xml.devicesettings_overwrite_settings_on_connection,
|
||||
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
}
|
||||
|
@ -910,18 +910,6 @@ public abstract class Huami2021Support extends HuamiSupport {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getTimeBytes(final Calendar calendar, final TimeUnit precision) {
|
||||
final byte[] bytes = BLETypeConversions.shortCalendarToRawBytes(calendar);
|
||||
|
||||
if (precision != TimeUnit.MINUTES && precision != TimeUnit.SECONDS) {
|
||||
throw new IllegalArgumentException("Unsupported precision, only MINUTES and SECONDS are supported");
|
||||
}
|
||||
final byte seconds = precision == TimeUnit.SECONDS ? fromUint8(calendar.get(Calendar.SECOND)) : 0;
|
||||
final byte tz = BLETypeConversions.mapTimeZone(calendar, BLETypeConversions.TZ_FLAG_INCLUDE_DST_IN_TZ);
|
||||
return BLETypeConversions.join(bytes, new byte[]{seconds, tz});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Huami2021Support setCurrentTimeWithService(TransactionBuilder builder) {
|
||||
// It seems that the format sent to the Current Time characteristic changed in newer devices
|
||||
@ -1398,15 +1386,6 @@ public abstract class Huami2021Support extends HuamiSupport {
|
||||
return 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeUnit getFetchOperationsTimeUnit() {
|
||||
// This is configurable because using seconds was causing issues on Amazfit GTR 3
|
||||
// However, using minutes can cause issues while fetching workouts shorter than 1 minute
|
||||
final Prefs devicePrefs = getDevicePrefs();
|
||||
final boolean truncate = devicePrefs.getBoolean("huami_truncate_fetch_operation_timestamps", true);
|
||||
return truncate ? TimeUnit.MINUTES : TimeUnit.SECONDS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean force2021Protocol() {
|
||||
return true;
|
||||
|
@ -275,6 +275,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_NAME;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_WEIGHT_KG;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_YEAR_OF_BIRTH;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions.fromUint8;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL;
|
||||
|
||||
public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements Huami2021Handler {
|
||||
@ -402,29 +403,15 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
||||
return weatherSpec.windSpeedAsBeaufort() + ""; // cast to string
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given date/time (calendar) as a byte sequence, suitable for sending to the
|
||||
* Mi Band 2 (or derivative). The band appears to not handle DST offsets, so we simply add this
|
||||
* to the timezone.
|
||||
*
|
||||
* @param calendar
|
||||
* @param precision
|
||||
* @return
|
||||
*/
|
||||
public byte[] getTimeBytes(Calendar calendar, TimeUnit precision) {
|
||||
byte[] bytes;
|
||||
if (precision == TimeUnit.MINUTES) {
|
||||
bytes = BLETypeConversions.shortCalendarToRawBytes(calendar);
|
||||
} else if (precision == TimeUnit.SECONDS) {
|
||||
bytes = BLETypeConversions.calendarToRawBytes(calendar);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported precision, only MINUTES and SECONDS are supported till now");
|
||||
public byte[] getTimeBytes(final Calendar calendar, final TimeUnit precision) {
|
||||
final byte[] bytes = BLETypeConversions.shortCalendarToRawBytes(calendar);
|
||||
|
||||
if (precision != TimeUnit.MINUTES && precision != TimeUnit.SECONDS) {
|
||||
throw new IllegalArgumentException("Unsupported precision, only MINUTES and SECONDS are supported");
|
||||
}
|
||||
byte[] tail = new byte[] { 0, BLETypeConversions.mapTimeZone(calendar, BLETypeConversions.TZ_FLAG_INCLUDE_DST_IN_TZ) };
|
||||
// 0 = adjust reason bitflags? or DST offset?? , timezone
|
||||
// byte[] tail = new byte[] { 0x2 }; // reason
|
||||
byte[] all = BLETypeConversions.join(bytes, tail);
|
||||
return all;
|
||||
final byte seconds = precision == TimeUnit.SECONDS ? fromUint8(calendar.get(Calendar.SECOND)) : 0;
|
||||
final byte tz = BLETypeConversions.mapTimeZone(calendar, BLETypeConversions.TZ_FLAG_INCLUDE_DST_IN_TZ);
|
||||
return BLETypeConversions.join(bytes, new byte[]{seconds, tz});
|
||||
}
|
||||
|
||||
public Calendar fromTimeBytes(byte[] bytes) {
|
||||
@ -434,7 +421,9 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
||||
|
||||
public HuamiSupport setCurrentTimeWithService(TransactionBuilder builder) {
|
||||
GregorianCalendar now = BLETypeConversions.createCalendar();
|
||||
byte[] bytes = getTimeBytes(now, TimeUnit.SECONDS);
|
||||
byte[] head = BLETypeConversions.calendarToRawBytes(now);
|
||||
byte[] tail = new byte[] { 0, BLETypeConversions.mapTimeZone(now, BLETypeConversions.TZ_FLAG_INCLUDE_DST_IN_TZ) };
|
||||
byte[] bytes = BLETypeConversions.join(head, tail);
|
||||
builder.write(getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_CURRENT_TIME), bytes);
|
||||
return this;
|
||||
}
|
||||
@ -4107,7 +4096,11 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
||||
}
|
||||
|
||||
public TimeUnit getFetchOperationsTimeUnit() {
|
||||
return TimeUnit.MINUTES;
|
||||
// This is configurable because using seconds was causing issues on Amazfit GTR 3
|
||||
// However, using minutes can cause issues while fetching workouts shorter than 1 minute
|
||||
final Prefs devicePrefs = getDevicePrefs();
|
||||
final boolean truncate = devicePrefs.getBoolean("huami_truncate_fetch_operation_timestamps", true);
|
||||
return truncate ? TimeUnit.MINUTES : TimeUnit.SECONDS;
|
||||
}
|
||||
|
||||
public boolean force2021Protocol() {
|
||||
|
Loading…
Reference in New Issue
Block a user