Restore bolus splitting hack.
This commit is contained in:
parent
ecd05bef2d
commit
b85f5324de
3 changed files with 66 additions and 28 deletions
|
@ -212,8 +212,8 @@ public class RuffyScripter {
|
||||||
|
|
||||||
synchronized (RuffyScripter.class) {
|
synchronized (RuffyScripter.class) {
|
||||||
try {
|
try {
|
||||||
long connectStart = System.currentTimeMillis();
|
|
||||||
activeCmd = cmd;
|
activeCmd = cmd;
|
||||||
|
long connectStart = System.currentTimeMillis();
|
||||||
ensureConnected();
|
ensureConnected();
|
||||||
final RuffyScripter scripter = this;
|
final RuffyScripter scripter = this;
|
||||||
final Returnable returnable = new Returnable();
|
final Returnable returnable = new Returnable();
|
||||||
|
|
|
@ -49,5 +49,9 @@ public class Config {
|
||||||
public static final boolean logDanaSerialEngine = true;
|
public static final boolean logDanaSerialEngine = true;
|
||||||
|
|
||||||
// Combo specific
|
// Combo specific
|
||||||
public static final boolean comboExperimentalBolus = false;
|
/** enable the UNFINISHED and currently BROKEN bolus cammand that reports progress and can be cancelled */
|
||||||
|
public static final boolean comboExperimentalBolus = true;
|
||||||
|
/** very quick hack to split up bolus into 2 U parts, spaced roughly 45s apart.
|
||||||
|
* Don't combine with experimental bolus */
|
||||||
|
public static final boolean comboSplitBoluses = false && !comboExperimentalBolus;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import android.media.RingtoneManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
|
||||||
|
@ -224,7 +225,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!boundSucceeded) {
|
if (!boundSucceeded) {
|
||||||
pump.stateSummary = "No connection to ruffy. Pump control not available.";
|
pump.stateSummary = "No connection to ruffy. Pump control unavailable.";
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -393,36 +394,41 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||||
if (detailedBolusInfo.insulin > 0) {
|
if (detailedBolusInfo.insulin > 0) {
|
||||||
// bolus needed, ask pump to deliver it
|
// bolus needed, ask pump to deliver it
|
||||||
|
if (!Config.comboSplitBoluses) {
|
||||||
// TODO read history to ensure there are no boluses delivered on the pump we aren't
|
return deliverBolus(detailedBolusInfo);
|
||||||
// aware of and haven't included in the bolus calulation
|
} else {
|
||||||
|
// split up bolus into 2 U parts
|
||||||
// Note that the BolusCommand sends progress updates to the bolusProgressReporterCallback,
|
|
||||||
// which then posts appropriate events on the bus, so in this branch no posts are needed
|
|
||||||
runningBolusCommand = Config.comboExperimentalBolus
|
|
||||||
? new CancellableBolusCommand(detailedBolusInfo.insulin, bolusProgressReportCallback)
|
|
||||||
: new BolusCommand(detailedBolusInfo.insulin);
|
|
||||||
CommandResult bolusCmdResult = runCommand(runningBolusCommand);
|
|
||||||
runningBolusCommand = null;
|
|
||||||
PumpEnactResult pumpEnactResult = new PumpEnactResult();
|
PumpEnactResult pumpEnactResult = new PumpEnactResult();
|
||||||
pumpEnactResult.success = bolusCmdResult.success;
|
pumpEnactResult.success = true;
|
||||||
pumpEnactResult.enacted = bolusCmdResult.enacted;
|
pumpEnactResult.enacted = true;
|
||||||
pumpEnactResult.comment = bolusCmdResult.message;
|
pumpEnactResult.bolusDelivered = 0d;
|
||||||
|
|
||||||
// if enacted by pump, add bolus and carbs to treatment history
|
|
||||||
if (pumpEnactResult.enacted) {
|
|
||||||
pumpEnactResult.bolusDelivered = detailedBolusInfo.insulin;
|
|
||||||
pumpEnactResult.carbsDelivered = detailedBolusInfo.carbs;
|
pumpEnactResult.carbsDelivered = detailedBolusInfo.carbs;
|
||||||
|
|
||||||
detailedBolusInfo.date = bolusCmdResult.completionTime;
|
double remainingBolus = detailedBolusInfo.insulin;
|
||||||
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
int split = 1;
|
||||||
} else {
|
while (remainingBolus > 0.05) {
|
||||||
pumpEnactResult.bolusDelivered = 0d;
|
double bolus = remainingBolus > 2 ? 2 : remainingBolus;
|
||||||
pumpEnactResult.carbsDelivered = 0d;
|
DetailedBolusInfo bolusInfo = new DetailedBolusInfo();
|
||||||
|
bolusInfo.insulin = bolus;
|
||||||
|
bolusInfo.isValid = false;
|
||||||
|
log.debug("Delivering split bolus #" + split + " with " + bolus + " U");
|
||||||
|
PumpEnactResult bolusResult = deliverBolus(bolusInfo);
|
||||||
|
if (!bolusResult.success) {
|
||||||
|
return bolusResult;
|
||||||
}
|
}
|
||||||
|
pumpEnactResult.bolusDelivered += bolus;
|
||||||
|
remainingBolus -= 2;
|
||||||
|
split++;
|
||||||
|
}
|
||||||
|
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||||
return pumpEnactResult;
|
return pumpEnactResult;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// no bolus required, carb only treatment
|
// 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()
|
||||||
SystemClock.sleep(6000);
|
SystemClock.sleep(6000);
|
||||||
PumpEnactResult pumpEnactResult = new PumpEnactResult();
|
PumpEnactResult pumpEnactResult = new PumpEnactResult();
|
||||||
pumpEnactResult.success = true;
|
pumpEnactResult.success = true;
|
||||||
|
@ -450,6 +456,35 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private PumpEnactResult deliverBolus(DetailedBolusInfo detailedBolusInfo) {
|
||||||
|
runningBolusCommand = Config.comboExperimentalBolus
|
||||||
|
? new CancellableBolusCommand(detailedBolusInfo.insulin, bolusProgressReportCallback)
|
||||||
|
: new BolusCommand(detailedBolusInfo.insulin);
|
||||||
|
CommandResult bolusCmdResult = runCommand(runningBolusCommand);
|
||||||
|
PumpEnactResult pumpEnactResult = new PumpEnactResult();
|
||||||
|
pumpEnactResult.success = bolusCmdResult.success;
|
||||||
|
pumpEnactResult.enacted = bolusCmdResult.enacted;
|
||||||
|
pumpEnactResult.comment = bolusCmdResult.message;
|
||||||
|
|
||||||
|
// if enacted, 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;
|
||||||
|
|
||||||
|
detailedBolusInfo.date = bolusCmdResult.completionTime;
|
||||||
|
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||||
|
} else {
|
||||||
|
pumpEnactResult.bolusDelivered = 0d;
|
||||||
|
pumpEnactResult.carbsDelivered = 0d;
|
||||||
|
}
|
||||||
|
return pumpEnactResult;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopBolusDelivering() {
|
public void stopBolusDelivering() {
|
||||||
BolusCommand localRunningBolusCommand = runningBolusCommand;
|
BolusCommand localRunningBolusCommand = runningBolusCommand;
|
||||||
|
@ -553,7 +588,6 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||||
// TODO GL#70
|
|
||||||
return OPERATION_NOT_SUPPORTED;
|
return OPERATION_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue