mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
oppo: rename PREF to MISC_CONFIG; add MISC_CONFIG_REQ and MISC_CONFIG_RET commands
This commit is contained in:
+1
-1
@@ -26,7 +26,7 @@ public class OppoHeadphonesPreferences {
|
||||
|
||||
public static final String LDAC = "pref_soundcore_ldac_mode";
|
||||
public static final String MULTIPOINT = "oppo_multipoint";
|
||||
public static final String GAME_MODE= "oppo_game_mode";
|
||||
public static final String GAME_MODE = "oppo_game_mode";
|
||||
|
||||
public static String getTouchKey(final TouchConfigSide side, final TouchConfigType type) {
|
||||
return String.format(
|
||||
|
||||
+76
-7
@@ -41,7 +41,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands.OppoCo
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands.TouchConfigSide;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands.TouchConfigType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands.TouchConfigValue;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands.PrefType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands.MiscConfigType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.preferences.DevicePrefs;
|
||||
|
||||
@@ -165,7 +165,19 @@ public class OppoHeadphonesProtocol extends GBDeviceProtocol {
|
||||
LOG.debug("Got find device ack, status={}", payload[0]);
|
||||
break;
|
||||
}
|
||||
case PREF_ACK: {
|
||||
case MISC_CONFIG_RET:
|
||||
if (payload[0] != 0) {
|
||||
LOG.warn("Unknown config ret {}", payload[0]);
|
||||
break;
|
||||
}
|
||||
if (payload.length < 2) {
|
||||
LOG.error("Unexpected pref ret payload size {}", payload.length);
|
||||
break;
|
||||
}
|
||||
|
||||
events.add(parseMiscConfig(payload));
|
||||
break;
|
||||
case MISC_CONFIG_ACK: {
|
||||
LOG.debug("Got config ack, status={}", payload[0]);
|
||||
break;
|
||||
}
|
||||
@@ -289,6 +301,54 @@ public class OppoHeadphonesProtocol extends GBDeviceProtocol {
|
||||
return events;
|
||||
}
|
||||
|
||||
private static GBDeviceEvent parseMiscConfig(final byte[] payload) {
|
||||
final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences();
|
||||
for (int i = 2; i < payload.length; i += 2) {
|
||||
if (i + 1 >= payload.length) {
|
||||
LOG.warn("Truncated pref ret pair at index {}", i);
|
||||
break;
|
||||
}
|
||||
|
||||
final int code = payload[i] & 0xff;
|
||||
final int value = payload[i + 1] & 0xff;
|
||||
|
||||
final MiscConfigType type = MiscConfigType.fromCode(code);
|
||||
if (type == null) {
|
||||
LOG.warn("Unknown misc config code {}", code);
|
||||
continue;
|
||||
}
|
||||
|
||||
final boolean isEnabled = (value == 1);
|
||||
switch (type) {
|
||||
case LDAC:
|
||||
LOG.debug("Got misc config for LDAC = {}", isEnabled);
|
||||
eventUpdatePreferences.withPreference(
|
||||
OppoHeadphonesPreferences.LDAC,
|
||||
isEnabled
|
||||
);
|
||||
break;
|
||||
case MULTIPOINT:
|
||||
LOG.debug("Got misc config for MULTIPOINT = {}", isEnabled);
|
||||
eventUpdatePreferences.withPreference(
|
||||
OppoHeadphonesPreferences.MULTIPOINT,
|
||||
isEnabled
|
||||
);
|
||||
break;
|
||||
case GAME_MODE:
|
||||
LOG.debug("Got misc config for GAME_MODE = {}", isEnabled);
|
||||
eventUpdatePreferences.withPreference(
|
||||
OppoHeadphonesPreferences.GAME_MODE,
|
||||
isEnabled
|
||||
);
|
||||
break;
|
||||
default:
|
||||
LOG.warn("Unknown misc config code {}", code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return eventUpdatePreferences;
|
||||
}
|
||||
|
||||
private static GBDeviceEvent parseTouchConfig(final byte[] payload) {
|
||||
final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences();
|
||||
|
||||
@@ -395,28 +455,37 @@ public class OppoHeadphonesProtocol extends GBDeviceProtocol {
|
||||
final byte[] payload = new byte[] {
|
||||
(byte) (enable ? 0x01 : 0x00)
|
||||
};
|
||||
return encodePrefSet(PrefType.LDAC, payload);
|
||||
return encodeMiscConfigSet(MiscConfigType.LDAC, payload);
|
||||
}
|
||||
|
||||
public byte[] encodeGameModeSet(final boolean enable) {
|
||||
final byte[] payload = new byte[] {
|
||||
(byte) (enable ? 0x01 : 0x00)
|
||||
};
|
||||
return encodePrefSet(PrefType.GAME_MODE, payload);
|
||||
return encodeMiscConfigSet(MiscConfigType.GAME_MODE, payload);
|
||||
}
|
||||
|
||||
public byte[] encodeMultipointSet(final boolean enable) {
|
||||
final byte[] payload = new byte[] {
|
||||
(byte) (enable ? 0x01 : 0x00)
|
||||
};
|
||||
return encodePrefSet(PrefType.MULTIPOINT, payload);
|
||||
return encodeMiscConfigSet(MiscConfigType.MULTIPOINT, payload);
|
||||
}
|
||||
|
||||
private byte[] encodePrefSet(final PrefType type, final byte[] value) {
|
||||
private byte[] encodeMiscConfigSet(final MiscConfigType type, final byte[] value) {
|
||||
final byte[] payload = new byte[1 + value.length];
|
||||
payload[0] = (byte) type.getCode();
|
||||
System.arraycopy(value, 0, payload, 1, value.length);
|
||||
return encodeMessage(OppoCommand.PREF_SET, payload);
|
||||
return encodeMessage(OppoCommand.MISC_CONFIG_SET, payload);
|
||||
}
|
||||
|
||||
public byte[] encodeMiscConfigReq() {
|
||||
return encodeMessage(OppoCommand.MISC_CONFIG_REQ, new byte[]{
|
||||
(byte) 0x03,
|
||||
(byte) MiscConfigType.LDAC.getCode(),
|
||||
(byte) MiscConfigType.MULTIPOINT.getCode(),
|
||||
(byte) MiscConfigType.GAME_MODE.getCode()
|
||||
});
|
||||
}
|
||||
|
||||
private byte[] encodeMessage(final OppoCommand command, final byte[] payload) {
|
||||
|
||||
+1
@@ -70,6 +70,7 @@ public class OppoHeadphonesSupport extends AbstractHeadphoneSerialDeviceSupportV
|
||||
@Override
|
||||
protected TransactionBuilder initializeDevice(final TransactionBuilder builder) {
|
||||
builder.write(mDeviceProtocol.encodeFirmwareVersionReq());
|
||||
builder.write(mDeviceProtocol.encodeMiscConfigReq());
|
||||
builder.write(mDeviceProtocol.encodeTouchConfigReq());
|
||||
builder.write(mDeviceProtocol.encodeBatteryReq());
|
||||
builder.setDeviceState(GBDevice.State.INITIALIZED);
|
||||
|
||||
+4
-4
@@ -18,7 +18,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public enum PrefType {
|
||||
public enum MiscConfigType {
|
||||
LDAC(0x18),
|
||||
GAME_MODE(0x06),
|
||||
MULTIPOINT(0x11),
|
||||
@@ -27,7 +27,7 @@ public enum PrefType {
|
||||
|
||||
private final int code;
|
||||
|
||||
PrefType(final int code) {
|
||||
MiscConfigType(final int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ public enum PrefType {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PrefType fromCode(final int code) {
|
||||
for (final PrefType param : PrefType.values()) {
|
||||
public static MiscConfigType fromCode(final int code) {
|
||||
for (final MiscConfigType param : MiscConfigType.values()) {
|
||||
if (param.code == code) {
|
||||
return param;
|
||||
}
|
||||
+4
-2
@@ -30,8 +30,10 @@ public enum OppoCommand {
|
||||
TOUCH_CONFIG_ACK(0x8401),
|
||||
FIND_DEVICE_REQ(0x0400),
|
||||
FIND_DEVICE_ACK(0x8400),
|
||||
PREF_SET(0x0403),
|
||||
PREF_ACK(0x8403),
|
||||
MISC_CONFIG_SET(0x0403),
|
||||
MISC_CONFIG_REQ(0x010d),
|
||||
MISC_CONFIG_ACK(0x8403),
|
||||
MISC_CONFIG_RET(0x810d),
|
||||
;
|
||||
|
||||
private final short code;
|
||||
|
||||
Reference in New Issue
Block a user