Search in sources :

Example 1 with SonyHeadphonesEnqueueRequestEvent

use of nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.deviceevents.SonyHeadphonesEnqueueRequestEvent 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 2 with SonyHeadphonesEnqueueRequestEvent

use of nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.deviceevents.SonyHeadphonesEnqueueRequestEvent in project Gadgetbridge by Freeyourgadget.

the class SonyHeadphonesSupport method evaluateGBDeviceEvent.

@Override
public void evaluateGBDeviceEvent(GBDeviceEvent deviceEvent) {
    final SonyHeadphonesProtocol sonyProtocol = (SonyHeadphonesProtocol) getDeviceProtocol();
    if (deviceEvent instanceof SonyHeadphonesEnqueueRequestEvent) {
        final SonyHeadphonesEnqueueRequestEvent enqueueRequestEvent = (SonyHeadphonesEnqueueRequestEvent) deviceEvent;
        sonyProtocol.enqueueRequests(enqueueRequestEvent.getRequests());
        if (sonyProtocol.getPendingAcks() == 0) {
            // There are no pending acks, send one request from the queue
            // TODO: A more elegant way of scheduling these?
            SonyHeadphonesIoThread deviceIOThread = getDeviceIOThread();
            deviceIOThread.write(sonyProtocol.getFromQueue());
        }
    }
    super.evaluateGBDeviceEvent(deviceEvent);
}
Also used : SonyHeadphonesEnqueueRequestEvent(nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.deviceevents.SonyHeadphonesEnqueueRequestEvent)

Aggregations

SonyHeadphonesEnqueueRequestEvent (nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.deviceevents.SonyHeadphonesEnqueueRequestEvent)2 ArrayList (java.util.ArrayList)1 DeviceType (nodomain.freeyourgadget.gadgetbridge.model.DeviceType)1 Request (nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request)1