Merge branch 'smb-events' into 'smb060'
Let IobCob handle EventNewBg and loop act on IobCob result. See merge request MilosKozak/AndroidAPS!379
This commit is contained in:
commit
c953086e3d
5 changed files with 42 additions and 14 deletions
|
@ -22,6 +22,7 @@ import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
import info.nightscout.androidaps.events.EventAppInitialized;
|
import info.nightscout.androidaps.events.EventAppInitialized;
|
||||||
import info.nightscout.androidaps.events.EventConfigBuilderChange;
|
import info.nightscout.androidaps.events.EventConfigBuilderChange;
|
||||||
import info.nightscout.androidaps.events.EventNewBG;
|
import info.nightscout.androidaps.events.EventNewBG;
|
||||||
|
@ -130,7 +131,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
IobCobCalculatorPlugin() {
|
private IobCobCalculatorPlugin() {
|
||||||
MainApp.bus().register(this);
|
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) {
|
if (bgReadings == null || bgReadings.size() < 3) {
|
||||||
bucketed_data = null;
|
bucketed_data = null;
|
||||||
return;
|
return;
|
||||||
|
@ -520,13 +521,13 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEventAppInitialized(EventAppInitialized ev) {
|
public void onEventAppInitialized(EventAppInitialized ev) {
|
||||||
runCalculation("onEventAppInitialized", true);
|
runCalculation("onEventAppInitialized", true, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEventNewBG(EventNewBG ev) {
|
public void onEventNewBG(EventNewBG ev) {
|
||||||
stopCalculation("onEventNewBG");
|
stopCalculation("onEventNewBG");
|
||||||
runCalculation("onEventNewBG", true);
|
runCalculation("onEventNewBG", true, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopCalculation(String from) {
|
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);
|
log.debug("Starting calculation thread: " + from);
|
||||||
if (thread == null || thread.getState() == Thread.State.TERMINATED) {
|
if (thread == null || thread.getState() == Thread.State.TERMINATED) {
|
||||||
thread = new IobCobThread(this, from, bgDataReload);
|
thread = new IobCobThread(this, from, bgDataReload, cause);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -565,7 +566,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
iobTable = new LongSparseArray<>();
|
iobTable = new LongSparseArray<>();
|
||||||
autosensDataTable = new LongSparseArray<>();
|
autosensDataTable = new LongSparseArray<>();
|
||||||
}
|
}
|
||||||
runCalculation("onNewProfile", false);
|
runCalculation("onNewProfile", false, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
@ -580,7 +581,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
iobTable = new LongSparseArray<>();
|
iobTable = new LongSparseArray<>();
|
||||||
autosensDataTable = new LongSparseArray<>();
|
autosensDataTable = new LongSparseArray<>();
|
||||||
}
|
}
|
||||||
runCalculation("onEventPreferenceChange", false);
|
runCalculation("onEventPreferenceChange", false, ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,7 +593,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
iobTable = new LongSparseArray<>();
|
iobTable = new LongSparseArray<>();
|
||||||
autosensDataTable = 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
|
// 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");
|
//log.debug("Releasing onNewHistoryData");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
||||||
import info.nightscout.androidaps.queue.QueueThread;
|
import info.nightscout.androidaps.queue.QueueThread;
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ import static info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculat
|
||||||
|
|
||||||
public class IobCobThread extends Thread {
|
public class IobCobThread extends Thread {
|
||||||
private static Logger log = LoggerFactory.getLogger(QueueThread.class);
|
private static Logger log = LoggerFactory.getLogger(QueueThread.class);
|
||||||
|
private final Event cause;
|
||||||
|
|
||||||
private IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
private IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
||||||
private boolean bgDataReload;
|
private boolean bgDataReload;
|
||||||
|
@ -38,12 +40,13 @@ public class IobCobThread extends Thread {
|
||||||
|
|
||||||
private PowerManager.WakeLock mWakeLock;
|
private PowerManager.WakeLock mWakeLock;
|
||||||
|
|
||||||
public IobCobThread(IobCobCalculatorPlugin plugin, String from, boolean bgDataReload) {
|
public IobCobThread(IobCobCalculatorPlugin plugin, String from, boolean bgDataReload, Event cause) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.iobCobCalculatorPlugin = plugin;
|
this.iobCobCalculatorPlugin = plugin;
|
||||||
this.bgDataReload = bgDataReload;
|
this.bgDataReload = bgDataReload;
|
||||||
this.from = from;
|
this.from = from;
|
||||||
|
this.cause = cause;
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
||||||
mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "iobCobThread");
|
mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "iobCobThread");
|
||||||
|
@ -235,7 +238,7 @@ public class IobCobThread extends Thread {
|
||||||
log.debug(autosensData.log(bgTime));
|
log.debug(autosensData.log(bgTime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventAutosensCalculationFinished());
|
MainApp.bus().post(new EventAutosensCalculationFinished(cause));
|
||||||
log.debug("Finishing calculation thread: " + from);
|
log.debug("Finishing calculation thread: " + from);
|
||||||
} finally {
|
} finally {
|
||||||
mWakeLock.release();
|
mWakeLock.release();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.IobCobCalculator.events;
|
package info.nightscout.androidaps.plugins.IobCobCalculator.events;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
import info.nightscout.androidaps.events.EventLoop;
|
import info.nightscout.androidaps.events.EventLoop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,4 +8,9 @@ import info.nightscout.androidaps.events.EventLoop;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class EventAutosensCalculationFinished extends 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.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
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.EventLoopSetLastRunGui;
|
||||||
import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
|
import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
|
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
|
||||||
|
@ -153,8 +155,10 @@ public class LoopPlugin implements PluginBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventNewBG ev) {
|
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
|
||||||
invoke("EventNewBG", true);
|
if (ev.cause instanceof EventNewBG) {
|
||||||
|
invoke(ev.getClass().getSimpleName() + "(" + ev.cause.getClass().getSimpleName() + ")", true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long suspendedTo() {
|
public long suspendedTo() {
|
||||||
|
@ -314,6 +318,8 @@ public class LoopPlugin implements PluginBase {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MainApp.bus().post(new EventLoopResult(resultAfterConstraints));
|
||||||
|
|
||||||
if (constraintsInterface.isClosedModeEnabled()) {
|
if (constraintsInterface.isClosedModeEnabled()) {
|
||||||
if (result.isChangeRequested()) {
|
if (result.isChangeRequested()) {
|
||||||
final PumpEnactResult waiting = new PumpEnactResult();
|
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