Search in sources :

Example 1 with GBDeviceEventUpdatePreferences

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

the class SonyProtocolImplV1 method handleAudioCodec.

public List<? extends GBDeviceEvent> handleAudioCodec(final byte[] payload) {
    if (payload.length != 3) {
        LOG.warn("Unexpected payload length {}", payload.length);
        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);
}
Also used : GBDeviceEventUpdatePreferences(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences) AudioCodec(nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.impl.v1.params.AudioCodec) GBDeviceEventUpdateDeviceInfo(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceInfo)

Example 2 with GBDeviceEventUpdatePreferences

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

the class SonyProtocolImplV1 method handleAudioUpsampling.

public List<? extends GBDeviceEvent> handleAudioUpsampling(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 audio upsampling code {}", String.format("%02x", payload[3]));
            return Collections.emptyList();
    }
    LOG.debug("Audio Upsampling: {}", enabled);
    final GBDeviceEventUpdatePreferences event = new GBDeviceEventUpdatePreferences().withPreferences(new AudioUpsampling(enabled).toPreferences());
    return Collections.singletonList(event);
}
Also used : AudioUpsampling(nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AudioUpsampling) GBDeviceEventUpdatePreferences(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences)

Example 3 with GBDeviceEventUpdatePreferences

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

the class SonyProtocolImplV1 method handleAutomaticPowerOff.

public List<? extends GBDeviceEvent> handleAutomaticPowerOff(final byte[] payload) {
    if (payload.length != 5) {
        LOG.warn("Unexpected payload length {}", payload.length);
        return Collections.emptyList();
    }
    if (payload[1] != 0x04) {
        // TODO: Handle these (Button Mode uses the same payload type?)
        LOG.warn("Not automatic power off config, ignoring");
        return Collections.emptyList();
    }
    AutomaticPowerOff mode = null;
    for (AutomaticPowerOff value : AutomaticPowerOff.values()) {
        if (value.getCode()[0] == payload[3] && value.getCode()[1] == payload[4]) {
            mode = value;
            break;
        }
    }
    if (mode == null) {
        LOG.warn("Unknown automatic power off codes {}", String.format("%02x %02x", payload[3], payload[4]));
        return Collections.emptyList();
    }
    LOG.debug("Automatic Power Off: {}", mode);
    final GBDeviceEventUpdatePreferences event = new GBDeviceEventUpdatePreferences().withPreferences(mode.toPreferences());
    return Collections.singletonList(event);
}
Also used : GBDeviceEventUpdatePreferences(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences) AutomaticPowerOff(nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AutomaticPowerOff)

Example 4 with GBDeviceEventUpdatePreferences

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

the class SonyProtocolImplV1 method handleTouchSensor.

public List<? extends GBDeviceEvent> handleTouchSensor(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 touch sensor code {}", String.format("%02x", payload[3]));
            return Collections.emptyList();
    }
    LOG.debug("Touch Sensor: {}", enabled);
    final GBDeviceEventUpdatePreferences event = new GBDeviceEventUpdatePreferences().withPreferences(new TouchSensor(enabled).toPreferences());
    return Collections.singletonList(event);
}
Also used : TouchSensor(nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.TouchSensor) GBDeviceEventUpdatePreferences(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences)

Example 5 with GBDeviceEventUpdatePreferences

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

the class SonyProtocolImplV1 method handleButtonModes.

public List<? extends GBDeviceEvent> handleButtonModes(final byte[] payload) {
    if (payload.length != 5) {
        LOG.warn("Unexpected payload length {}", payload.length);
        return Collections.emptyList();
    }
    ButtonModes.Mode modeLeft = null;
    for (ButtonModes.Mode value : ButtonModes.Mode.values()) {
        if (value.getCode() == payload[3]) {
            modeLeft = value;
            break;
        }
    }
    ButtonModes.Mode modeRight = null;
    for (ButtonModes.Mode value : ButtonModes.Mode.values()) {
        if (value.getCode() == payload[4]) {
            modeRight = value;
            break;
        }
    }
    if (modeLeft == null || modeRight == null) {
        LOG.warn("Unknown button mode codes {}", String.format("%02x %02x", payload[3], payload[4]));
        return Collections.emptyList();
    }
    LOG.debug("Button Modes: L: {}, R: {}", modeLeft, modeRight);
    final GBDeviceEventUpdatePreferences event = new GBDeviceEventUpdatePreferences().withPreferences(new ButtonModes(modeLeft, modeRight).toPreferences());
    return Collections.singletonList(event);
}
Also used : ButtonModes(nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.ButtonModes) 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