Let IobCob handle EventNewBg and loop act its result.
This commit is contained in:
parent
b4d13c727e
commit
7e264b1bfd
|
@ -22,6 +22,7 @@ import info.nightscout.androidaps.data.IobTotal;
|
|||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.events.Event;
|
||||
import info.nightscout.androidaps.events.EventAppInitialized;
|
||||
import info.nightscout.androidaps.events.EventConfigBuilderChange;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
|
@ -130,7 +131,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
return -1;
|
||||
}
|
||||
|
||||
IobCobCalculatorPlugin() {
|
||||
private IobCobCalculatorPlugin() {
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
|
@ -260,7 +261,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
}
|
||||
|
||||
|
||||
public void createBucketedData5min() {
|
||||
private void createBucketedData5min() {
|
||||
if (bgReadings == null || bgReadings.size() < 3) {
|
||||
bucketed_data = null;
|
||||
return;
|
||||
|
@ -520,13 +521,13 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
|
||||
@Subscribe
|
||||
public void onEventAppInitialized(EventAppInitialized ev) {
|
||||
runCalculation("onEventAppInitialized", true);
|
||||
runCalculation("onEventAppInitialized", true, ev);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEventNewBG(EventNewBG ev) {
|
||||
stopCalculation("onEventNewBG");
|
||||
runCalculation("onEventNewBG", true);
|
||||
runCalculation("onEventNewBG", true, ev);
|
||||
}
|
||||
|
||||
private void stopCalculation(String from) {
|
||||
|
@ -540,10 +541,10 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
}
|
||||
}
|
||||
|
||||
private void runCalculation(String from, boolean bgDataReload) {
|
||||
private void runCalculation(String from, boolean bgDataReload, Event cause) {
|
||||
log.debug("Starting calculation thread: " + from);
|
||||
if (thread == null || thread.getState() == Thread.State.TERMINATED) {
|
||||
thread = new IobCobThread(this, from, bgDataReload);
|
||||
thread = new IobCobThread(this, from, bgDataReload, cause);
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
|
@ -565,7 +566,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
iobTable = new LongSparseArray<>();
|
||||
autosensDataTable = new LongSparseArray<>();
|
||||
}
|
||||
runCalculation("onNewProfile", false);
|
||||
runCalculation("onNewProfile", false, ev);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
@ -580,7 +581,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
iobTable = new LongSparseArray<>();
|
||||
autosensDataTable = new LongSparseArray<>();
|
||||
}
|
||||
runCalculation("onEventPreferenceChange", false);
|
||||
runCalculation("onEventPreferenceChange", false, ev);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -592,7 +593,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
iobTable = new LongSparseArray<>();
|
||||
autosensDataTable = new LongSparseArray<>();
|
||||
}
|
||||
runCalculation("onEventConfigBuilderChange", false);
|
||||
runCalculation("onEventConfigBuilderChange", false, ev);
|
||||
}
|
||||
|
||||
// When historical data is changed (comming from NS etc) finished calculations after this date must be invalidated
|
||||
|
@ -632,7 +633,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
}
|
||||
}
|
||||
}
|
||||
runCalculation("onEventNewHistoryData", false);
|
||||
runCalculation("onEventNewHistoryData", false, ev);
|
||||
//log.debug("Releasing onNewHistoryData");
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import info.nightscout.androidaps.data.IobTotal;
|
|||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.Event;
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
||||
import info.nightscout.androidaps.queue.QueueThread;
|
||||
|
||||
|
@ -31,6 +32,7 @@ import static info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculat
|
|||
|
||||
public class IobCobThread extends Thread {
|
||||
private static Logger log = LoggerFactory.getLogger(QueueThread.class);
|
||||
private final Event cause;
|
||||
|
||||
private IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
||||
private boolean bgDataReload;
|
||||
|
@ -38,12 +40,13 @@ public class IobCobThread extends Thread {
|
|||
|
||||
private PowerManager.WakeLock mWakeLock;
|
||||
|
||||
public IobCobThread(IobCobCalculatorPlugin plugin, String from, boolean bgDataReload) {
|
||||
public IobCobThread(IobCobCalculatorPlugin plugin, String from, boolean bgDataReload, Event cause) {
|
||||
super();
|
||||
|
||||
this.iobCobCalculatorPlugin = plugin;
|
||||
this.bgDataReload = bgDataReload;
|
||||
this.from = from;
|
||||
this.cause = cause;
|
||||
|
||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
||||
mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "iobCobThread");
|
||||
|
@ -196,7 +199,7 @@ public class IobCobThread extends Thread {
|
|||
log.debug(autosensData.log(bgTime));
|
||||
}
|
||||
}
|
||||
MainApp.bus().post(new EventAutosensCalculationFinished());
|
||||
MainApp.bus().post(new EventAutosensCalculationFinished(cause));
|
||||
log.debug("Finishing calculation thread: " + from);
|
||||
} finally {
|
||||
mWakeLock.release();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package info.nightscout.androidaps.plugins.IobCobCalculator.events;
|
||||
|
||||
import info.nightscout.androidaps.events.Event;
|
||||
import info.nightscout.androidaps.events.EventLoop;
|
||||
|
||||
/**
|
||||
|
@ -7,4 +8,9 @@ import info.nightscout.androidaps.events.EventLoop;
|
|||
*/
|
||||
|
||||
public class EventAutosensCalculationFinished extends EventLoop {
|
||||
public Event cause;
|
||||
|
||||
public EventAutosensCalculationFinished(Event cause) {
|
||||
this.cause = cause;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
|||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
||||
import info.nightscout.androidaps.plugins.Loop.events.EventLoopResult;
|
||||
import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui;
|
||||
import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
|
||||
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
|
||||
|
@ -153,8 +155,10 @@ public class LoopPlugin implements PluginBase {
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewBG ev) {
|
||||
invoke("EventNewBG", true);
|
||||
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
|
||||
if (ev.cause instanceof EventNewBG) {
|
||||
invoke(ev.getClass().getSimpleName() + "(" + ev.cause.getClass().getSimpleName() + ")", true);
|
||||
}
|
||||
}
|
||||
|
||||
public long suspendedTo() {
|
||||
|
@ -314,6 +318,8 @@ public class LoopPlugin implements PluginBase {
|
|||
return;
|
||||
}
|
||||
|
||||
MainApp.bus().post(new EventLoopResult(resultAfterConstraints));
|
||||
|
||||
if (constraintsInterface.isClosedModeEnabled()) {
|
||||
if (result.changeRequested) {
|
||||
final PumpEnactResult waiting = new PumpEnactResult();
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package info.nightscout.androidaps.plugins.Loop.events;
|
||||
|
||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||
|
||||
public class EventLoopResult {
|
||||
public final APSResult apsResult;
|
||||
|
||||
public EventLoopResult(APSResult apsResult) {
|
||||
this.apsResult = apsResult;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue