RS connection improvement
This commit is contained in:
parent
c99830968a
commit
02c57fb9a3
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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;
|
||||
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
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -745,5 +745,6 @@
|
|||
<string name="reuse">reuse</string>
|
||||
<string name="wearcontrol_title">Controls from Watch</string>
|
||||
<string name="wearcontrol_summary">Set Temp-Targets and enter Treatments from the watch.</string>
|
||||
<string name="connectiontimedout">Connection timed out</string>
|
||||
</resources>
|
||||
|
||||
|
|
Loading…
Reference in a new issue