Search in sources :

Example 11 with GBDeviceEventUpdatePreferences

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences in project Gadgetbridge by Freeyourgadget.

the class SonyProtocolImplV1 method handlePauseWhenTakenOff.

public List<? extends GBDeviceEvent> handlePauseWhenTakenOff(final byte[] payload) {
    if (payload.length != 4) {
        LOG.warn("Unexpected payload length {}", payload.length);
        return Collections.emptyList();
    }
    boolean enabled;
    switch(payload[3]) {
        case 0x00:
            enabled = false;
            break;
        case 0x01:
            enabled = true;
            break;
        default:
            LOG.warn("Unknown pause when taken off code {}", String.format("%02x", payload[3]));
            return Collections.emptyList();
    }
    LOG.debug("Touch Sensor: {}", enabled);
    final GBDeviceEventUpdatePreferences event = new GBDeviceEventUpdatePreferences().withPreferences(new PauseWhenTakenOff(enabled).toPreferences());
    return Collections.singletonList(event);
}
Also used : GBDeviceEventUpdatePreferences(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences) PauseWhenTakenOff(nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.PauseWhenTakenOff)

Example 12 with GBDeviceEventUpdatePreferences

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences 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);
}
Also used : AmbientSoundControl(nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AmbientSoundControl) GBDeviceEventUpdatePreferences(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences)

Example 13 with GBDeviceEventUpdatePreferences

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences in project Gadgetbridge by Freeyourgadget.

the class SonyProtocolImplV1 method handleEqualizer.

public List<? extends GBDeviceEvent> handleEqualizer(final byte[] payload) {
    if (payload.length != 10) {
        LOG.warn("Unexpected payload length {}", payload.length);
        return Collections.emptyList();
    }
    EqualizerPreset mode = null;
    for (EqualizerPreset value : EqualizerPreset.values()) {
        if (value.getCode() == payload[2]) {
            mode = value;
            break;
        }
    }
    if (mode == null) {
        LOG.warn("Unknown equalizer preset code {}", String.format("%02x", payload[2]));
        return Collections.emptyList();
    }
    LOG.debug("Equalizer Preset: {}", mode);
    final int clearBass = payload[4] - 10;
    final List<Integer> bands = new ArrayList<>(5);
    for (int i = 0; i < 5; i++) {
        bands.add(payload[5 + i] - 10);
    }
    final EqualizerCustomBands customBands = new EqualizerCustomBands(bands, clearBass);
    LOG.info("Equalizer Custom Bands: {}", customBands);
    final GBDeviceEventUpdatePreferences event = new GBDeviceEventUpdatePreferences().withPreferences(mode.toPreferences()).withPreferences(customBands.toPreferences());
    return Collections.singletonList(event);
}
Also used : EqualizerCustomBands(nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.EqualizerCustomBands) EqualizerPreset(nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.EqualizerPreset) ArrayList(java.util.ArrayList) GBDeviceEventUpdatePreferences(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences)

Aggregations

GBDeviceEventUpdatePreferences (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences)13 ArrayList (java.util.ArrayList)1 GBDeviceEventUpdateDeviceInfo (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceInfo)1 AmbientSoundControl (nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AmbientSoundControl)1 AudioUpsampling (nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AudioUpsampling)1 AutomaticPowerOff (nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AutomaticPowerOff)1 ButtonModes (nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.ButtonModes)1 EqualizerCustomBands (nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.EqualizerCustomBands)1 EqualizerPreset (nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.EqualizerPreset)1 PauseWhenTakenOff (nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.PauseWhenTakenOff)1 SoundPosition (nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.SoundPosition)1 SurroundMode (nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.SurroundMode)1 TouchSensor (nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.TouchSensor)1 VoiceNotifications (nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.VoiceNotifications)1 AudioCodec (nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.impl.v1.params.AudioCodec)1 NoiseCancellingOptimizerStatus (nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.impl.v1.params.NoiseCancellingOptimizerStatus)1