Merge pull request #906 from jotomo/loop-invocations
Don't loop with old BG value, don't loop twice for the same value.
This commit is contained in:
commit
a0036bfb79
1 changed files with 28 additions and 2 deletions
|
@ -27,6 +27,9 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
import info.nightscout.androidaps.events.EventNewBG;
|
import info.nightscout.androidaps.events.EventNewBG;
|
||||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||||
|
@ -54,6 +57,7 @@ public class LoopPlugin extends PluginBase {
|
||||||
|
|
||||||
public static final String CHANNEL_ID = "AndroidAPS-Openloop";
|
public static final String CHANNEL_ID = "AndroidAPS-Openloop";
|
||||||
|
|
||||||
|
long lastBgTriggeredRun = 0;
|
||||||
|
|
||||||
protected static LoopPlugin loopPlugin;
|
protected static LoopPlugin loopPlugin;
|
||||||
|
|
||||||
|
@ -133,11 +137,33 @@ public class LoopPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is triggered once autosens calculation has completed, so the LoopPlugin
|
||||||
|
* has current data to work with. However, autosens calculation can be triggered by multiple
|
||||||
|
* sources and currently only a new BG should trigger a loop run. Hence we return early if
|
||||||
|
* the event causing the calculation is not EventNewBg.
|
||||||
|
*
|
||||||
|
* Callers of {@link info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin#runCalculation(String, long, boolean, Event)}
|
||||||
|
* are sources triggering a calculation which triggers this method upon completion.
|
||||||
|
*/
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
|
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
|
||||||
if (ev.cause instanceof EventNewBG) {
|
if (!(ev.cause instanceof EventNewBG)) {
|
||||||
invoke(ev.getClass().getSimpleName() + "(" + ev.cause.getClass().getSimpleName() + ")", true);
|
// 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() {
|
public long suspendedTo() {
|
||||||
|
|
Loading…
Reference in a new issue