This commit is contained in:
Johannes Mockenhaupt 2017-08-17 10:56:06 +02:00
parent 738dd72f5b
commit fabaf7c2ef
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 31 additions and 31 deletions

View file

@ -18,7 +18,6 @@ import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.DELI
import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.STOPPED;
import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.STOPPING;
import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.DELIVERED;
import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.PREPARING;
public class BolusCommand implements Command {
private static final Logger log = LoggerFactory.getLogger(BolusCommand.class);
@ -164,7 +163,8 @@ public class BolusCommand implements Command {
}
private boolean confirmAlert(String alertText, int maxWaitTillExpectedAlert) {
// TODO
return false;
}
private void enterBolusMenu(RuffyScripter scripter) {

View file

@ -369,36 +369,38 @@ public class ComboPlugin implements PluginBase, PumpInterface {
private static ProgressReportCallback bolusProgressReportCallback = new ProgressReportCallback() {
@Override
public void report(ProgressReportCallback.State state, int percent, double delivered) {
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
EventOverviewBolusProgress enent = EventOverviewBolusProgress.getInstance();
switch (state) {
// TODO move into enum as toString or so and make it translateb
case DELIVERING:
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivering), delivered);
enent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivering), delivered);
break;
case DELIVERED:
bolusingEvent.status = "Bolus delivery finished successfully";
break;
case STOPPED:
bolusingEvent.status = "Bolus delivery was cancelled";
enent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivered), delivered);
break;
case STOPPING:
bolusingEvent.status = "Cancelling bolus delivery";
enent.status = MainApp.sResources.getString(R.string.bolusstopping);
break;
case STOPPED:
enent.status = MainApp.sResources.getString(R.string.bolusstopped);
break;
}
bolusingEvent.percent = percent;
MainApp.bus().post(bolusingEvent);
enent.percent = percent;
MainApp.bus().post(enent);
}
};
// what a mess: pump integration code reading carb info from Detailed**Bolus**Info,
// writing carb treatments to the history table. What's PumpEnactResult for again?
/** Updates Treatment records with carbs and boluses and delivers a bolus if needed */
@Override
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
if (detailedBolusInfo.insulin > 0) {
// bolus needed, ask pump to deliver it
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
MainApp.bus().post(bolusingEvent);
// TODO read history to ensure there are no boluses delivered on the pump we aren't
// aware of and haven't included in the bolus calulation
// Note that the BolusCommand send progress updates to the bolusProgressReporterCallback,
// which then posts appropriate events on the bus, so in this branch no posts are needed
runningBolusCommand = new BolusCommand(detailedBolusInfo.insulin, bolusProgressReportCallback);
CommandResult bolusCmdResult = runCommand(runningBolusCommand);
runningBolusCommand = null;
@ -407,12 +409,8 @@ public class ComboPlugin implements PluginBase, PumpInterface {
pumpEnactResult.enacted = bolusCmdResult.enacted;
pumpEnactResult.comment = bolusCmdResult.message;
// if enacted, add bolus and carbs to treatment history
// if enacted by pump, add bolus and carbs to treatment history
if (pumpEnactResult.enacted) {
// TODO if no error occurred, the requested bolus is what the pump delievered,
// that has been checked. If an error occurred, we should check how much insulin
// was delivered, e.g. when the cartridge went empty mid-bolus
// For the first iteration, the alert the pump raises must suffice
pumpEnactResult.bolusDelivered = detailedBolusInfo.insulin;
pumpEnactResult.carbsDelivered = detailedBolusInfo.carbs;
@ -425,11 +423,6 @@ public class ComboPlugin implements PluginBase, PumpInterface {
return pumpEnactResult;
} else {
// no bolus required, carb only treatment
// TODO the ui freezes when the calculator issues a carb-only treatment
// so just wait, yeah, this is dumb. for now; proper fix via GL#10
// info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog.scheduleDismiss()
// send event to indicate popup can be dismissed?
SystemClock.sleep(6000);
PumpEnactResult pumpEnactResult = new PumpEnactResult();
pumpEnactResult.success = true;
@ -438,6 +431,10 @@ public class ComboPlugin implements PluginBase, PumpInterface {
pumpEnactResult.carbsDelivered = detailedBolusInfo.carbs;
pumpEnactResult.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
bolusingEvent.percent = 100;
MainApp.bus().post(bolusingEvent);
return pumpEnactResult;
}
} else {
@ -453,6 +450,12 @@ public class ComboPlugin implements PluginBase, PumpInterface {
}
}
@Override
public void stopBolusDelivering() {
BolusCommand localRunningBolusCommand = runningBolusCommand;
if (localRunningBolusCommand != null) localRunningBolusCommand.requestCancellation();
}
private CommandResult runCommand(Command command) {
if (ruffyScripter == null) {
String msg = "No connection to ruffy. Pump control not available.";
@ -486,11 +489,6 @@ public class ComboPlugin implements PluginBase, PumpInterface {
return commandResult;
}
@Override
public void stopBolusDelivering() {
if (runningBolusCommand != null) runningBolusCommand.requestCancellation();
}
// Note: AAPS calls this only to enact OpenAPS recommendations
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean force) {

View file

@ -702,6 +702,8 @@
<string name="ultrarapid_oref">Ultra-Rapid Oref</string>
<string name="dia_too_short" formatted="false">"DIA of %s too short - using %s instead!"</string>
<string name="activate_profile">ACTIVATE PROFILE</string>
<string name="bolusstopping">Stopping bolus delivery</string>
<string name="bolusstopped">Bolus delivery stopped</string>
</resources>