mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-25 00:30:37 +02:00
Sony WF-1000XM4: Fix audio codec
This commit is contained in:
parent
93c40e6457
commit
041aa4faf2
@ -19,6 +19,10 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.pro
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.MessageType;
|
||||
|
||||
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_REPLY(MessageType.COMMAND_1, 0x23),
|
||||
BATTERY_LEVEL_NOTIFY(MessageType.COMMAND_1, 0x25),
|
||||
|
@ -112,8 +112,13 @@ public class SonyProtocolImplV2 extends SonyProtocolImplV1 {
|
||||
|
||||
@Override
|
||||
public Request getAudioCodec() {
|
||||
LOG.warn("Audio codec not implemented for V2");
|
||||
return null;
|
||||
return new Request(
|
||||
PayloadTypeV2.AUDIO_CODEC_REQUEST.getMessageType(),
|
||||
new byte[]{
|
||||
PayloadTypeV2.AUDIO_CODEC_REQUEST.getCode(),
|
||||
(byte) 0x02
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -346,6 +351,9 @@ public class SonyProtocolImplV2 extends SonyProtocolImplV1 {
|
||||
final PayloadTypeV2 payloadType = PayloadTypeV2.fromCode(messageType, payload[0]);
|
||||
|
||||
switch (payloadType) {
|
||||
case AUDIO_CODEC_REPLY:
|
||||
case AUDIO_CODEC_NOTIFY:
|
||||
return handleAudioCodec(payload);
|
||||
case BATTERY_LEVEL_NOTIFY:
|
||||
case BATTERY_LEVEL_REPLY:
|
||||
return handleBattery(payload);
|
||||
@ -545,8 +553,28 @@ public class SonyProtocolImplV2 extends SonyProtocolImplV1 {
|
||||
|
||||
@Override
|
||||
public List<? extends GBDeviceEvent> handleAudioCodec(final byte[] payload) {
|
||||
LOG.warn("Audio codec not implemented for V2");
|
||||
return Collections.emptyList();
|
||||
if (payload.length != 3) {
|
||||
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
|
||||
|
@ -71,7 +71,8 @@ public class SonyProtocolImplV2Test {
|
||||
|
||||
@Test
|
||||
public void getAudioCodec() {
|
||||
// TODO
|
||||
final Request requestEnabled = protocol.getAudioCodec();
|
||||
assertRequest(requestEnabled, "3e:0c:01:00:00:00:02:12:02:23:3c");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user