Search in sources :

Example 1 with AutomaticPowerOff

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

Aggregations

GBDeviceEventUpdatePreferences (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences)1 AutomaticPowerOff (nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AutomaticPowerOff)1