diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java index 2bee778ed4..e6fd8310af 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java @@ -61,6 +61,13 @@ public class DanaRFragment extends SubscriberFragment { Button historyButton; Button statsButton; + static Runnable connectRunnable = new Runnable() { + @Override + public void run() { + MainApp.getConfigBuilder().refreshDataFromPump("Connect request from GUI"); + } + }; + public DanaRFragment() { if (sHandlerThread == null) { @@ -135,13 +142,8 @@ public class DanaRFragment extends SubscriberFragment { btConnectionView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - sHandler.post(new Runnable() { - @Override - public void run() { - MainApp.getConfigBuilder().refreshDataFromPump("Connect request from GUI"); - } - } - ); + log.debug("Clicked connect to pump"); + sHandler.post(connectRunnable); } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index dfb9f91570..04a82ed1bd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -27,6 +27,7 @@ import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.DanaRInterface; import info.nightscout.androidaps.interfaces.PluginBase; @@ -217,8 +218,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface, connect(from); } - public static void connect(String from) { - + public static synchronized void connect(String from) { + log.debug("RS connect from: " + from); if (danaRSService != null && !mDeviceAddress.equals("") && !mDeviceName.equals("")) { final Object o = new Object(); @@ -232,7 +233,13 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface, } pumpDescription.basalStep = pump.basalStep; pumpDescription.bolusStep = pump.bolusStep; - log.debug("RS connected:" + from); + if (isConnected()) + log.debug("RS connected: " + from); + else { + MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.connectiontimedout))); + danaRSService.stopConnecting(); + log.debug("RS connect failed from: " + from); + } } } @@ -420,9 +427,11 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface, @Override public void refreshDataFromPump(String reason) { + log.debug("Refreshing data from pump"); if (!isConnected() && !isConnecting()) { connect(reason); - } + } else + log.debug("Already connecting ..."); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java index 3fe3707bca..dde50a93e1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java @@ -194,6 +194,11 @@ public class BLEComm { return true; } + public void stopConnecting() { + isConnecting = false; + sHandler.removeCallbacks(updateProgress); // just to be sure + } + public void disconnect(String from) { log.debug("disconnect from: " + from); if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java index 2cd95ef9f3..6b39788342 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java @@ -109,6 +109,10 @@ public class DanaRSService extends Service { return bleComm.connect(from, address, confirmConnect); } + public void stopConnecting() { + bleComm.stopConnecting(); + } + public void disconnect(String from) { bleComm.disconnect(from); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 22be55eabc..b5f3037145 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -745,5 +745,6 @@ reuse Controls from Watch Set Temp-Targets and enter Treatments from the watch. + Connection timed out