Search in sources :

Example 1 with ButtonModes

use of nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.ButtonModes 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)1 ButtonModes (nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.ButtonModes)1