From a108158909126d0acdb761785e7d1cc072319126 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 15 Jun 2023 16:34:26 +0200 Subject: [PATCH] Loop: check for empty queue sooner --- .../java/info/nightscout/interfaces/aps/APS.kt | 3 ++- .../nightscout/plugins/aps/loop/LoopPlugin.kt | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/aps/APS.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/aps/APS.kt index 3f829ccfb1..c2b62f3931 100644 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/aps/APS.kt +++ b/core/interfaces/src/main/java/info/nightscout/interfaces/aps/APS.kt @@ -7,5 +7,6 @@ interface APS { var lastDetermineBasalAdapter: DetermineBasalAdapter? var lastAutosensResult: AutosensResult - operator fun invoke(initiator: String, tempBasalFallback: Boolean) + fun isEnabled(): Boolean + fun invoke(initiator: String, tempBasalFallback: Boolean) } \ No newline at end of file diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt index a8dfee3a78..6e0cd97baa 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt @@ -218,7 +218,7 @@ class LoopPlugin @Inject constructor( val start = dateUtil.now() while (start + T.mins(maxMinutes).msecs() > dateUtil.now()) { if (commandQueue.size() == 0 && commandQueue.performing() == null) return true - SystemClock.sleep(100) + SystemClock.sleep(1000) } return false } @@ -247,10 +247,16 @@ class LoopPlugin @Inject constructor( return } + if (!isEmptyQueue()) { + aapsLogger.debug(LTag.APS, rh.gs(info.nightscout.core.ui.R.string.pump_busy)) + rxBus.send(EventLoopSetLastRunGui(rh.gs(info.nightscout.core.ui.R.string.pump_busy))) + return + } + // Check if pump info is loaded if (pump.baseBasalRate < 0.01) return val usedAPS = activePlugin.activeAPS - if ((usedAPS as PluginBase).isEnabled()) { + if (usedAPS.isEnabled()) { usedAPS.invoke(initiator, tempBasalFallback) apsResult = usedAPS.lastAPSResult } @@ -261,12 +267,6 @@ class LoopPlugin @Inject constructor( return } - if (!isEmptyQueue()) { - aapsLogger.debug(LTag.APS, rh.gs(info.nightscout.core.ui.R.string.pump_busy)) - rxBus.send(EventLoopSetLastRunGui(rh.gs(info.nightscout.core.ui.R.string.pump_busy))) - return - } - // Prepare for pumps using % basals if (pump.pumpDescription.tempBasalStyle == PumpDescription.PERCENT && allowPercentage()) { apsResult.usePercent = true