diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleLESupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleLESupport.java index 6fa3d2c2..883cc13d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleLESupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/ble/PebbleLESupport.java @@ -10,6 +10,8 @@ import java.io.IOException; import java.io.PipedInputStream; import java.io.PipedOutputStream; +import nodomain.freeyourgadget.gadgetbridge.GBApplication; + public class PebbleLESupport { private static final Logger LOG = LoggerFactory.getLogger(PebbleLESupport.class); private final BluetoothDevice mBtDevice; @@ -19,6 +21,7 @@ public class PebbleLESupport { private PipedInputStream mPipedInputStream; private PipedOutputStream mPipedOutputStream; private int mMTU = 20; + private int mMTULimit = Integer.MAX_VALUE; boolean mIsConnected = false; public PebbleLESupport(Context context, final BluetoothDevice btDevice, PipedInputStream pipedInputStream, PipedOutputStream pipedOutputStream) throws IOException { @@ -31,6 +34,9 @@ public class PebbleLESupport { } catch (IOException e) { LOG.warn("could not connect input stream"); } + mMTULimit = GBApplication.getPrefs().getInt("pebble_mtu_limit", 512); + mMTULimit = Math.max(mMTULimit, 20); + mMTULimit = Math.min(mMTULimit, 512); mPebbleGATTServer = new PebbleGATTServer(this, context, mBtDevice); if (mPebbleGATTServer.initialize()) { @@ -99,7 +105,7 @@ public class PebbleLESupport { } void setMTU(int mtu) { - mMTU = mtu; + mMTU = Math.min(mtu, mMTULimit); } private class PipeReader extends Thread { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 09c215ed..a9d2e3e2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -120,6 +120,8 @@ Enable features that are untested. ENABLE ONLY IF YOU KNOW WHAT YOU ARE DOING! Always prefer BLE Use experimental Pebble LE support for all Pebbles instead of BT classic, requires paring a "Pebble LE" after non LE had been connected once + Pebble 2/LE GATT MTU limit + If your Pebble 2/Pebble LE does not work as expected, try this setting to limit the MTU (valid range 20–512) Enable Watch App Logging Will cause logs from watch apps to be logged by Gadgetbridge (requires reconnect) diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index efe3e4c7..b721a88f 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -341,6 +341,13 @@ android:key="pebble_force_le" android:summary="@string/pref_summary_pebble_forcele" android:title="@string/pref_title_pebble_forcele" /> +