Implement #8, add treatment to history.
This commit is contained in:
parent
e07d62bf79
commit
d39d58913d
1 changed files with 39 additions and 21 deletions
|
@ -23,6 +23,7 @@ import de.jotomo.ruffyscripter.commands.Command;
|
||||||
import de.jotomo.ruffyscripter.commands.CommandResult;
|
import de.jotomo.ruffyscripter.commands.CommandResult;
|
||||||
import de.jotomo.ruffyscripter.commands.SetTbrCommand;
|
import de.jotomo.ruffyscripter.commands.SetTbrCommand;
|
||||||
import info.nightscout.androidaps.BuildConfig;
|
import info.nightscout.androidaps.BuildConfig;
|
||||||
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
|
@ -32,6 +33,7 @@ import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -240,29 +242,45 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
if (detailedBolusInfo.insulin < 0.05) {
|
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||||
log.debug("Ignoring request to deliver bolus of " + detailedBolusInfo.insulin + " U");
|
detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
|
||||||
// Don't bother the pump when only carbs have been entered
|
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||||
// TODO find out if this should be prevented earlier on, or if there's a reason
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
// the pump (danar?) is still called (fetch data for next calc?)
|
if (detailedBolusInfo.insulin > 0) {
|
||||||
PumpEnactResult pumpEnactResult = new PumpEnactResult();
|
CommandResult bolusCmdResult = runCommand(new BolusCommand(detailedBolusInfo.insulin));
|
||||||
pumpEnactResult.success = true;
|
result.success = bolusCmdResult.success;
|
||||||
pumpEnactResult.enacted = false;
|
result.enacted = bolusCmdResult.enacted;
|
||||||
pumpEnactResult.bolusDelivered = 0d;
|
result.bolusDelivered = detailedBolusInfo.insulin;
|
||||||
return pumpEnactResult;
|
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||||
|
} else {
|
||||||
|
result.success = true;
|
||||||
|
result.enacted = false;
|
||||||
|
}
|
||||||
|
result.carbsDelivered = detailedBolusInfo.carbs;
|
||||||
|
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||||
|
if (Config.logPumpActions)
|
||||||
|
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
||||||
|
detailedBolusInfo.date = new Date().getTime();
|
||||||
|
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
result.success = false;
|
||||||
|
result.bolusDelivered = 0d;
|
||||||
|
result.carbsDelivered = 0d;
|
||||||
|
result.comment = MainApp.instance().getString(R.string.danar_invalidinput);
|
||||||
|
log.error("deliverTreatment: Invalid input");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
Command command = new BolusCommand(detailedBolusInfo.insulin);
|
|
||||||
CommandResult commandResult = ruffyScripter.runCommand(command);
|
|
||||||
|
|
||||||
PumpEnactResult pumpEnactResult = new PumpEnactResult();
|
private CommandResult runCommand(Command command) {
|
||||||
pumpEnactResult.success = commandResult.success;
|
// TODO call this for all cmnds
|
||||||
pumpEnactResult.enacted = commandResult.enacted;
|
// TODO use this to disptach methods to a service thread, like DanaRs executionService
|
||||||
pumpEnactResult.comment = commandResult.message;
|
// TODO add a monitor-something that raises an alarm if the command has finished
|
||||||
// Combo would have bailed if this wasn't set properly. Maybe we should
|
// with 90s or so
|
||||||
// have the command return this anyways ...
|
try {
|
||||||
pumpEnactResult.bolusDelivered = detailedBolusInfo.insulin;
|
return ruffyScripter.runCommand(command);
|
||||||
return pumpEnactResult;
|
|
||||||
} finally {
|
} finally {
|
||||||
ruffyScripter.disconnect();
|
ruffyScripter.disconnect();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue