More Injections

This commit is contained in:
Milos Kozak 2020-03-08 22:42:36 +01:00
parent 93820634b5
commit 72ba6815d8
95 changed files with 681 additions and 556 deletions

View file

@ -1,10 +1,10 @@
package info.nightscout.androidaps.activities
import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import dagger.android.support.DaggerAppCompatActivity
import info.nightscout.androidaps.utils.LocaleHelper
open class DialogAppCompatActivity : AppCompatActivity() {
open class DialogAppCompatActivity : DaggerAppCompatActivity() {
public override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(LocaleHelper.wrap(newBase))
}

View file

@ -8,7 +8,12 @@ import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.data.ProfileStore
import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.db.BgReading
import info.nightscout.androidaps.plugins.aps.loop.APSResult
import info.nightscout.androidaps.plugins.aps.openAPSAMA.DetermineBasalResultAMA
import info.nightscout.androidaps.plugins.aps.openAPSMA.DetermineBasalResultMA
import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback
import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalAdapterSMBJS
import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalResultSMB
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.*
import info.nightscout.androidaps.plugins.general.automation.AutomationEvent
import info.nightscout.androidaps.plugins.general.automation.actions.*
@ -40,6 +45,11 @@ interface AppComponent : AndroidInjector<MainApp> {
fun injectProfileStore(profileStore: ProfileStore)
fun injectPumpEnactResult(pumpEnactResult: PumpEnactResult)
fun injectAPSResult(apsResult: APSResult)
fun injectDetermineBasalResultSMB(determineBasalResultSMB: DetermineBasalResultSMB)
fun injectDetermineBasalResultMA(determineBasalResultMA: DetermineBasalResultMA)
fun injectDetermineBasalResultAMA(determineBasalResultAMA: DetermineBasalResultAMA)
fun injectDetermineBasalAdapterSMBJS(determineBasalAdapterSMBJS: DetermineBasalAdapterSMBJS)
fun injectCommandQueue(commandQueue: CommandQueue)
fun injectCommandBolus(commandBolus: CommandBolus)

View file

@ -7,7 +7,6 @@ import dagger.Module
import dagger.Provides
import dagger.android.ContributesAndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.data.ProfileStore
import info.nightscout.androidaps.data.PumpEnactResult
@ -15,9 +14,13 @@ import info.nightscout.androidaps.db.BgReading
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.AAPSLoggerDebug
import info.nightscout.androidaps.logging.AAPSLoggerProduction
import info.nightscout.androidaps.plugins.aps.loop.APSResult
import info.nightscout.androidaps.plugins.aps.openAPSAMA.DetermineBasalResultAMA
import info.nightscout.androidaps.plugins.aps.openAPSMA.DetermineBasalResultMA
import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback
import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalAdapterSMBJS
import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalResultSMB
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation
@ -81,13 +84,21 @@ open class AppModule {
@ContributesAndroidInjector fun pumpEnactResultInjector(): PumpEnactResult
@ContributesAndroidInjector fun apsResultInjector(): APSResult
@ContributesAndroidInjector fun determineBasalResultSMBInjector(): DetermineBasalResultSMB
@ContributesAndroidInjector fun determineBasalResultMAInjector(): DetermineBasalResultMA
@ContributesAndroidInjector fun determineBasalResultAMAInjector(): DetermineBasalResultAMA
@ContributesAndroidInjector fun determineBasalAdapterSMBJSInjector(): DetermineBasalAdapterSMBJS
@ContributesAndroidInjector fun commandQueueInjector(): CommandQueue
@ContributesAndroidInjector fun commandBolusInjector(): CommandBolus
@ContributesAndroidInjector
fun commandCancelExtendedBolusInjector(): CommandCancelExtendedBolus
@ContributesAndroidInjector fun commandCancelTempBasalInjector(): CommandCancelTempBasal
@ContributesAndroidInjector fun commandExtendedBolusInjector(): CommandExtendedBolus
@ContributesAndroidInjector
fun commandInsightSetTBROverNotificationInjector(): CommandInsightSetTBROverNotification
@ -123,6 +134,7 @@ open class AppModule {
@ContributesAndroidInjector fun triggerIobInjector(): TriggerIob
@ContributesAndroidInjector fun triggerLocationInjector(): TriggerLocation
@ContributesAndroidInjector fun triggerProfilePercentInjector(): TriggerProfilePercent
@ContributesAndroidInjector
fun triggerPumpLastConnectionInjector(): TriggerPumpLastConnection
@ -139,6 +151,7 @@ open class AppModule {
@ContributesAndroidInjector fun actionLoopSuspendInjector(): ActionLoopSuspend
@ContributesAndroidInjector fun actionNotificationInjector(): ActionNotification
@ContributesAndroidInjector fun actionProfileSwitchInjector(): ActionProfileSwitch
@ContributesAndroidInjector
fun actionProfileSwitchPercentInjector(): ActionProfileSwitchPercent

View file

@ -1,26 +1,21 @@
package info.nightscout.androidaps.interfaces;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
/**
* Created by mike on 19.03.2018.
*/
public class Constraint<T extends Comparable> {
private static Logger log = StacktraceLoggerWrapper.getLogger(L.CONSTRAINTS);
private T value;
private T originalValue;
T value;
T originalValue;
List<String> reasons = new ArrayList<>();
List<String> mostLimiting = new ArrayList<>();
private List<String> reasons = new ArrayList<>();
private List<String> mostLimiting = new ArrayList<>();
public Constraint(T value) {
this.value = value;
@ -35,27 +30,24 @@ public class Constraint<T extends Comparable> {
return originalValue;
}
public Constraint<T> set(T value) {
public Constraint<T> set(AAPSLogger aapsLogger, T value) {
this.value = value;
this.originalValue = value;
if (L.isEnabled(L.CONSTRAINTS))
log.debug("Setting value " + value);
aapsLogger.debug(LTag.CONSTRAINTS, "Setting value " + value);
return this;
}
public Constraint<T> set(T value, String reason, Object from) {
if (L.isEnabled(L.CONSTRAINTS))
log.debug("Setting value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]");
public Constraint<T> set(AAPSLogger aapsLogger, T value, String reason, Object from) {
aapsLogger.debug(LTag.CONSTRAINTS, "Setting value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]");
this.value = value;
addReason(reason, from);
addMostLimingReason(reason, from);
return this;
}
public Constraint<T> setIfDifferent(T value, String reason, Object from) {
public Constraint<T> setIfDifferent(AAPSLogger aapsLogger, T value, String reason, Object from) {
if (!this.value.equals(value)) {
if (L.isEnabled(L.CONSTRAINTS))
log.debug("Setting because of different value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]");
aapsLogger.debug(LTag.CONSTRAINTS, "Setting because of different value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]");
this.value = value;
addReason(reason, from);
addMostLimingReason(reason, from);
@ -63,10 +55,9 @@ public class Constraint<T extends Comparable> {
return this;
}
public Constraint<T> setIfSmaller(T value, String reason, Object from) {
public Constraint<T> setIfSmaller(AAPSLogger aapsLogger, T value, String reason, Object from) {
if (value.compareTo(this.value) < 0) {
if (L.isEnabled(L.CONSTRAINTS))
log.debug("Setting because of smaller value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]");
aapsLogger.debug(LTag.CONSTRAINTS, "Setting because of smaller value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]");
this.value = value;
mostLimiting.clear();
addMostLimingReason(reason, from);
@ -77,10 +68,9 @@ public class Constraint<T extends Comparable> {
return this;
}
public Constraint<T> setIfGreater(T value, String reason, Object from) {
public Constraint<T> setIfGreater(AAPSLogger aapsLogger, T value, String reason, Object from) {
if (value.compareTo(this.value) > 0) {
if (L.isEnabled(L.CONSTRAINTS))
log.debug("Setting because of greater value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]");
aapsLogger.debug(LTag.CONSTRAINTS, "Setting because of greater value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]");
this.value = value;
mostLimiting.clear();
addMostLimingReason(reason, from);
@ -105,31 +95,29 @@ public class Constraint<T extends Comparable> {
return this;
}
public String getReasons() {
public String getReasons(AAPSLogger aapsLogger) {
StringBuilder sb = new StringBuilder();
int count = 0;
for (String r : reasons) {
if (count++ != 0) sb.append("\n");
sb.append(r);
}
if (L.isEnabled(L.CONSTRAINTS))
log.debug("Limiting origial value: " + originalValue + " to " + value + ". Reason: " + sb.toString());
aapsLogger.debug(LTag.CONSTRAINTS, "Limiting origial value: " + originalValue + " to " + value + ". Reason: " + sb.toString());
return sb.toString();
}
public List<String> getReasonList() {
private List<String> getReasonList() {
return reasons;
}
public String getMostLimitedReasons() {
public String getMostLimitedReasons(AAPSLogger aapsLogger) {
StringBuilder sb = new StringBuilder();
int count = 0;
for (String r : mostLimiting) {
if (count++ != 0) sb.append("\n");
sb.append(r);
}
if (L.isEnabled(L.CONSTRAINTS))
log.debug("Limiting origial value: " + originalValue + " to " + value + ". Reason: " + sb.toString());
aapsLogger.debug(LTag.CONSTRAINTS, "Limiting origial value: " + originalValue + " to " + value + ". Reason: " + sb.toString());
return sb.toString();
}

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.interfaces
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -12,7 +13,8 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
abstract class PluginBase(
val pluginDescription: PluginDescription,
val aapsLogger: AAPSLogger,
val resourceHelper: ResourceHelper
val resourceHelper: ResourceHelper,
val injector: HasAndroidInjector
) {
enum class State {

View file

@ -1,15 +1,17 @@
package info.nightscout.androidaps.interfaces
import android.os.SystemClock
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.utils.resources.ResourceHelper
abstract class PumpPluginBase(
pluginDescription: PluginDescription,
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
val commandQueue: CommandQueueProvider
) : PluginBase(pluginDescription, aapsLogger, resourceHelper) {
) : PluginBase(pluginDescription, aapsLogger, resourceHelper, injector) {
override fun onStart() {
super.onStart()

View file

@ -6,35 +6,47 @@ import android.text.Spanned;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.MainApp;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.R;
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.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
/**
* Created by mike on 09.06.2016.
*/
public class APSResult {
private static Logger log = StacktraceLoggerWrapper.getLogger(L.APS);
@Inject public AAPSLogger aapsLogger;
@Inject ConstraintChecker constraintChecker;
@Inject SP sp;
@Inject ActivePluginProvider activePluginProvider;
@Inject TreatmentsPlugin treatmentsPlugin;
@Inject ProfileFunction profileFunction;
@Inject ResourceHelper resourceHelper;
@Inject
public APSResult(HasAndroidInjector injector) {
injector.androidInjector().inject(this);
}
public long date = 0;
public String reason;
@ -88,68 +100,65 @@ public class APSResult {
@Override
public String toString() {
final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
final PumpInterface pump = activePluginProvider.getActivePump();
if (isChangeRequested()) {
String ret;
// rate
if (rate == 0 && duration == 0)
ret = MainApp.gs(R.string.canceltemp) + "\n";
ret = resourceHelper.gs(R.string.canceltemp) + "\n";
else if (rate == -1)
ret = MainApp.gs(R.string.let_temp_basal_run) + "\n";
ret = resourceHelper.gs(R.string.let_temp_basal_run) + "\n";
else if (usePercent)
ret = MainApp.gs(R.string.rate) + ": " + DecimalFormatter.to2Decimal(percent) + "% " +
ret = resourceHelper.gs(R.string.rate) + ": " + DecimalFormatter.to2Decimal(percent) + "% " +
"(" + DecimalFormatter.to2Decimal(percent * pump.getBaseBasalRate() / 100d) + " U/h)\n" +
MainApp.gs(R.string.duration) + ": " + DecimalFormatter.to2Decimal(duration) + " min\n";
resourceHelper.gs(R.string.duration) + ": " + DecimalFormatter.to2Decimal(duration) + " min\n";
else
ret = MainApp.gs(R.string.rate) + ": " + DecimalFormatter.to2Decimal(rate) + " U/h " +
ret = resourceHelper.gs(R.string.rate) + ": " + DecimalFormatter.to2Decimal(rate) + " U/h " +
"(" + DecimalFormatter.to2Decimal(rate / pump.getBaseBasalRate() * 100) + "%) \n" +
MainApp.gs(R.string.duration) + ": " + DecimalFormatter.to2Decimal(duration) + " min\n";
resourceHelper.gs(R.string.duration) + ": " + DecimalFormatter.to2Decimal(duration) + " min\n";
// smb
if (smb != 0)
ret += ("SMB: " + DecimalFormatter.toPumpSupportedBolus(smb) + " U\n");
// reason
ret += MainApp.gs(R.string.reason) + ": " + reason;
ret += resourceHelper.gs(R.string.reason) + ": " + reason;
return ret;
} else
return MainApp.gs(R.string.nochangerequested);
return resourceHelper.gs(R.string.nochangerequested);
}
public Spanned toSpanned() {
final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
final PumpInterface pump = activePluginProvider.getActivePump();
if (isChangeRequested()) {
String ret;
// rate
if (rate == 0 && duration == 0)
ret = MainApp.gs(R.string.canceltemp) + "<br>";
ret = resourceHelper.gs(R.string.canceltemp) + "<br>";
else if (rate == -1)
ret = MainApp.gs(R.string.let_temp_basal_run) + "<br>";
ret = resourceHelper.gs(R.string.let_temp_basal_run) + "<br>";
else if (usePercent)
ret = "<b>" + MainApp.gs(R.string.rate) + "</b>: " + DecimalFormatter.to2Decimal(percent) + "% " +
ret = "<b>" + resourceHelper.gs(R.string.rate) + "</b>: " + DecimalFormatter.to2Decimal(percent) + "% " +
"(" + DecimalFormatter.to2Decimal(percent * pump.getBaseBasalRate() / 100d) + " U/h)<br>" +
"<b>" + MainApp.gs(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>";
"<b>" + resourceHelper.gs(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>";
else
ret = "<b>" + MainApp.gs(R.string.rate) + "</b>: " + DecimalFormatter.to2Decimal(rate) + " U/h " +
ret = "<b>" + resourceHelper.gs(R.string.rate) + "</b>: " + DecimalFormatter.to2Decimal(rate) + " U/h " +
"(" + DecimalFormatter.to2Decimal(rate / pump.getBaseBasalRate() * 100d) + "%) <br>" +
"<b>" + MainApp.gs(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>";
"<b>" + resourceHelper.gs(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>";
// smb
if (smb != 0)
ret += ("<b>" + "SMB" + "</b>: " + DecimalFormatter.toPumpSupportedBolus(smb) + " U<br>");
// reason
ret += "<b>" + MainApp.gs(R.string.reason) + "</b>: " + reason.replace("<", "&lt;").replace(">", "&gt;");
ret += "<b>" + resourceHelper.gs(R.string.reason) + "</b>: " + reason.replace("<", "&lt;").replace(">", "&gt;");
return Html.fromHtml(ret);
} else
return Html.fromHtml(MainApp.gs(R.string.nochangerequested));
return Html.fromHtml(resourceHelper.gs(R.string.nochangerequested));
}
public APSResult() {
}
public APSResult clone() {
APSResult newResult = new APSResult();
public APSResult newAndClone(HasAndroidInjector injector) {
APSResult newResult = new APSResult(injector);
doClone(newResult);
return newResult;
}
@ -165,7 +174,7 @@ public class APSResult {
try {
newResult.json = new JSONObject(json.toString());
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
newResult.hasPredictions = hasPredictions;
newResult.smb = smb;
@ -186,7 +195,7 @@ public class APSResult {
json.put("reason", reason);
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
return json;
}
@ -249,7 +258,7 @@ public class APSResult {
}
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
return array;
}
@ -282,66 +291,60 @@ public class APSResult {
}
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
return latest;
}
public boolean isChangeRequested() {
Constraint<Boolean> closedLoopEnabled = ConstraintChecker.getInstance().isClosedLoopAllowed();
Constraint<Boolean> closedLoopEnabled = constraintChecker.isClosedLoopAllowed();
// closed loop mode: handle change at driver level
if (closedLoopEnabled.value()) {
if (L.isEnabled(L.APS))
log.debug("DEFAULT: Closed mode");
aapsLogger.debug(LTag.APS, "DEFAULT: Closed mode");
return tempBasalRequested || bolusRequested;
}
// open loop mode: try to limit request
if (!tempBasalRequested && !bolusRequested) {
if (L.isEnabled(L.APS))
log.debug("FALSE: No request");
aapsLogger.debug(LTag.APS, "FALSE: No request");
return false;
}
long now = System.currentTimeMillis();
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now);
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
Profile profile = ProfileFunctions.getInstance().getProfile();
TemporaryBasal activeTemp = treatmentsPlugin.getTempBasalFromHistory(now);
PumpInterface pump = activePluginProvider.getActivePump();
Profile profile = profileFunction.getProfile();
if (profile == null) {
log.error("FALSE: No Profile");
aapsLogger.error("FALSE: No Profile");
return false;
}
if (usePercent) {
if (activeTemp == null && percent == 100) {
if (L.isEnabled(L.APS))
log.debug("FALSE: No temp running, asking cancel temp");
aapsLogger.debug(LTag.APS, "FALSE: No temp running, asking cancel temp");
return false;
}
if (activeTemp != null && Math.abs(percent - activeTemp.tempBasalConvertedToPercent(now, profile)) < pump.getPumpDescription().basalStep) {
if (L.isEnabled(L.APS))
log.debug("FALSE: Temp equal");
aapsLogger.debug(LTag.APS, "FALSE: Temp equal");
return false;
}
// always report zerotemp
if (percent == 0) {
if (L.isEnabled(L.APS))
log.debug("TRUE: Zero temp");
aapsLogger.debug(LTag.APS, "TRUE: Zero temp");
return true;
}
// always report hightemp
if (pump != null && pump.getPumpDescription().tempBasalStyle == PumpDescription.PERCENT) {
if (pump.getPumpDescription().tempBasalStyle == PumpDescription.PERCENT) {
double pumpLimit = pump.getPumpDescription().pumpType.getTbrSettings().getMaxDose();
if (percent == pumpLimit) {
if (L.isEnabled(L.APS))
log.debug("TRUE: Pump limit");
aapsLogger.debug(LTag.APS, "TRUE: Pump limit");
return true;
}
}
// report change bigger than 30%
double percentMinChangeChange = SP.getDouble(R.string.key_loop_openmode_min_change, 30d);
double percentMinChangeChange = sp.getDouble(R.string.key_loop_openmode_min_change, 30d);
percentMinChangeChange /= 100d;
double lowThreshold = 1 - percentMinChangeChange;
double highThreshold = 1 + percentMinChangeChange;
@ -350,42 +353,36 @@ public class APSResult {
change = percent / (double) activeTemp.tempBasalConvertedToPercent(now, profile);
if (change < lowThreshold || change > highThreshold) {
if (L.isEnabled(L.APS))
log.debug("TRUE: Outside allowed range " + (change * 100d) + "%");
aapsLogger.debug(LTag.APS, "TRUE: Outside allowed range " + (change * 100d) + "%");
return true;
} else {
if (L.isEnabled(L.APS))
log.debug("TRUE: Inside allowed range " + (change * 100d) + "%");
aapsLogger.debug(LTag.APS, "TRUE: Inside allowed range " + (change * 100d) + "%");
return false;
}
} else {
if (activeTemp == null && rate == pump.getBaseBasalRate()) {
if (L.isEnabled(L.APS))
log.debug("FALSE: No temp running, asking cancel temp");
aapsLogger.debug(LTag.APS, "FALSE: No temp running, asking cancel temp");
return false;
}
if (activeTemp != null && Math.abs(rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < pump.getPumpDescription().basalStep) {
if (L.isEnabled(L.APS))
log.debug("FALSE: Temp equal");
aapsLogger.debug(LTag.APS, "FALSE: Temp equal");
return false;
}
// always report zerotemp
if (rate == 0) {
if (L.isEnabled(L.APS))
log.debug("TRUE: Zero temp");
aapsLogger.debug(LTag.APS, "TRUE: Zero temp");
return true;
}
// always report hightemp
if (pump != null && pump.getPumpDescription().tempBasalStyle == PumpDescription.ABSOLUTE) {
if (pump.getPumpDescription().tempBasalStyle == PumpDescription.ABSOLUTE) {
double pumpLimit = pump.getPumpDescription().pumpType.getTbrSettings().getMaxDose();
if (rate == pumpLimit) {
if (L.isEnabled(L.APS))
log.debug("TRUE: Pump limit");
aapsLogger.debug(LTag.APS, "TRUE: Pump limit");
return true;
}
}
// report change bigger than 30%
double percentMinChangeChange = SP.getDouble(R.string.key_loop_openmode_min_change, 30d);
double percentMinChangeChange = sp.getDouble(R.string.key_loop_openmode_min_change, 30d);
percentMinChangeChange /= 100d;
double lowThreshold = 1 - percentMinChangeChange;
double highThreshold = 1 + percentMinChangeChange;
@ -394,12 +391,10 @@ public class APSResult {
change = rate / activeTemp.tempBasalConvertedToAbsolute(now, profile);
if (change < lowThreshold || change > highThreshold) {
if (L.isEnabled(L.APS))
log.debug("TRUE: Outside allowed range " + (change * 100d) + "%");
aapsLogger.debug(LTag.APS, "TRUE: Outside allowed range " + (change * 100d) + "%");
return true;
} else {
if (L.isEnabled(L.APS))
log.debug("TRUE: Inside allowed range " + (change * 100d) + "%");
aapsLogger.debug(LTag.APS, "TRUE: Inside allowed range " + (change * 100d) + "%");
return false;
}
}

View file

@ -7,6 +7,7 @@ import android.view.ViewGroup
import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui
import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
@ -22,6 +23,7 @@ import kotlinx.android.synthetic.main.loop_fragment.*
import javax.inject.Inject
class LoopFragment : DaggerFragment() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var sp: SP
@Inject lateinit var resourceHelper: ResourceHelper
@ -96,7 +98,7 @@ class LoopFragment : DaggerFragment() {
val allConstraints = Constraint(0.0)
constraintsProcessed.rateConstraint?.let { rateConstraint -> allConstraints.copyReasons(rateConstraint) }
constraintsProcessed.smbConstraint?.let { smbConstraint -> allConstraints.copyReasons(smbConstraint) }
allConstraints.mostLimitedReasons
allConstraints.getMostLimitedReasons(aapsLogger)
} ?: ""
loop_constraints?.text = constraints
}

View file

@ -22,6 +22,7 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.Lazy;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
@ -73,6 +74,7 @@ import io.reactivex.schedulers.Schedulers;
@Singleton
public class LoopPlugin extends PluginBase {
private final HasAndroidInjector injector;
private final SP sp;
private final RxBusWrapper rxBus;
private final ConstraintChecker constraintChecker;
@ -114,6 +116,7 @@ public class LoopPlugin extends PluginBase {
@Inject
public LoopPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
SP sp,
@ -135,8 +138,9 @@ public class LoopPlugin extends PluginBase {
.shortName(R.string.loop_shortname)
.preferencesId(R.xml.pref_loop)
.description(R.string.description_loop),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
);
this.injector = injector;
this.sp = sp;
this.rxBus = rxBus;
this.constraintChecker = constraintChecker;
@ -311,7 +315,7 @@ public class LoopPlugin extends PluginBase {
Constraint<Boolean> loopEnabled = constraintChecker.isLoopInvocationAllowed();
if (!loopEnabled.value()) {
String message = resourceHelper.gs(R.string.loopdisabled) + "\n" + loopEnabled.getReasons();
String message = resourceHelper.gs(R.string.loopdisabled) + "\n" + loopEnabled.getReasons(getAapsLogger());
getAapsLogger().debug(LTag.APS, message);
rxBus.send(new EventLoopSetLastRunGui(message));
return;
@ -355,7 +359,7 @@ public class LoopPlugin extends PluginBase {
result.percent = (int) (result.rate / profile.getBasal() * 100);
// check rate for constrais
final APSResult resultAfterConstraints = result.clone();
final APSResult resultAfterConstraints = result.newAndClone(injector);
resultAfterConstraints.rateConstraint = new Constraint<>(resultAfterConstraints.rate);
resultAfterConstraints.rate = constraintChecker.applyBasalConstraints(resultAfterConstraints.rateConstraint, profile).value();

View file

@ -17,7 +17,9 @@ import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import javax.annotation.Nullable;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal;
@ -34,13 +36,15 @@ import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
public class DetermineBasalAdapterAMAJS {
private final AAPSLogger aapsLogger;
private HasAndroidInjector injector;
@Inject AAPSLogger aapsLogger;
@Inject ConstraintChecker constraintChecker;
@Inject SP sp;
private ScriptReader mScriptReader = null;
private ScriptReader mScriptReader;
private JSONObject mProfile;
private JSONObject mGlucoseStatus;
@ -58,9 +62,10 @@ public class DetermineBasalAdapterAMAJS {
private String scriptDebug = "";
public DetermineBasalAdapterAMAJS(ScriptReader scriptReader, AAPSLogger aapsLogger) {
DetermineBasalAdapterAMAJS(ScriptReader scriptReader, HasAndroidInjector injector) {
injector.androidInjector().inject(this);
mScriptReader = scriptReader;
this.aapsLogger = aapsLogger;
this.injector = injector;
}
@Nullable
@ -125,7 +130,7 @@ public class DetermineBasalAdapterAMAJS {
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
aapsLogger.debug(LTag.APS, "Result: " + result);
try {
determineBasalResultAMA = new DetermineBasalResultAMA(jsResult, new JSONObject(result), aapsLogger);
determineBasalResultAMA = new DetermineBasalResultAMA(injector, jsResult, new JSONObject(result));
} catch (JSONException e) {
aapsLogger.error(LTag.APS, "Unhandled exception", e);
}
@ -204,17 +209,17 @@ public class DetermineBasalAdapterAMAJS {
mProfile.put("target_bg", targetBg);
mProfile.put("carb_ratio", profile.getIc());
mProfile.put("sens", profile.getIsfMgdl());
mProfile.put("max_daily_safety_multiplier", SP.getInt(R.string.key_openapsama_max_daily_safety_multiplier, 3));
mProfile.put("current_basal_safety_multiplier", SP.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d));
mProfile.put("max_daily_safety_multiplier", sp.getInt(R.string.key_openapsama_max_daily_safety_multiplier, 3));
mProfile.put("current_basal_safety_multiplier", sp.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d));
mProfile.put("skip_neutral_temps", true);
mProfile.put("current_basal", basalrate);
mProfile.put("temptargetSet", tempTargetSet);
mProfile.put("autosens_adjust_targets", SP.getBoolean(R.string.key_openapsama_autosens_adjusttargets, true));
mProfile.put("autosens_adjust_targets", sp.getBoolean(R.string.key_openapsama_autosens_adjusttargets, true));
//align with max-absorption model in AMA sensitivity
if (mealData.usedMinCarbsImpact > 0) {
mProfile.put("min_5m_carbimpact", mealData.usedMinCarbsImpact);
} else {
mProfile.put("min_5m_carbimpact", SP.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact));
mProfile.put("min_5m_carbimpact", sp.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact));
}
if (ProfileFunctions.getSystemUnits().equals(Constants.MMOL)) {
@ -240,7 +245,7 @@ public class DetermineBasalAdapterAMAJS {
mGlucoseStatus = new JSONObject();
mGlucoseStatus.put("glucose", glucoseStatus.glucose);
if (SP.getBoolean(R.string.key_always_use_shortavg, false)) {
if (sp.getBoolean(R.string.key_always_use_shortavg, false)) {
mGlucoseStatus.put("delta", glucoseStatus.short_avgdelta);
} else {
mGlucoseStatus.put("delta", glucoseStatus.delta);
@ -253,7 +258,7 @@ public class DetermineBasalAdapterAMAJS {
mMealData.put("boluses", mealData.boluses);
mMealData.put("mealCOB", mealData.mealCOB);
if (ConstraintChecker.getInstance().isAutosensModeEnabled().value()) {
if (constraintChecker.isAutosensModeEnabled().value()) {
mAutosensData = new JSONObject();
mAutosensData.put("ratio", autosensDataRatio);
} else {

View file

@ -4,6 +4,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.javascript.NativeObject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.loop.APSResult;
@ -15,8 +16,8 @@ public class DetermineBasalResultAMA extends APSResult {
private double eventualBG;
private double snoozeBG;
DetermineBasalResultAMA(NativeObject result, JSONObject j, AAPSLogger aapsLogger) {
this(aapsLogger);
DetermineBasalResultAMA(HasAndroidInjector injector, NativeObject result, JSONObject j) {
this(injector);
date = DateUtil.now();
json = j;
if (result.containsKey("error")) {
@ -47,14 +48,14 @@ public class DetermineBasalResultAMA extends APSResult {
bolusRequested = false;
}
private DetermineBasalResultAMA(AAPSLogger aapsLogger) {
private DetermineBasalResultAMA(HasAndroidInjector injector) {
super(injector);
hasPredictions = true;
this.aapsLogger = aapsLogger;
}
@Override
public DetermineBasalResultAMA clone() {
DetermineBasalResultAMA newResult = new DetermineBasalResultAMA(aapsLogger);
public DetermineBasalResultAMA newAndClone(HasAndroidInjector injector) {
DetermineBasalResultAMA newResult = new DetermineBasalResultAMA(injector);
doClone(newResult);
newResult.eventualBG = eventualBG;

View file

@ -5,6 +5,7 @@ import org.json.JSONException;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal;
@ -58,6 +59,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
@Inject
public OpenAPSAMAPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
ConstraintChecker constraintChecker,
@ -75,7 +77,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
.shortName(R.string.oaps_shortname)
.preferencesId(R.xml.pref_openapsama)
.description(R.string.description_ama),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
);
this.aapsLogger = aapsLogger;
this.rxBus = rxBus;
@ -119,7 +121,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
aapsLogger.debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
lastAPSResult = null;
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS;
determineBasalAdapterAMAJS = new DetermineBasalAdapterAMAJS(new ScriptReader(mainApp), aapsLogger);
determineBasalAdapterAMAJS = new DetermineBasalAdapterAMAJS(new ScriptReader(mainApp), getInjector());
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
Profile profile = profileFunction.getProfile();

View file

@ -15,7 +15,9 @@ import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import javax.annotation.Nullable;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal;
@ -33,7 +35,8 @@ import info.nightscout.androidaps.utils.SP;
public class DetermineBasalAdapterMAJS {
private final AAPSLogger aapsLogger;
private HasAndroidInjector injector;
@Inject AAPSLogger aapsLogger;
private ScriptReader mScriptReader;
private JSONObject mProfile;
private JSONObject mGlucoseStatus;
@ -47,9 +50,10 @@ public class DetermineBasalAdapterMAJS {
private String storedProfile = null;
private String storedMeal_data = null;
DetermineBasalAdapterMAJS(ScriptReader scriptReader, AAPSLogger aapsLogger) {
DetermineBasalAdapterMAJS(ScriptReader scriptReader, HasAndroidInjector injector) {
injector.androidInjector().inject(this);
mScriptReader = scriptReader;
this.aapsLogger = aapsLogger;
this.injector = injector;
}
@Nullable
@ -105,7 +109,7 @@ public class DetermineBasalAdapterMAJS {
if (L.isEnabled(L.APS))
aapsLogger.debug(LTag.APS, "Result: " + result);
try {
determineBasalResultMA = new DetermineBasalResultMA(jsResult, new JSONObject(result), aapsLogger);
determineBasalResultMA = new DetermineBasalResultMA(injector, jsResult, new JSONObject(result));
} catch (JSONException e) {
aapsLogger.error(LTag.APS, "Unhandled exception", e);
}

View file

@ -4,6 +4,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.javascript.NativeObject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.loop.APSResult;
@ -15,8 +16,8 @@ public class DetermineBasalResultMA extends APSResult {
private double snoozeBG;
private String mealAssist;
DetermineBasalResultMA(NativeObject result, JSONObject j, AAPSLogger aapsLogger) {
this(aapsLogger);
DetermineBasalResultMA(HasAndroidInjector injector, NativeObject result, JSONObject j) {
this(injector);
json = j;
if (result.containsKey("error")) {
reason = (String) result.get("error");
@ -49,13 +50,13 @@ public class DetermineBasalResultMA extends APSResult {
}
}
private DetermineBasalResultMA(AAPSLogger aapsLogger) {
this.aapsLogger = aapsLogger;
private DetermineBasalResultMA(HasAndroidInjector injector) {
super(injector);
}
@Override
public DetermineBasalResultMA clone() {
DetermineBasalResultMA newResult = new DetermineBasalResultMA(aapsLogger);
public DetermineBasalResultMA newAndClone(HasAndroidInjector injector) {
DetermineBasalResultMA newResult = new DetermineBasalResultMA(injector);
doClone(newResult);
newResult.eventualBG = eventualBG;

View file

@ -5,6 +5,7 @@ import org.json.JSONException;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal;
@ -57,6 +58,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
@Inject
public OpenAPSMAPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
ConstraintChecker constraintChecker,
@ -74,7 +76,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
.shortName(R.string.oaps_shortname)
.preferencesId(R.xml.pref_openapsma)
.description(R.string.description_ma),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
);
this.constraintChecker = constraintChecker;
@ -118,7 +120,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
getAapsLogger().debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
lastAPSResult = null;
DetermineBasalAdapterMAJS determineBasalAdapterMAJS;
determineBasalAdapterMAJS = new DetermineBasalAdapterMAJS(new ScriptReader(mainApp), getAapsLogger());
determineBasalAdapterMAJS = new DetermineBasalAdapterMAJS(new ScriptReader(mainApp), getInjector());
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
Profile profile = profileFunction.getProfile();

View file

@ -17,7 +17,9 @@ import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import javax.annotation.Nullable;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
@ -34,12 +36,14 @@ import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.SafeParse;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
public class DetermineBasalAdapterSMBJS {
private final AAPSLogger aapsLogger;
private final HasAndroidInjector injector;
@Inject AAPSLogger aapsLogger;
@Inject ConstraintChecker constraintChecker;
@Inject SP sp;
private ScriptReader mScriptReader;
private JSONObject mProfile;
@ -67,9 +71,10 @@ public class DetermineBasalAdapterSMBJS {
* Main code
*/
DetermineBasalAdapterSMBJS(ScriptReader scriptReader, AAPSLogger aapsLogger) {
DetermineBasalAdapterSMBJS(ScriptReader scriptReader, HasAndroidInjector injector) {
mScriptReader = scriptReader;
this.aapsLogger = aapsLogger;
this.injector = injector;
injector.androidInjector().inject(this);
}
@ -143,7 +148,7 @@ public class DetermineBasalAdapterSMBJS {
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
aapsLogger.debug(LTag.APS, "Result: " + result);
try {
determineBasalResultSMB = new DetermineBasalResultSMB(new JSONObject(result), aapsLogger);
determineBasalResultSMB = new DetermineBasalResultSMB(injector, new JSONObject(result));
} catch (JSONException e) {
aapsLogger.error(LTag.APS, "Unhandled exception", e);
}
@ -231,8 +236,8 @@ public class DetermineBasalAdapterSMBJS {
mProfile.put("target_bg", targetBg);
mProfile.put("carb_ratio", profile.getIc());
mProfile.put("sens", profile.getIsfMgdl());
mProfile.put("max_daily_safety_multiplier", SP.getInt(R.string.key_openapsama_max_daily_safety_multiplier, 3));
mProfile.put("current_basal_safety_multiplier", SP.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d));
mProfile.put("max_daily_safety_multiplier", sp.getInt(R.string.key_openapsama_max_daily_safety_multiplier, 3));
mProfile.put("current_basal_safety_multiplier", sp.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d));
// TODO AS-FIX
// mProfile.put("high_temptarget_raises_sensitivity", SP.getBoolean(R.string.key_high_temptarget_raises_sensitivity, SMBDefaults.high_temptarget_raises_sensitivity));
@ -258,18 +263,18 @@ public class DetermineBasalAdapterSMBJS {
mProfile.put("enableUAM", uamAllowed);
mProfile.put("A52_risk_enable", SMBDefaults.A52_risk_enable);
boolean smbEnabled = SP.getBoolean(MainApp.gs(R.string.key_use_smb), false);
mProfile.put("enableSMB_with_COB", smbEnabled && SP.getBoolean(R.string.key_enableSMB_with_COB, false));
mProfile.put("enableSMB_with_temptarget", smbEnabled && SP.getBoolean(R.string.key_enableSMB_with_temptarget, false));
mProfile.put("allowSMB_with_high_temptarget", smbEnabled && SP.getBoolean(R.string.key_allowSMB_with_high_temptarget, false));
mProfile.put("enableSMB_always", smbEnabled && SP.getBoolean(R.string.key_enableSMB_always, false) && advancedFiltering);
mProfile.put("enableSMB_after_carbs", smbEnabled && SP.getBoolean(R.string.key_enableSMB_after_carbs, false) && advancedFiltering);
mProfile.put("maxSMBBasalMinutes", SP.getInt(R.string.key_smbmaxminutes, SMBDefaults.maxSMBBasalMinutes));
boolean smbEnabled = sp.getBoolean(MainApp.gs(R.string.key_use_smb), false);
mProfile.put("enableSMB_with_COB", smbEnabled && sp.getBoolean(R.string.key_enableSMB_with_COB, false));
mProfile.put("enableSMB_with_temptarget", smbEnabled && sp.getBoolean(R.string.key_enableSMB_with_temptarget, false));
mProfile.put("allowSMB_with_high_temptarget", smbEnabled && sp.getBoolean(R.string.key_allowSMB_with_high_temptarget, false));
mProfile.put("enableSMB_always", smbEnabled && sp.getBoolean(R.string.key_enableSMB_always, false) && advancedFiltering);
mProfile.put("enableSMB_after_carbs", smbEnabled && sp.getBoolean(R.string.key_enableSMB_after_carbs, false) && advancedFiltering);
mProfile.put("maxSMBBasalMinutes", sp.getInt(R.string.key_smbmaxminutes, SMBDefaults.maxSMBBasalMinutes));
mProfile.put("carbsReqThreshold", SMBDefaults.carbsReqThreshold);
mProfile.put("current_basal", basalrate);
mProfile.put("temptargetSet", tempTargetSet);
mProfile.put("autosens_max", SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_max, "1.2")));
mProfile.put("autosens_max", SafeParse.stringToDouble(sp.getString(R.string.key_openapsama_autosens_max, "1.2")));
if (ProfileFunctions.getSystemUnits().equals(Constants.MMOL)) {
mProfile.put("out_units", "mmol/L");
@ -295,7 +300,7 @@ public class DetermineBasalAdapterSMBJS {
mGlucoseStatus = new JSONObject();
mGlucoseStatus.put("glucose", glucoseStatus.glucose);
if (SP.getBoolean(R.string.key_always_use_shortavg, false)) {
if (sp.getBoolean(R.string.key_always_use_shortavg, false)) {
mGlucoseStatus.put("delta", glucoseStatus.short_avgdelta);
} else {
mGlucoseStatus.put("delta", glucoseStatus.delta);
@ -314,7 +319,7 @@ public class DetermineBasalAdapterSMBJS {
mMealData.put("lastCarbTime", mealData.lastCarbTime);
if (ConstraintChecker.getInstance().isAutosensModeEnabled().value()) {
if (constraintChecker.isAutosensModeEnabled().value()) {
mAutosensData = new JSONObject();
mAutosensData.put("ratio", autosensDataRatio);
} else {

View file

@ -3,19 +3,24 @@ package info.nightscout.androidaps.plugins.aps.openAPSSMB;
import org.json.JSONException;
import org.json.JSONObject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.loop.APSResult;
import info.nightscout.androidaps.utils.DateUtil;
public class DetermineBasalResultSMB extends APSResult {
private final AAPSLogger aapsLogger;
private double eventualBG;
private double snoozeBG;
DetermineBasalResultSMB(JSONObject result, AAPSLogger aapsLogger) {
this(aapsLogger);
private DetermineBasalResultSMB(HasAndroidInjector injector) {
super(injector);
hasPredictions = true;
}
DetermineBasalResultSMB(HasAndroidInjector injector, JSONObject result) {
this(injector);
date = DateUtil.now();
json = result;
try {
@ -60,14 +65,9 @@ public class DetermineBasalResultSMB extends APSResult {
}
}
private DetermineBasalResultSMB(AAPSLogger aapsLogger) {
hasPredictions = true;
this.aapsLogger = aapsLogger;
}
@Override
public DetermineBasalResultSMB clone() {
DetermineBasalResultSMB newResult = new DetermineBasalResultSMB(aapsLogger);
public DetermineBasalResultSMB newAndClone(HasAndroidInjector injector) {
DetermineBasalResultSMB newResult = new DetermineBasalResultSMB(injector);
doClone(newResult);
newResult.eventualBG = eventualBG;

View file

@ -95,7 +95,7 @@ class OpenAPSSMBFragment : DaggerFragment() {
openapsma_mealdata.text = JSONFormatter.format(determineBasalAdapterSMBJS.mealDataParam)
openapsma_scriptdebugdata.text = determineBasalAdapterSMBJS.scriptDebug
openAPSSMBPlugin.lastAPSResult?.inputConstraints?.let {
openapsma_constraints.text = it.reasons
openapsma_constraints.text = it.getReasons(aapsLogger)
}
}
if (openAPSSMBPlugin.lastAPSRun != 0L) {

View file

@ -6,6 +6,7 @@ import org.json.JSONException;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal;
@ -45,6 +46,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
@Singleton
public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, ConstraintsInterface {
private final HasAndroidInjector injector;
private final ConstraintChecker constraintChecker;
private final ResourceHelper resourceHelper;
private final ProfileFunction profileFunction;
@ -62,6 +64,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
@Inject
public OpenAPSSMBPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
ConstraintChecker constraintChecker,
@ -79,9 +82,9 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
.shortName(R.string.smb_shortname)
.preferencesId(R.xml.pref_openapssmb)
.description(R.string.description_smb),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
);
this.injector = injector;
this.constraintChecker = constraintChecker;
this.resourceHelper = resourceHelper;
this.profileFunction = profileFunction;
@ -123,7 +126,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
getAapsLogger().debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
lastAPSResult = null;
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS;
determineBasalAdapterSMBJS = new DetermineBasalAdapterSMBJS(new ScriptReader(mainApp), getAapsLogger());
determineBasalAdapterSMBJS = new DetermineBasalAdapterSMBJS(new ScriptReader(mainApp), injector);
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
Profile profile = profileFunction.getProfile();
@ -303,7 +306,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
@NotNull
@Override
public Constraint<Boolean> isSuperBolusEnabled(Constraint<Boolean> value) {
value.set(false);
value.set(getAapsLogger(), false);
return value;
}

View file

@ -12,6 +12,7 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.Lazy;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventAppInitialized;
@ -105,6 +106,7 @@ public class ConfigBuilderPlugin extends PluginBase implements ActivePluginProvi
Lazy<TreatmentsPlugin> treatmentsPlugin,
Lazy<SensitivityOref0Plugin> sensitivityOref0Plugin,
Lazy<SensitivityOref1Plugin> sensitivityOref1Plugin,
HasAndroidInjector injector,
SP sp,
RxBusWrapper rxBus,
AAPSLogger aapsLogger,
@ -121,7 +123,7 @@ public class ConfigBuilderPlugin extends PluginBase implements ActivePluginProvi
.pluginName(R.string.configbuilder)
.shortName(R.string.configbuilder_shortname)
.description(R.string.description_config_builder),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
);
this.insulinOrefRapidActingPlugin = insulinOrefRapidActingPlugin;
this.localProfilePlugin = localProfilePlugin;

View file

@ -12,16 +12,6 @@ import javax.inject.Singleton
@Singleton
class ConstraintChecker @Inject constructor(private val mainApp: MainApp) : ConstraintsInterface {
init {
instance = this
}
companion object {
@JvmStatic
@Deprecated("Get via Dagger. Will be removed once fully transitioned to Dagger")
lateinit var instance: ConstraintChecker //TODO: remove as soon as Dagger is fully set up
}
fun isLoopInvocationAllowed(): Constraint<Boolean> =
isLoopInvocationAllowed(Constraint(true))

View file

@ -19,7 +19,7 @@ import javax.inject.Singleton
@Singleton
class DstHelperPlugin @Inject constructor(
private var injector: HasAndroidInjector,
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
private var rxBus: RxBusWrapper,
resourceHelper: ResourceHelper,
@ -32,7 +32,7 @@ class DstHelperPlugin @Inject constructor(
.alwaysEnabled(true)
.showInList(false)
.pluginName(R.string.dst_plugin_name),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
), ConstraintsInterface {
companion object {
@ -75,7 +75,7 @@ class DstHelperPlugin @Inject constructor(
} else {
aapsLogger.debug(LTag.CONSTRAINTS, "Loop already suspended")
}
value.set(false, "DST in last 3 hours.", this)
value.set(aapsLogger, false, "DST in last 3 hours.", this)
}
return value
}

View file

@ -25,7 +25,7 @@ import javax.inject.Singleton
@Singleton
class ObjectivesPlugin @Inject constructor(
private val injector: HasAndroidInjector,
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
private val configBuilderPlugin: ConfigBuilderPlugin,
@ -39,7 +39,7 @@ class ObjectivesPlugin @Inject constructor(
.pluginName(R.string.objectives)
.shortName(R.string.objectives_shortname)
.description(R.string.description_objectives),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
), ConstraintsInterface {
var objectives: MutableList<Objective> = ArrayList()
@ -151,37 +151,37 @@ class ObjectivesPlugin @Inject constructor(
*/
override fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
if (!objectives[FIRST_OBJECTIVE].isStarted)
value.set(false, resourceHelper.gs(R.string.objectivenotstarted, FIRST_OBJECTIVE + 1), this)
value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, FIRST_OBJECTIVE + 1), this)
return value
}
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
if (!objectives[MAXIOB_ZERO_CL_OBJECTIVE].isStarted)
value.set(false, resourceHelper.gs(R.string.objectivenotstarted, MAXIOB_ZERO_CL_OBJECTIVE + 1), this)
value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, MAXIOB_ZERO_CL_OBJECTIVE + 1), this)
return value
}
override fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
if (!objectives[AUTOSENS_OBJECTIVE].isStarted)
value.set(false, resourceHelper.gs(R.string.objectivenotstarted, AUTOSENS_OBJECTIVE + 1), this)
value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, AUTOSENS_OBJECTIVE + 1), this)
return value
}
override fun isAMAModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
if (!objectives[AMA_OBJECTIVE].isStarted)
value.set(false, resourceHelper.gs(R.string.objectivenotstarted, AMA_OBJECTIVE + 1), this)
value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, AMA_OBJECTIVE + 1), this)
return value
}
override fun isSMBModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
if (!objectives[SMB_OBJECTIVE].isStarted)
value.set(false, resourceHelper.gs(R.string.objectivenotstarted, SMB_OBJECTIVE + 1), this)
value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, SMB_OBJECTIVE + 1), this)
return value
}
override fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> {
if (objectives[MAXIOB_ZERO_CL_OBJECTIVE].isStarted && !objectives[MAXIOB_ZERO_CL_OBJECTIVE].isAccomplished)
maxIob.set(0.0, resourceHelper.gs(R.string.objectivenotfinished, MAXIOB_ZERO_CL_OBJECTIVE + 1), this)
maxIob.set(aapsLogger, 0.0, resourceHelper.gs(R.string.objectivenotfinished, MAXIOB_ZERO_CL_OBJECTIVE + 1), this)
return maxIob
}
}

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.constraints.phoneChecker
import android.content.Context
import android.os.Build
import com.scottyab.rootbeer.RootBeer
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.ConstraintsInterface
import info.nightscout.androidaps.interfaces.PluginBase
@ -15,6 +16,7 @@ import javax.inject.Singleton
@Singleton
class PhoneCheckerPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
private val context: Context
@ -24,7 +26,7 @@ class PhoneCheckerPlugin @Inject constructor(
.alwaysEnabled(true)
.showInList(false)
.pluginName(R.string.phonechecker),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
), ConstraintsInterface {
var phoneRooted: Boolean = false

View file

@ -5,6 +5,7 @@ import androidx.annotation.NonNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
@ -49,14 +50,19 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
@Inject ActivePluginProvider activePlugin;
@Inject
public SafetyPlugin(AAPSLogger aapsLogger, ResourceHelper resourceHelper) {
public SafetyPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
ResourceHelper resourceHelper
) {
super(new PluginDescription()
.mainType(PluginType.CONSTRAINTS)
.neverVisible(true)
.alwaysEnabled(true)
.showInList(false)
.pluginName(R.string.safety)
.preferencesId(R.xml.pref_safety), aapsLogger, resourceHelper
.mainType(PluginType.CONSTRAINTS)
.neverVisible(true)
.alwaysEnabled(true)
.showInList(false)
.pluginName(R.string.safety)
.preferencesId(R.xml.pref_safety),
aapsLogger, resourceHelper, injector
);
}
@ -66,7 +72,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
@NonNull @Override
public Constraint<Boolean> isLoopInvocationAllowed(@NonNull Constraint<Boolean> value) {
if (!activePlugin.getActivePumpPlugin().getPumpDescription().isTempBasalCapable)
value.set(false, resourceHelper.gs(R.string.pumpisnottempbasalcapable), this);
value.set(getAapsLogger(), false, resourceHelper.gs(R.string.pumpisnottempbasalcapable), this);
return value;
}
@ -74,18 +80,18 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
public Constraint<Boolean> isClosedLoopAllowed(@NonNull Constraint<Boolean> value) {
String mode = sp.getString(R.string.key_aps_mode, "open");
if (!mode.equals("closed"))
value.set(false, resourceHelper.gs(R.string.closedmodedisabledinpreferences), this);
value.set(getAapsLogger(), false, resourceHelper.gs(R.string.closedmodedisabledinpreferences), this);
if (!MainApp.isEngineeringModeOrRelease()) {
if (value.value()) {
Notification n = new Notification(Notification.TOAST_ALARM, resourceHelper.gs(R.string.closed_loop_disabled_on_dev_branch), Notification.NORMAL);
rxBus.send(new EventNewNotification(n));
}
value.set(false, resourceHelper.gs(R.string.closed_loop_disabled_on_dev_branch), this);
value.set(getAapsLogger(), false, resourceHelper.gs(R.string.closed_loop_disabled_on_dev_branch), this);
}
PumpInterface pump = activePlugin.getActivePumpPlugin();
if (pump != null && !pump.isFakingTempsByExtendedBoluses() && TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) {
value.set(false, MainApp.gs(R.string.closed_loop_disabled_with_eb), this);
value.set(getAapsLogger(), false, MainApp.gs(R.string.closed_loop_disabled_with_eb), this);
}
return value;
}
@ -94,7 +100,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
public Constraint<Boolean> isAutosensModeEnabled(@NonNull Constraint<Boolean> value) {
boolean enabled = sp.getBoolean(R.string.key_openapsama_useautosens, false);
if (!enabled)
value.set(false, resourceHelper.gs(R.string.autosensdisabledinpreferences), this);
value.set(getAapsLogger(), false, resourceHelper.gs(R.string.autosensdisabledinpreferences), this);
return value;
}
@ -102,10 +108,10 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
public Constraint<Boolean> isSMBModeEnabled(@NonNull Constraint<Boolean> value) {
boolean enabled = sp.getBoolean(R.string.key_use_smb, false);
if (!enabled)
value.set(false, resourceHelper.gs(R.string.smbdisabledinpreferences), this);
value.set(getAapsLogger(), false, resourceHelper.gs(R.string.smbdisabledinpreferences), this);
Constraint<Boolean> closedLoop = constraintChecker.isClosedLoopAllowed();
if (!closedLoop.value())
value.set(false, resourceHelper.gs(R.string.smbnotallowedinopenloopmode), this);
value.set(getAapsLogger(), false, resourceHelper.gs(R.string.smbnotallowedinopenloopmode), this);
return value;
}
@ -113,10 +119,10 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
public Constraint<Boolean> isUAMEnabled(@NonNull Constraint<Boolean> value) {
boolean enabled = sp.getBoolean(R.string.key_use_uam, false);
if (!enabled)
value.set(false, resourceHelper.gs(R.string.uamdisabledinpreferences), this);
value.set(getAapsLogger(), false, resourceHelper.gs(R.string.uamdisabledinpreferences), this);
boolean oref1Enabled = sensitivityOref1Plugin.isEnabled(PluginType.SENSITIVITY);
if (!oref1Enabled)
value.set(false, resourceHelper.gs(R.string.uamdisabledoref1notselected), this);
value.set(getAapsLogger(), false, resourceHelper.gs(R.string.uamdisabledoref1notselected), this);
return value;
}
@ -126,7 +132,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
if (bgSource != null) {
if (!bgSource.advancedFilteringSupported())
value.set(false, resourceHelper.gs(R.string.smbalwaysdisabled), this);
value.set(getAapsLogger(), false, resourceHelper.gs(R.string.smbalwaysdisabled), this);
}
return value;
}
@ -134,7 +140,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
@NonNull @Override
public Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, @NonNull Profile profile) {
absoluteRate.setIfGreater(0d, String.format(resourceHelper.gs(R.string.limitingbasalratio), 0d, resourceHelper.gs(R.string.itmustbepositivevalue)), this);
absoluteRate.setIfGreater(getAapsLogger(), 0d, String.format(resourceHelper.gs(R.string.limitingbasalratio), 0d, resourceHelper.gs(R.string.itmustbepositivevalue)), this);
if (Config.APS) {
double maxBasal = sp.getDouble(R.string.key_openapsma_max_basal, 1d);
@ -142,30 +148,30 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
maxBasal = profile.getMaxDailyBasal();
absoluteRate.addReason(resourceHelper.gs(R.string.increasingmaxbasal), this);
}
absoluteRate.setIfSmaller(maxBasal, String.format(resourceHelper.gs(R.string.limitingbasalratio), maxBasal, resourceHelper.gs(R.string.maxvalueinpreferences)), this);
absoluteRate.setIfSmaller(getAapsLogger(), maxBasal, String.format(resourceHelper.gs(R.string.limitingbasalratio), maxBasal, resourceHelper.gs(R.string.maxvalueinpreferences)), this);
// Check percentRate but absolute rate too, because we know real current basal in pump
Double maxBasalMult = sp.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d);
double maxFromBasalMult = Math.floor(maxBasalMult * profile.getBasal() * 100) / 100;
absoluteRate.setIfSmaller(maxFromBasalMult, String.format(resourceHelper.gs(R.string.limitingbasalratio), maxFromBasalMult, resourceHelper.gs(R.string.maxbasalmultiplier)), this);
absoluteRate.setIfSmaller(getAapsLogger(), maxFromBasalMult, String.format(resourceHelper.gs(R.string.limitingbasalratio), maxFromBasalMult, resourceHelper.gs(R.string.maxbasalmultiplier)), this);
Double maxBasalFromDaily = sp.getDouble(R.string.key_openapsama_max_daily_safety_multiplier, 3d);
double maxFromDaily = Math.floor(profile.getMaxDailyBasal() * maxBasalFromDaily * 100) / 100;
absoluteRate.setIfSmaller(maxFromDaily, String.format(resourceHelper.gs(R.string.limitingbasalratio), maxFromDaily, resourceHelper.gs(R.string.maxdailybasalmultiplier)), this);
absoluteRate.setIfSmaller(getAapsLogger(), maxFromDaily, String.format(resourceHelper.gs(R.string.limitingbasalratio), maxFromDaily, resourceHelper.gs(R.string.maxdailybasalmultiplier)), this);
}
absoluteRate.setIfSmaller(HardLimits.maxBasal(), String.format(resourceHelper.gs(R.string.limitingbasalratio), HardLimits.maxBasal(), resourceHelper.gs(R.string.hardlimit)), this);
absoluteRate.setIfSmaller(getAapsLogger(), HardLimits.maxBasal(), String.format(resourceHelper.gs(R.string.limitingbasalratio), HardLimits.maxBasal(), resourceHelper.gs(R.string.hardlimit)), this);
PumpInterface pump = activePlugin.getActivePumpPlugin();
// check for pump max
if (pump != null && pump.getPumpDescription().tempBasalStyle == PumpDescription.ABSOLUTE) {
double pumpLimit = pump.getPumpDescription().pumpType.getTbrSettings().getMaxDose();
absoluteRate.setIfSmaller(pumpLimit, String.format(resourceHelper.gs(R.string.limitingbasalratio), pumpLimit, resourceHelper.gs(R.string.pumplimit)), this);
absoluteRate.setIfSmaller(getAapsLogger(), pumpLimit, String.format(resourceHelper.gs(R.string.limitingbasalratio), pumpLimit, resourceHelper.gs(R.string.pumplimit)), this);
}
// do rounding
if (pump != null && pump.getPumpDescription().tempBasalStyle == PumpDescription.ABSOLUTE) {
absoluteRate.set(Round.roundTo(absoluteRate.value(), pump.getPumpDescription().tempAbsoluteStep));
absoluteRate.set(getAapsLogger(), Round.roundTo(absoluteRate.value(), pump.getPumpDescription().tempAbsoluteStep));
}
return absoluteRate;
}
@ -192,11 +198,11 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
percentRateAfterConst = Round.floorTo((double) percentRateAfterConst, (double) pump.getPumpDescription().tempPercentStep).intValue();
}
percentRate.set(percentRateAfterConst, String.format(resourceHelper.gs(R.string.limitingpercentrate), percentRateAfterConst, resourceHelper.gs(R.string.pumplimit)), this);
percentRate.set(getAapsLogger(), percentRateAfterConst, String.format(resourceHelper.gs(R.string.limitingpercentrate), percentRateAfterConst, resourceHelper.gs(R.string.pumplimit)), this);
if (pump != null && pump.getPumpDescription().tempBasalStyle == PumpDescription.PERCENT) {
double pumpLimit = pump.getPumpDescription().pumpType.getTbrSettings().getMaxDose();
percentRate.setIfSmaller((int) pumpLimit, String.format(resourceHelper.gs(R.string.limitingbasalratio), pumpLimit, resourceHelper.gs(R.string.pumplimit)), this);
percentRate.setIfSmaller(getAapsLogger(), (int) pumpLimit, String.format(resourceHelper.gs(R.string.limitingbasalratio), pumpLimit, resourceHelper.gs(R.string.pumplimit)), this);
}
return percentRate;
@ -204,44 +210,44 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
@NonNull @Override
public Constraint<Double> applyBolusConstraints(Constraint<Double> insulin) {
insulin.setIfGreater(0d, String.format(resourceHelper.gs(R.string.limitingbolus), 0d, resourceHelper.gs(R.string.itmustbepositivevalue)), this);
insulin.setIfGreater(getAapsLogger(), 0d, String.format(resourceHelper.gs(R.string.limitingbolus), 0d, resourceHelper.gs(R.string.itmustbepositivevalue)), this);
Double maxBolus = sp.getDouble(R.string.key_treatmentssafety_maxbolus, 3d);
insulin.setIfSmaller(maxBolus, String.format(resourceHelper.gs(R.string.limitingbolus), maxBolus, resourceHelper.gs(R.string.maxvalueinpreferences)), this);
insulin.setIfSmaller(getAapsLogger(), maxBolus, String.format(resourceHelper.gs(R.string.limitingbolus), maxBolus, resourceHelper.gs(R.string.maxvalueinpreferences)), this);
insulin.setIfSmaller(HardLimits.maxBolus(), String.format(resourceHelper.gs(R.string.limitingbolus), HardLimits.maxBolus(), resourceHelper.gs(R.string.hardlimit)), this);
insulin.setIfSmaller(getAapsLogger(), HardLimits.maxBolus(), String.format(resourceHelper.gs(R.string.limitingbolus), HardLimits.maxBolus(), resourceHelper.gs(R.string.hardlimit)), this);
PumpInterface pump = activePlugin.getActivePumpPlugin();
if (pump != null) {
double rounded = pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulin.value());
insulin.setIfDifferent(rounded, resourceHelper.gs(R.string.pumplimit), this);
insulin.setIfDifferent(getAapsLogger(), rounded, resourceHelper.gs(R.string.pumplimit), this);
}
return insulin;
}
@NonNull @Override
public Constraint<Double> applyExtendedBolusConstraints(Constraint<Double> insulin) {
insulin.setIfGreater(0d, String.format(resourceHelper.gs(R.string.limitingextendedbolus), 0d, resourceHelper.gs(R.string.itmustbepositivevalue)), this);
insulin.setIfGreater(getAapsLogger(), 0d, String.format(resourceHelper.gs(R.string.limitingextendedbolus), 0d, resourceHelper.gs(R.string.itmustbepositivevalue)), this);
Double maxBolus = sp.getDouble(R.string.key_treatmentssafety_maxbolus, 3d);
insulin.setIfSmaller(maxBolus, String.format(resourceHelper.gs(R.string.limitingextendedbolus), maxBolus, resourceHelper.gs(R.string.maxvalueinpreferences)), this);
insulin.setIfSmaller(getAapsLogger(), maxBolus, String.format(resourceHelper.gs(R.string.limitingextendedbolus), maxBolus, resourceHelper.gs(R.string.maxvalueinpreferences)), this);
insulin.setIfSmaller(HardLimits.maxBolus(), String.format(resourceHelper.gs(R.string.limitingextendedbolus), HardLimits.maxBolus(), resourceHelper.gs(R.string.hardlimit)), this);
insulin.setIfSmaller(getAapsLogger(), HardLimits.maxBolus(), String.format(resourceHelper.gs(R.string.limitingextendedbolus), HardLimits.maxBolus(), resourceHelper.gs(R.string.hardlimit)), this);
PumpInterface pump = activePlugin.getActivePumpPlugin();
if (pump != null) {
double rounded = pump.getPumpDescription().pumpType.determineCorrectExtendedBolusSize(insulin.value());
insulin.setIfDifferent(rounded, resourceHelper.gs(R.string.pumplimit), this);
insulin.setIfDifferent(getAapsLogger(), rounded, resourceHelper.gs(R.string.pumplimit), this);
}
return insulin;
}
@NonNull @Override
public Constraint<Integer> applyCarbsConstraints(Constraint<Integer> carbs) {
carbs.setIfGreater(0, String.format(resourceHelper.gs(R.string.limitingcarbs), 0, resourceHelper.gs(R.string.itmustbepositivevalue)), this);
carbs.setIfGreater(getAapsLogger(), 0, String.format(resourceHelper.gs(R.string.limitingcarbs), 0, resourceHelper.gs(R.string.itmustbepositivevalue)), this);
Integer maxCarbs = sp.getInt(R.string.key_treatmentssafety_maxcarbs, 48);
carbs.setIfSmaller(maxCarbs, String.format(resourceHelper.gs(R.string.limitingcarbs), maxCarbs, resourceHelper.gs(R.string.maxvalueinpreferences)), this);
carbs.setIfSmaller(getAapsLogger(), maxCarbs, String.format(resourceHelper.gs(R.string.limitingcarbs), maxCarbs, resourceHelper.gs(R.string.maxvalueinpreferences)), this);
return carbs;
}
@ -253,14 +259,14 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
maxIobPref = sp.getDouble(R.string.key_openapssmb_max_iob, 3d);
else
maxIobPref = sp.getDouble(R.string.key_openapsma_max_iob, 1.5d);
maxIob.setIfSmaller(maxIobPref, String.format(resourceHelper.gs(R.string.limitingiob), maxIobPref, resourceHelper.gs(R.string.maxvalueinpreferences)), this);
maxIob.setIfSmaller(getAapsLogger(), maxIobPref, String.format(resourceHelper.gs(R.string.limitingiob), maxIobPref, resourceHelper.gs(R.string.maxvalueinpreferences)), this);
if (openAPSMAPlugin.isEnabled(PluginType.APS))
maxIob.setIfSmaller(HardLimits.maxIobAMA(), String.format(resourceHelper.gs(R.string.limitingiob), HardLimits.maxIobAMA(), resourceHelper.gs(R.string.hardlimit)), this);
maxIob.setIfSmaller(getAapsLogger(), HardLimits.maxIobAMA(), String.format(resourceHelper.gs(R.string.limitingiob), HardLimits.maxIobAMA(), resourceHelper.gs(R.string.hardlimit)), this);
if (openAPSAMAPlugin.isEnabled(PluginType.APS))
maxIob.setIfSmaller(HardLimits.maxIobAMA(), String.format(resourceHelper.gs(R.string.limitingiob), HardLimits.maxIobAMA(), resourceHelper.gs(R.string.hardlimit)), this);
maxIob.setIfSmaller(getAapsLogger(), HardLimits.maxIobAMA(), String.format(resourceHelper.gs(R.string.limitingiob), HardLimits.maxIobAMA(), resourceHelper.gs(R.string.hardlimit)), this);
if (openAPSSMBPlugin.isEnabled(PluginType.APS))
maxIob.setIfSmaller(HardLimits.maxIobSMB(), String.format(resourceHelper.gs(R.string.limitingiob), HardLimits.maxIobSMB(), resourceHelper.gs(R.string.hardlimit)), this);
maxIob.setIfSmaller(getAapsLogger(), HardLimits.maxIobSMB(), String.format(resourceHelper.gs(R.string.limitingiob), HardLimits.maxIobSMB(), resourceHelper.gs(R.string.hardlimit)), this);
return maxIob;
}

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.constraints.signatureVerifier
import android.content.Context
import android.content.pm.PackageManager
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.ConstraintsInterface
@ -9,14 +10,11 @@ import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.slf4j.LoggerFactory
import org.spongycastle.util.encoders.Hex
import java.io.*
import java.net.URL
@ -35,6 +33,7 @@ import javax.inject.Singleton
*/
@Singleton
class SignatureVerifierPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
private val sp: SP,
@ -46,13 +45,12 @@ class SignatureVerifierPlugin @Inject constructor(
.alwaysEnabled(true)
.showInList(false)
.pluginName(R.string.signature_verifier),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
), ConstraintsInterface {
private val REVOKED_CERTS_URL = "https://raw.githubusercontent.com/MilosKozak/AndroidAPS/master/app/src/main/assets/revoked_certs.txt"
private val UPDATE_INTERVAL = TimeUnit.DAYS.toMillis(1)
private val log = StacktraceLoggerWrapper.getLogger(L.CORE)
private val lock: Any = arrayOfNulls<Any>(0)
private var revokedCertsFile: File? = null
private var revokedCerts: List<ByteArray>? = null
@ -65,7 +63,7 @@ class SignatureVerifierPlugin @Inject constructor(
try {
downloadAndSaveRevokedCerts()
} catch (e: IOException) {
log.error("Could not download revoked certs", e)
aapsLogger.error("Could not download revoked certs", e)
}
}
if (hasIllegalSignature()) showNotification()
@ -75,14 +73,14 @@ class SignatureVerifierPlugin @Inject constructor(
override fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
if (hasIllegalSignature()) {
showNotification()
value.set(false)
value.set(aapsLogger, false)
}
if (shouldDownloadCerts()) {
Thread(Runnable {
try {
downloadAndSaveRevokedCerts()
} catch (e: IOException) {
log.error("Could not download revoked certs", e)
aapsLogger.error("Could not download revoked certs", e)
}
}).start()
}
@ -114,9 +112,9 @@ class SignatureVerifierPlugin @Inject constructor(
}
}
} catch (e: PackageManager.NameNotFoundException) {
log.error("Error in SignatureVerifierPlugin", e)
aapsLogger.error("Error in SignatureVerifierPlugin", e)
} catch (e: NoSuchAlgorithmException) {
log.error("Error in SignatureVerifierPlugin", e)
aapsLogger.error("Error in SignatureVerifierPlugin", e)
}
return false
}
@ -132,15 +130,15 @@ class SignatureVerifierPlugin @Inject constructor(
val digest = MessageDigest.getInstance("SHA256")
val fingerprint = digest.digest(signature.toByteArray())
val hash = Hex.toHexString(fingerprint)
log.debug("Found signature: $hash")
log.debug("Found signature (short): " + singleCharMap(fingerprint))
aapsLogger.debug("Found signature: $hash")
aapsLogger.debug("Found signature (short): " + singleCharMap(fingerprint))
hashes.add(singleCharMap(fingerprint))
}
}
} catch (e: PackageManager.NameNotFoundException) {
log.error("Error in SignatureVerifierPlugin", e)
aapsLogger.error("Error in SignatureVerifierPlugin", e)
} catch (e: NoSuchAlgorithmException) {
log.error("Error in SignatureVerifierPlugin", e)
aapsLogger.error("Error in SignatureVerifierPlugin", e)
}
return hashes
}
@ -181,7 +179,7 @@ class SignatureVerifierPlugin @Inject constructor(
if (revokedCerts == null) revokedCerts = readRevokedCertsInAssets()
synchronized(lock) { this.revokedCerts = parseRevokedCertsFile(revokedCerts) }
} catch (e: IOException) {
log.error("Error in SignatureVerifierPlugin", e)
aapsLogger.error("Error in SignatureVerifierPlugin", e)
}
}

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.constraints.storage
import android.os.Environment
import android.os.StatFs
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.Constraint
@ -21,6 +22,7 @@ import javax.inject.Singleton
@Singleton
open class StorageConstraintPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
private val rxBus: RxBusWrapper
@ -30,14 +32,14 @@ open class StorageConstraintPlugin @Inject constructor(
.alwaysEnabled(true)
.showInList(false)
.pluginName(R.string.storage),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
), ConstraintsInterface {
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
val diskFree = availableInternalMemorySize
aapsLogger.debug(LTag.CONSTRAINTS, "Internal storage free (Mb):$diskFree")
if (diskFree < Constants.MINIMUM_FREE_SPACE) {
value[false, resourceHelper.gs(R.string.diskfull, Constants.MINIMUM_FREE_SPACE)] = this
value[aapsLogger, false, resourceHelper.gs(R.string.diskfull, Constants.MINIMUM_FREE_SPACE)] = this
val notification = Notification(Notification.DISKFULL, resourceHelper.gs(R.string.diskfull, Constants.MINIMUM_FREE_SPACE), Notification.NORMAL)
rxBus.send(EventNewNotification(notification))
} else {

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.constraints.versionChecker
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.Constraint
@ -21,6 +22,7 @@ import kotlin.math.roundToInt
@Singleton
class VersionCheckerPlugin @Inject constructor(
injector: HasAndroidInjector,
private val sp: SP,
resourceHelper: ResourceHelper,
private val versionCheckerUtils: VersionCheckerUtils,
@ -32,7 +34,7 @@ class VersionCheckerPlugin @Inject constructor(
.alwaysEnabled(true)
.showInList(false)
.pluginName(R.string.versionChecker),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
), ConstraintsInterface {
enum class GracePeriod(val warning: Long, val old: Long, val veryOld: Long) {
@ -56,7 +58,7 @@ class VersionCheckerPlugin @Inject constructor(
checkWarning()
versionCheckerUtils.triggerCheckVersion()
return if (isOldVersion(gracePeriod.veryOld.daysToMillis()))
value.set(false, resourceHelper.gs(R.string.very_old_version), this)
value.set(aapsLogger,false, resourceHelper.gs(R.string.very_old_version), this)
else
value
}
@ -90,7 +92,7 @@ class VersionCheckerPlugin @Inject constructor(
override fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> =
if (isOldVersion(gracePeriod.old.daysToMillis()))
maxIob.set(0.toDouble(), resourceHelper.gs(R.string.old_version), this)
maxIob.set(aapsLogger, 0.0, resourceHelper.gs(R.string.old_version), this)
else
maxIob

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.general.actions
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.PluginBase
@ -11,7 +12,10 @@ import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class ActionsPlugin @Inject constructor(aapsLogger: AAPSLogger, resourceHelper: ResourceHelper
class ActionsPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper
) : PluginBase(PluginDescription()
.mainType(PluginType.GENERAL)
.fragmentClass(ActionsFragment::class.qualifiedName)
@ -20,5 +24,5 @@ class ActionsPlugin @Inject constructor(aapsLogger: AAPSLogger, resourceHelper:
.pluginName(R.string.actions)
.shortName(R.string.actions_shortname)
.description(R.string.description_actions),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
)

View file

@ -41,7 +41,7 @@ import javax.inject.Singleton
@Singleton
class AutomationPlugin @Inject constructor(
private val injector: HasAndroidInjector,
injector: HasAndroidInjector,
resourceHelper: ResourceHelper,
private val context: Context,
private val sp: SP,
@ -55,7 +55,8 @@ class AutomationPlugin @Inject constructor(
.pluginName(R.string.automation)
.shortName(R.string.automation_short)
.preferencesId(R.xml.pref_automation)
.description(R.string.automation_description), aapsLogger, resourceHelper
.description(R.string.automation_description),
aapsLogger, resourceHelper, injector
) {
private var disposable: CompositeDisposable = CompositeDisposable()

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.general.careportal
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.PluginBase
@ -11,7 +12,10 @@ import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class CareportalPlugin @Inject constructor(aapsLogger: AAPSLogger, resourceHelper: ResourceHelper
class CareportalPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper
) : PluginBase(PluginDescription()
.mainType(PluginType.GENERAL)
.fragmentClass(CareportalFragment::class.java.name)
@ -20,6 +24,5 @@ class CareportalPlugin @Inject constructor(aapsLogger: AAPSLogger, resourceHelpe
.visibleByDefault(Config.NSCLIENT)
.enableByDefault(Config.NSCLIENT)
.description(R.string.description_careportal),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
)

View file

@ -5,6 +5,7 @@ import android.content.Intent
import android.content.pm.ResolveInfo
import android.os.Bundle
import dagger.Lazy
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.IobTotal
@ -41,6 +42,7 @@ import javax.inject.Singleton
@Singleton
class DataBroadcastPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
private val context: Context,
@ -59,7 +61,7 @@ class DataBroadcastPlugin @Inject constructor(
.alwaysEnabled(true)
.neverVisible(true)
.showInList(false),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
) {
private val disposable = CompositeDisposable()

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.general.food
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription
@ -10,14 +11,17 @@ import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class FoodPlugin @Inject constructor(aapsLogger: AAPSLogger, resourceHelper: ResourceHelper
class FoodPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper
) : PluginBase(PluginDescription()
.mainType(PluginType.GENERAL)
.fragmentClass(FoodFragment::class.java.name)
.pluginName(R.string.food)
.shortName(R.string.food_short)
.description(R.string.description_food),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
) {
var service: FoodService? = null

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.maintenance
import android.content.Intent
import android.net.Uri
import androidx.core.content.FileProvider
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.MainApp
@ -23,6 +24,7 @@ import javax.inject.Singleton
@Singleton
class MaintenancePlugin @Inject constructor(
injector: HasAndroidInjector,
private val mainApp: MainApp,
resourceHelper: ResourceHelper,
private val sp: SP,
@ -37,7 +39,7 @@ class MaintenancePlugin @Inject constructor(
.shortName(R.string.maintenance_shortname)
.preferencesId(R.xml.pref_maintenance)
.description(R.string.description_maintenance),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
) {
fun sendLogs() {

View file

@ -15,7 +15,6 @@ import androidx.preference.PreferenceScreen;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
@ -23,6 +22,7 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
@ -73,10 +73,11 @@ public class NSClientPlugin extends PluginBase {
public NSClientService nsClientService = null;
private NsClientReceiverDelegate nsClientReceiverDelegate = new NsClientReceiverDelegate();
private NsClientReceiverDelegate nsClientReceiverDelegate = new NsClientReceiverDelegate();
@Inject
public NSClientPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
ResourceHelper resourceHelper
@ -88,7 +89,7 @@ public class NSClientPlugin extends PluginBase {
.shortName(R.string.nsclientinternal_shortname)
.preferencesId(R.xml.pref_nsclientinternal)
.description(R.string.description_ns_client),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
);
this.aapsLogger = aapsLogger;

View file

@ -14,6 +14,7 @@ import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
@ -457,8 +458,8 @@ public class NSDeviceStatus {
return Html.fromHtml(string.toString());
}
public static APSResult getAPSResult() {
APSResult result = new APSResult();
public static APSResult getAPSResult(HasAndroidInjector injector) {
APSResult result = new APSResult(injector);
result.json = deviceStatusOpenAPSData.suggested;
result.date = deviceStatusOpenAPSData.clockSuggested;
return result;

View file

@ -45,6 +45,7 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import dagger.android.support.DaggerFragment;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
@ -127,6 +128,7 @@ import io.reactivex.schedulers.Schedulers;
import static info.nightscout.androidaps.utils.DateUtil.now;
public class OverviewFragment extends DaggerFragment implements View.OnClickListener, View.OnLongClickListener {
@Inject HasAndroidInjector injector;
@Inject AAPSLogger aapsLogger;
@Inject SP sp;
@Inject RxBusWrapper rxBus;
@ -1400,7 +1402,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
if (Config.APS)
apsResult = loopPlugin.lastRun.constraintsProcessed;
else
apsResult = NSDeviceStatus.getAPSResult();
apsResult = NSDeviceStatus.getAPSResult(injector);
int predHours = (int) (Math.ceil(apsResult.getLatestPredictionsTime() - System.currentTimeMillis()) / (60 * 60 * 1000));
predHours = Math.min(2, predHours);
predHours = Math.max(0, predHours);

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.general.overview
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventRefreshOverview
import info.nightscout.androidaps.interfaces.PluginBase
@ -20,6 +21,7 @@ import javax.inject.Singleton
@Singleton
class OverviewPlugin @Inject constructor(
injector: HasAndroidInjector,
private val notificationStore: NotificationStore,
private val fabricPrivacy: FabricPrivacy,
private val rxBus: RxBusWrapper,
@ -33,7 +35,8 @@ class OverviewPlugin @Inject constructor(
.pluginName(R.string.overview)
.shortName(R.string.overview_shortname)
.preferencesId(R.xml.pref_overview)
.description(R.string.description_overview), aapsLogger, resourceHelper
.description(R.string.description_overview),
aapsLogger, resourceHelper, injector
) {
private var disposable: CompositeDisposable = CompositeDisposable()

View file

@ -9,6 +9,7 @@ import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.RemoteInput
import androidx.core.app.TaskStackBuilder
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.MainActivity
import info.nightscout.androidaps.MainApp
@ -35,6 +36,7 @@ import javax.inject.Singleton
@Singleton
class PersistentNotificationPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
private var profileFunction: ProfileFunction,
@ -52,7 +54,7 @@ class PersistentNotificationPlugin @Inject constructor(
.alwaysEnabled(true)
.showInList(false)
.description(R.string.description_persistent_notification),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
) {
// For Android Auto

View file

@ -7,6 +7,7 @@ import android.text.TextUtils
import androidx.preference.EditTextPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R
@ -46,6 +47,7 @@ import javax.inject.Singleton
@Singleton
class SmsCommunicatorPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
private val sp: SP,
@ -64,7 +66,7 @@ class SmsCommunicatorPlugin @Inject constructor(
.shortName(R.string.smscommunicator_shortname)
.preferencesId(R.xml.pref_smscommunicator)
.description(R.string.description_sms_communicator),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
) {
private val disposable = CompositeDisposable()

View file

@ -4,6 +4,7 @@ import android.content.Context
import android.text.Spanned
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventNetworkChange
@ -41,6 +42,7 @@ import javax.inject.Singleton
@Singleton
class TidepoolPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
private val rxBus: RxBusWrapper,
@ -56,7 +58,7 @@ class TidepoolPlugin @Inject constructor(
.fragmentClass(TidepoolFragment::class.qualifiedName)
.preferencesId(R.xml.pref_tidepool)
.description(R.string.description_tidepool),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
) {
private var disposable: CompositeDisposable = CompositeDisposable()

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.general.wear
import android.content.Intent
import dagger.Lazy
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.*
@ -26,6 +27,7 @@ import javax.inject.Singleton
@Singleton
class WearPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
private val sp: SP,
@ -41,7 +43,7 @@ class WearPlugin @Inject constructor(
.shortName(R.string.wear_shortname)
.preferencesId(R.xml.pref_wear)
.description(R.string.description_wear),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
) {
private val disposable = CompositeDisposable()

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.xdripStatusline
import android.content.Context
import android.content.Intent
import android.os.Bundle
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.events.*
@ -28,6 +29,7 @@ import javax.inject.Singleton
@Singleton
class StatusLinePlugin @Inject constructor(
injector: HasAndroidInjector,
private val sp: SP,
private val profileFunction: ProfileFunction,
resourceHelper: ResourceHelper,
@ -45,7 +47,9 @@ class StatusLinePlugin @Inject constructor(
.shortName(R.string.xdripstatus_shortname)
.neverVisible(true)
.preferencesId(R.xml.pref_xdripstatus)
.description(R.string.description_xdrip_status_line), aapsLogger, resourceHelper) {
.description(R.string.description_xdrip_status_line),
aapsLogger, resourceHelper, injector
) {
private val disposable = CompositeDisposable()
private var lastLoopStatus = false
@ -54,8 +58,10 @@ class StatusLinePlugin @Inject constructor(
//broadcast related constants
@Suppress("SpellCheckingInspection")
private const val EXTRA_STATUSLINE = "com.eveningoutpost.dexdrip.Extras.Statusline"
@Suppress("SpellCheckingInspection")
private const val ACTION_NEW_EXTERNAL_STATUSLINE = "com.eveningoutpost.dexdrip.ExternalStatusline"
@Suppress("SpellCheckingInspection", "unused")
private const val RECEIVER_PERMISSION = "com.eveningoutpost.dexdrip.permissions.RECEIVE_EXTERNAL_STATUSLINE"
}

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.insulin
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Iob
import info.nightscout.androidaps.interfaces.InsulinInterface
@ -21,6 +22,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
*
*/
abstract class InsulinOrefBasePlugin(
injector: HasAndroidInjector,
resourceHelper: ResourceHelper,
val profileFunction: ProfileFunction,
val rxBus: RxBusWrapper, aapsLogger: AAPSLogger
@ -29,7 +31,7 @@ abstract class InsulinOrefBasePlugin(
.fragmentClass(InsulinFragment::class.java.name)
.shortName(R.string.insulin_shortname)
.visibleByDefault(false),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
), InsulinInterface {
private var lastWarned: Long = 0

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.insulin
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.InsulinInterface
import info.nightscout.androidaps.logging.AAPSLogger
@ -15,11 +16,12 @@ import javax.inject.Singleton
*/
@Singleton
class InsulinOrefFreePeakPlugin @Inject constructor(
injector: HasAndroidInjector,
private val sp: SP,
resourceHelper: ResourceHelper,
profileFunction: ProfileFunction,
rxBus: RxBusWrapper, aapsLogger: AAPSLogger
) : InsulinOrefBasePlugin(resourceHelper, profileFunction, rxBus, aapsLogger) {
) : InsulinOrefBasePlugin(injector, resourceHelper, profileFunction, rxBus, aapsLogger) {
override fun getId(): Int {
return InsulinInterface.OREF_FREE_PEAK

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.insulin
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.InsulinInterface
import info.nightscout.androidaps.logging.AAPSLogger
@ -14,10 +15,11 @@ import javax.inject.Singleton
*/
@Singleton
class InsulinOrefRapidActingPlugin @Inject constructor(
injector: HasAndroidInjector,
resourceHelper: ResourceHelper,
profileFunction: ProfileFunction,
rxBus: RxBusWrapper, aapsLogger: AAPSLogger
) : InsulinOrefBasePlugin(resourceHelper, profileFunction, rxBus, aapsLogger) {
) : InsulinOrefBasePlugin(injector, resourceHelper, profileFunction, rxBus, aapsLogger) {
override fun getId(): Int {

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.insulin
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.InsulinInterface
import info.nightscout.androidaps.logging.AAPSLogger
@ -14,10 +15,11 @@ import javax.inject.Singleton
*/
@Singleton
class InsulinOrefUltraRapidActingPlugin @Inject constructor(
injector: HasAndroidInjector,
resourceHelper: ResourceHelper,
profileFunction: ProfileFunction,
rxBus: RxBusWrapper, aapsLogger: AAPSLogger
) : InsulinOrefBasePlugin(resourceHelper, profileFunction, rxBus, aapsLogger) {
) : InsulinOrefBasePlugin(injector, resourceHelper, profileFunction, rxBus, aapsLogger) {
override fun getId(): Int = InsulinInterface.OREF_ULTRA_RAPID_ACTING

View file

@ -1,8 +1,5 @@
package info.nightscout.androidaps.plugins.iob.iobCobCalculator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@ -13,8 +10,8 @@ import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface;
@ -28,8 +25,8 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
public class AutosensData implements DataPointWithLabelInterface {
private static Logger log = StacktraceLoggerWrapper.getLogger(L.AUTOSENS);
@Inject AAPSLogger aapsLogger;
@Inject SP sp;
@Inject ResourceHelper resourceHelper;
@Inject SensitivityWeightedAveragePlugin sensitivityWeightedAveragePlugin;
@ -60,8 +57,7 @@ public class AutosensData implements DataPointWithLabelInterface {
double sens = profile.getIsfMgdl(t.date);
double ic = profile.getIc(t.date);
min5minCarbImpact = t.carbs / (maxAbsorptionHours * 60 / 5) * sens / ic;
if (L.isEnabled(L.AUTOSENS))
log.debug("Min 5m carbs impact for " + carbs + "g @" + DateUtil.dateAndTimeString(t.date) + " for " + maxAbsorptionHours + "h calculated to " + min5minCarbImpact + " ISF: " + sens + " IC: " + ic);
aapsLogger.debug(LTag.AUTOSENS, "Min 5m carbs impact for " + carbs + "g @" + DateUtil.dateAndTimeString(t.date) + " for " + maxAbsorptionHours + "h calculated to " + min5minCarbImpact + " ISF: " + sens + " IC: " + ic);
} else {
min5minCarbImpact = sp.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact);
}
@ -139,8 +135,7 @@ public class AutosensData implements DataPointWithLabelInterface {
activeCarbsList.remove(i--);
if (c.remaining > 0)
cob -= c.remaining;
if (L.isEnabled(L.AUTOSENS))
log.debug("Removing carbs at " + DateUtil.dateAndTimeString(toTime) + " after " + maxAbsorptionHours + "h > " + c.toString());
aapsLogger.debug(LTag.AUTOSENS, "Removing carbs at " + DateUtil.dateAndTimeString(toTime) + " after " + maxAbsorptionHours + "h > " + c.toString());
}
}
}

View file

@ -110,7 +110,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
.showInList(false)
.neverVisible(true)
.alwaysEnabled(true),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
);
this.plugin = this;
this.injector = injector;

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.profile.local
import android.app.Activity
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Profile
@ -31,6 +32,7 @@ import kotlin.math.max
@Singleton
class LocalProfilePlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
private val rxBus: RxBusWrapper,
resourceHelper: ResourceHelper,
@ -42,7 +44,9 @@ class LocalProfilePlugin @Inject constructor(
.enableByDefault(true)
.pluginName(R.string.localprofile)
.shortName(R.string.localprofile_shortname)
.description(R.string.description_profile_local), aapsLogger, resourceHelper), ProfileInterface {
.description(R.string.description_profile_local),
aapsLogger, resourceHelper, injector
), ProfileInterface {
var rawProfile: ProfileStore? = null

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.profile.ns
import android.content.Intent
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.ProfileStore
@ -22,6 +23,7 @@ import javax.inject.Singleton
@Singleton
class NSProfilePlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
private val rxBus: RxBusWrapper,
resourceHelper: ResourceHelper,
@ -35,7 +37,7 @@ class NSProfilePlugin @Inject constructor(
.alwaysVisible(Config.NSCLIENT)
.showInList(!Config.NSCLIENT)
.description(R.string.description_profile_nightscout),
aapsLogger, resourceHelper
aapsLogger, resourceHelper, injector
), ProfileInterface {
private var profile: ProfileStore? = null
@ -47,6 +49,7 @@ class NSProfilePlugin @Inject constructor(
fun handleNewData(intent: Intent) {
val bundles = intent.extras ?: return
@Suppress("SpellCheckingInspection")
val activeProfile = bundles.getString("activeprofile")
val profileString = bundles.getString("profile")

View file

@ -7,7 +7,6 @@ import androidx.annotation.Nullable;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Calendar;
@ -20,6 +19,7 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
@ -138,6 +138,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
@Inject
public ComboPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
MainApp maiApp,
@ -154,7 +155,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
.pluginName(R.string.combopump)
.shortName(R.string.combopump_shortname)
.description(R.string.description_pump_combo),
aapsLogger, resourceHelper, commandQueue
injector, aapsLogger, resourceHelper, commandQueue
);
this.rxBus = rxBus;
this.resourceHelper = resourceHelper;
@ -1391,14 +1392,14 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
@Override
public Constraint<Boolean> isLoopInvocationAllowed(Constraint<Boolean> value) {
if (!validBasalRateProfileSelectedOnPump)
value.set(false, MainApp.gs(R.string.novalidbasalrate), this);
value.set(getAapsLogger(), false, MainApp.gs(R.string.novalidbasalrate), this);
return value;
}
@Override
public Constraint<Double> applyMaxIOBConstraints(Constraint<Double> maxIob) {
if (lowSuspendOnlyLoopEnforcedUntil > System.currentTimeMillis())
maxIob.setIfSmaller(0d, String.format(MainApp.gs(R.string.limitingmaxiob), 0d, MainApp.gs(R.string.unsafeusage)), this);
maxIob.setIfSmaller(getAapsLogger(), 0d, String.format(MainApp.gs(R.string.limitingmaxiob), 0d, MainApp.gs(R.string.unsafeusage)), this);
return maxIob;
}

View file

@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory;
import java.util.Date;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
@ -71,9 +72,9 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
protected boolean displayConnectionMessages = false;
protected PumpPluginAbstract(PluginDescription pluginDescription, PumpType pumpType, ResourceHelper resourceHelper, AAPSLogger aapsLogger, CommandQueueProvider commandQueue) {
protected PumpPluginAbstract(PluginDescription pluginDescription, PumpType pumpType, HasAndroidInjector injector, ResourceHelper resourceHelper, AAPSLogger aapsLogger, CommandQueueProvider commandQueue) {
super(pluginDescription, aapsLogger, resourceHelper, commandQueue);
super(pluginDescription, injector, aapsLogger, resourceHelper, commandQueue);
pumpDescription.setPumpDescription(pumpType);

View file

@ -5,11 +5,11 @@ import androidx.annotation.NonNull;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.List;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
@ -28,7 +28,6 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.PumpPluginBase;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.common.ManufacturerType;
@ -60,10 +59,13 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
public PumpDescription pumpDescription = new PumpDescription();
protected DanaRPump danaRPump;
protected ConstraintChecker constraintChecker;
protected AbstractDanaRPlugin(
HasAndroidInjector injector,
DanaRPump danaRPump,
ResourceHelper resourceHelper,
ConstraintChecker constraintChecker,
AAPSLogger aapsLogger,
CommandQueueProvider commandQueue) {
super(new PluginDescription()
@ -73,9 +75,10 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
.shortName(R.string.danarpump_shortname)
.preferencesId(R.xml.pref_danars)
.description(R.string.description_pump_dana_r),
aapsLogger, resourceHelper, commandQueue
injector, aapsLogger, resourceHelper, commandQueue
);
this.danaRPump = danaRPump;
this.constraintChecker = constraintChecker;
}
@Override
@ -178,7 +181,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
DanaRPump pump = danaRPump;
PumpEnactResult result = new PumpEnactResult();
percent = ConstraintChecker.getInstance().applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
percent = constraintChecker.applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
if (percent < 0) {
result.isTempCancel = false;
result.enacted = false;
@ -227,7 +230,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
@NonNull @Override
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
DanaRPump pump = danaRPump;
insulin = ConstraintChecker.getInstance().applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
// needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
@ -408,21 +411,21 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
@Override
public Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, Profile profile) {
absoluteRate.setIfSmaller(danaRPump.getMaxBasal(), String.format(MainApp.gs(R.string.limitingbasalratio), danaRPump.getMaxBasal(), MainApp.gs(R.string.pumplimit)), this);
absoluteRate.setIfSmaller(getAapsLogger(), danaRPump.getMaxBasal(), String.format(MainApp.gs(R.string.limitingbasalratio), danaRPump.getMaxBasal(), MainApp.gs(R.string.pumplimit)), this);
return absoluteRate;
}
@Override
public Constraint<Integer> applyBasalPercentConstraints(Constraint<Integer> percentRate, Profile profile) {
percentRate.setIfGreater(0, String.format(MainApp.gs(R.string.limitingpercentrate), 0, MainApp.gs(R.string.itmustbepositivevalue)), this);
percentRate.setIfSmaller(getPumpDescription().maxTempPercent, String.format(MainApp.gs(R.string.limitingpercentrate), getPumpDescription().maxTempPercent, MainApp.gs(R.string.pumplimit)), this);
percentRate.setIfGreater(getAapsLogger(), 0, String.format(MainApp.gs(R.string.limitingpercentrate), 0, MainApp.gs(R.string.itmustbepositivevalue)), this);
percentRate.setIfSmaller(getAapsLogger(), getPumpDescription().maxTempPercent, String.format(MainApp.gs(R.string.limitingpercentrate), getPumpDescription().maxTempPercent, MainApp.gs(R.string.pumplimit)), this);
return percentRate;
}
@Override
public Constraint<Double> applyBolusConstraints(Constraint<Double> insulin) {
insulin.setIfSmaller(danaRPump.getMaxBolus(), String.format(MainApp.gs(R.string.limitingbolus), danaRPump.getMaxBolus(), MainApp.gs(R.string.pumplimit)), this);
insulin.setIfSmaller(getAapsLogger(), danaRPump.getMaxBolus(), String.format(MainApp.gs(R.string.limitingbolus), danaRPump.getMaxBolus(), MainApp.gs(R.string.pumplimit)), this);
return insulin;
}

View file

@ -11,6 +11,7 @@ import androidx.annotation.NonNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
@ -28,7 +29,6 @@ import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStartWithSpeed;
import info.nightscout.androidaps.plugins.pump.danaR.services.DanaRExecutionService;
import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
@ -53,6 +53,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
@Inject
public DanaRPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
MainApp maiApp,
@ -63,7 +64,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
CommandQueueProvider commandQueue,
DanaRPump danaRPump
) {
super(danaRPump, resourceHelper, aapsLogger, commandQueue);
super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue);
this.aapsLogger = aapsLogger;
this.rxBus = rxBus;
this.mainApp = maiApp;
@ -171,7 +172,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
result.bolusDelivered = t.insulin;
result.carbsDelivered = detailedBolusInfo.carbs;
if (!result.success)
result.comment = String.format(resourceHelper.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, MsgBolusStartWithSpeed.errorCode);
result.comment = String.format(resourceHelper.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, danaRPump.getMessageStartErrorCode());
else
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
@ -293,7 +294,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
extendedRateToSet = Round.roundTo(extendedRateToSet, pumpDescription.extendedBolusStep * 2); // *2 because of halfhours
// What is current rate of extended bolusing in u/h?
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Extended bolus in progress: " + (activeExtended != null) + " rate: " + danaRPump.getExtendedBolusAbsoluteRate()+ "U/h duration remaining: " + danaRPump.getExtendedBolusRemainingMinutes() + "min");
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Extended bolus in progress: " + (activeExtended != null) + " rate: " + danaRPump.getExtendedBolusAbsoluteRate() + "U/h duration remaining: " + danaRPump.getExtendedBolusRemainingMinutes() + "min");
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h");
// Compare with extended rate in progress

View file

@ -113,6 +113,9 @@ class DanaRPump @Inject constructor(
return if (units == UNITS_MGDL) Constants.MGDL else Constants.MMOL
}
// last start bolus erroCode
var messageStartErrorCode: Int = 0
fun createConvertedProfile(): ProfileStore? {
pumpProfiles?.let {
val json = JSONObject()

View file

@ -5,6 +5,7 @@ import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
@ -18,6 +19,7 @@ class MessageHashTableR @Inject constructor(
aapsLogger: AAPSLogger,
rxBus: RxBusWrapper,
resourceHelper: ResourceHelper,
constraintChecker: ConstraintChecker,
danaRPump: DanaRPump,
danaRPlugin: DanaRPlugin,
danaRKoreanPlugin: DanaRKoreanPlugin,
@ -30,8 +32,8 @@ class MessageHashTableR @Inject constructor(
init {
put(MsgBolusStop()) // 0x0101 CMD_MEALINS_STOP
put(MsgBolusStart()) // 0x0102 CMD_MEALINS_START_DATA
put(MsgBolusStartWithSpeed()) // 0x0104 CMD_MEALINS_START_DATA_SPEED
put(MsgBolusStart(aapsLogger, constraintChecker, danaRPump, 0.0)) // 0x0102 CMD_MEALINS_START_DATA
put(MsgBolusStartWithSpeed(aapsLogger, constraintChecker, danaRPump, 0.0, 0)) // 0x0104 CMD_MEALINS_START_DATA_SPEED
put(MsgBolusProgress()) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
put(MsgStatusProfile(aapsLogger, danaRPump)) // 0x0204 CMD_PUMP_CALCULATION_SETTING
put(MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin)) // 0x0205 CMD_PUMP_EXERCISE_MODE
@ -47,7 +49,7 @@ class MessageHashTableR @Inject constructor(
put(MsgSetCarbsEntry()) // 0x0402 CMD_PUMPSET_HIS_S
put(MsgSetTempBasalStop()) // 0x0403 CMD_PUMPSET_EXERCISE_STOP
put(MsgSetExtendedBolusStop()) // 0x0406 CMD_PUMPSET_EXPANS_INS_STOP
put(MsgSetExtendedBolusStart()) // 0x0407 CMD_PUMPSET_EXPANS_INS_S
put(MsgSetExtendedBolusStart(aapsLogger, constraintChecker, 0.0, 0)) // 0x0407 CMD_PUMPSET_EXPANS_INS_S
put(MsgError()) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS
put(MsgPCCommStart()) // 0x3001 CMD_CONNECT
put(MsgPCCommStop()) // 0x3002 CMD_DISCONNECT

View file

@ -1,44 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
public class MsgBolusStart extends MessageBase {
private static Logger log = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
public static int errorCode;
public MsgBolusStart() {
SetCommand(0x0102);
}
public MsgBolusStart(double amount) {
this();
// HARDCODED LIMIT
amount = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(amount)).value();
AddParamInt((int) (amount * 100));
if (L.isEnabled(L.PUMPCOMM))
log.debug("Bolus start : " + amount);
}
@Override
public void handleMessage(byte[] bytes) {
errorCode = intFromBuff(bytes, 0, 1);
if (errorCode != 2) {
failed = true;
if (L.isEnabled(L.PUMPCOMM))
log.debug("Messsage response: " + errorCode + " FAILED!!");
} else {
if (L.isEnabled(L.PUMPCOMM))
log.debug("Messsage response: " + errorCode + " OK");
}
}
}

View file

@ -0,0 +1,35 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
class MsgBolusStart(
private val aapsLogger: AAPSLogger,
constraintChecker: ConstraintChecker,
private val danaRPump: DanaRPump,
private var amount: Double
) : MessageBase() {
init {
SetCommand(0x0102)
// HARDCODED LIMIT
amount = constraintChecker.applyBolusConstraints(Constraint(amount)).value()
AddParamInt((amount * 100).toInt())
aapsLogger.debug(LTag.PUMPBTCOMM, "Bolus start : $amount")
}
override fun handleMessage(bytes: ByteArray) {
val errorCode = intFromBuff(bytes, 0, 1)
if (errorCode != 2) {
failed = true
aapsLogger.debug(LTag.PUMPBTCOMM, "Messsage response: $errorCode FAILED!!")
} else {
aapsLogger.debug(LTag.PUMPBTCOMM, "Messsage response: $errorCode OK")
}
danaRPump.messageStartErrorCode = errorCode
}
}

View file

@ -1,45 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
public class MsgBolusStartWithSpeed extends MessageBase {
private static Logger log = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
public static int errorCode;
public MsgBolusStartWithSpeed() {
SetCommand(0x0104);
}
public MsgBolusStartWithSpeed(double amount, int speed) {
this();
// HARDCODED LIMIT
amount = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(amount)).value();
AddParamInt((int) (amount * 100));
AddParamByte((byte) speed);
if (L.isEnabled(L.PUMPCOMM))
log.debug("Bolus start : " + amount + " speed: " + speed);
}
@Override
public void handleMessage(byte[] bytes) {
errorCode = intFromBuff(bytes, 0, 1);
if (errorCode != 2) {
failed = true;
if (L.isEnabled(L.PUMPCOMM))
log.debug("Messsage response: " + errorCode + " FAILED!!");
} else {
if (L.isEnabled(L.PUMPCOMM))
log.debug("Messsage response: " + errorCode + " OK");
}
}
}

View file

@ -0,0 +1,37 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
class MsgBolusStartWithSpeed(
private val aapsLogger: AAPSLogger,
constraintChecker: ConstraintChecker,
private val danaRPump: DanaRPump,
private var amount: Double,
speed: Int
) : MessageBase() {
init {
SetCommand(0x0104)
// HARDCODED LIMIT
amount = constraintChecker.applyBolusConstraints(Constraint(amount)).value()
AddParamInt((amount * 100).toInt())
AddParamByte(speed.toByte())
aapsLogger.debug(LTag.PUMPBTCOMM, "Bolus start : $amount speed: $speed")
}
override fun handleMessage(bytes: ByteArray) {
val errorCode = intFromBuff(bytes, 0, 1)
if (errorCode != 2) {
failed = true
aapsLogger.debug(LTag.PUMPBTCOMM, "Messsage response: $errorCode FAILED!!")
} else {
aapsLogger.debug(LTag.PUMPBTCOMM, "Messsage response: $errorCode OK")
}
danaRPump.messageStartErrorCode = errorCode
}
}

View file

@ -1,45 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
public class MsgSetExtendedBolusStart extends MessageBase {
private static Logger log = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
public MsgSetExtendedBolusStart() {
SetCommand(0x0407);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public MsgSetExtendedBolusStart(double amount, byte halfhours) {
this();
// HARDCODED LIMITS
if (halfhours < 1) halfhours = 1;
if (halfhours > 16) halfhours = 16;
Constraint<Double> constrainedAmount = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(amount));
AddParamInt((int) (constrainedAmount.value() * 100));
AddParamByte(halfhours);
if (L.isEnabled(L.PUMPCOMM))
log.debug("Set extended bolus start: " + (((int) (amount * 100)) / 100d) + "U halfhours: " + (int) halfhours);
}
@Override
public void handleMessage(byte[] bytes) {
int result = intFromBuff(bytes, 0, 1);
if (result != 1) {
failed = true;
if (L.isEnabled(L.PUMPCOMM))
log.debug("Set extended bolus start result: " + result + " FAILED!!!");
} else {
if (L.isEnabled(L.PUMPCOMM))
log.debug("Set extended bolus start result: " + result);
}
}
}

View file

@ -0,0 +1,37 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
class MsgSetExtendedBolusStart(
private val aapsLogger: AAPSLogger,
constraintChecker: ConstraintChecker,
private var amount: Double,
private var halfhours: Byte
) : MessageBase() {
init {
SetCommand(0x0407)
aapsLogger.debug(LTag.PUMPBTCOMM, "New message")
// HARDCODED LIMITS
if (halfhours < 1) halfhours = 1
if (halfhours > 16) halfhours = 16
amount = constraintChecker.applyBolusConstraints(Constraint(amount)).value()
AddParamInt((amount * 100).toInt())
AddParamByte(halfhours)
aapsLogger.debug(LTag.PUMPBTCOMM, "Set extended bolus start: " + (amount * 100).toInt() / 100.0 + "U halfhours: " + halfhours.toInt())
}
override fun handleMessage(bytes: ByteArray) {
val result = intFromBuff(bytes, 0, 1)
if (result != 1) {
failed = true
aapsLogger.debug(LTag.PUMPBTCOMM, "Set extended bolus start result: $result FAILED!!!")
} else {
aapsLogger.debug(LTag.PUMPBTCOMM, "Set extended bolus start result: $result")
}
}
}

View file

@ -27,6 +27,7 @@ import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
@ -81,6 +82,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
@Inject AAPSLogger aapsLogger;
@Inject RxBusWrapper rxBus;
@Inject ResourceHelper resourceHelper;
@Inject ConstraintChecker constraintChecker;
@Inject DanaRPump danaRPump;
@Inject DanaRPlugin danaRPlugin;
@Inject DanaRKoreanPlugin danaRKoreanPlugin;
@ -287,7 +289,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
public boolean extendedBolus(double insulin, int durationInHalfHours) {
if (!isConnected()) return false;
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(aapsLogger, constraintChecker, insulin, (byte) (durationInHalfHours & 0xFF)));
mSerialIOThread.sendMessage(new MsgStatusBolusExtended(aapsLogger, danaRPump, activePlugin));
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
return true;
@ -315,9 +317,9 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
MessageBase start;
if (preferencesSpeed == 0)
start = new MsgBolusStart(amount);
start = new MsgBolusStart(aapsLogger, constraintChecker, danaRPump, amount);
else
start = new MsgBolusStartWithSpeed(amount, preferencesSpeed);
start = new MsgBolusStartWithSpeed(aapsLogger, constraintChecker, danaRPump, amount, preferencesSpeed);
MsgBolusStop stop = new MsgBolusStop(amount, t);
if (carbs > 0) {

View file

@ -11,6 +11,7 @@ import androidx.annotation.NonNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
@ -30,7 +31,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.danaR.AbstractDanaRPlugin;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStart;
import info.nightscout.androidaps.plugins.pump.danaRKorean.services.DanaRKoreanExecutionService;
import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
@ -55,6 +55,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
@Inject
public DanaRKoreanPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
DanaRPump danaRPump,
@ -66,7 +67,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
CommandQueueProvider commandQueue
) {
super(danaRPump, resourceHelper, aapsLogger, commandQueue);
super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue);
this.aapsLogger = aapsLogger;
this.rxBus = rxBus;
this.mainApp = maiApp;
@ -174,7 +175,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
result.bolusDelivered = t.insulin;
result.carbsDelivered = detailedBolusInfo.carbs;
if (!result.success)
result.comment = resourceHelper.gs(R.string.boluserrorcode, detailedBolusInfo.insulin, t.insulin, MsgBolusStart.errorCode);
result.comment = resourceHelper.gs(R.string.boluserrorcode, detailedBolusInfo.insulin, t.insulin, danaRPump.getMessageStartErrorCode());
else
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);

View file

@ -5,6 +5,7 @@ import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.*
@ -19,6 +20,7 @@ class MessageHashTableRKorean @Inject constructor(
aapsLogger: AAPSLogger,
rxBus: RxBusWrapper,
resourceHelper: ResourceHelper,
constraintChecker: ConstraintChecker,
danaRPump: DanaRPump,
danaRPlugin: DanaRPlugin,
danaRKoreanPlugin: DanaRKoreanPlugin,
@ -31,7 +33,7 @@ class MessageHashTableRKorean @Inject constructor(
init {
put(MsgBolusStop()) // 0x0101 CMD_MEALINS_STOP
put(MsgBolusStart()) // 0x0102 CMD_MEALINS_START_DATA
put(MsgBolusStart(aapsLogger, constraintChecker, danaRPump, 0.0)) // 0x0102 CMD_MEALINS_START_DATA
put(MsgBolusProgress()) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
put(MsgStatusProfile(aapsLogger, danaRPump)) // 0x0204 CMD_PUMP_CALCULATION_SETTING
put(MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin)) // 0x0205 CMD_PUMP_EXERCISE_MODE
@ -45,7 +47,7 @@ class MessageHashTableRKorean @Inject constructor(
put(MsgSetCarbsEntry()) // 0x0402 CMD_PUMPSET_HIS_S
put(MsgSetTempBasalStop()) // 0x0403 CMD_PUMPSET_EXERCISE_STOP
put(MsgSetExtendedBolusStop()) // 0x0406 CMD_PUMPSET_EXPANS_INS_STOP
put(MsgSetExtendedBolusStart()) // 0x0407 CMD_PUMPSET_EXPANS_INS_S
put(MsgSetExtendedBolusStart(aapsLogger, constraintChecker, 0.0, 0)) // 0x0407 CMD_PUMPSET_EXPANS_INS_S
put(MsgError()) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS
put(MsgPCCommStart()) // 0x3001 CMD_CONNECT
put(MsgPCCommStop()) // 0x3002 CMD_DISCONNECT

View file

@ -11,7 +11,6 @@ class MsgSettingBasal_k(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump,
private val danaRKoreanPlugin: DanaRKoreanPlugin
) : MessageBase() {
init {

View file

@ -27,6 +27,7 @@ import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
@ -73,6 +74,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
@Inject AAPSLogger aapsLogger;
@Inject RxBusWrapper rxBus;
@Inject ResourceHelper resourceHelper;
@Inject ConstraintChecker constraintChecker;
@Inject DanaRPump danaRPump;
@Inject DanaRPlugin danaRPlugin;
@Inject DanaRKoreanPlugin danaRKoreanPlugin;
@ -277,7 +279,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
public boolean extendedBolus(double insulin, int durationInHalfHours) {
if (!isConnected()) return false;
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(aapsLogger, constraintChecker, insulin, (byte) (durationInHalfHours & 0xFF)));
mSerialIOThread.sendMessage(new MsgStatusBolusExtended(aapsLogger, danaRPump, activePlugin));
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
return true;
@ -302,7 +304,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
if (BolusProgressDialog.stopPressed) return false;
mBolusingTreatment = t;
MsgBolusStart start = new MsgBolusStart(amount);
MsgBolusStart start = new MsgBolusStart(aapsLogger, constraintChecker, danaRPump, amount);
MsgBolusStop stop = new MsgBolusStop(amount, t);
if (carbs > 0) {

View file

@ -18,6 +18,7 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
@ -99,6 +100,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
@Inject
public DanaRSPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
Context context,
@ -117,7 +119,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
.shortName(R.string.danarspump_shortname)
.preferencesId(R.xml.pref_danars)
.description(R.string.description_pump_dana_rs),
aapsLogger, resourceHelper, commandQueue
injector, aapsLogger, resourceHelper, commandQueue
);
this.context = context;
this.rxBus = rxBus;
@ -257,15 +259,15 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
@NonNull
@Override
public Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, @NonNull Profile profile) {
absoluteRate.setIfSmaller(danaRPump.getMaxBasal(), resourceHelper.gs(R.string.limitingbasalratio, danaRPump.getMaxBasal(), resourceHelper.gs(R.string.pumplimit)), this);
absoluteRate.setIfSmaller(getAapsLogger(), danaRPump.getMaxBasal(), resourceHelper.gs(R.string.limitingbasalratio, danaRPump.getMaxBasal(), resourceHelper.gs(R.string.pumplimit)), this);
return absoluteRate;
}
@NonNull
@Override
public Constraint<Integer> applyBasalPercentConstraints(Constraint<Integer> percentRate, @NonNull Profile profile) {
percentRate.setIfGreater(0, resourceHelper.gs(R.string.limitingpercentrate, 0, resourceHelper.gs(R.string.itmustbepositivevalue)), this);
percentRate.setIfSmaller(getPumpDescription().maxTempPercent, resourceHelper.gs(R.string.limitingpercentrate, getPumpDescription().maxTempPercent, resourceHelper.gs(R.string.pumplimit)), this);
percentRate.setIfGreater(getAapsLogger(), 0, resourceHelper.gs(R.string.limitingpercentrate, 0, resourceHelper.gs(R.string.itmustbepositivevalue)), this);
percentRate.setIfSmaller(getAapsLogger(), getPumpDescription().maxTempPercent, resourceHelper.gs(R.string.limitingpercentrate, getPumpDescription().maxTempPercent, resourceHelper.gs(R.string.pumplimit)), this);
return percentRate;
}
@ -274,7 +276,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
@NonNull
@Override
public Constraint<Double> applyBolusConstraints(Constraint<Double> insulin) {
insulin.setIfSmaller(danaRPump.getMaxBolus(), resourceHelper.gs(R.string.limitingbolus, danaRPump.getMaxBolus(), resourceHelper.gs(R.string.pumplimit)), this);
insulin.setIfSmaller(getAapsLogger(), danaRPump.getMaxBolus(), resourceHelper.gs(R.string.limitingbolus, danaRPump.getMaxBolus(), resourceHelper.gs(R.string.pumplimit)), this);
return insulin;
}

View file

@ -11,6 +11,7 @@ import androidx.annotation.NonNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
@ -55,6 +56,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
@Inject
public DanaRv2Plugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
MainApp maiApp,
@ -66,7 +68,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
CommandQueueProvider commandQueue
) {
super(danaRPump, resourceHelper, aapsLogger, commandQueue);
super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue);
this.aapsLogger = aapsLogger;
this.rxBus = rxBus;
this.mainApp = maiApp;
@ -188,7 +190,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
result.bolusDelivered = t.insulin;
result.carbsDelivered = detailedBolusInfo.carbs;
if (!result.success)
result.comment = String.format(resourceHelper.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, MsgBolusStartWithSpeed.errorCode);
result.comment = String.format(resourceHelper.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, danaRPump.getMessageStartErrorCode());
else
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);

View file

@ -5,6 +5,7 @@ import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.*
@ -20,6 +21,7 @@ class MessageHashTableRv2 @Inject constructor(
aapsLogger: AAPSLogger,
rxBus: RxBusWrapper,
resourceHelper: ResourceHelper,
constraintChecker: ConstraintChecker,
danaRPump: DanaRPump,
danaRPlugin: DanaRPlugin,
danaRKoreanPlugin: DanaRKoreanPlugin,
@ -33,8 +35,8 @@ class MessageHashTableRv2 @Inject constructor(
init {
put(MsgBolusStop()) // 0x0101 CMD_MEALINS_STOP
put(MsgBolusStart()) // 0x0102 CMD_MEALINS_START_DATA
put(MsgBolusStartWithSpeed()) // 0x0104 CMD_MEALINS_START_DATA_SPEED
put(MsgBolusStart(aapsLogger, constraintChecker, danaRPump, 0.0)) // 0x0102 CMD_MEALINS_START_DATA
put(MsgBolusStartWithSpeed(aapsLogger, constraintChecker, danaRPump, 0.0, 0)) // 0x0104 CMD_MEALINS_START_DATA_SPEED
put(MsgBolusProgress()) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
put(MsgStatusProfile(aapsLogger, danaRPump)) // 0x0204 CMD_PUMP_CALCULATION_SETTING
put(MsgStatusTempBasal_v2(aapsLogger, danaRPump)) // 0x0205 CMD_PUMP_EXERCISE_MODE
@ -49,7 +51,7 @@ class MessageHashTableRv2 @Inject constructor(
put(MsgSetCarbsEntry()) // 0x0402 CMD_PUMPSET_HIS_S
put(MsgSetTempBasalStop()) // 0x0403 CMD_PUMPSET_EXERCISE_STOP
put(MsgSetExtendedBolusStop()) // 0x0406 CMD_PUMPSET_EXPANS_INS_STOP
put(MsgSetExtendedBolusStart()) // 0x0407 CMD_PUMPSET_EXPANS_INS_S
put(MsgSetExtendedBolusStart(aapsLogger, constraintChecker, 0.0, 0)) // 0x0407 CMD_PUMPSET_EXPANS_INS_S
put(MsgError()) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS
put(MsgPCCommStart()) // 0x3001 CMD_CONNECT
put(MsgPCCommStop()) // 0x3002 CMD_DISCONNECT

View file

@ -29,6 +29,7 @@ import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
@ -89,6 +90,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
@Inject AAPSLogger aapsLogger;
@Inject RxBusWrapper rxBus;
@Inject ResourceHelper resourceHelper;
@Inject ConstraintChecker constraintChecker;
@Inject DanaRPump danaRPump;
@Inject DanaRPlugin danaRPlugin;
@Inject DanaRKoreanPlugin danaRKoreanPlugin;
@ -358,7 +360,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
public boolean extendedBolus(double insulin, int durationInHalfHours) {
if (!isConnected()) return false;
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(aapsLogger, constraintChecker, insulin, (byte) (durationInHalfHours & 0xFF)));
mSerialIOThread.sendMessage(new MsgStatusBolusExtended_v2(aapsLogger, danaRPump));
loadEvents();
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
@ -384,9 +386,9 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
final int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
MessageBase start;
if (preferencesSpeed == 0)
start = new MsgBolusStart(amount);
start = new MsgBolusStart(aapsLogger, constraintChecker, danaRPump, amount);
else
start = new MsgBolusStartWithSpeed(amount, preferencesSpeed);
start = new MsgBolusStartWithSpeed(aapsLogger, constraintChecker, danaRPump, amount, preferencesSpeed);
MsgBolusStop stop = new MsgBolusStop(amount, t);
if (carbs > 0) {

View file

@ -13,7 +13,6 @@ import androidx.annotation.NonNull;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Calendar;
@ -25,6 +24,7 @@ import java.util.TimeZone;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
@ -198,6 +198,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
@Inject
public LocalInsightPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
ResourceHelper resourceHelper,
@ -213,7 +214,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
.description(R.string.description_pump_insight_local)
.fragmentClass(LocalInsightFragment.class.getName())
.preferencesId(Config.APS ? R.xml.pref_insight_local_full : R.xml.pref_insight_local_pumpcontrol),
aapsLogger, resourceHelper, commandQueue
injector, aapsLogger, resourceHelper, commandQueue
);
@ -1596,22 +1597,22 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
@Override
public Constraint<Integer> applyBasalPercentConstraints(Constraint<Integer> percentRate, Profile profile) {
percentRate.setIfGreater(0, String.format(resourceHelper.gs(R.string.limitingpercentrate), 0, resourceHelper.gs(R.string.itmustbepositivevalue)), this);
percentRate.setIfSmaller(getPumpDescription().maxTempPercent, String.format(resourceHelper.gs(R.string.limitingpercentrate), getPumpDescription().maxTempPercent, resourceHelper.gs(R.string.pumplimit)), this);
percentRate.setIfGreater(getAapsLogger(), 0, String.format(resourceHelper.gs(R.string.limitingpercentrate), 0, resourceHelper.gs(R.string.itmustbepositivevalue)), this);
percentRate.setIfSmaller(getAapsLogger(), getPumpDescription().maxTempPercent, String.format(resourceHelper.gs(R.string.limitingpercentrate), getPumpDescription().maxTempPercent, resourceHelper.gs(R.string.pumplimit)), this);
return percentRate;
}
@Override
public Constraint<Double> applyBolusConstraints(Constraint<Double> insulin) {
if (!limitsFetched) return insulin;
insulin.setIfSmaller(maximumBolusAmount, String.format(resourceHelper.gs(R.string.limitingbolus), maximumBolusAmount, resourceHelper.gs(R.string.pumplimit)), this);
insulin.setIfSmaller(getAapsLogger(), maximumBolusAmount, String.format(resourceHelper.gs(R.string.limitingbolus), maximumBolusAmount, resourceHelper.gs(R.string.pumplimit)), this);
if (insulin.value() < minimumBolusAmount) {
//TODO: Add function to Constraints or use different approach
// This only works if the interface of the InsightPlugin is called last.
// If not, another constraint could theoretically set the value between 0 and minimumBolusAmount
insulin.set(0d, String.format(resourceHelper.gs(R.string.limitingbolus), minimumBolusAmount, resourceHelper.gs(R.string.pumplimit)), this);
insulin.set(getAapsLogger(), 0d, String.format(resourceHelper.gs(R.string.limitingbolus), minimumBolusAmount, resourceHelper.gs(R.string.pumplimit)), this);
}
return insulin;
}

View file

@ -5,13 +5,13 @@ import androidx.annotation.NonNull;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
@ -49,6 +49,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
@Inject
public MDIPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
ResourceHelper resourceHelper,
@ -58,7 +59,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
.mainType(PluginType.PUMP)
.pluginName(R.string.mdi)
.description(R.string.description_pump_mdi),
aapsLogger, resourceHelper, commandQueue
injector, aapsLogger, resourceHelper, commandQueue
);
pumpDescription.isBolusCapable = true;
pumpDescription.bolusStep = 0.5d;

View file

@ -10,7 +10,6 @@ import androidx.annotation.NonNull;
import org.joda.time.LocalDateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Arrays;
@ -27,6 +26,7 @@ import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.ErrorHelperActivity;
@ -130,6 +130,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
@Inject
public MedtronicPumpPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
MainApp maiApp,
@ -148,7 +149,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
.shortName(R.string.medtronic_name_short) //
.preferencesId(R.xml.pref_medtronic).description(R.string.description_pump_medtronic), //
PumpType.Medtronic_522_722, // we default to most basic model, correct model from config is loaded later
resourceHelper, aapsLogger, commandQueue
injector, resourceHelper, aapsLogger, commandQueue
);
this.plugin = this;

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.pump.virtual
import android.os.SystemClock
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.R
@ -41,6 +42,7 @@ import kotlin.math.min
@Singleton
class VirtualPumpPlugin @Inject constructor(
injector:HasAndroidInjector,
aapsLogger: AAPSLogger,
private val rxBus: RxBusWrapper,
private var fabricPrivacy: FabricPrivacy,
@ -57,7 +59,7 @@ class VirtualPumpPlugin @Inject constructor(
.preferencesId(R.xml.pref_virtualpump)
.neverVisible(Config.NSCLIENT)
.description(R.string.description_pump_virtual),
aapsLogger, resourceHelper, commandQueue
injector, aapsLogger, resourceHelper, commandQueue
), PumpInterface {

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.sensitivity
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription
@ -12,8 +13,17 @@ import info.nightscout.androidaps.utils.Round
import info.nightscout.androidaps.utils.SafeParse
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
import kotlin.math.max
import kotlin.math.min
abstract class AbstractSensitivityPlugin(pluginDescription: PluginDescription, aapsLogger: AAPSLogger, resourceHelper: ResourceHelper, val sp: SP) : PluginBase(pluginDescription, aapsLogger, resourceHelper), SensitivityInterface {
abstract class AbstractSensitivityPlugin(
pluginDescription: PluginDescription,
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper:
ResourceHelper,
val sp: SP
) : PluginBase(pluginDescription, aapsLogger, resourceHelper, injector), SensitivityInterface {
abstract override fun detectSensitivity(plugin: IobCobCalculatorPlugin, fromTime: Long, toTime: Long): AutosensResult
@ -25,19 +35,19 @@ abstract class AbstractSensitivityPlugin(pluginDescription: PluginDescription, a
SafeParse.stringToDouble(sp.getString(R.string.key_openapsama_autosens_max, "1.2")))
}
fun fillResult(ratio: Double, carbsAbsorbed: Double, pastSensitivity: String,
ratioLimit: String, sensResult: String, deviationsArraySize: Int,
fun fillResult(ratioParam: Double, carbsAbsorbed: Double, pastSensitivity: String,
ratioLimitParam: String, sensResult: String, deviationsArraySize: Int,
ratioMin: Double, ratioMax: Double): AutosensResult {
var ratio = ratio
var ratioLimit = ratioLimit
var ratio = ratioParam
var ratioLimit = ratioLimitParam
val rawRatio = ratio
ratio = Math.max(ratio, ratioMin)
ratio = Math.min(ratio, ratioMax)
ratio = max(ratio, ratioMin)
ratio = min(ratio, ratioMax)
//If not-excluded data <= MIN_HOURS -> don't do Autosens
//If not-excluded data >= MIN_HOURS_FULL_AUTOSENS -> full Autosens
//Between MIN_HOURS and MIN_HOURS_FULL_AUTOSENS: gradually increase autosens
val autosensContrib = (Math.min(Math.max(SensitivityInterface.MIN_HOURS, deviationsArraySize / 12.0),
val autosensContrib = (min(max(SensitivityInterface.MIN_HOURS, deviationsArraySize / 12.0),
SensitivityInterface.MIN_HOURS_FULL_AUTOSENS) - SensitivityInterface.MIN_HOURS) / (SensitivityInterface.MIN_HOURS_FULL_AUTOSENS - SensitivityInterface.MIN_HOURS)
ratio = autosensContrib * (ratio - 1) + 1
if (autosensContrib != 1.0) {

View file

@ -9,6 +9,7 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
@ -37,6 +38,7 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin {
@Inject
public SensitivityAAPSPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
ResourceHelper resourceHelper,
SP sp
@ -47,7 +49,7 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin {
.shortName(R.string.sensitivity_shortname)
.preferencesId(R.xml.pref_absorption_aaps)
.description(R.string.description_sensitivity_aaps),
aapsLogger, resourceHelper, sp
injector, aapsLogger, resourceHelper, sp
);
this.sp = sp;
}

View file

@ -10,6 +10,7 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
@ -37,6 +38,7 @@ public class SensitivityOref0Plugin extends AbstractSensitivityPlugin {
@Inject
public SensitivityOref0Plugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
ResourceHelper resourceHelper,
SP sp,
@ -48,7 +50,7 @@ public class SensitivityOref0Plugin extends AbstractSensitivityPlugin {
.shortName(R.string.sensitivity_shortname)
.preferencesId(R.xml.pref_absorption_oref0)
.description(R.string.description_sensitivity_oref0),
aapsLogger, resourceHelper, sp
injector, aapsLogger, resourceHelper, sp
);
this.profileFunction = profileFunction;
}

View file

@ -9,6 +9,7 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
@ -34,6 +35,7 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin {
@Inject
public SensitivityOref1Plugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
ResourceHelper resourceHelper,
SP sp
@ -45,7 +47,7 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin {
.enableByDefault(true)
.preferencesId(R.xml.pref_absorption_oref1)
.description(R.string.description_sensitivity_oref1),
aapsLogger, resourceHelper, sp
injector, aapsLogger, resourceHelper, sp
);
}

View file

@ -7,6 +7,7 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
@ -36,6 +37,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin
@Inject
public SensitivityWeightedAveragePlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
ResourceHelper resourceHelper,
SP sp,
@ -47,7 +49,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin
.shortName(R.string.sensitivity_shortname)
.preferencesId(R.xml.pref_absorption_aaps)
.description(R.string.description_sensitivity_weighted_average),
aapsLogger, resourceHelper, sp
injector, aapsLogger, resourceHelper, sp
);
this.sp = sp;
this.resourceHelper = resourceHelper;

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.source
import android.content.Intent
import android.content.pm.PackageManager
import androidx.core.content.ContextCompat
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
@ -10,7 +11,6 @@ import info.nightscout.androidaps.activities.RequestDexcomPermissionActivity
import info.nightscout.androidaps.db.BgReading
import info.nightscout.androidaps.db.CareportalEvent
import info.nightscout.androidaps.db.Source
import info.nightscout.androidaps.dialogs.CareDialog
import info.nightscout.androidaps.interfaces.BgSourceInterface
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription
@ -27,6 +27,7 @@ import javax.inject.Singleton
@Singleton
class DexcomPlugin @Inject constructor(
injector: HasAndroidInjector,
private val sp: SP,
private val mainApp: MainApp,
resourceHelper: ResourceHelper,
@ -38,7 +39,8 @@ class DexcomPlugin @Inject constructor(
.shortName(R.string.dexcom_short)
.preferencesId(R.xml.pref_bgsourcedexcom)
.description(R.string.description_source_dexcom),
aapsLogger, resourceHelper), BgSourceInterface {
aapsLogger, resourceHelper, injector
), BgSourceInterface {
override fun advancedFilteringSupported(): Boolean {
return true

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.source
import android.content.Intent
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
@ -26,6 +27,7 @@ import javax.inject.Singleton
@Singleton
class EversensePlugin @Inject constructor(
injector: HasAndroidInjector,
private val sp: SP,
resourceHelper: ResourceHelper,
aapsLogger: AAPSLogger
@ -36,8 +38,7 @@ class EversensePlugin @Inject constructor(
.shortName(R.string.eversense_shortname)
.preferencesId(R.xml.pref_bgsource)
.description(R.string.description_source_eversense),
aapsLogger,
resourceHelper
aapsLogger, resourceHelper, injector
), BgSourceInterface {
override fun advancedFilteringSupported(): Boolean {

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.source
import android.content.Intent
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.db.BgReading
@ -17,6 +18,7 @@ import javax.inject.Singleton
@Singleton
class GlimpPlugin @Inject constructor(
injector: HasAndroidInjector,
resourceHelper: ResourceHelper,
aapsLogger: AAPSLogger
) : PluginBase(PluginDescription()
@ -25,8 +27,7 @@ class GlimpPlugin @Inject constructor(
.pluginName(R.string.Glimp)
.preferencesId(R.xml.pref_bgsource)
.description(R.string.description_source_glimp),
aapsLogger,
resourceHelper
aapsLogger, resourceHelper, injector
), BgSourceInterface {
override fun advancedFilteringSupported(): Boolean {

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.source
import android.content.Intent
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.db.BgReading
@ -18,6 +19,7 @@ import javax.inject.Singleton
@Singleton
class MM640gPlugin @Inject constructor(
injector: HasAndroidInjector,
resourceHelper: ResourceHelper,
aapsLogger: AAPSLogger
) : PluginBase(PluginDescription()
@ -25,8 +27,7 @@ class MM640gPlugin @Inject constructor(
.fragmentClass(BGSourceFragment::class.java.name)
.pluginName(R.string.MM640g)
.description(R.string.description_source_mm640g),
aapsLogger,
resourceHelper
aapsLogger, resourceHelper, injector
), BgSourceInterface {
override fun advancedFilteringSupported(): Boolean {

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.source
import android.content.Intent
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.db.BgReading
@ -22,6 +23,7 @@ import javax.inject.Singleton
@Singleton
class NSClientSourcePlugin @Inject constructor(
injector: HasAndroidInjector,
resourceHelper: ResourceHelper,
aapsLogger: AAPSLogger,
private val sp: SP
@ -30,8 +32,7 @@ class NSClientSourcePlugin @Inject constructor(
.fragmentClass(BGSourceFragment::class.java.name)
.pluginName(R.string.nsclientbg)
.description(R.string.description_source_ns_client),
aapsLogger,
resourceHelper
aapsLogger, resourceHelper, injector
), BgSourceInterface {
private var lastBGTimeStamp: Long = 0

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.source
import android.content.Intent
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
@ -22,6 +23,7 @@ import javax.inject.Singleton
@Singleton
class PoctechPlugin @Inject constructor(
injector: HasAndroidInjector,
resourceHelper: ResourceHelper,
aapsLogger: AAPSLogger,
private val sp: SP
@ -31,8 +33,7 @@ class PoctechPlugin @Inject constructor(
.pluginName(R.string.poctech)
.preferencesId(R.xml.pref_bgsource)
.description(R.string.description_source_poctech),
aapsLogger,
resourceHelper
aapsLogger, resourceHelper, injector
), BgSourceInterface {
override fun advancedFilteringSupported(): Boolean {

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.source
import android.content.Intent
import android.os.Handler
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.db.BgReading
@ -24,6 +25,7 @@ import kotlin.math.sin
@Singleton
class RandomBgPlugin @Inject constructor(
injector: HasAndroidInjector,
resourceHelper: ResourceHelper,
aapsLogger: AAPSLogger,
private var virtualPumpPlugin: VirtualPumpPlugin
@ -33,8 +35,7 @@ class RandomBgPlugin @Inject constructor(
.pluginName(R.string.randombg)
.shortName(R.string.randombg_short)
.description(R.string.description_source_randombg),
aapsLogger,
resourceHelper
aapsLogger, resourceHelper, injector
), BgSourceInterface {
private val loopHandler = Handler()

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.source
import android.content.Intent
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.db.BgReading
@ -18,6 +19,7 @@ import javax.inject.Singleton
@Singleton
class TomatoPlugin @Inject constructor(
injector: HasAndroidInjector,
resourceHelper: ResourceHelper,
aapsLogger: AAPSLogger,
private val sp: SP
@ -28,8 +30,7 @@ class TomatoPlugin @Inject constructor(
.preferencesId(R.xml.pref_bgsource)
.shortName(R.string.tomato_short)
.description(R.string.description_source_tomato),
aapsLogger,
resourceHelper
aapsLogger, resourceHelper, injector
), BgSourceInterface {
override fun advancedFilteringSupported(): Boolean {

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.source
import android.content.Intent
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.db.BgReading
@ -18,6 +19,7 @@ import javax.inject.Singleton
@Singleton
class XdripPlugin @Inject constructor(
injector: HasAndroidInjector,
resourceHelper: ResourceHelper,
aapsLogger: AAPSLogger
) : PluginBase(PluginDescription()
@ -25,8 +27,7 @@ class XdripPlugin @Inject constructor(
.fragmentClass(BGSourceFragment::class.java.name)
.pluginName(R.string.xdrip)
.description(R.string.description_source_xdrip),
aapsLogger,
resourceHelper
aapsLogger, resourceHelper, injector
), BgSourceInterface {
private var advancedFiltering = false

View file

@ -16,6 +16,7 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
@ -98,13 +99,15 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
private final ProfileIntervals<ProfileSwitch> profiles = new ProfileIntervals<>();
@Inject
public TreatmentsPlugin(AAPSLogger aapsLogger,
RxBusWrapper rxBus,
ResourceHelper resourceHelper,
MainApp mainApp,
SP sp,
ProfileFunction profileFunction,
ConfigBuilderPlugin configBuilderPlugin
public TreatmentsPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
ResourceHelper resourceHelper,
MainApp mainApp,
SP sp,
ProfileFunction profileFunction,
ConfigBuilderPlugin configBuilderPlugin
) {
super(new PluginDescription()
.mainType(PluginType.TREATMENT)
@ -113,8 +116,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
.shortName(R.string.treatments_shortname)
.alwaysEnabled(true)
.description(R.string.description_treatments),
aapsLogger,
resourceHelper
aapsLogger, resourceHelper, injector
);
this.resourceHelper = resourceHelper;
this.mainApp = mainApp;

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.utils
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.DialogInterface
@ -16,18 +17,19 @@ import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
object OKDialog {
@SuppressLint("InflateParams")
@JvmStatic
@JvmOverloads
fun show(context: Context, title: String, message: String, runnable: Runnable? = null) {
var notEmptytitle = title
if (notEmptytitle.isEmpty()) notEmptytitle = MainApp.gs(R.string.message)
if (notEmptytitle.isEmpty()) notEmptytitle = context.getString(R.string.message)
val titleLayout = LayoutInflater.from(context).inflate(R.layout.dialog_alert_custom, null)
(titleLayout.findViewById<View>(R.id.alertdialog_title) as TextView).text = notEmptytitle
(titleLayout.findViewById<View>(R.id.alertdialog_icon) as ImageView).setImageResource(R.drawable.ic_check_while_48dp)
AlertDialog.Builder(ContextThemeWrapper(context, R.style.AppTheme))
.setCustomTitle(titleLayout)
.setMessage(message)
.setPositiveButton(MainApp.gs(R.string.ok)) { dialog: DialogInterface, _: Int ->
.setPositiveButton(context.getString(R.string.ok)) { dialog: DialogInterface, _: Int ->
dialog.dismiss()
SystemClock.sleep(100)
runOnUiThread(runnable)
@ -41,18 +43,19 @@ object OKDialog {
theRunnable?.let { mainHandler.post(it) }
}
@SuppressLint("InflateParams")
@JvmStatic
@JvmOverloads
fun show(activity: Activity, title: String, message: Spanned, runnable: Runnable? = null) {
var notEmptytitle = title
if (notEmptytitle.isEmpty()) notEmptytitle = MainApp.gs(R.string.message)
if (notEmptytitle.isEmpty()) notEmptytitle = activity.getString(R.string.message)
val titleLayout = activity.layoutInflater.inflate(R.layout.dialog_alert_custom, null)
(titleLayout.findViewById<View>(R.id.alertdialog_title) as TextView).text = notEmptytitle
(titleLayout.findViewById<View>(R.id.alertdialog_icon) as ImageView).setImageResource(R.drawable.ic_check_while_48dp)
AlertDialog.Builder(ContextThemeWrapper(activity, R.style.AppTheme))
.setCustomTitle(titleLayout)
.setMessage(message)
.setPositiveButton(MainApp.gs(R.string.ok)) { dialog: DialogInterface, _: Int ->
.setPositiveButton(activity.getString(R.string.ok)) { dialog: DialogInterface, _: Int ->
dialog.dismiss()
SystemClock.sleep(100)
runnable?.let { activity.runOnUiThread(it) }
@ -63,14 +66,15 @@ object OKDialog {
@JvmStatic
fun showConfirmation(activity: Activity, message: String, ok: Runnable?) {
showConfirmation(activity, MainApp.gs(R.string.confirmation), message, ok, null)
showConfirmation(activity, activity.getString(R.string.confirmation), message, ok, null)
}
@JvmStatic
fun showConfirmation(activity: Activity, message: Spanned, ok: Runnable?) {
showConfirmation(activity, MainApp.gs(R.string.confirmation), message, ok, null)
showConfirmation(activity, activity.getString(R.string.confirmation), message, ok, null)
}
@SuppressLint("InflateParams")
@JvmStatic
@JvmOverloads
fun showConfirmation(activity: Activity, title: String, message: Spanned, ok: Runnable?, cancel: Runnable? = null) {
@ -95,6 +99,7 @@ object OKDialog {
.setCanceledOnTouchOutside(false)
}
@SuppressLint("InflateParams")
@JvmStatic
fun showConfirmation(activity: Activity, title: String, message: String, ok: Runnable?, cancel: Runnable? = null) {
val titleLayout = activity.layoutInflater.inflate(R.layout.dialog_alert_custom, null)
@ -120,9 +125,10 @@ object OKDialog {
@JvmStatic
@JvmOverloads
fun showConfirmation(context: Context, message: Spanned, ok: Runnable?, cancel: Runnable? = null) {
showConfirmation(context, MainApp.gs(R.string.confirmation), message, ok, cancel)
showConfirmation(context, context.getString(R.string.confirmation), message, ok, cancel)
}
@SuppressLint("InflateParams")
@JvmStatic
@JvmOverloads
fun showConfirmation(context: Context, title: String, message: Spanned, ok: Runnable?, cancel: Runnable? = null) {
@ -150,9 +156,10 @@ object OKDialog {
@JvmStatic
@JvmOverloads
fun showConfirmation(context: Context, message: String, ok: Runnable?, cancel: Runnable? = null) {
showConfirmation(context, MainApp.gs(R.string.confirmation), message, ok, cancel)
showConfirmation(context, context.getString(R.string.confirmation), message, ok, cancel)
}
@SuppressLint("InflateParams")
@JvmStatic
@JvmOverloads
fun showConfirmation(context: Context, title: String, message: String, ok: Runnable?, cancel: Runnable? = null) {
@ -176,6 +183,7 @@ object OKDialog {
.setCanceledOnTouchOutside(false)
}
@SuppressLint("InflateParams")
@JvmStatic
@JvmOverloads
fun showConfirmation(context: Context, title: String, message: String, ok: DialogInterface.OnClickListener?, cancel: DialogInterface.OnClickListener? = null) {

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.utils.stats
import android.text.Spanned
import android.util.LongSparseArray
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.db.TDD
@ -21,6 +22,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP
import javax.inject.Inject
class TddCalculator @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
rxBus: RxBusWrapper,
resourceHelper: ResourceHelper,
@ -28,7 +30,7 @@ class TddCalculator @Inject constructor(
val sp: SP,
val configBuilderPlugin: ConfigBuilderPlugin,
val profileFunction: ProfileFunction
) : TreatmentsPlugin(aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, configBuilderPlugin) {
) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, configBuilderPlugin) {
init {
service = TreatmentService() // plugin is not started

View file

@ -180,14 +180,6 @@ public class AAPSMocker {
when(ConfigBuilderPlugin.getPlugin()).thenReturn(configBuilderPlugin);
}
public static ConstraintChecker mockConstraintsChecker() {
PowerMockito.mockStatic(ConstraintChecker.class);
constraintChecker = mock(ConstraintChecker.class);
when(ConstraintChecker.getInstance())
.thenReturn(constraintChecker);
return constraintChecker;
}
public static void mockSP() {
PowerMockito.mockStatic(SP.class);
when(SP.getLong(anyInt(), anyLong())).thenReturn(0L);

View file

@ -47,8 +47,8 @@ class DanaRSPluginTest : DanaRSTestBase() {
val c = Constraint(Constants.REALLYHIGHBASALRATE)
danaRSPlugin.applyBasalConstraints(c, AAPSMocker.getValidProfile())
Assert.assertEquals(java.lang.Double.valueOf(0.8), c.value(), 0.0001)
Assert.assertEquals("DanaRS: limitingbasalratio", c.reasons)
Assert.assertEquals("DanaRS: limitingbasalratio", c.mostLimitedReasons)
Assert.assertEquals("DanaRS: limitingbasalratio", c.getReasons(aapsLogger))
Assert.assertEquals("DanaRS: limitingbasalratio", c.getMostLimitedReasons(aapsLogger))
}
@Test
@ -59,8 +59,8 @@ class DanaRSPluginTest : DanaRSTestBase() {
val c = Constraint(Constants.REALLYHIGHPERCENTBASALRATE)
danaRSPlugin.applyBasalPercentConstraints(c, AAPSMocker.getValidProfile())
Assert.assertEquals(200, c.value())
Assert.assertEquals("DanaRS: limitingpercentrate", c.reasons)
Assert.assertEquals("DanaRS: limitingpercentrate", c.mostLimitedReasons)
Assert.assertEquals("DanaRS: limitingpercentrate", c.getReasons(aapsLogger))
Assert.assertEquals("DanaRS: limitingpercentrate", c.getMostLimitedReasons(aapsLogger))
}
@Before