Combo-specifici hack: Consider a TBR with less than 60 seconds left as completed

when determining whether to set a new TBR.

Setting a new TBR overrides an running TBR if any, so this won't fail on
the Combo. Without this, a TBR mostly runs out 20 seconds after a loop
iteration (when receiving a SGV), so for that almost 5 minutes to TBR
is set.

Note that this is Combo-specific and needs to be revised when
integrating this with mainline.
This commit is contained in:
Johannes Mockenhaupt 2017-07-20 13:05:16 +02:00
parent 3bd865a870
commit 0029fdad01
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
2 changed files with 10 additions and 1 deletions

View file

@ -252,6 +252,11 @@ public class TemporaryBasal implements Interval {
return Math.round(msecs / 60f / 1000); return Math.round(msecs / 60f / 1000);
} }
public int getPlannedRemainingSeconds() {
Float remainingMin = (end() - System.currentTimeMillis()) / 1000f;
return remainingMin.intValue();
}
public int getPlannedRemainingMinutes() { public int getPlannedRemainingMinutes() {
float remainingMin = (end() - System.currentTimeMillis()) / 1000f / 60; float remainingMin = (end() - System.currentTimeMillis()) / 1000f / 60;
return (remainingMin < 0) ? 0 : Math.round(remainingMin); return (remainingMin < 0) ? 0 : Math.round(remainingMin);
@ -280,6 +285,8 @@ public class TemporaryBasal implements Interval {
", isAbsolute=" + isAbsolute + ", isAbsolute=" + isAbsolute +
", isFakeExtended=" + isFakeExtended + ", isFakeExtended=" + isFakeExtended +
", netExtendedRate=" + netExtendedRate + ", netExtendedRate=" + netExtendedRate +
", minutesRemaining=" + getPlannedRemainingMinutes() +
", secondsRemaining=" + getPlannedRemainingSeconds() +
'}'; '}';
} }

View file

@ -263,7 +263,9 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Override @Override
public boolean isTempBasalInProgress() { public boolean isTempBasalInProgress() {
return getTempBasalFromHistory(System.currentTimeMillis()) != null; TemporaryBasal tempBasalFromHistory = getTempBasalFromHistory(System.currentTimeMillis());
log.debug("activeTempbasal: " + tempBasalFromHistory);
return tempBasalFromHistory != null && tempBasalFromHistory.getPlannedRemainingSeconds() > 60;
} }
@Override @Override