use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences in project Gadgetbridge by Freeyourgadget.
the class SonyProtocolImplV1 method handlePauseWhenTakenOff.
public List<? extends GBDeviceEvent> handlePauseWhenTakenOff(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 pause when taken off code {}", String.format("%02x", payload[3]));
return Collections.emptyList();
}
LOG.debug("Touch Sensor: {}", enabled);
final GBDeviceEventUpdatePreferences event = new GBDeviceEventUpdatePreferences().withPreferences(new PauseWhenTakenOff(enabled).toPreferences());
return Collections.singletonList(event);
}
use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences in project Gadgetbridge by Freeyourgadget.
the class SonyProtocolImplV1 method handleAmbientSoundControl.
public List<? extends GBDeviceEvent> handleAmbientSoundControl(final byte[] payload) {
if (payload.length != 8) {
LOG.warn("Unexpected payload length {}", payload.length);
return Collections.emptyList();
}
AmbientSoundControl.Mode mode = null;
if (payload[2] == (byte) 0x00) {
mode = AmbientSoundControl.Mode.OFF;
} else if (payload[2] == (byte) 0x01) {
if (payload[3] == 0x00) {
// Only ANC and Ambient Sound supported?
if (payload[4] == (byte) 0x00) {
mode = AmbientSoundControl.Mode.AMBIENT_SOUND;
} else if (payload[4] == (byte) 0x01) {
mode = AmbientSoundControl.Mode.NOISE_CANCELLING;
}
} else if (payload[3] == 0x02) {
// Supports wind noise reduction
if (payload[4] == (byte) 0x00) {
mode = AmbientSoundControl.Mode.AMBIENT_SOUND;
} else if (payload[4] == (byte) 0x01) {
mode = AmbientSoundControl.Mode.WIND_NOISE_REDUCTION;
} else if (payload[4] == (byte) 0x02) {
mode = AmbientSoundControl.Mode.NOISE_CANCELLING;
}
}
}
if (mode == null) {
LOG.warn("Unable to determine ambient sound control mode from {}", GB.hexdump(payload));
return Collections.emptyList();
}
boolean focusOnVoice;
switch(payload[6]) {
case 0x00:
focusOnVoice = false;
break;
case 0x01:
focusOnVoice = true;
break;
default:
LOG.warn("Unknown focus on voice mode {}", String.format("%02x", payload[6]));
return Collections.emptyList();
}
int ambientSound = payload[7];
if (ambientSound < 0 || ambientSound > 20) {
LOG.warn("Ambient sound level {} is out of range", String.format("%02x", payload[7]));
return Collections.emptyList();
}
final AmbientSoundControl ambientSoundControl = new AmbientSoundControl(mode, focusOnVoice, ambientSound);
LOG.warn("Ambient sound control: {}", ambientSoundControl);
final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences().withPreferences(ambientSoundControl.toPreferences());
return Collections.singletonList(eventUpdatePreferences);
}
use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences in project Gadgetbridge by Freeyourgadget.
the class SonyProtocolImplV1 method handleEqualizer.
public List<? extends GBDeviceEvent> handleEqualizer(final byte[] payload) {
if (payload.length != 10) {
LOG.warn("Unexpected payload length {}", payload.length);
return Collections.emptyList();
}
EqualizerPreset mode = null;
for (EqualizerPreset value : EqualizerPreset.values()) {
if (value.getCode() == payload[2]) {
mode = value;
break;
}
}
if (mode == null) {
LOG.warn("Unknown equalizer preset code {}", String.format("%02x", payload[2]));
return Collections.emptyList();
}
LOG.debug("Equalizer Preset: {}", mode);
final int clearBass = payload[4] - 10;
final List<Integer> bands = new ArrayList<>(5);
for (int i = 0; i < 5; i++) {
bands.add(payload[5 + i] - 10);
}
final EqualizerCustomBands customBands = new EqualizerCustomBands(bands, clearBass);
LOG.info("Equalizer Custom Bands: {}", customBands);
final GBDeviceEventUpdatePreferences event = new GBDeviceEventUpdatePreferences().withPreferences(mode.toPreferences()).withPreferences(customBands.toPreferences());
return Collections.singletonList(event);
}
Aggregations