1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 02:25:50 +01:00

Sony WF-1000XM4: Fix audio codec

This commit is contained in:
José Rebelo 2022-12-30 18:26:44 +00:00
parent 93c40e6457
commit 041aa4faf2
3 changed files with 38 additions and 5 deletions

View File

@ -19,6 +19,10 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.pro
import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.MessageType; import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.MessageType;
public enum PayloadTypeV2 { public enum PayloadTypeV2 {
AUDIO_CODEC_REQUEST(MessageType.COMMAND_1, 0x12),
AUDIO_CODEC_REPLY(MessageType.COMMAND_1, 0x13),
AUDIO_CODEC_NOTIFY(MessageType.COMMAND_1, 0x15),
BATTERY_LEVEL_REQUEST(MessageType.COMMAND_1, 0x22), BATTERY_LEVEL_REQUEST(MessageType.COMMAND_1, 0x22),
BATTERY_LEVEL_REPLY(MessageType.COMMAND_1, 0x23), BATTERY_LEVEL_REPLY(MessageType.COMMAND_1, 0x23),
BATTERY_LEVEL_NOTIFY(MessageType.COMMAND_1, 0x25), BATTERY_LEVEL_NOTIFY(MessageType.COMMAND_1, 0x25),

View File

@ -112,8 +112,13 @@ public class SonyProtocolImplV2 extends SonyProtocolImplV1 {
@Override @Override
public Request getAudioCodec() { public Request getAudioCodec() {
LOG.warn("Audio codec not implemented for V2"); return new Request(
return null; PayloadTypeV2.AUDIO_CODEC_REQUEST.getMessageType(),
new byte[]{
PayloadTypeV2.AUDIO_CODEC_REQUEST.getCode(),
(byte) 0x02
}
);
} }
@Override @Override
@ -346,6 +351,9 @@ public class SonyProtocolImplV2 extends SonyProtocolImplV1 {
final PayloadTypeV2 payloadType = PayloadTypeV2.fromCode(messageType, payload[0]); final PayloadTypeV2 payloadType = PayloadTypeV2.fromCode(messageType, payload[0]);
switch (payloadType) { switch (payloadType) {
case AUDIO_CODEC_REPLY:
case AUDIO_CODEC_NOTIFY:
return handleAudioCodec(payload);
case BATTERY_LEVEL_NOTIFY: case BATTERY_LEVEL_NOTIFY:
case BATTERY_LEVEL_REPLY: case BATTERY_LEVEL_REPLY:
return handleBattery(payload); return handleBattery(payload);
@ -545,8 +553,28 @@ public class SonyProtocolImplV2 extends SonyProtocolImplV1 {
@Override @Override
public List<? extends GBDeviceEvent> handleAudioCodec(final byte[] payload) { public List<? extends GBDeviceEvent> handleAudioCodec(final byte[] payload) {
LOG.warn("Audio codec not implemented for V2"); if (payload.length != 3) {
return Collections.emptyList(); LOG.warn("Unexpected payload length {}", payload.length);
return Collections.emptyList();
}
if (payload[1] != 0x02) {
LOG.warn("Not audio codec, ignoring");
return Collections.emptyList();
}
final AudioCodec audioCodec = AudioCodec.fromCode(payload[2]);
if (audioCodec == null) {
LOG.warn("Unable to determine audio codec from {}", GB.hexdump(payload));
return Collections.emptyList();
}
final GBDeviceEventUpdateDeviceInfo gbDeviceEventUpdateDeviceInfo = new GBDeviceEventUpdateDeviceInfo("AUDIO_CODEC: ", audioCodec.name());
final GBDeviceEventUpdatePreferences gbDeviceEventUpdatePreferences = new GBDeviceEventUpdatePreferences()
.withPreference(DeviceSettingsPreferenceConst.PREF_SONY_AUDIO_CODEC, audioCodec.name().toLowerCase(Locale.getDefault()));
return Arrays.asList(gbDeviceEventUpdateDeviceInfo, gbDeviceEventUpdatePreferences);
} }
@Override @Override

View File

@ -71,7 +71,8 @@ public class SonyProtocolImplV2Test {
@Test @Test
public void getAudioCodec() { public void getAudioCodec() {
// TODO final Request requestEnabled = protocol.getAudioCodec();
assertRequest(requestEnabled, "3e:0c:01:00:00:00:02:12:02:23:3c");
} }
@Test @Test