Search in sources :

Example 1 with Request

use of nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request in project Gadgetbridge by Freeyourgadget.

the class SonyProtocolImplV1 method setAmbientSoundControl.

@Override
public Request setAmbientSoundControl(final AmbientSoundControl ambientSoundControl) {
    final ByteBuffer buf = ByteBuffer.allocate(8);
    buf.put(PayloadType.AMBIENT_SOUND_CONTROL_SET.getCode());
    buf.put((byte) 0x02);
    if (AmbientSoundControl.Mode.OFF.equals(ambientSoundControl.getMode())) {
        buf.put((byte) 0x00);
    } else {
        buf.put((byte) 0x11);
    }
    if (supportsWindNoiseCancelling()) {
        buf.put((byte) 0x02);
        switch(ambientSoundControl.getMode()) {
            case NOISE_CANCELLING:
                buf.put((byte) 2);
                break;
            case WIND_NOISE_REDUCTION:
                buf.put((byte) 1);
                break;
            case OFF:
            case AMBIENT_SOUND:
            default:
                buf.put((byte) 0);
                break;
        }
    } else {
        buf.put((byte) 0x00);
        if (AmbientSoundControl.Mode.NOISE_CANCELLING.equals(ambientSoundControl.getMode())) {
            buf.put((byte) 1);
        } else {
            buf.put((byte) 0);
        }
    }
    // ?
    buf.put((byte) 0x01);
    buf.put((byte) (ambientSoundControl.isFocusOnVoice() ? 0x01 : 0x00));
    switch(ambientSoundControl.getMode()) {
        case OFF:
        case AMBIENT_SOUND:
            buf.put((byte) (ambientSoundControl.getAmbientSound()));
            break;
        case WIND_NOISE_REDUCTION:
        case NOISE_CANCELLING:
            buf.put((byte) 0);
            break;
    }
    return new Request(PayloadType.AMBIENT_SOUND_CONTROL_SET.getMessageType(), buf.array());
}
Also used : Request(nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request) ByteBuffer(java.nio.ByteBuffer)

Example 2 with Request

use of nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request in project Gadgetbridge by Freeyourgadget.

the class SonyHeadphonesProtocol method encodeSendConfiguration.

@Override
public byte[] encodeSendConfiguration(String config) {
    if (protocolImpl == null) {
        LOG.error("No protocol implementation, ignoring config {}", config);
        return super.encodeSendConfiguration(config);
    }
    final SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress());
    final Request configRequest;
    switch(config) {
        case DeviceSettingsPreferenceConst.PREF_SONY_AMBIENT_SOUND_CONTROL:
        case DeviceSettingsPreferenceConst.PREF_SONY_FOCUS_VOICE:
        case DeviceSettingsPreferenceConst.PREF_SONY_AMBIENT_SOUND_LEVEL:
            configRequest = protocolImpl.setAmbientSoundControl(AmbientSoundControl.fromPreferences(prefs));
            break;
        case DeviceSettingsPreferenceConst.PREF_SONY_NOISE_OPTIMIZER_START:
            configRequest = protocolImpl.startNoiseCancellingOptimizer(true);
            break;
        case DeviceSettingsPreferenceConst.PREF_SONY_NOISE_OPTIMIZER_CANCEL:
            configRequest = protocolImpl.startNoiseCancellingOptimizer(false);
            break;
        case DeviceSettingsPreferenceConst.PREF_SONY_SOUND_POSITION:
            configRequest = protocolImpl.setSoundPosition(SoundPosition.fromPreferences(prefs));
            break;
        case DeviceSettingsPreferenceConst.PREF_SONY_SURROUND_MODE:
            configRequest = protocolImpl.setSurroundMode(SurroundMode.fromPreferences(prefs));
            break;
        case DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_MODE:
            configRequest = protocolImpl.setEqualizerPreset(EqualizerPreset.fromPreferences(prefs));
            break;
        case DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_400:
        case DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_1000:
        case DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_2500:
        case DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_6300:
        case DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_16000:
        case DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BASS:
            configRequest = protocolImpl.setEqualizerCustomBands(EqualizerCustomBands.fromPreferences(prefs));
            break;
        case DeviceSettingsPreferenceConst.PREF_SONY_AUDIO_UPSAMPLING:
            configRequest = protocolImpl.setAudioUpsampling(AudioUpsampling.fromPreferences(prefs));
            break;
        case DeviceSettingsPreferenceConst.PREF_SONY_TOUCH_SENSOR:
            configRequest = protocolImpl.setTouchSensor(TouchSensor.fromPreferences(prefs));
            break;
        case DeviceSettingsPreferenceConst.PREF_SONY_AUTOMATIC_POWER_OFF:
            configRequest = protocolImpl.setAutomaticPowerOff(AutomaticPowerOff.fromPreferences(prefs));
            break;
        case DeviceSettingsPreferenceConst.PREF_SONY_BUTTON_MODE_LEFT:
        case DeviceSettingsPreferenceConst.PREF_SONY_BUTTON_MODE_RIGHT:
            configRequest = protocolImpl.setButtonModes(ButtonModes.fromPreferences(prefs));
            break;
        case DeviceSettingsPreferenceConst.PREF_SONY_PAUSE_WHEN_TAKEN_OFF:
            configRequest = protocolImpl.setPauseWhenTakenOff(PauseWhenTakenOff.fromPreferences(prefs));
            break;
        case DeviceSettingsPreferenceConst.PREF_SONY_NOTIFICATION_VOICE_GUIDE:
            configRequest = protocolImpl.setVoiceNotifications(VoiceNotifications.fromPreferences(prefs));
            break;
        case DeviceSettingsPreferenceConst.PREF_SONY_CONNECT_TWO_DEVICES:
            LOG.warn("Connection to two devices not implemented ('{}')", config);
            return super.encodeSendConfiguration(config);
        case DeviceSettingsPreferenceConst.PREF_SONY_SPEAK_TO_CHAT:
        case DeviceSettingsPreferenceConst.PREF_SONY_SPEAK_TO_CHAT_SENSITIVITY:
        case DeviceSettingsPreferenceConst.PREF_SONY_SPEAK_TO_CHAT_FOCUS_ON_VOICE:
        case DeviceSettingsPreferenceConst.PREF_SONY_SPEAK_TO_CHAT_TIMEOUT:
            LOG.warn("Speak-to-chat is not implemented ('{}')", config);
            return super.encodeSendConfiguration(config);
        default:
            LOG.warn("Unknown config '{}'", config);
            return super.encodeSendConfiguration(config);
    }
    pendingAcks++;
    return configRequest.encode(sequenceNumber);
}
Also used : SharedPreferences(android.content.SharedPreferences) Request(nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request)

Example 3 with Request

use of nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request in project Gadgetbridge by Freeyourgadget.

the class SonyHeadphonesProtocol method handleAck.

private GBDeviceEvent handleAck() {
    pendingAcks--;
    if (!requestQueue.isEmpty()) {
        LOG.debug("Outstanding requests in queue: {}", requestQueue.size());
        final Request request = requestQueue.remove();
        return new GBDeviceEventSendBytes(request.encode(sequenceNumber));
    }
    if (GBDevice.State.INITIALIZING.equals(getDevice().getState())) {
        return new GBDeviceEventUpdateDeviceState(GBDevice.State.INITIALIZED);
    }
    return null;
}
Also used : Request(nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request) GBDeviceEventUpdateDeviceState(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceState) GBDeviceEventSendBytes(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes)

Example 4 with Request

use of nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request in project Gadgetbridge by Freeyourgadget.

the class SonyProtocolImplV1 method handleInitResponse.

public List<? extends GBDeviceEvent> handleInitResponse(final byte[] payload) {
    if (payload.length != 4) {
        LOG.warn("Unexpected payload length {}", payload.length);
        return Collections.emptyList();
    }
    final DeviceType deviceType = getDevice().getType();
    final List<Request> capabilityRequests = new ArrayList<>();
    // TODO: We should be determine which of these we need from the device...
    switch(deviceType) {
        case SONY_WH_1000XM3:
            capabilityRequests.add(getFirmwareVersion());
            capabilityRequests.add(getBattery(BatteryType.SINGLE));
            capabilityRequests.add(getAudioCodec());
            capabilityRequests.add(getAmbientSoundControl());
            capabilityRequests.add(getNoiseCancellingOptimizerState());
            capabilityRequests.add(getAudioUpsampling());
            capabilityRequests.add(getVoiceNotifications());
            capabilityRequests.add(getAutomaticPowerOff());
            capabilityRequests.add(getTouchSensor());
            capabilityRequests.add(getSurroundMode());
            capabilityRequests.add(getSoundPosition());
            capabilityRequests.add(getEqualizer());
            break;
        case SONY_WH_1000XM4:
            capabilityRequests.add(getFirmwareVersion());
            capabilityRequests.add(getBattery(BatteryType.SINGLE));
            capabilityRequests.add(getAudioCodec());
            capabilityRequests.add(getAmbientSoundControl());
            capabilityRequests.add(getNoiseCancellingOptimizerState());
            capabilityRequests.add(getAudioUpsampling());
            capabilityRequests.add(getVoiceNotifications());
            capabilityRequests.add(getAutomaticPowerOff());
            capabilityRequests.add(getTouchSensor());
            capabilityRequests.add(getEqualizer());
            capabilityRequests.add(getPauseWhenTakenOff());
            break;
        case SONY_WF_SP800N:
            capabilityRequests.add(getFirmwareVersion());
            capabilityRequests.add(getBattery(BatteryType.DUAL));
            capabilityRequests.add(getBattery(BatteryType.CASE));
            capabilityRequests.add(getAudioCodec());
            capabilityRequests.add(getAmbientSoundControl());
            capabilityRequests.add(getVoiceNotifications());
            capabilityRequests.add(getAutomaticPowerOff());
            capabilityRequests.add(getEqualizer());
            capabilityRequests.add(getButtonModes());
            capabilityRequests.add(getPauseWhenTakenOff());
            break;
        default:
            LOG.error("Unsupported Sony device type '{}' with key '{}'", deviceType, deviceType.getKey());
            return null;
    }
    return Collections.singletonList(new SonyHeadphonesEnqueueRequestEvent(capabilityRequests));
}
Also used : DeviceType(nodomain.freeyourgadget.gadgetbridge.model.DeviceType) SonyHeadphonesEnqueueRequestEvent(nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.deviceevents.SonyHeadphonesEnqueueRequestEvent) Request(nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request) ArrayList(java.util.ArrayList)

Example 5 with Request

use of nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request in project Gadgetbridge by Freeyourgadget.

the class SonyProtocolImplV1 method setEqualizerCustomBands.

@Override
public Request setEqualizerCustomBands(final EqualizerCustomBands config) {
    final ByteBuffer buf = ByteBuffer.allocate(10);
    buf.put(PayloadType.EQUALIZER_SET.getCode());
    buf.put((byte) 0x01);
    buf.put((byte) 0xff);
    buf.put((byte) 0x06);
    buf.put((byte) (config.getBass() + 10));
    for (final Integer band : config.getBands()) {
        buf.put((byte) (band + 10));
    }
    return new Request(PayloadType.EQUALIZER_SET.getMessageType(), buf.array());
}
Also used : Request(nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Request (nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request)5 ByteBuffer (java.nio.ByteBuffer)2 SharedPreferences (android.content.SharedPreferences)1 ArrayList (java.util.ArrayList)1 GBDeviceEventSendBytes (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes)1 GBDeviceEventUpdateDeviceState (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceState)1 DeviceType (nodomain.freeyourgadget.gadgetbridge.model.DeviceType)1 SonyHeadphonesEnqueueRequestEvent (nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.deviceevents.SonyHeadphonesEnqueueRequestEvent)1