diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java
index 72eb79718..cda7bf042 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java
@@ -112,34 +112,20 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_GALAXY_BUDS_LIVE_ANC = "pref_galaxy_buds_live_anc";
public static final String PREF_GALAXY_BUDS_PRESSURE_RELIEF = "pref_galaxy_buds_live_pressure_relief";
+ public static final String PREF_SONY_AUDIO_CODEC = "pref_sony_audio_codec";
public static final String PREF_SONY_AMBIENT_SOUND_CONTROL = "pref_sony_ambient_sound_control";
public static final String PREF_SONY_FOCUS_VOICE = "pref_sony_focus_voice";
public static final String PREF_SONY_AMBIENT_SOUND_LEVEL = "pref_sony_ambient_sound_level";
public static final String PREF_SONY_SOUND_POSITION = "pref_sony_sound_position";
public static final String PREF_SONY_SURROUND_MODE = "pref_sony_surround_mode";
public static final String PREF_SONY_EQUALIZER_MODE = "pref_sony_equalizer_mode";
- public static final String PREF_SONY_DSEE_HX = "pref_sony_dsee_hx";
- public static final String PREF_SONY_EQUALIZER_PRESET_MANUAL = "pref_sony_equalizer_preset_manual";
- public static final String PREF_SONY_EQUALIZER_PRESET_CUSTOM_1 = "pref_sony_equalizer_preset_custom_1";
- public static final String PREF_SONY_EQUALIZER_PRESET_CUSTOM_2 = "pref_sony_equalizer_preset_custom_2";
- public static final String PREF_SONY_EQUALIZER_MANUAL_BAND_400 = "pref_sony_equalizer_manual_band_400";
- public static final String PREF_SONY_EQUALIZER_MANUAL_BAND_1000 = "pref_sony_equalizer_manual_band_1000";
- public static final String PREF_SONY_EQUALIZER_MANUAL_BAND_2500 = "pref_sony_equalizer_manual_band_2500";
- public static final String PREF_SONY_EQUALIZER_MANUAL_BAND_6300 = "pref_sony_equalizer_manual_band_6300";
- public static final String PREF_SONY_EQUALIZER_MANUAL_BAND_16000 = "pref_sony_equalizer_manual_band_16000";
- public static final String PREF_SONY_EQUALIZER_MANUAL_CLEAR_BASS = "pref_sony_equalizer_manual_clear_bass";
- public static final String PREF_SONY_EQUALIZER_CUSTOM_1_BAND_400 = "pref_sony_equalizer_custom_1_band_400";
- public static final String PREF_SONY_EQUALIZER_CUSTOM_1_BAND_1000 = "pref_sony_equalizer_custom_1_band_1000";
- public static final String PREF_SONY_EQUALIZER_CUSTOM_1_BAND_2500 = "pref_sony_equalizer_custom_1_band_2500";
- public static final String PREF_SONY_EQUALIZER_CUSTOM_1_BAND_6300 = "pref_sony_equalizer_custom_1_band_6300";
- public static final String PREF_SONY_EQUALIZER_CUSTOM_1_BAND_16000 = "pref_sony_equalizer_custom_1_band_16000";
- public static final String PREF_SONY_EQUALIZER_CUSTOM_1_CLEAR_BASS = "pref_sony_equalizer_custom_1_clear_bass";
- public static final String PREF_SONY_EQUALIZER_CUSTOM_2_BAND_400 = "pref_sony_equalizer_custom_2_band_400";
- public static final String PREF_SONY_EQUALIZER_CUSTOM_2_BAND_1000 = "pref_sony_equalizer_custom_2_band_1000";
- public static final String PREF_SONY_EQUALIZER_CUSTOM_2_BAND_2500 = "pref_sony_equalizer_custom_2_band_2500";
- public static final String PREF_SONY_EQUALIZER_CUSTOM_2_BAND_6300 = "pref_sony_equalizer_custom_2_band_6300";
- public static final String PREF_SONY_EQUALIZER_CUSTOM_2_BAND_16000 = "pref_sony_equalizer_custom_2_band_16000";
- public static final String PREF_SONY_EQUALIZER_CUSTOM_2_CLEAR_BASS = "pref_sony_equalizer_custom_2_clear_bass";
+ public static final String PREF_SONY_AUDIO_UPSAMPLING = "pref_sony_audio_upsampling";
+ public static final String PREF_SONY_EQUALIZER_BAND_400 = "pref_sony_equalizer_band_400";
+ public static final String PREF_SONY_EQUALIZER_BAND_1000 = "pref_sony_equalizer_band_1000";
+ public static final String PREF_SONY_EQUALIZER_BAND_2500 = "pref_sony_equalizer_band_2500";
+ public static final String PREF_SONY_EQUALIZER_BAND_6300 = "pref_sony_equalizer_band_6300";
+ public static final String PREF_SONY_EQUALIZER_BAND_16000 = "pref_sony_equalizer_band_16000";
+ public static final String PREF_SONY_EQUALIZER_BASS = "pref_sony_equalizer_bass";
public static final String PREF_SONY_TOUCH_SENSOR = "pref_sony_touch_sensor";
public static final String PREF_SONY_AUTOMATIC_POWER_OFF = "pref_sony_automatic_power_off";
public static final String PREF_SONY_NOTIFICATION_VOICE_GUIDE = "pref_sony_notification_voice_guide";
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java
index 23bfed87a..63aab472b 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java
@@ -51,7 +51,6 @@ import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
import nodomain.freeyourgadget.gadgetbridge.devices.makibeshr3.MakibesHR3Constants;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
-import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.XTimePreference;
@@ -124,7 +123,6 @@ import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.Dev
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONYSWR12_STAMINA;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SOUNDS;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_TIMEFORMAT;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_TRANSLITERATION_ENABLED;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_VIBRATION_STRENGH_PERCENTAGE;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_WEARLOCATION;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_VIBRATION_ENABLE;
@@ -136,25 +134,13 @@ import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.Dev
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_SOUND_POSITION;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_SURROUND_MODE;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_MODE;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_MANUAL_BAND_400;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_MANUAL_BAND_1000;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_MANUAL_BAND_2500;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_MANUAL_BAND_6300;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_MANUAL_BAND_16000;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_MANUAL_CLEAR_BASS;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_CUSTOM_1_BAND_400;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_CUSTOM_1_BAND_1000;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_CUSTOM_1_BAND_2500;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_CUSTOM_1_BAND_6300;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_CUSTOM_1_BAND_16000;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_CUSTOM_1_CLEAR_BASS;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_CUSTOM_2_BAND_400;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_CUSTOM_2_BAND_1000;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_CUSTOM_2_BAND_2500;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_CUSTOM_2_BAND_6300;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_CUSTOM_2_BAND_16000;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_CUSTOM_2_CLEAR_BASS;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_DSEE_HX;
+import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_400;
+import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_1000;
+import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_2500;
+import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_6300;
+import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_16000;
+import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BASS;
+import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_AUDIO_UPSAMPLING;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_TOUCH_SENSOR;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_AUTOMATIC_POWER_OFF;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_NOTIFICATION_VOICE_GUIDE;
@@ -566,25 +552,13 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
addPreferenceHandlerFor(PREF_SONY_SOUND_POSITION);
addPreferenceHandlerFor(PREF_SONY_SURROUND_MODE);
addPreferenceHandlerFor(PREF_SONY_EQUALIZER_MODE);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_MANUAL_BAND_400);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_MANUAL_BAND_1000);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_MANUAL_BAND_2500);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_MANUAL_BAND_6300);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_MANUAL_BAND_16000);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_MANUAL_CLEAR_BASS);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_CUSTOM_1_BAND_400);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_CUSTOM_1_BAND_1000);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_CUSTOM_1_BAND_2500);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_CUSTOM_1_BAND_6300);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_CUSTOM_1_BAND_16000);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_CUSTOM_1_CLEAR_BASS);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_CUSTOM_2_BAND_400);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_CUSTOM_2_BAND_1000);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_CUSTOM_2_BAND_2500);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_CUSTOM_2_BAND_6300);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_CUSTOM_2_BAND_16000);
- addPreferenceHandlerFor(PREF_SONY_EQUALIZER_CUSTOM_2_CLEAR_BASS);
- addPreferenceHandlerFor(PREF_SONY_DSEE_HX);
+ addPreferenceHandlerFor(PREF_SONY_EQUALIZER_BAND_400);
+ addPreferenceHandlerFor(PREF_SONY_EQUALIZER_BAND_1000);
+ addPreferenceHandlerFor(PREF_SONY_EQUALIZER_BAND_2500);
+ addPreferenceHandlerFor(PREF_SONY_EQUALIZER_BAND_6300);
+ addPreferenceHandlerFor(PREF_SONY_EQUALIZER_BAND_16000);
+ addPreferenceHandlerFor(PREF_SONY_EQUALIZER_BASS);
+ addPreferenceHandlerFor(PREF_SONY_AUDIO_UPSAMPLING);
addPreferenceHandlerFor(PREF_SONY_TOUCH_SENSOR);
addPreferenceHandlerFor(PREF_SONY_AUTOMATIC_POWER_OFF);
addPreferenceHandlerFor(PREF_SONY_NOTIFICATION_VOICE_GUIDE);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/AmbientSoundControl.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/AmbientSoundControl.java
deleted file mode 100644
index 915fe5764..000000000
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/AmbientSoundControl.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Copyright (C) 2021 José Rebelo
-
- This file is part of Gadgetbridge.
-
- Gadgetbridge is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- Gadgetbridge is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see . */
-package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones;
-
-public enum AmbientSoundControl {
- OFF,
- NOISE_CANCELLING,
- WIND_NOISE_REDUCTION,
- AMBIENT_SOUND
-}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/EqualizerCustomBands.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/EqualizerCustomBands.java
deleted file mode 100644
index d739cd2f8..000000000
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/EqualizerCustomBands.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/* Copyright (C) 2021 José Rebelo
-
- This file is part of Gadgetbridge.
-
- Gadgetbridge is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- Gadgetbridge is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see . */
-package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones;
-
-import java.util.List;
-
-public class EqualizerCustomBands {
- private List bands;
- private int clearBass;
-
- public EqualizerCustomBands(List bands, int clearBass) {
- if (bands.size() != 5) {
- throw new IllegalArgumentException("Equalizer needs exactly 5 bands");
- }
-
- for (Integer band : bands) {
- if (band < -10 || band > 10) {
- throw new IllegalArgumentException(String.format("Bands should be between -10 and 10, got %d", band));
- }
- }
-
- if (clearBass < -10 || clearBass > 10) {
- throw new IllegalArgumentException(String.format("Clear Bass value shoulud be between -10 and 10, got %d", clearBass));
- }
-
- this.bands = bands;
- this.clearBass = clearBass;
- }
-
- public List getBands() {
- return bands;
- }
-
- public int getClearBass() {
- return clearBass;
- }
-}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SonyHeadphonesCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SonyHeadphonesCoordinator.java
index 90f5f9a85..1834e462e 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SonyHeadphonesCoordinator.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SonyHeadphonesCoordinator.java
@@ -41,7 +41,7 @@ public abstract class SonyHeadphonesCoordinator extends AbstractDeviceCoordinato
@Override
public DeviceSpecificSettingsCustomizer getDeviceSpecificSettingsCustomizer(final GBDevice device) {
- return new SonySettingsCustomizer();
+ return new SonyHeadphonesSettingsCustomizer();
}
@Override
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SonyHeadphonesSettingsCustomizer.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SonyHeadphonesSettingsCustomizer.java
new file mode 100644
index 000000000..7cb85c9af
--- /dev/null
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SonyHeadphonesSettingsCustomizer.java
@@ -0,0 +1,56 @@
+/* Copyright (C) 2021 José Rebelo
+
+ This file is part of Gadgetbridge.
+
+ Gadgetbridge is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Gadgetbridge is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see . */
+package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones;
+
+import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_AMBIENT_SOUND_CONTROL;
+import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_AMBIENT_SOUND_LEVEL;
+import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_FOCUS_VOICE;
+
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+
+import java.util.Locale;
+
+import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer;
+import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsHandler;
+import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AmbientSoundControl;
+
+public class SonyHeadphonesSettingsCustomizer implements DeviceSpecificSettingsCustomizer {
+ @Override
+ public void customizeSettings(final DeviceSpecificSettingsHandler handler) {
+ // Only enable the focus on voice check and voice level slider if the ambient sound control mode is ambient sound
+
+ final ListPreference ambientSoundControl = handler.findPreference(PREF_SONY_AMBIENT_SOUND_CONTROL);
+ if (ambientSoundControl != null) {
+ final Preference focusOnVoice = handler.findPreference(PREF_SONY_FOCUS_VOICE);
+ final Preference ambientSoundLevel = handler.findPreference(PREF_SONY_AMBIENT_SOUND_LEVEL);
+
+ final Preference.OnPreferenceChangeListener ambientSoundControlPrefListener = new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newVal) {
+ boolean isAmbientSoundEnabled = AmbientSoundControl.Mode.AMBIENT_SOUND.name().toLowerCase(Locale.getDefault()).equals(newVal);
+ focusOnVoice.setEnabled(isAmbientSoundEnabled);
+ ambientSoundLevel.setEnabled(isAmbientSoundEnabled);
+
+ return true;
+ }
+ };
+
+ ambientSoundControlPrefListener.onPreferenceChange(ambientSoundControl, ambientSoundControl.getValue());
+ handler.addPreferenceHandlerFor(PREF_SONY_AMBIENT_SOUND_CONTROL, ambientSoundControlPrefListener);
+ }
+ }
+}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SonySettingsCustomizer.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SonySettingsCustomizer.java
deleted file mode 100644
index 03bf5919b..000000000
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SonySettingsCustomizer.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/* Copyright (C) 2021 José Rebelo
-
- This file is part of Gadgetbridge.
-
- Gadgetbridge is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- Gadgetbridge is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see . */
-package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones;
-
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_AMBIENT_SOUND_CONTROL;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_AMBIENT_SOUND_LEVEL;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_MODE;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_PRESET_CUSTOM_1;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_PRESET_CUSTOM_2;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_PRESET_MANUAL;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_FOCUS_VOICE;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_SOUND_POSITION;
-import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_SURROUND_MODE;
-
-import androidx.preference.ListPreference;
-import androidx.preference.Preference;
-
-import java.util.Locale;
-
-import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer;
-import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsHandler;
-
-public class SonySettingsCustomizer implements DeviceSpecificSettingsCustomizer {
- @Override
- public void customizeSettings(final DeviceSpecificSettingsHandler handler) {
- // Only enable the focus on voice check and voice level slider if the ambient sound control mode is ambient sound
-
- final ListPreference ambientSoundControl = handler.findPreference(PREF_SONY_AMBIENT_SOUND_CONTROL);
- if (ambientSoundControl != null) {
- final Preference focusOnVoice = handler.findPreference(PREF_SONY_FOCUS_VOICE);
- final Preference ambientSoundLevel = handler.findPreference(PREF_SONY_AMBIENT_SOUND_LEVEL);
-
- final Preference.OnPreferenceChangeListener ambientSoundControlPrefListener = new Preference.OnPreferenceChangeListener() {
- public boolean onPreferenceChange(Preference preference, Object newVal) {
- boolean isAmbientSoundEnabled = AmbientSoundControl.AMBIENT_SOUND.name().toLowerCase(Locale.ROOT).equals(newVal);
- focusOnVoice.setEnabled(isAmbientSoundEnabled);
- ambientSoundLevel.setEnabled(isAmbientSoundEnabled);
-
- return true;
- }
- };
-
- ambientSoundControlPrefListener.onPreferenceChange(ambientSoundControl, ambientSoundControl.getValue());
- handler.addPreferenceHandlerFor(PREF_SONY_AMBIENT_SOUND_CONTROL, ambientSoundControlPrefListener);
- }
-
- // Make the sound position and surround mode settings mutually exclusive
-
- final ListPreference soundPositionPref = handler.findPreference(PREF_SONY_SOUND_POSITION);
- final ListPreference surroundModePref = handler.findPreference(PREF_SONY_SURROUND_MODE);
-
- if (soundPositionPref != null && surroundModePref != null) {
- final Preference.OnPreferenceChangeListener soundPositionPrefListener = new Preference.OnPreferenceChangeListener() {
- public boolean onPreferenceChange(Preference preference, Object newVal) {
- SoundPosition soundPosition = SoundPosition.valueOf(newVal.toString().toUpperCase(Locale.ROOT));
- surroundModePref.setEnabled(SoundPosition.OFF.equals(soundPosition));
-
- return true;
- }
- };
-
- final Preference.OnPreferenceChangeListener surroundModePrefListener = new Preference.OnPreferenceChangeListener() {
- public boolean onPreferenceChange(Preference preference, Object newVal) {
- SurroundMode surroundMode = SurroundMode.valueOf(newVal.toString().toUpperCase(Locale.ROOT));
- soundPositionPref.setEnabled(SurroundMode.OFF.equals(surroundMode));
-
- return true;
- }
- };
-
- soundPositionPrefListener.onPreferenceChange(soundPositionPref, soundPositionPref.getValue());
- surroundModePrefListener.onPreferenceChange(surroundModePref, surroundModePref.getValue());
- handler.addPreferenceHandlerFor(PREF_SONY_SOUND_POSITION, soundPositionPrefListener);
- handler.addPreferenceHandlerFor(PREF_SONY_SURROUND_MODE, surroundModePrefListener);
- }
-
- // Only enable the equalizer preset if the corresponding mode is selected
-
- final ListPreference equalizerModePref = handler.findPreference(PREF_SONY_EQUALIZER_MODE);
-
- if (equalizerModePref != null) {
- handler.addPreferenceHandlerFor(PREF_SONY_EQUALIZER_MODE);
-
- final Preference presetManual = handler.findPreference(PREF_SONY_EQUALIZER_PRESET_MANUAL);
- final Preference presetCustom1 = handler.findPreference(PREF_SONY_EQUALIZER_PRESET_CUSTOM_1);
- final Preference presetCustom2 = handler.findPreference(PREF_SONY_EQUALIZER_PRESET_CUSTOM_2);
-
- final Preference.OnPreferenceChangeListener equalizerModePrefListener = new Preference.OnPreferenceChangeListener() {
- public boolean onPreferenceChange(Preference preference, Object newVal) {
- final EqualizerPreset equalizerPreset = EqualizerPreset.valueOf(newVal.toString().toUpperCase(Locale.ROOT));
-
- presetManual.setEnabled(EqualizerPreset.MANUAL.equals(equalizerPreset));
- presetCustom1.setEnabled(EqualizerPreset.CUSTOM_1.equals(equalizerPreset));
- presetCustom2.setEnabled(EqualizerPreset.CUSTOM_2.equals(equalizerPreset));
-
- return true;
- }
- };
-
- equalizerModePrefListener.onPreferenceChange(equalizerModePref, equalizerModePref.getValue());
- handler.addPreferenceHandlerFor(PREF_SONY_EQUALIZER_MODE, equalizerModePrefListener);
- }
- }
-}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/wh1000xm3/SonyWh1000Xm3Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM3Coordinator.java
similarity index 75%
rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/wh1000xm3/SonyWh1000Xm3Coordinator.java
rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM3Coordinator.java
index 71fb6de01..bfd9a6d4c 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/wh1000xm3/SonyWh1000Xm3Coordinator.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/coordinators/SonyWH1000XM3Coordinator.java
@@ -14,7 +14,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see . */
-package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.wh1000xm3;
+package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.coordinators;
import androidx.annotation.NonNull;
@@ -24,13 +24,14 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
-public class SonyWh1000Xm3Coordinator extends SonyHeadphonesCoordinator {
+public class SonyWH1000XM3Coordinator extends SonyHeadphonesCoordinator {
@NonNull
@Override
public DeviceType getSupportedType(GBDeviceCandidate candidate) {
if (candidate.getName().contains("WH-1000XM3")) {
return DeviceType.SONY_WH_1000XM3;
}
+
return DeviceType.UNKNOWN;
}
@@ -44,9 +45,15 @@ public class SonyWh1000Xm3Coordinator extends SonyHeadphonesCoordinator {
return new int[]{
R.xml.devicesettings_sony_warning_wh1000xm3,
R.xml.devicesettings_sony_headphones_ambient_sound_control,
+ R.xml.devicesettings_header_other,
R.xml.devicesettings_sony_headphones_equalizer,
- R.xml.devicesettings_sony_headphones_other,
- R.xml.devicesettings_sony_wh_1000xm3
+ R.xml.devicesettings_sony_headphones_sound_position,
+ R.xml.devicesettings_sony_headphones_surround_mode,
+ R.xml.devicesettings_sony_headphones_audio_upsampling,
+ R.xml.devicesettings_header_system,
+ R.xml.devicesettings_sony_headphones_touch_sensor_single,
+ R.xml.devicesettings_automatic_power_off,
+ R.xml.devicesettings_sony_headphones_notifications_voice_guide
};
}
}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/AmbientSoundControl.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/AmbientSoundControl.java
new file mode 100644
index 000000000..ed4a6a067
--- /dev/null
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/AmbientSoundControl.java
@@ -0,0 +1,87 @@
+/* Copyright (C) 2021 José Rebelo
+
+ This file is part of Gadgetbridge.
+
+ Gadgetbridge is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Gadgetbridge is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see . */
+package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs;
+
+import android.content.SharedPreferences;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
+
+public class AmbientSoundControl {
+ public enum Mode {
+ OFF,
+ NOISE_CANCELLING,
+ WIND_NOISE_REDUCTION,
+ AMBIENT_SOUND
+ }
+
+ private final Mode mode;
+ private final boolean focusOnVoice;
+ private final int ambientSound;
+
+ public AmbientSoundControl(Mode mode, boolean focusOnVoice, int ambientSound) {
+ if (ambientSound < 0 || ambientSound > 20) {
+ throw new IllegalArgumentException(String.format("Level must be between 0 and 20 (was %d)", ambientSound));
+ }
+
+ this.mode = mode;
+ this.focusOnVoice = focusOnVoice;
+ this.ambientSound = ambientSound;
+ }
+
+ public String toString() {
+ return String.format(Locale.getDefault(), "AmbientSoundControl{mode=%s, focusOnVoice=%s, ambientSound=%d}", mode, focusOnVoice, ambientSound);
+ }
+
+ public Mode getMode() {
+ return mode;
+ }
+
+ public boolean isFocusOnVoice() {
+ return focusOnVoice;
+ }
+
+ public int getAmbientSound() {
+ return ambientSound;
+ }
+
+ public Map toPreferences() {
+ return new HashMap() {{
+ put(DeviceSettingsPreferenceConst.PREF_SONY_AMBIENT_SOUND_CONTROL, mode.name().toLowerCase(Locale.getDefault()));
+
+ if (AmbientSoundControl.Mode.AMBIENT_SOUND.equals(mode)) {
+ // Only use the ambient sound levels and focus on voice if we're on ambient sound mode,
+ // to prevent overriding the user settings
+ put(DeviceSettingsPreferenceConst.PREF_SONY_FOCUS_VOICE, focusOnVoice);
+ // Level is offset by 1 because we can't configure the SeekBarPreference min level on the current api level
+ put(DeviceSettingsPreferenceConst.PREF_SONY_AMBIENT_SOUND_LEVEL, ambientSound - 1);
+ }
+ }};
+ }
+
+ public static AmbientSoundControl fromPreferences(final SharedPreferences prefs) {
+ final String soundControl = prefs.getString(DeviceSettingsPreferenceConst.PREF_SONY_AMBIENT_SOUND_CONTROL, "noise_cancelling");
+ final boolean focusVoice = prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_SONY_FOCUS_VOICE, false);
+ // Level is offset by 1 because we can't configure the SeekBarPreference min level on the current api level
+ final int ambientSound = prefs.getInt(DeviceSettingsPreferenceConst.PREF_SONY_AMBIENT_SOUND_LEVEL, 0) + 1;
+
+ return new AmbientSoundControl(AmbientSoundControl.Mode.valueOf(soundControl.toUpperCase()), focusVoice, ambientSound);
+ }
+}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/AudioUpsampling.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/AudioUpsampling.java
new file mode 100644
index 000000000..4f4f1811c
--- /dev/null
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/AudioUpsampling.java
@@ -0,0 +1,46 @@
+/* Copyright (C) 2021 José Rebelo
+
+ This file is part of Gadgetbridge.
+
+ Gadgetbridge is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Gadgetbridge is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see . */
+package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs;
+
+import android.content.SharedPreferences;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
+
+public class AudioUpsampling {
+ private final boolean enabled;
+
+ public AudioUpsampling(final boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public Map toPreferences() {
+ return new HashMap() {{
+ put(DeviceSettingsPreferenceConst.PREF_SONY_AUDIO_UPSAMPLING, enabled);
+ }};
+ }
+
+ public static AudioUpsampling fromPreferences(final SharedPreferences prefs) {
+ return new AudioUpsampling(prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_SONY_AUDIO_UPSAMPLING, false));
+ }
+}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/AutomaticPowerOff.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/AutomaticPowerOff.java
similarity index 61%
rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/AutomaticPowerOff.java
rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/AutomaticPowerOff.java
index 2c9c3fc20..325f4fe03 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/AutomaticPowerOff.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/AutomaticPowerOff.java
@@ -14,7 +14,15 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see . */
-package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones;
+package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs;
+
+import android.content.SharedPreferences;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
public enum AutomaticPowerOff {
OFF(new byte[]{(byte) 0x11, (byte) 0x00}),
@@ -24,9 +32,23 @@ public enum AutomaticPowerOff {
AFTER_3_HOUR(new byte[]{(byte) 0x03, (byte) 0x03}),
WHEN_TAKEN_OFF(new byte[]{(byte) 0x10, (byte) 0x00});
- public final byte[] code;
+ private final byte[] code;
AutomaticPowerOff(final byte[] code) {
this.code = code;
}
+
+ public byte[] getCode() {
+ return this.code;
+ }
+
+ public Map toPreferences() {
+ return new HashMap() {{
+ put(DeviceSettingsPreferenceConst.PREF_SONY_AUTOMATIC_POWER_OFF, name().toLowerCase(Locale.getDefault()));
+ }};
+ }
+
+ public static AutomaticPowerOff fromPreferences(final SharedPreferences prefs) {
+ return AutomaticPowerOff.valueOf(prefs.getString(DeviceSettingsPreferenceConst.PREF_SONY_AUTOMATIC_POWER_OFF, "off").toUpperCase());
+ }
}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/EqualizerCustomBands.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/EqualizerCustomBands.java
new file mode 100644
index 000000000..ee61e1464
--- /dev/null
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/EqualizerCustomBands.java
@@ -0,0 +1,85 @@
+/* Copyright (C) 2021 José Rebelo
+
+ This file is part of Gadgetbridge.
+
+ Gadgetbridge is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Gadgetbridge is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see . */
+package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs;
+
+import android.content.SharedPreferences;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
+
+public class EqualizerCustomBands {
+ private List bands;
+ private int bass;
+
+ public EqualizerCustomBands(final List bands, final int bass) {
+ if (bands.size() != 5) {
+ throw new IllegalArgumentException("Equalizer needs exactly 5 bands");
+ }
+
+ for (final Integer band : bands) {
+ if (band < -10 || band > 10) {
+ throw new IllegalArgumentException(String.format("Bands should be between -10 and 10, got %d", band));
+ }
+ }
+
+ if (bass < -10 || bass > 10) {
+ throw new IllegalArgumentException(String.format("Clear Bass value shoulud be between -10 and 10, got %d", bass));
+ }
+
+ this.bands = bands;
+ this.bass = bass;
+ }
+
+ public List getBands() {
+ return bands;
+ }
+
+ public int getBass() {
+ return bass;
+ }
+
+ public String toString() {
+ return String.format("EqualizerCustomBands{clearBass=%d, bands=%s}", bass, bands);
+ }
+
+ public Map toPreferences() {
+ return new HashMap() {{
+ put(DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_400, bands.get(0) + 10);
+ put(DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_1000, bands.get(1) + 10);
+ put(DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_2500, bands.get(2) + 10);
+ put(DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_6300, bands.get(3) + 10);
+ put(DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_16000, bands.get(4) + 10);
+ put(DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BASS, bass + 10);
+ ;
+ }};
+ }
+
+ public static EqualizerCustomBands fromPreferences(final SharedPreferences prefs) {
+ int band1 = prefs.getInt(DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_400, 10) - 10;
+ int band2 = prefs.getInt(DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_1000, 10) - 10;
+ int band3 = prefs.getInt(DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_2500, 10) - 10;
+ int band4 = prefs.getInt(DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_6300, 10) - 10;
+ int band5 = prefs.getInt(DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_16000, 10) - 10;
+ int bass = prefs.getInt(DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BASS, 10) - 10;
+
+ return new EqualizerCustomBands(Arrays.asList(band1, band2, band3, band4, band5), bass);
+ }
+}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/EqualizerPreset.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/EqualizerPreset.java
new file mode 100644
index 000000000..b0ac4883e
--- /dev/null
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/EqualizerPreset.java
@@ -0,0 +1,60 @@
+/* Copyright (C) 2021 José Rebelo
+
+ This file is part of Gadgetbridge.
+
+ Gadgetbridge is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Gadgetbridge is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see . */
+package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs;
+
+import android.content.SharedPreferences;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
+
+public enum EqualizerPreset {
+ OFF((byte) 0x00),
+ BRIGHT((byte) 0x10),
+ EXCITED((byte) 0x11),
+ MELLOW((byte) 0x12),
+ RELAXED((byte) 0x13),
+ VOCAL((byte) 0x14),
+ TREBLE_BOOST((byte) 0x15),
+ BASS_BOOST((byte) 0x16),
+ SPEECH((byte) 0x17),
+ MANUAL((byte) 0xa0),
+ CUSTOM_1((byte) 0xa1),
+ CUSTOM_2((byte) 0xa2);
+
+ private final byte code;
+
+ EqualizerPreset(final byte code) {
+ this.code = code;
+ }
+
+ public byte getCode() {
+ return this.code;
+ }
+
+ public Map toPreferences() {
+ return new HashMap() {{
+ put(DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_MODE, name().toLowerCase(Locale.getDefault()));
+ }};
+ }
+
+ public static EqualizerPreset fromPreferences(final SharedPreferences prefs) {
+ return EqualizerPreset.valueOf(prefs.getString(DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_MODE, "off").toUpperCase());
+ }
+}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SoundPosition.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/SoundPosition.java
similarity index 58%
rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SoundPosition.java
rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/SoundPosition.java
index eca7063aa..15b2bf4fd 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SoundPosition.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/SoundPosition.java
@@ -14,7 +14,15 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see . */
-package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones;
+package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs;
+
+import android.content.SharedPreferences;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
public enum SoundPosition {
OFF((byte) 0x00),
@@ -24,9 +32,23 @@ public enum SoundPosition {
REAR_LEFT((byte) 0x11),
REAR_RIGHT((byte) 0x12);
- public final byte code;
+ private final byte code;
SoundPosition(final byte code) {
this.code = code;
}
+
+ public byte getCode() {
+ return this.code;
+ }
+
+ public Map toPreferences() {
+ return new HashMap() {{
+ put(DeviceSettingsPreferenceConst.PREF_SONY_SOUND_POSITION, name().toLowerCase(Locale.getDefault()));
+ }};
+ }
+
+ public static SoundPosition fromPreferences(final SharedPreferences prefs) {
+ return SoundPosition.valueOf(prefs.getString(DeviceSettingsPreferenceConst.PREF_SONY_SOUND_POSITION, "off").toUpperCase());
+ }
}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SurroundMode.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/SurroundMode.java
similarity index 57%
rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SurroundMode.java
rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/SurroundMode.java
index 0953c0e1c..a62fecea8 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/SurroundMode.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/SurroundMode.java
@@ -14,7 +14,15 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see . */
-package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones;
+package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs;
+
+import android.content.SharedPreferences;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
public enum SurroundMode {
OFF((byte) 0x00),
@@ -23,9 +31,23 @@ public enum SurroundMode {
OUTDOOR_STAGE((byte) 0x01),
CONCERT_HALL((byte) 0x03);
- public final byte code;
+ private final byte code;
SurroundMode(final byte code) {
this.code = code;
}
+
+ public byte getCode() {
+ return this.code;
+ }
+
+ public Map toPreferences() {
+ return new HashMap() {{
+ put(DeviceSettingsPreferenceConst.PREF_SONY_SURROUND_MODE, name().toLowerCase(Locale.getDefault()));
+ }};
+ }
+
+ public static SurroundMode fromPreferences(final SharedPreferences prefs) {
+ return SurroundMode.valueOf(prefs.getString(DeviceSettingsPreferenceConst.PREF_SONY_SOUND_POSITION, "off").toUpperCase());
+ }
}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/EqualizerPreset.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/TouchSensor.java
similarity index 50%
rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/EqualizerPreset.java
rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/TouchSensor.java
index 94aa0a1df..3923edf3b 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/EqualizerPreset.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/TouchSensor.java
@@ -14,25 +14,33 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see . */
-package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones;
+package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs;
-public enum EqualizerPreset {
- OFF(new byte[] {(byte) 0x00, (byte) 0x00}),
- BRIGHT(new byte[] {(byte) 0x10, (byte) 0x00}),
- EXCITED(new byte[] {(byte) 0x11, (byte) 0x00}),
- MELLOW(new byte[] {(byte) 0x12, (byte) 0x00}),
- RELAXED(new byte[] {(byte) 0x13, (byte) 0x00}),
- VOCAL(new byte[] {(byte) 0x14, (byte) 0x00}),
- TREBLE_BOOST(new byte[] {(byte) 0x15, (byte) 0x00}),
- BASS_BOOST(new byte[] {(byte) 0x16, (byte) 0x00}),
- SPEECH(new byte[] {(byte) 0x17, (byte) 0x00}),
- MANUAL(new byte[] {(byte) 0xa0, (byte) 0x00}),
- CUSTOM_1(new byte[] {(byte) 0xa1, (byte) 0x00}),
- CUSTOM_2(new byte[] {(byte) 0xa2, (byte) 0x00});
+import android.content.SharedPreferences;
- public final byte[] code;
+import java.util.HashMap;
+import java.util.Map;
- EqualizerPreset(final byte[] code) {
- this.code = code;
+import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
+
+public class TouchSensor {
+ private final boolean enabled;
+
+ public TouchSensor(final boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public Map toPreferences() {
+ return new HashMap() {{
+ put(DeviceSettingsPreferenceConst.PREF_SONY_TOUCH_SENSOR, enabled);
+ }};
+ }
+
+ public static TouchSensor fromPreferences(final SharedPreferences prefs) {
+ return new TouchSensor(prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_SONY_TOUCH_SENSOR, true));
}
}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/VoiceNotifications.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/VoiceNotifications.java
new file mode 100644
index 000000000..8fbbc9a65
--- /dev/null
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/headphones/prefs/VoiceNotifications.java
@@ -0,0 +1,46 @@
+/* Copyright (C) 2021 José Rebelo
+
+ This file is part of Gadgetbridge.
+
+ Gadgetbridge is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Gadgetbridge is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see . */
+package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs;
+
+import android.content.SharedPreferences;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
+
+public class VoiceNotifications {
+ private final boolean enabled;
+
+ public VoiceNotifications(final boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public Map toPreferences() {
+ return new HashMap() {{
+ put(DeviceSettingsPreferenceConst.PREF_SONY_NOTIFICATION_VOICE_GUIDE, enabled);
+ }};
+ }
+
+ public static VoiceNotifications fromPreferences(final SharedPreferences prefs) {
+ return new VoiceNotifications(prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_SONY_NOTIFICATION_VOICE_GUIDE, true));
+ }
+}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btclassic/BtClassicIoThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btclassic/BtClassicIoThread.java
index 6db2d9832..10dad1269 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btclassic/BtClassicIoThread.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btclassic/BtClassicIoThread.java
@@ -82,7 +82,7 @@ public abstract class BtClassicIoThread extends GBDeviceIoThread {
LOG.error("mOutStream is null");
return;
}
- LOG.debug("writing:" + GB.hexdump(bytes, 0, bytes.length));
+ LOG.debug("writing: {}", GB.hexdump(bytes, 0, bytes.length));
try {
mOutStream.write(bytes);
mOutStream.flush();
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesIoThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesIoThread.java
index 952e733d3..db80e8639 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesIoThread.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesIoThread.java
@@ -18,6 +18,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
+import android.os.Handler;
import android.os.ParcelUuid;
import androidx.annotation.NonNull;
@@ -32,38 +33,80 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.service.btclassic.BtClassicIoThread;
+import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Message;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class SonyHeadphonesIoThread extends BtClassicIoThread {
private static final Logger LOG = LoggerFactory.getLogger(SonyHeadphonesIoThread.class);
+ private final SonyHeadphonesProtocol mProtocol;
+
+ // Track whether we got the first reply
+ private boolean firstReply = false;
+ private final Handler handler = new Handler();
+ private int initRetries = 0;
+
+ /**
+ * Sometimes the headphones will ignore the first init request, so we retry a few times
+ * TODO: Implement this in a more elegant way. Ideally, we should retry every command for which we didn't get an ACK.
+ */
+ private final Runnable initSendRunnable = new Runnable() {
+ public void run() {
+ // If we still haven't got any reply, re-send the init
+ if (!firstReply) {
+ if (initRetries++ < 2) {
+ LOG.warn("Init retry {}", initRetries);
+
+ write(mProtocol.encodeInit());
+ scheduleInitRetry();
+ } else {
+ LOG.error("Failed to start headphones init after {} tries", initRetries);
+ quit();
+ }
+ }
+ }
+ };
+
public SonyHeadphonesIoThread(GBDevice gbDevice, Context context, SonyHeadphonesProtocol protocol, SonyHeadphonesSupport support, BluetoothAdapter btAdapter) {
super(gbDevice, context, protocol, support, btAdapter);
+ mProtocol = protocol;
+ }
+
+ @Override
+ protected void initialize() {
+ write(mProtocol.encodeInit());
+ scheduleInitRetry();
+ setUpdateState(GBDevice.State.INITIALIZING);
+ }
+
+ @Override
+ public synchronized void write(byte[] bytes) {
+ // Log the human-readable message, for debugging
+ LOG.info("Writing {}", Message.fromBytes(bytes));
+
+ super.write(bytes);
}
@Override
protected byte[] parseIncoming(InputStream inputStream) throws IOException {
- ByteArrayOutputStream msgStream = new ByteArrayOutputStream();
- byte[] incoming = new byte[1];
+ final ByteArrayOutputStream msgStream = new ByteArrayOutputStream();
+ final byte[] incoming = new byte[1];
- while (true) {
+ do {
inputStream.read(incoming);
- if (incoming[0] == SonyHeadphonesProtocol.PACKET_HEADER) {
+ if (incoming[0] == Message.MESSAGE_HEADER) {
msgStream.reset();
- continue;
- }
-
- if (incoming[0] == SonyHeadphonesProtocol.PACKET_TRAILER) {
- break;
}
msgStream.write(incoming);
- }
+ } while (incoming[0] != Message.MESSAGE_TRAILER);
- byte[] msgArray = msgStream.toByteArray();
- LOG.debug("Received: " + GB.hexdump(msgArray, 0, msgArray.length));
- return msgArray;
+ firstReply = true;
+
+ LOG.trace("Raw message: {}", GB.hexdump(msgStream.toByteArray()));
+
+ return msgStream.toByteArray();
}
@NonNull
@@ -71,4 +114,10 @@ public class SonyHeadphonesIoThread extends BtClassicIoThread {
protected UUID getUuidToConnect(@NonNull ParcelUuid[] uuids) {
return UUID.fromString("96CC203E-5068-46ad-B32D-E316F5E069BA");
}
+
+ private void scheduleInitRetry() {
+ LOG.info("Scheduling init retry");
+
+ handler.postDelayed(initSendRunnable, 1250);
+ }
}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesProtocol.java
index e203fd537..4ec87f4db 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesProtocol.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/sony/headphones/SonyHeadphonesProtocol.java
@@ -21,386 +21,233 @@ import android.content.SharedPreferences;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
-import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.AmbientSoundControl;
-import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.AutomaticPowerOff;
-import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.EqualizerCustomBands;
-import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.EqualizerPreset;
-import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SoundPosition;
-import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SurroundMode;
+import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceState;
+import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AmbientSoundControl;
+import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AudioUpsampling;
+import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AutomaticPowerOff;
+import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.EqualizerCustomBands;
+import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.EqualizerPreset;
+import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.VoiceNotifications;
+import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.SoundPosition;
+import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.SurroundMode;
+import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.TouchSensor;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
+import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request;
+import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Message;
+import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.MessageType;
+import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.impl.AbstractSonyProtocolImpl;
+import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.impl.v1.SonyProtocolImplV1;
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
-import nodomain.freeyourgadget.gadgetbridge.util.GB;
-public abstract class SonyHeadphonesProtocol extends GBDeviceProtocol {
+public class SonyHeadphonesProtocol extends GBDeviceProtocol {
private static final Logger LOG = LoggerFactory.getLogger(SonyHeadphonesProtocol.class);
- /**
- * Packet format:
- *
- * - PACKET_HEADER
- * - Command type? - almost always 0x0c or 0x0e?
- * - Sequence Number - needs to be updated with the one sent in the ACK responses
- * - 4-byte big endian int with number of bytes that will follow
- * - N bytes of data
- * - Checksum (1-byte sum, excluding header)
- * - PACKET_TRAILER
- *
- * Data between PACKET_HEADER and PACKET_TRAILER is escaped with PACKET_ESCAPE, and the
- * following byte masked with PACKET_ESCAPE_MASK.
- */
-
- public static final byte PACKET_HEADER = 0x3e;
- public static final byte PACKET_TRAILER = 0x3c;
- public static final byte PACKET_ESCAPE = 0x3d;
- public static final byte PACKET_ESCAPE_MASK = (byte) 0b11101111;
-
- private static final byte MSG_TYPE_ACK = 0x01;
-
- private static final byte CMD_SOUND_SURROUND = 0x01;
- private static final byte CMD_SOUND_POSITION = 0x02;
-
private byte sequenceNumber = 0;
+ // Request queue, sent every ACK, as we can't send them all at once
+ // Initially, it should contain all the init requests
+ private final Queue requestQueue = new LinkedList<>();
+ private int pendingAcks = 0;
+
+ private AbstractSonyProtocolImpl protocolImpl = null;
+
public SonyHeadphonesProtocol(GBDevice device) {
super(device);
}
@Override
public GBDeviceEvent[] decodeResponse(byte[] res) {
- byte[] message = unescape(res);
- String hexdump = GB.hexdump(message, 0, message.length);
-
- LOG.debug("Received {}", hexdump);
-
- byte messageChecksum = message[message.length - 1];
- byte expectedChecksum = calcChecksum(message, true);
-
- if (messageChecksum != expectedChecksum) {
- LOG.error("Invalid checksum for {}", hexdump);
+ final Message message = Message.fromBytes(res);
+ if (message == null) {
return null;
}
- int payloadLength = ((message[2] << 24) & 0xFF000000) | ((message[3] << 16) & 0xFF0000) | ((message[4] << 8) & 0xFF00) | (message[5] & 0xFF);
- if (payloadLength != message.length - 7) {
- LOG.error("Unexpected payload length {}, expected {}", message.length - 7, payloadLength);
+ LOG.info("Received {}", message);
+
+ final MessageType messageType = message.getType();
+
+ if (messageType == MessageType.ACK) {
+ if (sequenceNumber == message.getSequenceNumber()) {
+ LOG.warn("Unexpected ACK sequence number {}", message.getSequenceNumber());
+ return null;
+ }
+
+ sequenceNumber = message.getSequenceNumber();
+
+ return new GBDeviceEvent[]{handleAck()};
+ }
+
+ if (message.getPayload().length == 0) {
+ LOG.warn("Empty message: {}", message);
return null;
}
- if (message[0] == MSG_TYPE_ACK) {
- LOG.info("Received ACK: {}", hexdump);
- sequenceNumber = message[1];
- return new GBDeviceEvent[]{new GBDeviceEventSendBytes(encodeAck())};
+ final List