1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 20:36:51 +01:00

Zepp OS: Map known watchfaces to human-readable names

This commit is contained in:
José Rebelo 2023-04-26 09:51:14 +01:00
parent b27fc05a6e
commit 94c7b43ad4
6 changed files with 120 additions and 13 deletions

View File

@ -1460,6 +1460,11 @@ public abstract class Huami2021Support extends HuamiSupport {
return this;
}
public void requestWatchfaces(final TransactionBuilder builder) {
watchfaceService.requestWatchfaces(builder);
watchfaceService.requestCurrentWatchface(builder);
}
protected Huami2021Support requestShortcuts(final TransactionBuilder builder) {
LOG.info("Requesting shortcuts");

View File

@ -28,14 +28,14 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService;
import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuamiFirmwareInfo;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.Huami2021Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
public class UpdateFirmwareOperation2021 extends UpdateFirmwareOperation2020 {
private static final Logger LOG = LoggerFactory.getLogger(UpdateFirmwareOperation2021.class);
public UpdateFirmwareOperation2021(final Uri uri, final HuamiSupport support) {
public UpdateFirmwareOperation2021(final Uri uri, final Huami2021Support support) {
super(uri, support);
}
@ -61,6 +61,11 @@ public class UpdateFirmwareOperation2021 extends UpdateFirmwareOperation2020 {
*/
}
@Override
public Huami2021Support getSupport() {
return (Huami2021Support) super.getSupport();
}
@Override
protected void handleNotificationNotif(byte[] value) {
super.handleNotificationNotif(value);
@ -75,6 +80,15 @@ public class UpdateFirmwareOperation2021 extends UpdateFirmwareOperation2020 {
} catch (final IOException e) {
LOG.error("Failed to request display items after app install", e);
}
} else if (getFirmwareInfo().getFirmwareType() == HuamiFirmwareType.WATCHFACE) {
// After a watchface is installed, request the watchfaces from the band (new watchface will be at the end)
try {
TransactionBuilder builder = performInitialized("request watchfaces");
getSupport().requestWatchfaces(builder);
builder.queue(getQueue());
} catch (final IOException e) {
LOG.error("Failed to request watchfaces after watchface install", e);
}
}
}
}

View File

@ -48,6 +48,41 @@ public class ZeppOsWatchfaceService extends AbstractZeppOsService {
public static final byte CMD_CURRENT_GET = 0x09;
public static final byte CMD_CURRENT_RET = 0x0a;
public enum Watchface {
// Codes are from GTR 4, not sure if they match on other watches
RED_FANTASY(0x00002D38),
MULTIPLE_DATA(0x00002D10),
RUSH(0x00002D37),
MINIMALIST(0x00002D0E),
SIMPLICITY_DATA(0x00002D08),
VIBRANT(0x00002D09),
BUSINESS_STYLE(0x00002D0D),
EMERALD_MOONLIGHT(0x00002D0A),
ROTATING_EARTH(0x00002D0F),
SUPERPOSITION(0x00002D0C),
;
private final int code;
Watchface(final int code) {
this.code = code;
}
public int getCode() {
return code;
}
public static Watchface fromCode(final int code) {
for (final Watchface watchface : values()) {
if (watchface.getCode() == code) {
return watchface;
}
}
return null;
}
}
public ZeppOsWatchfaceService(final Huami2021Support support) {
super(support);
}
@ -104,8 +139,15 @@ public class ZeppOsWatchfaceService extends AbstractZeppOsService {
final List<String> watchfaces = new ArrayList<>();
for (int i = 0; i < numWatchfaces; i++) {
final int watchface = buf.getInt();
watchfaces.add(String.format(Locale.ROOT, "0x%08X", watchface));
final int watchfaceCode = buf.getInt();
final Watchface watchface = Watchface.fromCode(watchfaceCode);
if (watchface != null) {
watchfaces.add(watchface.name().toLowerCase(Locale.ROOT));
} else {
final String watchfaceHex = String.format(Locale.ROOT, "0x%08X", watchfaceCode);
LOG.warn("Unknown watchface code {}", watchfaceHex);
watchfaces.add(watchfaceHex);
}
}
final GBDeviceEventUpdatePreferences evt = new GBDeviceEventUpdatePreferences()
@ -113,18 +155,26 @@ public class ZeppOsWatchfaceService extends AbstractZeppOsService {
getSupport().evaluateGBDeviceEvent(evt);
}
public void setWatchface(final String watchface) {
if (watchface == null) {
public void setWatchface(final String watchfacePrefValue) {
if (watchfacePrefValue == null) {
LOG.warn("watchface is null");
return;
}
final Matcher matcher = Pattern.compile("^0[xX]([0-9a-fA-F]+)$").matcher(watchface);
int watchfaceInt;
try {
final Watchface watchfaceEnum = Watchface.valueOf(watchfacePrefValue.toUpperCase(Locale.ROOT));
watchfaceInt = watchfaceEnum.getCode();
} catch (final IllegalArgumentException e) {
// attempt to parse as hex
final Matcher matcher = Pattern.compile("^0[xX]([0-9a-fA-F]+)$").matcher(watchfacePrefValue);
if (!matcher.find()) {
LOG.warn("Failed to parse watchface '{}' as hex", watchface);
LOG.warn("Failed to parse watchface '{}' as hex", watchfacePrefValue);
return;
}
final int watchfaceInt = Integer.parseInt(matcher.group(1), 16);
watchfaceInt = Integer.parseInt(matcher.group(1), 16);
}
final ByteBuffer buf = ByteBuffer.allocate(5).order(ByteOrder.LITTLE_ENDIAN);
buf.put(CMD_SET);

View File

@ -754,6 +754,34 @@
<item>low</item>
</string-array>
<string-array name="pref_zepp_os_watchfaces">
<!-- GTR 4 -->
<item>@string/zepp_os_watchface_red_fantasy</item>
<item>@string/zepp_os_watchface_multiple_data</item>
<item>@string/zepp_os_watchface_rush</item>
<item>@string/zepp_os_watchface_minimalist</item>
<item>@string/zepp_os_watchface_simplicity_data</item>
<item>@string/zepp_os_watchface_vibrant</item>
<item>@string/zepp_os_watchface_business_style</item>
<item>@string/zepp_os_watchface_emerald_moonlight</item>
<item>@string/zepp_os_watchface_rotating_earth</item>
<item>@string/zepp_os_watchface_superposition</item>
</string-array>
<string-array name="pref_zepp_os_watchfaces_values">
<!-- GTR 4 -->
<item>red_fantasy</item>
<item>multiple_data</item>
<item>rush</item>
<item>minimalist</item>
<item>simplicity_data</item>
<item>vibrant</item>
<item>business_style</item>
<item>emerald_moonlight</item>
<item>rotating_earth</item>
<item>superposition</item>
</string-array>
<string-array name="pref_zepp_os_apps">
<item>@string/menuitem_activity</item>
<item>@string/menuitem_alarm</item>

View File

@ -1362,6 +1362,16 @@
<string name='menuitem_eject_water'>Eject Water</string>
<string name="menuitem_unknown_app">Unknown (%s)</string>
<string name="menuitem_unsupported">[UNSUPPORTED] %s</string>
<string name="zepp_os_watchface_red_fantasy">Red Fantasy</string>
<string name="zepp_os_watchface_multiple_data">Multiple Data</string>
<string name="zepp_os_watchface_rush">Rush</string>
<string name="zepp_os_watchface_minimalist">Minimalist</string>
<string name="zepp_os_watchface_simplicity_data">Simplicity Data</string>
<string name="zepp_os_watchface_vibrant">Vibrant</string>
<string name="zepp_os_watchface_business_style">Business Style</string>
<string name="zepp_os_watchface_emerald_moonlight">Emerald Moonlight</string>
<string name="zepp_os_watchface_rotating_earth">Rotating Earth</string>
<string name="zepp_os_watchface_superposition">superposition</string>
<string name="yesterdays_activity">Yesterday\'s Activity</string>
<string name="watch9_time_minutes">Minutes:</string>
<string name="watch9_time_hours">Hours:</string>

View File

@ -3,8 +3,8 @@
<ListPreference
android:defaultValue=""
android:dialogTitle="@string/kind_watchface"
android:entries="@array/pref_huami2021_empty_array"
android:entryValues="@array/pref_huami2021_empty_array"
android:entries="@array/pref_zepp_os_watchfaces"
android:entryValues="@array/pref_zepp_os_watchfaces_values"
android:icon="@drawable/ic_watch"
android:key="watchface"
android:title="@string/kind_watchface" />