Don't loop with old BG value, don't loop twice for the same value.
Loop is potentially triggered twice when BG reading sent to NS comes back. This should also deal with backfilled data coming in, since any previous reading will be older than 9m, for which DatabaseHelper.actualBg() returns null. The previous approach to solve multiple invocations for the same value added a isNew flag to EventNewBG, but since DatabaseHelper.scheduleBgChange() drops excessive updates the event carrying that flag is not guarantued to be delivered, resulting in missed loop invocations. The approach taken now lets the receiver of the event fully decide how to deal with it. Should fix, or at least improve, #901, #671.
This commit is contained in:
parent
c0250dd62c
commit
d0405014b2
1 changed files with 18 additions and 2 deletions
|
@ -27,6 +27,8 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||
|
@ -54,6 +56,7 @@ public class LoopPlugin extends PluginBase {
|
|||
|
||||
public static final String CHANNEL_ID = "AndroidAPS-Openloop";
|
||||
|
||||
long lastBgTriggeredRun = 0;
|
||||
|
||||
protected static LoopPlugin loopPlugin;
|
||||
|
||||
|
@ -135,9 +138,22 @@ public class LoopPlugin extends PluginBase {
|
|||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
|
||||
if (ev.cause instanceof EventNewBG) {
|
||||
invoke(ev.getClass().getSimpleName() + "(" + ev.cause.getClass().getSimpleName() + ")", true);
|
||||
if (!(ev.cause instanceof EventNewBG)) {
|
||||
// Autosens calculation not triggered by a new BG
|
||||
return;
|
||||
}
|
||||
BgReading bgReading = DatabaseHelper.actualBg();
|
||||
if (bgReading == null) {
|
||||
// BG outdated
|
||||
return;
|
||||
}
|
||||
if (bgReading.date <= lastBgTriggeredRun) {
|
||||
// already looped with that value
|
||||
return;
|
||||
}
|
||||
|
||||
lastBgTriggeredRun = bgReading.date;
|
||||
invoke("AutosenseCalculation for " + bgReading, true);
|
||||
}
|
||||
|
||||
public long suspendedTo() {
|
||||
|
|
Loading…
Reference in a new issue