use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences in project Gadgetbridge by Freeyourgadget.
the class SonyProtocolImplV1 method handleAudioCodec.
public List<? extends GBDeviceEvent> handleAudioCodec(final byte[] payload) {
if (payload.length != 3) {
LOG.warn("Unexpected payload length {}", payload.length);
return Collections.emptyList();
}
final AudioCodec audioCodec = AudioCodec.fromCode(payload[2]);
if (audioCodec == null) {
LOG.warn("Unable to determine audio codec from {}", GB.hexdump(payload));
return Collections.emptyList();
}
final GBDeviceEventUpdateDeviceInfo gbDeviceEventUpdateDeviceInfo = new GBDeviceEventUpdateDeviceInfo("AUDIO_CODEC: ", audioCodec.name());
final GBDeviceEventUpdatePreferences gbDeviceEventUpdatePreferences = new GBDeviceEventUpdatePreferences().withPreference(DeviceSettingsPreferenceConst.PREF_SONY_AUDIO_CODEC, audioCodec.name().toLowerCase(Locale.getDefault()));
return Arrays.asList(gbDeviceEventUpdateDeviceInfo, gbDeviceEventUpdatePreferences);
}
use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences in project Gadgetbridge by Freeyourgadget.
the class SonyProtocolImplV1 method handleAudioUpsampling.
public List<? extends GBDeviceEvent> handleAudioUpsampling(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 audio upsampling code {}", String.format("%02x", payload[3]));
return Collections.emptyList();
}
LOG.debug("Audio Upsampling: {}", enabled);
final GBDeviceEventUpdatePreferences event = new GBDeviceEventUpdatePreferences().withPreferences(new AudioUpsampling(enabled).toPreferences());
return Collections.singletonList(event);
}
use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences 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);
}
use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences in project Gadgetbridge by Freeyourgadget.
the class SonyProtocolImplV1 method handleTouchSensor.
public List<? extends GBDeviceEvent> handleTouchSensor(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 touch sensor code {}", String.format("%02x", payload[3]));
return Collections.emptyList();
}
LOG.debug("Touch Sensor: {}", enabled);
final GBDeviceEventUpdatePreferences event = new GBDeviceEventUpdatePreferences().withPreferences(new TouchSensor(enabled).toPreferences());
return Collections.singletonList(event);
}
use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences 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);
}
Aggregations