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 package info.nightscout.androidaps.activities
import android.content.Context import android.content.Context
import androidx.appcompat.app.AppCompatActivity import dagger.android.support.DaggerAppCompatActivity
import info.nightscout.androidaps.utils.LocaleHelper import info.nightscout.androidaps.utils.LocaleHelper
open class DialogAppCompatActivity : AppCompatActivity() { open class DialogAppCompatActivity : DaggerAppCompatActivity() {
public override fun attachBaseContext(newBase: Context) { public override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(LocaleHelper.wrap(newBase)) 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.ProfileStore
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.db.BgReading 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.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.constraints.objectives.objectives.*
import info.nightscout.androidaps.plugins.general.automation.AutomationEvent import info.nightscout.androidaps.plugins.general.automation.AutomationEvent
import info.nightscout.androidaps.plugins.general.automation.actions.* import info.nightscout.androidaps.plugins.general.automation.actions.*
@ -40,6 +45,11 @@ interface AppComponent : AndroidInjector<MainApp> {
fun injectProfileStore(profileStore: ProfileStore) fun injectProfileStore(profileStore: ProfileStore)
fun injectPumpEnactResult(pumpEnactResult: PumpEnactResult) 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 injectCommandQueue(commandQueue: CommandQueue)
fun injectCommandBolus(commandBolus: CommandBolus) fun injectCommandBolus(commandBolus: CommandBolus)

View file

@ -7,7 +7,6 @@ import dagger.Module
import dagger.Provides import dagger.Provides
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.data.ProfileStore import info.nightscout.androidaps.data.ProfileStore
import info.nightscout.androidaps.data.PumpEnactResult 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.ActivePluginProvider
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.AAPSLoggerDebug
import info.nightscout.androidaps.logging.AAPSLoggerProduction 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.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.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation
@ -81,13 +84,21 @@ open class AppModule {
@ContributesAndroidInjector fun pumpEnactResultInjector(): PumpEnactResult @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 commandQueueInjector(): CommandQueue
@ContributesAndroidInjector fun commandBolusInjector(): CommandBolus @ContributesAndroidInjector fun commandBolusInjector(): CommandBolus
@ContributesAndroidInjector @ContributesAndroidInjector
fun commandCancelExtendedBolusInjector(): CommandCancelExtendedBolus fun commandCancelExtendedBolusInjector(): CommandCancelExtendedBolus
@ContributesAndroidInjector fun commandCancelTempBasalInjector(): CommandCancelTempBasal @ContributesAndroidInjector fun commandCancelTempBasalInjector(): CommandCancelTempBasal
@ContributesAndroidInjector fun commandExtendedBolusInjector(): CommandExtendedBolus @ContributesAndroidInjector fun commandExtendedBolusInjector(): CommandExtendedBolus
@ContributesAndroidInjector @ContributesAndroidInjector
fun commandInsightSetTBROverNotificationInjector(): CommandInsightSetTBROverNotification fun commandInsightSetTBROverNotificationInjector(): CommandInsightSetTBROverNotification
@ -123,6 +134,7 @@ open class AppModule {
@ContributesAndroidInjector fun triggerIobInjector(): TriggerIob @ContributesAndroidInjector fun triggerIobInjector(): TriggerIob
@ContributesAndroidInjector fun triggerLocationInjector(): TriggerLocation @ContributesAndroidInjector fun triggerLocationInjector(): TriggerLocation
@ContributesAndroidInjector fun triggerProfilePercentInjector(): TriggerProfilePercent @ContributesAndroidInjector fun triggerProfilePercentInjector(): TriggerProfilePercent
@ContributesAndroidInjector @ContributesAndroidInjector
fun triggerPumpLastConnectionInjector(): TriggerPumpLastConnection fun triggerPumpLastConnectionInjector(): TriggerPumpLastConnection
@ -139,6 +151,7 @@ open class AppModule {
@ContributesAndroidInjector fun actionLoopSuspendInjector(): ActionLoopSuspend @ContributesAndroidInjector fun actionLoopSuspendInjector(): ActionLoopSuspend
@ContributesAndroidInjector fun actionNotificationInjector(): ActionNotification @ContributesAndroidInjector fun actionNotificationInjector(): ActionNotification
@ContributesAndroidInjector fun actionProfileSwitchInjector(): ActionProfileSwitch @ContributesAndroidInjector fun actionProfileSwitchInjector(): ActionProfileSwitch
@ContributesAndroidInjector @ContributesAndroidInjector
fun actionProfileSwitchPercentInjector(): ActionProfileSwitchPercent fun actionProfileSwitchPercentInjector(): ActionProfileSwitchPercent

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -22,6 +22,7 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import dagger.Lazy; import dagger.Lazy;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainActivity; import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
@ -73,6 +74,7 @@ import io.reactivex.schedulers.Schedulers;
@Singleton @Singleton
public class LoopPlugin extends PluginBase { public class LoopPlugin extends PluginBase {
private final HasAndroidInjector injector;
private final SP sp; private final SP sp;
private final RxBusWrapper rxBus; private final RxBusWrapper rxBus;
private final ConstraintChecker constraintChecker; private final ConstraintChecker constraintChecker;
@ -114,6 +116,7 @@ public class LoopPlugin extends PluginBase {
@Inject @Inject
public LoopPlugin( public LoopPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
RxBusWrapper rxBus, RxBusWrapper rxBus,
SP sp, SP sp,
@ -135,8 +138,9 @@ public class LoopPlugin extends PluginBase {
.shortName(R.string.loop_shortname) .shortName(R.string.loop_shortname)
.preferencesId(R.xml.pref_loop) .preferencesId(R.xml.pref_loop)
.description(R.string.description_loop), .description(R.string.description_loop),
aapsLogger, resourceHelper aapsLogger, resourceHelper, injector
); );
this.injector = injector;
this.sp = sp; this.sp = sp;
this.rxBus = rxBus; this.rxBus = rxBus;
this.constraintChecker = constraintChecker; this.constraintChecker = constraintChecker;
@ -311,7 +315,7 @@ public class LoopPlugin extends PluginBase {
Constraint<Boolean> loopEnabled = constraintChecker.isLoopInvocationAllowed(); Constraint<Boolean> loopEnabled = constraintChecker.isLoopInvocationAllowed();
if (!loopEnabled.value()) { 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); getAapsLogger().debug(LTag.APS, message);
rxBus.send(new EventLoopSetLastRunGui(message)); rxBus.send(new EventLoopSetLastRunGui(message));
return; return;
@ -355,7 +359,7 @@ public class LoopPlugin extends PluginBase {
result.percent = (int) (result.rate / profile.getBasal() * 100); result.percent = (int) (result.rate / profile.getBasal() * 100);
// check rate for constrais // check rate for constrais
final APSResult resultAfterConstraints = result.clone(); final APSResult resultAfterConstraints = result.newAndClone(injector);
resultAfterConstraints.rateConstraint = new Constraint<>(resultAfterConstraints.rate); resultAfterConstraints.rateConstraint = new Constraint<>(resultAfterConstraints.rate);
resultAfterConstraints.rate = constraintChecker.applyBasalConstraints(resultAfterConstraints.rateConstraint, profile).value(); 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 java.nio.charset.StandardCharsets;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal; 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.GlucoseStatus;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
public class DetermineBasalAdapterAMAJS { public class DetermineBasalAdapterAMAJS {
private final AAPSLogger aapsLogger; private HasAndroidInjector injector;
@Inject AAPSLogger aapsLogger;
@Inject ConstraintChecker constraintChecker;
@Inject SP sp;
private ScriptReader mScriptReader;
private ScriptReader mScriptReader = null;
private JSONObject mProfile; private JSONObject mProfile;
private JSONObject mGlucoseStatus; private JSONObject mGlucoseStatus;
@ -58,9 +62,10 @@ public class DetermineBasalAdapterAMAJS {
private String scriptDebug = ""; private String scriptDebug = "";
public DetermineBasalAdapterAMAJS(ScriptReader scriptReader, AAPSLogger aapsLogger) { DetermineBasalAdapterAMAJS(ScriptReader scriptReader, HasAndroidInjector injector) {
injector.androidInjector().inject(this);
mScriptReader = scriptReader; mScriptReader = scriptReader;
this.aapsLogger = aapsLogger; this.injector = injector;
} }
@Nullable @Nullable
@ -125,7 +130,7 @@ public class DetermineBasalAdapterAMAJS {
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString(); String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
aapsLogger.debug(LTag.APS, "Result: " + result); aapsLogger.debug(LTag.APS, "Result: " + result);
try { try {
determineBasalResultAMA = new DetermineBasalResultAMA(jsResult, new JSONObject(result), aapsLogger); determineBasalResultAMA = new DetermineBasalResultAMA(injector, jsResult, new JSONObject(result));
} catch (JSONException e) { } catch (JSONException e) {
aapsLogger.error(LTag.APS, "Unhandled exception", e); aapsLogger.error(LTag.APS, "Unhandled exception", e);
} }
@ -204,17 +209,17 @@ public class DetermineBasalAdapterAMAJS {
mProfile.put("target_bg", targetBg); mProfile.put("target_bg", targetBg);
mProfile.put("carb_ratio", profile.getIc()); mProfile.put("carb_ratio", profile.getIc());
mProfile.put("sens", profile.getIsfMgdl()); mProfile.put("sens", profile.getIsfMgdl());
mProfile.put("max_daily_safety_multiplier", SP.getInt(R.string.key_openapsama_max_daily_safety_multiplier, 3)); 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("current_basal_safety_multiplier", sp.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d));
mProfile.put("skip_neutral_temps", true); mProfile.put("skip_neutral_temps", true);
mProfile.put("current_basal", basalrate); mProfile.put("current_basal", basalrate);
mProfile.put("temptargetSet", tempTargetSet); 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 //align with max-absorption model in AMA sensitivity
if (mealData.usedMinCarbsImpact > 0) { if (mealData.usedMinCarbsImpact > 0) {
mProfile.put("min_5m_carbimpact", mealData.usedMinCarbsImpact); mProfile.put("min_5m_carbimpact", mealData.usedMinCarbsImpact);
} else { } 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)) { if (ProfileFunctions.getSystemUnits().equals(Constants.MMOL)) {
@ -240,7 +245,7 @@ public class DetermineBasalAdapterAMAJS {
mGlucoseStatus = new JSONObject(); mGlucoseStatus = new JSONObject();
mGlucoseStatus.put("glucose", glucoseStatus.glucose); 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); mGlucoseStatus.put("delta", glucoseStatus.short_avgdelta);
} else { } else {
mGlucoseStatus.put("delta", glucoseStatus.delta); mGlucoseStatus.put("delta", glucoseStatus.delta);
@ -253,7 +258,7 @@ public class DetermineBasalAdapterAMAJS {
mMealData.put("boluses", mealData.boluses); mMealData.put("boluses", mealData.boluses);
mMealData.put("mealCOB", mealData.mealCOB); mMealData.put("mealCOB", mealData.mealCOB);
if (ConstraintChecker.getInstance().isAutosensModeEnabled().value()) { if (constraintChecker.isAutosensModeEnabled().value()) {
mAutosensData = new JSONObject(); mAutosensData = new JSONObject();
mAutosensData.put("ratio", autosensDataRatio); mAutosensData.put("ratio", autosensDataRatio);
} else { } else {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -12,16 +12,6 @@ import javax.inject.Singleton
@Singleton @Singleton
class ConstraintChecker @Inject constructor(private val mainApp: MainApp) : ConstraintsInterface { 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> = fun isLoopInvocationAllowed(): Constraint<Boolean> =
isLoopInvocationAllowed(Constraint(true)) isLoopInvocationAllowed(Constraint(true))

View file

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

View file

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

View file

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

View file

@ -5,6 +5,7 @@ import androidx.annotation.NonNull;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
@ -49,14 +50,19 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
@Inject ActivePluginProvider activePlugin; @Inject ActivePluginProvider activePlugin;
@Inject @Inject
public SafetyPlugin(AAPSLogger aapsLogger, ResourceHelper resourceHelper) { public SafetyPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
ResourceHelper resourceHelper
) {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.CONSTRAINTS) .mainType(PluginType.CONSTRAINTS)
.neverVisible(true) .neverVisible(true)
.alwaysEnabled(true) .alwaysEnabled(true)
.showInList(false) .showInList(false)
.pluginName(R.string.safety) .pluginName(R.string.safety)
.preferencesId(R.xml.pref_safety), aapsLogger, resourceHelper .preferencesId(R.xml.pref_safety),
aapsLogger, resourceHelper, injector
); );
} }
@ -66,7 +72,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
@NonNull @Override @NonNull @Override
public Constraint<Boolean> isLoopInvocationAllowed(@NonNull Constraint<Boolean> value) { public Constraint<Boolean> isLoopInvocationAllowed(@NonNull Constraint<Boolean> value) {
if (!activePlugin.getActivePumpPlugin().getPumpDescription().isTempBasalCapable) 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; return value;
} }
@ -74,18 +80,18 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
public Constraint<Boolean> isClosedLoopAllowed(@NonNull Constraint<Boolean> value) { public Constraint<Boolean> isClosedLoopAllowed(@NonNull Constraint<Boolean> value) {
String mode = sp.getString(R.string.key_aps_mode, "open"); String mode = sp.getString(R.string.key_aps_mode, "open");
if (!mode.equals("closed")) 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 (!MainApp.isEngineeringModeOrRelease()) {
if (value.value()) { if (value.value()) {
Notification n = new Notification(Notification.TOAST_ALARM, resourceHelper.gs(R.string.closed_loop_disabled_on_dev_branch), Notification.NORMAL); Notification n = new Notification(Notification.TOAST_ALARM, resourceHelper.gs(R.string.closed_loop_disabled_on_dev_branch), Notification.NORMAL);
rxBus.send(new EventNewNotification(n)); 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(); PumpInterface pump = activePlugin.getActivePumpPlugin();
if (pump != null && !pump.isFakingTempsByExtendedBoluses() && TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) { 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; return value;
} }
@ -94,7 +100,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
public Constraint<Boolean> isAutosensModeEnabled(@NonNull Constraint<Boolean> value) { public Constraint<Boolean> isAutosensModeEnabled(@NonNull Constraint<Boolean> value) {
boolean enabled = sp.getBoolean(R.string.key_openapsama_useautosens, false); boolean enabled = sp.getBoolean(R.string.key_openapsama_useautosens, false);
if (!enabled) if (!enabled)
value.set(false, resourceHelper.gs(R.string.autosensdisabledinpreferences), this); value.set(getAapsLogger(), false, resourceHelper.gs(R.string.autosensdisabledinpreferences), this);
return value; return value;
} }
@ -102,10 +108,10 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
public Constraint<Boolean> isSMBModeEnabled(@NonNull Constraint<Boolean> value) { public Constraint<Boolean> isSMBModeEnabled(@NonNull Constraint<Boolean> value) {
boolean enabled = sp.getBoolean(R.string.key_use_smb, false); boolean enabled = sp.getBoolean(R.string.key_use_smb, false);
if (!enabled) 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(); Constraint<Boolean> closedLoop = constraintChecker.isClosedLoopAllowed();
if (!closedLoop.value()) if (!closedLoop.value())
value.set(false, resourceHelper.gs(R.string.smbnotallowedinopenloopmode), this); value.set(getAapsLogger(), false, resourceHelper.gs(R.string.smbnotallowedinopenloopmode), this);
return value; return value;
} }
@ -113,10 +119,10 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
public Constraint<Boolean> isUAMEnabled(@NonNull Constraint<Boolean> value) { public Constraint<Boolean> isUAMEnabled(@NonNull Constraint<Boolean> value) {
boolean enabled = sp.getBoolean(R.string.key_use_uam, false); boolean enabled = sp.getBoolean(R.string.key_use_uam, false);
if (!enabled) 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); boolean oref1Enabled = sensitivityOref1Plugin.isEnabled(PluginType.SENSITIVITY);
if (!oref1Enabled) if (!oref1Enabled)
value.set(false, resourceHelper.gs(R.string.uamdisabledoref1notselected), this); value.set(getAapsLogger(), false, resourceHelper.gs(R.string.uamdisabledoref1notselected), this);
return value; return value;
} }
@ -126,7 +132,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
if (bgSource != null) { if (bgSource != null) {
if (!bgSource.advancedFilteringSupported()) if (!bgSource.advancedFilteringSupported())
value.set(false, resourceHelper.gs(R.string.smbalwaysdisabled), this); value.set(getAapsLogger(), false, resourceHelper.gs(R.string.smbalwaysdisabled), this);
} }
return value; return value;
} }
@ -134,7 +140,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
@NonNull @Override @NonNull @Override
public Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, @NonNull Profile profile) { 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) { if (Config.APS) {
double maxBasal = sp.getDouble(R.string.key_openapsma_max_basal, 1d); 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(); maxBasal = profile.getMaxDailyBasal();
absoluteRate.addReason(resourceHelper.gs(R.string.increasingmaxbasal), this); 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 // 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 maxBasalMult = sp.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d);
double maxFromBasalMult = Math.floor(maxBasalMult * profile.getBasal() * 100) / 100; 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 maxBasalFromDaily = sp.getDouble(R.string.key_openapsama_max_daily_safety_multiplier, 3d);
double maxFromDaily = Math.floor(profile.getMaxDailyBasal() * maxBasalFromDaily * 100) / 100; 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(); PumpInterface pump = activePlugin.getActivePumpPlugin();
// check for pump max // check for pump max
if (pump != null && pump.getPumpDescription().tempBasalStyle == PumpDescription.ABSOLUTE) { if (pump != null && pump.getPumpDescription().tempBasalStyle == PumpDescription.ABSOLUTE) {
double pumpLimit = pump.getPumpDescription().pumpType.getTbrSettings().getMaxDose(); 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 // do rounding
if (pump != null && pump.getPumpDescription().tempBasalStyle == PumpDescription.ABSOLUTE) { 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; return absoluteRate;
} }
@ -192,11 +198,11 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
percentRateAfterConst = Round.floorTo((double) percentRateAfterConst, (double) pump.getPumpDescription().tempPercentStep).intValue(); 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) { if (pump != null && pump.getPumpDescription().tempBasalStyle == PumpDescription.PERCENT) {
double pumpLimit = pump.getPumpDescription().pumpType.getTbrSettings().getMaxDose(); 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; return percentRate;
@ -204,44 +210,44 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
@NonNull @Override @NonNull @Override
public Constraint<Double> applyBolusConstraints(Constraint<Double> insulin) { 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); 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(); PumpInterface pump = activePlugin.getActivePumpPlugin();
if (pump != null) { if (pump != null) {
double rounded = pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulin.value()); 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; return insulin;
} }
@NonNull @Override @NonNull @Override
public Constraint<Double> applyExtendedBolusConstraints(Constraint<Double> insulin) { 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); 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(); PumpInterface pump = activePlugin.getActivePumpPlugin();
if (pump != null) { if (pump != null) {
double rounded = pump.getPumpDescription().pumpType.determineCorrectExtendedBolusSize(insulin.value()); 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; return insulin;
} }
@NonNull @Override @NonNull @Override
public Constraint<Integer> applyCarbsConstraints(Constraint<Integer> carbs) { 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); 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; return carbs;
} }
@ -253,14 +259,14 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
maxIobPref = sp.getDouble(R.string.key_openapssmb_max_iob, 3d); maxIobPref = sp.getDouble(R.string.key_openapssmb_max_iob, 3d);
else else
maxIobPref = sp.getDouble(R.string.key_openapsma_max_iob, 1.5d); 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)) 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)) 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)) 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; return maxIob;
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.general.careportal package info.nightscout.androidaps.plugins.general.careportal
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config import info.nightscout.androidaps.Config
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginBase
@ -11,7 +12,10 @@ import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@Singleton @Singleton
class CareportalPlugin @Inject constructor(aapsLogger: AAPSLogger, resourceHelper: ResourceHelper class CareportalPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper
) : PluginBase(PluginDescription() ) : PluginBase(PluginDescription()
.mainType(PluginType.GENERAL) .mainType(PluginType.GENERAL)
.fragmentClass(CareportalFragment::class.java.name) .fragmentClass(CareportalFragment::class.java.name)
@ -20,6 +24,5 @@ class CareportalPlugin @Inject constructor(aapsLogger: AAPSLogger, resourceHelpe
.visibleByDefault(Config.NSCLIENT) .visibleByDefault(Config.NSCLIENT)
.enableByDefault(Config.NSCLIENT) .enableByDefault(Config.NSCLIENT)
.description(R.string.description_careportal), .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.content.pm.ResolveInfo
import android.os.Bundle import android.os.Bundle
import dagger.Lazy import dagger.Lazy
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config import info.nightscout.androidaps.Config
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.IobTotal import info.nightscout.androidaps.data.IobTotal
@ -41,6 +42,7 @@ import javax.inject.Singleton
@Singleton @Singleton
class DataBroadcastPlugin @Inject constructor( class DataBroadcastPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper, resourceHelper: ResourceHelper,
private val context: Context, private val context: Context,
@ -59,7 +61,7 @@ class DataBroadcastPlugin @Inject constructor(
.alwaysEnabled(true) .alwaysEnabled(true)
.neverVisible(true) .neverVisible(true)
.showInList(false), .showInList(false),
aapsLogger, resourceHelper aapsLogger, resourceHelper, injector
) { ) {
private val disposable = CompositeDisposable() private val disposable = CompositeDisposable()

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory;
import java.util.Date; import java.util.Date;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
@ -71,9 +72,9 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
protected boolean displayConnectionMessages = false; 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); pumpDescription.setPumpDescription(pumpType);

View file

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

View file

@ -11,6 +11,7 @@ import androidx.annotation.NonNull;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo; 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.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker; import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; 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.pump.danaR.services.DanaRExecutionService;
import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
@ -53,6 +53,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
@Inject @Inject
public DanaRPlugin( public DanaRPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
RxBusWrapper rxBus, RxBusWrapper rxBus,
MainApp maiApp, MainApp maiApp,
@ -63,7 +64,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
CommandQueueProvider commandQueue, CommandQueueProvider commandQueue,
DanaRPump danaRPump DanaRPump danaRPump
) { ) {
super(danaRPump, resourceHelper, aapsLogger, commandQueue); super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue);
this.aapsLogger = aapsLogger; this.aapsLogger = aapsLogger;
this.rxBus = rxBus; this.rxBus = rxBus;
this.mainApp = maiApp; this.mainApp = maiApp;
@ -171,7 +172,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
result.bolusDelivered = t.insulin; result.bolusDelivered = t.insulin;
result.carbsDelivered = detailedBolusInfo.carbs; result.carbsDelivered = detailedBolusInfo.carbs;
if (!result.success) 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 else
result.comment = resourceHelper.gs(R.string.virtualpump_resultok); result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);

View file

@ -113,6 +113,9 @@ class DanaRPump @Inject constructor(
return if (units == UNITS_MGDL) Constants.MGDL else Constants.MMOL return if (units == UNITS_MGDL) Constants.MGDL else Constants.MMOL
} }
// last start bolus erroCode
var messageStartErrorCode: Int = 0
fun createConvertedProfile(): ProfileStore? { fun createConvertedProfile(): ProfileStore? {
pumpProfiles?.let { pumpProfiles?.let {
val json = JSONObject() 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.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin 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.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
@ -18,6 +19,7 @@ class MessageHashTableR @Inject constructor(
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
rxBus: RxBusWrapper, rxBus: RxBusWrapper,
resourceHelper: ResourceHelper, resourceHelper: ResourceHelper,
constraintChecker: ConstraintChecker,
danaRPump: DanaRPump, danaRPump: DanaRPump,
danaRPlugin: DanaRPlugin, danaRPlugin: DanaRPlugin,
danaRKoreanPlugin: DanaRKoreanPlugin, danaRKoreanPlugin: DanaRKoreanPlugin,
@ -30,8 +32,8 @@ class MessageHashTableR @Inject constructor(
init { init {
put(MsgBolusStop()) // 0x0101 CMD_MEALINS_STOP 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(MsgBolusStartWithSpeed()) // 0x0104 CMD_MEALINS_START_DATA_SPEED put(MsgBolusStartWithSpeed(aapsLogger, constraintChecker, danaRPump, 0.0, 0)) // 0x0104 CMD_MEALINS_START_DATA_SPEED
put(MsgBolusProgress()) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS put(MsgBolusProgress()) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
put(MsgStatusProfile(aapsLogger, danaRPump)) // 0x0204 CMD_PUMP_CALCULATION_SETTING put(MsgStatusProfile(aapsLogger, danaRPump)) // 0x0204 CMD_PUMP_CALCULATION_SETTING
put(MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin)) // 0x0205 CMD_PUMP_EXERCISE_MODE 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(MsgSetCarbsEntry()) // 0x0402 CMD_PUMPSET_HIS_S
put(MsgSetTempBasalStop()) // 0x0403 CMD_PUMPSET_EXERCISE_STOP put(MsgSetTempBasalStop()) // 0x0403 CMD_PUMPSET_EXERCISE_STOP
put(MsgSetExtendedBolusStop()) // 0x0406 CMD_PUMPSET_EXPANS_INS_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(MsgError()) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS
put(MsgPCCommStart()) // 0x3001 CMD_CONNECT put(MsgPCCommStart()) // 0x3001 CMD_CONNECT
put(MsgPCCommStop()) // 0x3002 CMD_DISCONNECT 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.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; 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.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
@ -81,6 +82,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
@Inject AAPSLogger aapsLogger; @Inject AAPSLogger aapsLogger;
@Inject RxBusWrapper rxBus; @Inject RxBusWrapper rxBus;
@Inject ResourceHelper resourceHelper; @Inject ResourceHelper resourceHelper;
@Inject ConstraintChecker constraintChecker;
@Inject DanaRPump danaRPump; @Inject DanaRPump danaRPump;
@Inject DanaRPlugin danaRPlugin; @Inject DanaRPlugin danaRPlugin;
@Inject DanaRKoreanPlugin danaRKoreanPlugin; @Inject DanaRKoreanPlugin danaRKoreanPlugin;
@ -287,7 +289,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
public boolean extendedBolus(double insulin, int durationInHalfHours) { public boolean extendedBolus(double insulin, int durationInHalfHours) {
if (!isConnected()) return false; if (!isConnected()) return false;
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingextendedbolus))); 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)); mSerialIOThread.sendMessage(new MsgStatusBolusExtended(aapsLogger, danaRPump, activePlugin));
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
return true; return true;
@ -315,9 +317,9 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0); int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
MessageBase start; MessageBase start;
if (preferencesSpeed == 0) if (preferencesSpeed == 0)
start = new MsgBolusStart(amount); start = new MsgBolusStart(aapsLogger, constraintChecker, danaRPump, amount);
else else
start = new MsgBolusStartWithSpeed(amount, preferencesSpeed); start = new MsgBolusStartWithSpeed(aapsLogger, constraintChecker, danaRPump, amount, preferencesSpeed);
MsgBolusStop stop = new MsgBolusStop(amount, t); MsgBolusStop stop = new MsgBolusStop(amount, t);
if (carbs > 0) { if (carbs > 0) {

View file

@ -11,6 +11,7 @@ import androidx.annotation.NonNull;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo; 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.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.danaR.AbstractDanaRPlugin; import info.nightscout.androidaps.plugins.pump.danaR.AbstractDanaRPlugin;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; 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.pump.danaRKorean.services.DanaRKoreanExecutionService;
import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
@ -55,6 +55,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
@Inject @Inject
public DanaRKoreanPlugin( public DanaRKoreanPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
RxBusWrapper rxBus, RxBusWrapper rxBus,
DanaRPump danaRPump, DanaRPump danaRPump,
@ -66,7 +67,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
CommandQueueProvider commandQueue CommandQueueProvider commandQueue
) { ) {
super(danaRPump, resourceHelper, aapsLogger, commandQueue); super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue);
this.aapsLogger = aapsLogger; this.aapsLogger = aapsLogger;
this.rxBus = rxBus; this.rxBus = rxBus;
this.mainApp = maiApp; this.mainApp = maiApp;
@ -174,7 +175,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
result.bolusDelivered = t.insulin; result.bolusDelivered = t.insulin;
result.carbsDelivered = detailedBolusInfo.carbs; result.carbsDelivered = detailedBolusInfo.carbs;
if (!result.success) 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 else
result.comment = resourceHelper.gs(R.string.virtualpump_resultok); result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); 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.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin 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.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.* import info.nightscout.androidaps.plugins.pump.danaR.comm.*
@ -19,6 +20,7 @@ class MessageHashTableRKorean @Inject constructor(
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
rxBus: RxBusWrapper, rxBus: RxBusWrapper,
resourceHelper: ResourceHelper, resourceHelper: ResourceHelper,
constraintChecker: ConstraintChecker,
danaRPump: DanaRPump, danaRPump: DanaRPump,
danaRPlugin: DanaRPlugin, danaRPlugin: DanaRPlugin,
danaRKoreanPlugin: DanaRKoreanPlugin, danaRKoreanPlugin: DanaRKoreanPlugin,
@ -31,7 +33,7 @@ class MessageHashTableRKorean @Inject constructor(
init { init {
put(MsgBolusStop()) // 0x0101 CMD_MEALINS_STOP 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(MsgBolusProgress()) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
put(MsgStatusProfile(aapsLogger, danaRPump)) // 0x0204 CMD_PUMP_CALCULATION_SETTING put(MsgStatusProfile(aapsLogger, danaRPump)) // 0x0204 CMD_PUMP_CALCULATION_SETTING
put(MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin)) // 0x0205 CMD_PUMP_EXERCISE_MODE 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(MsgSetCarbsEntry()) // 0x0402 CMD_PUMPSET_HIS_S
put(MsgSetTempBasalStop()) // 0x0403 CMD_PUMPSET_EXERCISE_STOP put(MsgSetTempBasalStop()) // 0x0403 CMD_PUMPSET_EXERCISE_STOP
put(MsgSetExtendedBolusStop()) // 0x0406 CMD_PUMPSET_EXPANS_INS_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(MsgError()) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS
put(MsgPCCommStart()) // 0x3001 CMD_CONNECT put(MsgPCCommStart()) // 0x3001 CMD_CONNECT
put(MsgPCCommStop()) // 0x3002 CMD_DISCONNECT put(MsgPCCommStop()) // 0x3002 CMD_DISCONNECT

View file

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

View file

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

View file

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

View file

@ -11,6 +11,7 @@ import androidx.annotation.NonNull;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.DetailedBolusInfo;
@ -55,6 +56,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
@Inject @Inject
public DanaRv2Plugin( public DanaRv2Plugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
RxBusWrapper rxBus, RxBusWrapper rxBus,
MainApp maiApp, MainApp maiApp,
@ -66,7 +68,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
CommandQueueProvider commandQueue CommandQueueProvider commandQueue
) { ) {
super(danaRPump, resourceHelper, aapsLogger, commandQueue); super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue);
this.aapsLogger = aapsLogger; this.aapsLogger = aapsLogger;
this.rxBus = rxBus; this.rxBus = rxBus;
this.mainApp = maiApp; this.mainApp = maiApp;
@ -188,7 +190,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
result.bolusDelivered = t.insulin; result.bolusDelivered = t.insulin;
result.carbsDelivered = detailedBolusInfo.carbs; result.carbsDelivered = detailedBolusInfo.carbs;
if (!result.success) 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 else
result.comment = resourceHelper.gs(R.string.virtualpump_resultok); result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); 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.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin 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.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.* import info.nightscout.androidaps.plugins.pump.danaR.comm.*
@ -20,6 +21,7 @@ class MessageHashTableRv2 @Inject constructor(
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
rxBus: RxBusWrapper, rxBus: RxBusWrapper,
resourceHelper: ResourceHelper, resourceHelper: ResourceHelper,
constraintChecker: ConstraintChecker,
danaRPump: DanaRPump, danaRPump: DanaRPump,
danaRPlugin: DanaRPlugin, danaRPlugin: DanaRPlugin,
danaRKoreanPlugin: DanaRKoreanPlugin, danaRKoreanPlugin: DanaRKoreanPlugin,
@ -33,8 +35,8 @@ class MessageHashTableRv2 @Inject constructor(
init { init {
put(MsgBolusStop()) // 0x0101 CMD_MEALINS_STOP 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(MsgBolusStartWithSpeed()) // 0x0104 CMD_MEALINS_START_DATA_SPEED put(MsgBolusStartWithSpeed(aapsLogger, constraintChecker, danaRPump, 0.0, 0)) // 0x0104 CMD_MEALINS_START_DATA_SPEED
put(MsgBolusProgress()) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS put(MsgBolusProgress()) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
put(MsgStatusProfile(aapsLogger, danaRPump)) // 0x0204 CMD_PUMP_CALCULATION_SETTING put(MsgStatusProfile(aapsLogger, danaRPump)) // 0x0204 CMD_PUMP_CALCULATION_SETTING
put(MsgStatusTempBasal_v2(aapsLogger, danaRPump)) // 0x0205 CMD_PUMP_EXERCISE_MODE 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(MsgSetCarbsEntry()) // 0x0402 CMD_PUMPSET_HIS_S
put(MsgSetTempBasalStop()) // 0x0403 CMD_PUMPSET_EXERCISE_STOP put(MsgSetTempBasalStop()) // 0x0403 CMD_PUMPSET_EXERCISE_STOP
put(MsgSetExtendedBolusStop()) // 0x0406 CMD_PUMPSET_EXPANS_INS_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(MsgError()) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS
put(MsgPCCommStart()) // 0x3001 CMD_CONNECT put(MsgPCCommStart()) // 0x3001 CMD_CONNECT
put(MsgPCCommStop()) // 0x3002 CMD_DISCONNECT 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.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; 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.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
@ -89,6 +90,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
@Inject AAPSLogger aapsLogger; @Inject AAPSLogger aapsLogger;
@Inject RxBusWrapper rxBus; @Inject RxBusWrapper rxBus;
@Inject ResourceHelper resourceHelper; @Inject ResourceHelper resourceHelper;
@Inject ConstraintChecker constraintChecker;
@Inject DanaRPump danaRPump; @Inject DanaRPump danaRPump;
@Inject DanaRPlugin danaRPlugin; @Inject DanaRPlugin danaRPlugin;
@Inject DanaRKoreanPlugin danaRKoreanPlugin; @Inject DanaRKoreanPlugin danaRKoreanPlugin;
@ -358,7 +360,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
public boolean extendedBolus(double insulin, int durationInHalfHours) { public boolean extendedBolus(double insulin, int durationInHalfHours) {
if (!isConnected()) return false; if (!isConnected()) return false;
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingextendedbolus))); 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)); mSerialIOThread.sendMessage(new MsgStatusBolusExtended_v2(aapsLogger, danaRPump));
loadEvents(); loadEvents();
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); 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); final int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
MessageBase start; MessageBase start;
if (preferencesSpeed == 0) if (preferencesSpeed == 0)
start = new MsgBolusStart(amount); start = new MsgBolusStart(aapsLogger, constraintChecker, danaRPump, amount);
else else
start = new MsgBolusStartWithSpeed(amount, preferencesSpeed); start = new MsgBolusStartWithSpeed(aapsLogger, constraintChecker, danaRPump, amount, preferencesSpeed);
MsgBolusStop stop = new MsgBolusStop(amount, t); MsgBolusStop stop = new MsgBolusStop(amount, t);
if (carbs > 0) { if (carbs > 0) {

View file

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

View file

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

View file

@ -10,7 +10,6 @@ import androidx.annotation.NonNull;
import org.joda.time.LocalDateTime; import org.joda.time.LocalDateTime;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -27,6 +26,7 @@ import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.ErrorHelperActivity; import info.nightscout.androidaps.activities.ErrorHelperActivity;
@ -130,6 +130,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
@Inject @Inject
public MedtronicPumpPlugin( public MedtronicPumpPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
RxBusWrapper rxBus, RxBusWrapper rxBus,
MainApp maiApp, MainApp maiApp,
@ -148,7 +149,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
.shortName(R.string.medtronic_name_short) // .shortName(R.string.medtronic_name_short) //
.preferencesId(R.xml.pref_medtronic).description(R.string.description_pump_medtronic), // .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 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; this.plugin = this;

View file

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

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.sensitivity package info.nightscout.androidaps.plugins.sensitivity
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription 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.SafeParse
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP 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 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"))) SafeParse.stringToDouble(sp.getString(R.string.key_openapsama_autosens_max, "1.2")))
} }
fun fillResult(ratio: Double, carbsAbsorbed: Double, pastSensitivity: String, fun fillResult(ratioParam: Double, carbsAbsorbed: Double, pastSensitivity: String,
ratioLimit: String, sensResult: String, deviationsArraySize: Int, ratioLimitParam: String, sensResult: String, deviationsArraySize: Int,
ratioMin: Double, ratioMax: Double): AutosensResult { ratioMin: Double, ratioMax: Double): AutosensResult {
var ratio = ratio var ratio = ratioParam
var ratioLimit = ratioLimit var ratioLimit = ratioLimitParam
val rawRatio = ratio val rawRatio = ratio
ratio = Math.max(ratio, ratioMin) ratio = max(ratio, ratioMin)
ratio = Math.min(ratio, ratioMax) ratio = min(ratio, ratioMax)
//If not-excluded data <= MIN_HOURS -> don't do Autosens //If not-excluded data <= MIN_HOURS -> don't do Autosens
//If not-excluded data >= MIN_HOURS_FULL_AUTOSENS -> full Autosens //If not-excluded data >= MIN_HOURS_FULL_AUTOSENS -> full Autosens
//Between MIN_HOURS and MIN_HOURS_FULL_AUTOSENS: gradually increase 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) SensitivityInterface.MIN_HOURS_FULL_AUTOSENS) - SensitivityInterface.MIN_HOURS) / (SensitivityInterface.MIN_HOURS_FULL_AUTOSENS - SensitivityInterface.MIN_HOURS)
ratio = autosensContrib * (ratio - 1) + 1 ratio = autosensContrib * (ratio - 1) + 1
if (autosensContrib != 1.0) { if (autosensContrib != 1.0) {

View file

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

View file

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

View file

@ -9,6 +9,7 @@ import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
@ -34,6 +35,7 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin {
@Inject @Inject
public SensitivityOref1Plugin( public SensitivityOref1Plugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
ResourceHelper resourceHelper, ResourceHelper resourceHelper,
SP sp SP sp
@ -45,7 +47,7 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin {
.enableByDefault(true) .enableByDefault(true)
.preferencesId(R.xml.pref_absorption_oref1) .preferencesId(R.xml.pref_absorption_oref1)
.description(R.string.description_sensitivity_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.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
@ -36,6 +37,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin
@Inject @Inject
public SensitivityWeightedAveragePlugin( public SensitivityWeightedAveragePlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
ResourceHelper resourceHelper, ResourceHelper resourceHelper,
SP sp, SP sp,
@ -47,7 +49,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin
.shortName(R.string.sensitivity_shortname) .shortName(R.string.sensitivity_shortname)
.preferencesId(R.xml.pref_absorption_aaps) .preferencesId(R.xml.pref_absorption_aaps)
.description(R.string.description_sensitivity_weighted_average), .description(R.string.description_sensitivity_weighted_average),
aapsLogger, resourceHelper, sp injector, aapsLogger, resourceHelper, sp
); );
this.sp = sp; this.sp = sp;
this.resourceHelper = resourceHelper; this.resourceHelper = resourceHelper;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.utils package info.nightscout.androidaps.utils
import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.content.DialogInterface import android.content.DialogInterface
@ -16,18 +17,19 @@ import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
object OKDialog { object OKDialog {
@SuppressLint("InflateParams")
@JvmStatic @JvmStatic
@JvmOverloads @JvmOverloads
fun show(context: Context, title: String, message: String, runnable: Runnable? = null) { fun show(context: Context, title: String, message: String, runnable: Runnable? = null) {
var notEmptytitle = title 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) 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_title) as TextView).text = notEmptytitle
(titleLayout.findViewById<View>(R.id.alertdialog_icon) as ImageView).setImageResource(R.drawable.ic_check_while_48dp) (titleLayout.findViewById<View>(R.id.alertdialog_icon) as ImageView).setImageResource(R.drawable.ic_check_while_48dp)
AlertDialog.Builder(ContextThemeWrapper(context, R.style.AppTheme)) AlertDialog.Builder(ContextThemeWrapper(context, R.style.AppTheme))
.setCustomTitle(titleLayout) .setCustomTitle(titleLayout)
.setMessage(message) .setMessage(message)
.setPositiveButton(MainApp.gs(R.string.ok)) { dialog: DialogInterface, _: Int -> .setPositiveButton(context.getString(R.string.ok)) { dialog: DialogInterface, _: Int ->
dialog.dismiss() dialog.dismiss()
SystemClock.sleep(100) SystemClock.sleep(100)
runOnUiThread(runnable) runOnUiThread(runnable)
@ -41,18 +43,19 @@ object OKDialog {
theRunnable?.let { mainHandler.post(it) } theRunnable?.let { mainHandler.post(it) }
} }
@SuppressLint("InflateParams")
@JvmStatic @JvmStatic
@JvmOverloads @JvmOverloads
fun show(activity: Activity, title: String, message: Spanned, runnable: Runnable? = null) { fun show(activity: Activity, title: String, message: Spanned, runnable: Runnable? = null) {
var notEmptytitle = title 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) 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_title) as TextView).text = notEmptytitle
(titleLayout.findViewById<View>(R.id.alertdialog_icon) as ImageView).setImageResource(R.drawable.ic_check_while_48dp) (titleLayout.findViewById<View>(R.id.alertdialog_icon) as ImageView).setImageResource(R.drawable.ic_check_while_48dp)
AlertDialog.Builder(ContextThemeWrapper(activity, R.style.AppTheme)) AlertDialog.Builder(ContextThemeWrapper(activity, R.style.AppTheme))
.setCustomTitle(titleLayout) .setCustomTitle(titleLayout)
.setMessage(message) .setMessage(message)
.setPositiveButton(MainApp.gs(R.string.ok)) { dialog: DialogInterface, _: Int -> .setPositiveButton(activity.getString(R.string.ok)) { dialog: DialogInterface, _: Int ->
dialog.dismiss() dialog.dismiss()
SystemClock.sleep(100) SystemClock.sleep(100)
runnable?.let { activity.runOnUiThread(it) } runnable?.let { activity.runOnUiThread(it) }
@ -63,14 +66,15 @@ object OKDialog {
@JvmStatic @JvmStatic
fun showConfirmation(activity: Activity, message: String, ok: Runnable?) { 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 @JvmStatic
fun showConfirmation(activity: Activity, message: Spanned, ok: Runnable?) { 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 @JvmStatic
@JvmOverloads @JvmOverloads
fun showConfirmation(activity: Activity, title: String, message: Spanned, ok: Runnable?, cancel: Runnable? = null) { fun showConfirmation(activity: Activity, title: String, message: Spanned, ok: Runnable?, cancel: Runnable? = null) {
@ -95,6 +99,7 @@ object OKDialog {
.setCanceledOnTouchOutside(false) .setCanceledOnTouchOutside(false)
} }
@SuppressLint("InflateParams")
@JvmStatic @JvmStatic
fun showConfirmation(activity: Activity, title: String, message: String, ok: Runnable?, cancel: Runnable? = null) { fun showConfirmation(activity: Activity, title: String, message: String, ok: Runnable?, cancel: Runnable? = null) {
val titleLayout = activity.layoutInflater.inflate(R.layout.dialog_alert_custom, null) val titleLayout = activity.layoutInflater.inflate(R.layout.dialog_alert_custom, null)
@ -120,9 +125,10 @@ object OKDialog {
@JvmStatic @JvmStatic
@JvmOverloads @JvmOverloads
fun showConfirmation(context: Context, message: Spanned, ok: Runnable?, cancel: Runnable? = null) { 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 @JvmStatic
@JvmOverloads @JvmOverloads
fun showConfirmation(context: Context, title: String, message: Spanned, ok: Runnable?, cancel: Runnable? = null) { fun showConfirmation(context: Context, title: String, message: Spanned, ok: Runnable?, cancel: Runnable? = null) {
@ -150,9 +156,10 @@ object OKDialog {
@JvmStatic @JvmStatic
@JvmOverloads @JvmOverloads
fun showConfirmation(context: Context, message: String, ok: Runnable?, cancel: Runnable? = null) { 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 @JvmStatic
@JvmOverloads @JvmOverloads
fun showConfirmation(context: Context, title: String, message: String, ok: Runnable?, cancel: Runnable? = null) { fun showConfirmation(context: Context, title: String, message: String, ok: Runnable?, cancel: Runnable? = null) {
@ -176,6 +183,7 @@ object OKDialog {
.setCanceledOnTouchOutside(false) .setCanceledOnTouchOutside(false)
} }
@SuppressLint("InflateParams")
@JvmStatic @JvmStatic
@JvmOverloads @JvmOverloads
fun showConfirmation(context: Context, title: String, message: String, ok: DialogInterface.OnClickListener?, cancel: DialogInterface.OnClickListener? = null) { 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.text.Spanned
import android.util.LongSparseArray import android.util.LongSparseArray
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.db.TDD import info.nightscout.androidaps.db.TDD
@ -21,6 +22,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP
import javax.inject.Inject import javax.inject.Inject
class TddCalculator @Inject constructor( class TddCalculator @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
rxBus: RxBusWrapper, rxBus: RxBusWrapper,
resourceHelper: ResourceHelper, resourceHelper: ResourceHelper,
@ -28,7 +30,7 @@ class TddCalculator @Inject constructor(
val sp: SP, val sp: SP,
val configBuilderPlugin: ConfigBuilderPlugin, val configBuilderPlugin: ConfigBuilderPlugin,
val profileFunction: ProfileFunction val profileFunction: ProfileFunction
) : TreatmentsPlugin(aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, configBuilderPlugin) { ) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, configBuilderPlugin) {
init { init {
service = TreatmentService() // plugin is not started service = TreatmentService() // plugin is not started

View file

@ -180,14 +180,6 @@ public class AAPSMocker {
when(ConfigBuilderPlugin.getPlugin()).thenReturn(configBuilderPlugin); 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() { public static void mockSP() {
PowerMockito.mockStatic(SP.class); PowerMockito.mockStatic(SP.class);
when(SP.getLong(anyInt(), anyLong())).thenReturn(0L); when(SP.getLong(anyInt(), anyLong())).thenReturn(0L);

View file

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