fix disconnecting pump

This commit is contained in:
Milos Kozak 2017-12-22 01:35:52 +01:00
parent 6b23ba10bd
commit 74abdc0271
12 changed files with 29 additions and 24 deletions

View file

@ -36,7 +36,7 @@ public interface PumpInterface {
PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo); PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo);
void stopBolusDelivering(); void stopBolusDelivering();
PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew); PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew);
PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes); PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew);
PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes); PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes);
//some pumps might set a very short temp close to 100% as cancelling a temp can be noisy //some pumps might set a very short temp close to 100% as cancelling a temp can be noisy
//when the cancel request is requested by the user (forced), the pump should always do a real cancel //when the cancel request is requested by the user (forced), the pump should always do a real cancel

View file

@ -155,7 +155,7 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
} }
}; };
if (setAsPercent) { if (setAsPercent) {
ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(finalBasalPercent, finalDurationInMinutes, callback); ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(finalBasalPercent, finalDurationInMinutes, true, callback);
} else { } else {
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(finalBasal, finalDurationInMinutes, true, callback); ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(finalBasal, finalDurationInMinutes, true, callback);
} }

View file

@ -344,7 +344,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000); activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
MainApp.bus().post(new EventRefreshOverview("WizardDialog")); MainApp.bus().post(new EventRefreshOverview("WizardDialog"));
} }
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 120, true, new Callback() { ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 120, true, new Callback() {
@Override @Override
public void run() { public void run() {
if (!result.success) { if (!result.success) {

View file

@ -78,6 +78,7 @@ import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.events.EventTempTargetChange;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
@ -330,6 +331,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
super.onCreateContextMenu(menu, v, menuInfo); super.onCreateContextMenu(menu, v, menuInfo);
if (v == apsModeView) { if (v == apsModeView) {
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
final PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription();
if (activeloop == null) if (activeloop == null)
return; return;
menu.setHeaderTitle(MainApp.sResources.getString(R.string.loop)); menu.setHeaderTitle(MainApp.sResources.getString(R.string.loop));
@ -340,6 +342,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
menu.add(MainApp.sResources.getString(R.string.suspendloopfor2h)); menu.add(MainApp.sResources.getString(R.string.suspendloopfor2h));
menu.add(MainApp.sResources.getString(R.string.suspendloopfor3h)); menu.add(MainApp.sResources.getString(R.string.suspendloopfor3h));
menu.add(MainApp.sResources.getString(R.string.suspendloopfor10h)); menu.add(MainApp.sResources.getString(R.string.suspendloopfor10h));
if (pumpDescription.tempDurationStep <= 30)
menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor30m)); menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor30m));
menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor1h)); menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor1h));
menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor2h)); menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor2h));
@ -479,7 +482,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor30m))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor30m))) {
activeloop.disconnectTo(System.currentTimeMillis() + 30L * 60 * 1000); activeloop.disconnectTo(System.currentTimeMillis() + 30L * 60 * 1000);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 30, true, new Callback() { ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 30, true, new Callback() {
@Override @Override
public void run() { public void run() {
if (!result.success) { if (!result.success) {
@ -492,7 +495,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor1h))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor1h))) {
activeloop.disconnectTo(System.currentTimeMillis() + 1 * 60L * 60 * 1000); activeloop.disconnectTo(System.currentTimeMillis() + 1 * 60L * 60 * 1000);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 60, true, new Callback() { ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 60, true, new Callback() {
@Override @Override
public void run() { public void run() {
if (!result.success) { if (!result.success) {
@ -505,7 +508,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor2h))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor2h))) {
activeloop.disconnectTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000); activeloop.disconnectTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 2 * 60, true, new Callback() { ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 2 * 60, true, new Callback() {
@Override @Override
public void run() { public void run() {
if (!result.success) { if (!result.success) {
@ -518,7 +521,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor3h))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor3h))) {
activeloop.disconnectTo(System.currentTimeMillis() + 3 * 60L * 60 * 1000); activeloop.disconnectTo(System.currentTimeMillis() + 3 * 60L * 60 * 1000);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 3 * 60, true, new Callback() { ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 3 * 60, true, new Callback() {
@Override @Override
public void run() { public void run() {
if (!result.success) { if (!result.success) {

View file

@ -434,7 +434,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
// Convert duration from minutes to hours // Convert duration from minutes to hours
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)"); log.debug("setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)");
return setTempBasalPercent(percentRate, durationInMinutes); return setTempBasalPercent(percentRate, durationInMinutes, false);
} }
if (doExtendedTemp) { if (doExtendedTemp) {
// Check if some temp is already in progress // Check if some temp is already in progress
@ -499,7 +499,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
} }
@Override @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
percent = configBuilderPlugin.applyBasalConstraints(percent); percent = configBuilderPlugin.applyBasalConstraints(percent);
@ -514,7 +514,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
if (percent > getPumpDescription().maxTempPercent) if (percent > getPumpDescription().maxTempPercent)
percent = getPumpDescription().maxTempPercent; percent = getPumpDescription().maxTempPercent;
TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
if (runningTB != null && runningTB.percentRate == percent) { if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
result.enacted = false; result.enacted = false;
result.success = true; result.success = true;
result.isTempCancel = false; result.isTempCancel = false;

View file

@ -436,7 +436,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
// Convert duration from minutes to hours // Convert duration from minutes to hours
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)"); log.debug("setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)");
return setTempBasalPercent(percentRate, durationInMinutes); return setTempBasalPercent(percentRate, durationInMinutes, false);
} }
if (doExtendedTemp) { if (doExtendedTemp) {
// Check if some temp is already in progress // Check if some temp is already in progress
@ -501,7 +501,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
} }
@Override @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
percent = configBuilderPlugin.applyBasalConstraints(percent); percent = configBuilderPlugin.applyBasalConstraints(percent);
@ -516,7 +516,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
if (percent > getPumpDescription().maxTempPercent) if (percent > getPumpDescription().maxTempPercent)
percent = getPumpDescription().maxTempPercent; percent = getPumpDescription().maxTempPercent;
TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
if (runningTB != null && runningTB.percentRate == percent) { if (runningTB != null && runningTB.percentRate == percent && enforceNew) {
result.enacted = false; result.enacted = false;
result.success = true; result.success = true;
result.isTempCancel = false; result.isTempCancel = false;

View file

@ -580,7 +580,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
} }
@Override @Override
public synchronized PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { public synchronized PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
percent = configBuilderPlugin.applyBasalConstraints(percent); percent = configBuilderPlugin.applyBasalConstraints(percent);
@ -595,7 +595,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
if (percent > getPumpDescription().maxTempPercent) if (percent > getPumpDescription().maxTempPercent)
percent = getPumpDescription().maxTempPercent; percent = getPumpDescription().maxTempPercent;
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
if (runningTB != null && runningTB.percentRate == percent) { if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
result.enacted = false; result.enacted = false;
result.success = true; result.success = true;
result.isTempCancel = false; result.isTempCancel = false;

View file

@ -437,7 +437,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
} }
@Override @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
percent = configBuilderPlugin.applyBasalConstraints(percent); percent = configBuilderPlugin.applyBasalConstraints(percent);
@ -452,7 +452,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
if (percent > getPumpDescription().maxTempPercent) if (percent > getPumpDescription().maxTempPercent)
percent = getPumpDescription().maxTempPercent; percent = getPumpDescription().maxTempPercent;
TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
if (runningTB != null && runningTB.percentRate == percent) { if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
result.enacted = false; result.enacted = false;
result.success = true; result.success = true;
result.isTempCancel = false; result.isTempCancel = false;

View file

@ -204,7 +204,7 @@ public class MDIPlugin implements PluginBase, PumpInterface {
} }
@Override @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
result.success = false; result.success = false;
result.comment = MainApp.instance().getString(R.string.pumperror); result.comment = MainApp.instance().getString(R.string.pumperror);

View file

@ -304,7 +304,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
} }
@Override @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) {
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
if (MainApp.getConfigBuilder().isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {

View file

@ -203,7 +203,7 @@ public class CommandQueue {
} }
// returns true if command is queued // returns true if command is queued
public boolean tempBasalPercent(int percent, int durationInMinutes, Callback callback) { public boolean tempBasalPercent(int percent, int durationInMinutes, boolean enforceNew, Callback callback) {
if (isRunning(Command.CommandType.TEMPBASAL)) { if (isRunning(Command.CommandType.TEMPBASAL)) {
if (callback != null) if (callback != null)
callback.result(executingNowError()).run(); callback.result(executingNowError()).run();
@ -216,7 +216,7 @@ public class CommandQueue {
Integer percentAfterConstraints = MainApp.getConfigBuilder().applyBasalConstraints(percent); Integer percentAfterConstraints = MainApp.getConfigBuilder().applyBasalConstraints(percent);
// add new command to queue // add new command to queue
add(new CommandTempBasalPercent(percentAfterConstraints, durationInMinutes, callback)); add(new CommandTempBasalPercent(percentAfterConstraints, durationInMinutes, enforceNew, callback));
notifyAboutNewCommand(); notifyAboutNewCommand();

View file

@ -18,17 +18,19 @@ public class CommandTempBasalPercent extends Command {
int durationInMinutes; int durationInMinutes;
int percent; int percent;
boolean enforceNew;
public CommandTempBasalPercent(int percent, int durationInMinutes, Callback callback) { public CommandTempBasalPercent(int percent, int durationInMinutes, boolean enforceNew, Callback callback) {
commandType = CommandType.TEMPBASAL; commandType = CommandType.TEMPBASAL;
this.percent = percent; this.percent = percent;
this.durationInMinutes = durationInMinutes; this.durationInMinutes = durationInMinutes;
this.enforceNew = enforceNew;
this.callback = callback; this.callback = callback;
} }
@Override @Override
public void execute() { public void execute() {
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setTempBasalPercent(percent, durationInMinutes); PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setTempBasalPercent(percent, durationInMinutes, enforceNew);
if (Config.logCongigBuilderActions) if (Config.logCongigBuilderActions)
log.debug("setTempBasalPercent percent: " + percent + " durationInMinutes: " + durationInMinutes + " success: " + r.success + " enacted: " + r.enacted); log.debug("setTempBasalPercent percent: " + percent + " durationInMinutes: " + durationInMinutes + " success: " + r.success + " enacted: " + r.enacted);
if (callback != null) if (callback != null)