CB.applySMBRequest: return reason when skipping due to frequency.

This commit is contained in:
Johannes Mockenhaupt 2018-03-18 23:44:33 +01:00
parent 94d862fb81
commit 379df79bf8
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
2 changed files with 51 additions and 39 deletions

View file

@ -355,11 +355,13 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
* expect absolute request and allow both absolute and percent response based on pump capabilities
*/
public void applyTBRRequest(APSResult request, Profile profile, Callback callback) {
if (!request.tempBasalReqested) {
return;
}
PumpInterface pump = getActivePump();
request.rate = applyBasalConstraints(request.rate);
long now = System.currentTimeMillis();
if (!pump.isInitialized()) {
log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpNotInitialized));
if (callback != null) {
@ -379,7 +381,7 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
if (Config.logCongigBuilderActions)
log.debug("applyAPSRequest: " + request.toString());
if (request.tempBasalReqested) {
long now = System.currentTimeMillis();
TemporaryBasal activeTemp = getTempBasalFromHistory(now);
if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - pump.getBaseBasalRate()) < pump.getPumpDescription().basalStep) {
if (activeTemp != null) {
@ -407,9 +409,22 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
getCommandQueue().tempBasalAbsolute(request.rate, request.duration, false, callback);
}
}
}
public void applySMBRequest(APSResult request, Callback callback) {
if (!request.bolusRequested) {
return;
}
long lastBolusTime = getLastBolusTime();
if (lastBolusTime != 0 && lastBolusTime + 3 * 60 * 1000 > System.currentTimeMillis()) {
log.debug("SMB requested but still in 3 min interval");
if (callback != null) {
callback.result(new PumpEnactResult()
.comment(MainApp.gs(R.string.smb_frequency_exceeded))
.enacted(false).success(false)).run();
}
}
PumpInterface pump = getActivePump();
if (!pump.isInitialized()) {
@ -431,21 +446,17 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
if (Config.logCongigBuilderActions)
log.debug("applySMBRequest: " + request.toString());
if (request.bolusRequested) {
long lastBolusTime = getLastBolusTime();
if (lastBolusTime != 0 && lastBolusTime + 3 * 60 * 1000 > System.currentTimeMillis()) {
log.debug("SMB requsted but still in 3 min interval");
} else {
// deliver SMB
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS;
detailedBolusInfo.insulin = request.smb;
detailedBolusInfo.isSMB = true;
detailedBolusInfo.source = Source.USER;
detailedBolusInfo.deliverAt = request.deliverAt;
if (Config.logCongigBuilderActions)
log.debug("applyAPSRequest: bolus()");
getCommandQueue().bolus(detailedBolusInfo, callback);
}
}
}
/**
* Constraints interface

View file

@ -962,5 +962,6 @@
<string name="profileswitch_ismissing">ProfileSwitch missing. Please do a profile switch or press \"Activate Profile\" in the LocalProfile.</string>
<string name="combo_bolus_count">Bolus count</string>
<string name="combo_tbr_count">TBR count</string>
<string name="smb_frequency_exceeded">A bolus was delivered within the last 3 minutes, skipping SMB</string>
</resources>