mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
oppo: rename DeviceInfo to Subscription
This commit is contained in:
+25
-17
@@ -30,6 +30,8 @@ import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
@@ -48,7 +50,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands.TouchC
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands.MiscConfigType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands.AncConfigType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands.AncConfigValue;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands.DeviceInfoType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands.SubscriptionType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.preferences.DevicePrefs;
|
||||
|
||||
@@ -145,11 +147,11 @@ public class OppoHeadphonesProtocol extends GBDeviceProtocol {
|
||||
events.addAll(parseBattery(payload));
|
||||
break;
|
||||
}
|
||||
case DEVICE_INFO_ACK:
|
||||
LOG.debug("Got device info ack, return={}", StringUtils.bytesToHex(payload));
|
||||
case SUBSCRIPTION_ACK:
|
||||
LOG.debug("Got subscription ack, return={}", StringUtils.bytesToHex(payload));
|
||||
break;
|
||||
case DEVICE_INFO_RET: {
|
||||
events.addAll(parseDeviceInfo(payload));
|
||||
case SUBSCRIPTION_RET: {
|
||||
events.addAll(parseSubscription(payload));
|
||||
break;
|
||||
}
|
||||
case FIRMWARE_RET: {
|
||||
@@ -340,12 +342,12 @@ public class OppoHeadphonesProtocol extends GBDeviceProtocol {
|
||||
}
|
||||
|
||||
|
||||
private static List<GBDeviceEvent> parseDeviceInfo(final byte[] payload) {
|
||||
private static List<GBDeviceEvent> parseSubscription(final byte[] payload) {
|
||||
final List<GBDeviceEvent> events = new ArrayList<>();
|
||||
final int typeCode = payload[0] & 0xff;
|
||||
final DeviceInfoType type = DeviceInfoType.fromCode(typeCode);
|
||||
final SubscriptionType type = SubscriptionType.fromCode(typeCode);
|
||||
if (type == null) {
|
||||
LOG.warn("Unknown device info {}", String.format(Locale.ROOT, "0x%02x", typeCode));
|
||||
LOG.warn("Unknown subcription type {}", String.format(Locale.ROOT, "0x%02x", typeCode));
|
||||
return events;
|
||||
}
|
||||
|
||||
@@ -385,7 +387,7 @@ public class OppoHeadphonesProtocol extends GBDeviceProtocol {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
LOG.warn("Unhandled device info type {}", type);
|
||||
LOG.warn("Unhandled subscription type {}", type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -671,14 +673,20 @@ public class OppoHeadphonesProtocol extends GBDeviceProtocol {
|
||||
return encodeMessage(OppoCommand.ANC_CONFIG_REQ, payload);
|
||||
}
|
||||
|
||||
public byte[] encodeDeviceInfoSet() {
|
||||
final byte[] payload = new byte[] {
|
||||
(byte) 0x09,
|
||||
(byte) DeviceInfoType.BATTERY.getCode(),
|
||||
(byte) DeviceInfoType.ANC_SELECTOR.getCode(),
|
||||
(byte) DeviceInfoType.GAME_MODE.getCode(),
|
||||
};
|
||||
return encodeMessage(OppoCommand.DEVICE_INFO_SET, payload);
|
||||
public byte[] encodeSubscriptionSet(@NonNull final EnumSet<SubscriptionType> subscriptions) {
|
||||
if (subscriptions.isEmpty()) {
|
||||
throw new IllegalArgumentException("Subscription list cannot be empty");
|
||||
}
|
||||
|
||||
byte[] payload = new byte[1 + subscriptions.size()];
|
||||
payload[0] = (byte) 0x09;
|
||||
|
||||
int i = 1;
|
||||
for (SubscriptionType type : subscriptions) {
|
||||
payload[i++] = (byte) type.getCode();
|
||||
}
|
||||
|
||||
return encodeMessage(OppoCommand.SUBSCRIPTION_SET, payload);
|
||||
}
|
||||
|
||||
private byte[] encodeMessage(final OppoCommand command, final byte[] payload) {
|
||||
|
||||
+15
-6
@@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.UUID;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
||||
@@ -31,6 +32,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btbr.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.serial.AbstractHeadphoneSerialDeviceSupportV2;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands.MiscConfigType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands.AncConfigType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands.SubscriptionType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.oppo.OppoHeadphonesCoordinator;
|
||||
|
||||
public class OppoHeadphonesSupport extends AbstractHeadphoneSerialDeviceSupportV2<OppoHeadphonesProtocol> {
|
||||
@@ -74,29 +76,36 @@ public class OppoHeadphonesSupport extends AbstractHeadphoneSerialDeviceSupportV
|
||||
|
||||
@Override
|
||||
protected TransactionBuilder initializeDevice(final TransactionBuilder builder) {
|
||||
builder.write(mDeviceProtocol.encodeDeviceInfoSet());
|
||||
builder.write(mDeviceProtocol.encodeFirmwareVersionReq());
|
||||
|
||||
final OppoHeadphonesCoordinator coordinator = (OppoHeadphonesCoordinator) getDevice().getDeviceCoordinator();
|
||||
final List<MiscConfigType> supportedMiscConfigs = new ArrayList<>();
|
||||
final EnumSet<SubscriptionType> supportedSubscriptions = EnumSet.of(SubscriptionType.BATTERY);
|
||||
if (coordinator.supportsLdac(getDevice())) {
|
||||
supportedMiscConfigs.add(MiscConfigType.LDAC);
|
||||
}
|
||||
|
||||
if (coordinator.supportsMultipoint(getDevice())) {
|
||||
supportedMiscConfigs.add(MiscConfigType.MULTIPOINT);
|
||||
}
|
||||
|
||||
if (coordinator.supportsGameMode(getDevice())) {
|
||||
supportedMiscConfigs.add(MiscConfigType.GAME_MODE);
|
||||
supportedSubscriptions.add(SubscriptionType.GAME_MODE);
|
||||
}
|
||||
if (!supportedMiscConfigs.isEmpty()) {
|
||||
builder.write(mDeviceProtocol.encodeMiscConfigReq(supportedMiscConfigs));
|
||||
}
|
||||
builder.write(mDeviceProtocol.encodeTouchConfigReq());
|
||||
|
||||
if (coordinator.supportsAnc(getDevice())) {
|
||||
builder.write(mDeviceProtocol.encodeAncConfigReq(AncConfigType.MODE));
|
||||
builder.write(mDeviceProtocol.encodeAncConfigReq(AncConfigType.TOUCH_CYCLE_MODES));
|
||||
supportedSubscriptions.add(SubscriptionType.ANC_SELECTOR);
|
||||
}
|
||||
|
||||
if (!supportedMiscConfigs.isEmpty()) {
|
||||
builder.write(mDeviceProtocol.encodeMiscConfigReq(supportedMiscConfigs));
|
||||
}
|
||||
|
||||
builder.write(mDeviceProtocol.encodeSubscriptionSet(supportedSubscriptions));
|
||||
builder.write(mDeviceProtocol.encodeTouchConfigReq());
|
||||
builder.write(mDeviceProtocol.encodeFirmwareVersionReq());
|
||||
builder.write(mDeviceProtocol.encodeBatteryReq());
|
||||
builder.setDeviceState(GBDevice.State.INITIALIZED);
|
||||
scheduleBatteryRequestRetry();
|
||||
|
||||
+3
-3
@@ -21,9 +21,9 @@ import androidx.annotation.Nullable;
|
||||
public enum OppoCommand {
|
||||
BATTERY_REQ(0x0106),
|
||||
BATTERY_RET(0x8106),
|
||||
DEVICE_INFO_SET(0x0205),
|
||||
DEVICE_INFO_ACK(0x8205),
|
||||
DEVICE_INFO_RET(0x0204),
|
||||
SUBSCRIPTION_SET(0x0205),
|
||||
SUBSCRIPTION_ACK(0x8205),
|
||||
SUBSCRIPTION_RET(0x0204),
|
||||
FIRMWARE_GET(0x0105),
|
||||
FIRMWARE_RET(0x8105),
|
||||
TOUCH_CONFIG_REQ(0x0108),
|
||||
|
||||
+4
-4
@@ -18,7 +18,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.oppo.commands;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public enum DeviceInfoType {
|
||||
public enum SubscriptionType {
|
||||
BATTERY(0x01),
|
||||
STATUS(0x02),
|
||||
ANC_SELECTOR(0x03),
|
||||
@@ -27,7 +27,7 @@ public enum DeviceInfoType {
|
||||
|
||||
private final int code;
|
||||
|
||||
DeviceInfoType(final int code) {
|
||||
SubscriptionType(final int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ public enum DeviceInfoType {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static DeviceInfoType fromCode(final int code) {
|
||||
for (final DeviceInfoType param : DeviceInfoType.values()) {
|
||||
public static SubscriptionType fromCode(final int code) {
|
||||
for (final SubscriptionType param : SubscriptionType.values()) {
|
||||
if (param.code == code) {
|
||||
return param;
|
||||
}
|
||||
Reference in New Issue
Block a user