use of nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AmbientSoundControl in project Gadgetbridge by Freeyourgadget.
the class SonyProtocolImplV1 method handleAmbientSoundControl.
public List<? extends GBDeviceEvent> handleAmbientSoundControl(final byte[] payload) {
if (payload.length != 8) {
LOG.warn("Unexpected payload length {}", payload.length);
return Collections.emptyList();
}
AmbientSoundControl.Mode mode = null;
if (payload[2] == (byte) 0x00) {
mode = AmbientSoundControl.Mode.OFF;
} else if (payload[2] == (byte) 0x01) {
if (payload[3] == 0x00) {
// Only ANC and Ambient Sound supported?
if (payload[4] == (byte) 0x00) {
mode = AmbientSoundControl.Mode.AMBIENT_SOUND;
} else if (payload[4] == (byte) 0x01) {
mode = AmbientSoundControl.Mode.NOISE_CANCELLING;
}
} else if (payload[3] == 0x02) {
// Supports wind noise reduction
if (payload[4] == (byte) 0x00) {
mode = AmbientSoundControl.Mode.AMBIENT_SOUND;
} else if (payload[4] == (byte) 0x01) {
mode = AmbientSoundControl.Mode.WIND_NOISE_REDUCTION;
} else if (payload[4] == (byte) 0x02) {
mode = AmbientSoundControl.Mode.NOISE_CANCELLING;
}
}
}
if (mode == null) {
LOG.warn("Unable to determine ambient sound control mode from {}", GB.hexdump(payload));
return Collections.emptyList();
}
boolean focusOnVoice;
switch(payload[6]) {
case 0x00:
focusOnVoice = false;
break;
case 0x01:
focusOnVoice = true;
break;
default:
LOG.warn("Unknown focus on voice mode {}", String.format("%02x", payload[6]));
return Collections.emptyList();
}
int ambientSound = payload[7];
if (ambientSound < 0 || ambientSound > 20) {
LOG.warn("Ambient sound level {} is out of range", String.format("%02x", payload[7]));
return Collections.emptyList();
}
final AmbientSoundControl ambientSoundControl = new AmbientSoundControl(mode, focusOnVoice, ambientSound);
LOG.warn("Ambient sound control: {}", ambientSoundControl);
final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences().withPreferences(ambientSoundControl.toPreferences());
return Collections.singletonList(eventUpdatePreferences);
}
Aggregations