Insulin interface
This commit is contained in:
parent
04ae55ac63
commit
25491fbac6
34 changed files with 338 additions and 88 deletions
|
@ -43,8 +43,8 @@ android {
|
|||
applicationId "info.nightscout.androidaps"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 23
|
||||
versionCode 1100
|
||||
version "1.33"
|
||||
versionCode 1400
|
||||
version "1.4"
|
||||
buildConfigField "String", "VERSION", '"' + version + '"'
|
||||
buildConfigField "String", "BUILDVERSION", generateGitBuild()
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ public class Constants {
|
|||
public static final double MMOLL_TO_MGDL = 18; // 18.0182;
|
||||
public static final double MGDL_TO_MMOLL = 1 / MMOLL_TO_MGDL;
|
||||
|
||||
public static final double defaultDIA = 3d;
|
||||
|
||||
public static final double basalAbsoluteOnlyForCheckLimit = 10101010d;
|
||||
public static final Integer basalPercentOnlyForCheckLimit = 10101010;
|
||||
public static final double bolusOnlyForCheckLimit = 10101010d;
|
||||
|
|
|
@ -27,6 +27,7 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
|
|||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.DanaR.DanaRFragment;
|
||||
import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanFragment;
|
||||
import info.nightscout.androidaps.plugins.InsulinFastacting.InsulinFastactingFragment;
|
||||
import info.nightscout.androidaps.plugins.LocalProfile.LocalProfileFragment;
|
||||
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
|
||||
import info.nightscout.androidaps.plugins.MDI.MDIFragment;
|
||||
|
@ -86,6 +87,7 @@ public class MainApp extends Application {
|
|||
// Register all tabs in app here
|
||||
pluginsList.add(OverviewFragment.getPlugin());
|
||||
if (Config.ACTION) pluginsList.add(ActionsFragment.getPlugin());
|
||||
pluginsList.add(InsulinFastactingFragment.getPlugin());
|
||||
if (Config.DANAR) pluginsList.add(DanaRFragment.getPlugin());
|
||||
if (Config.DANARKOREAN) pluginsList.add(DanaRKoreanFragment.getPlugin());
|
||||
pluginsList.add(CareportalFragment.getPlugin());
|
||||
|
|
|
@ -32,10 +32,12 @@ import info.nightscout.androidaps.db.TempTarget;
|
|||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.DanaR.History.DanaRNSHistorySync;
|
||||
import info.nightscout.androidaps.plugins.InsulinFastacting.InsulinFastactingFragment;
|
||||
import info.nightscout.androidaps.plugins.NSProfile.NSProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.Objectives.ObjectivesPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||
|
@ -520,7 +522,9 @@ public class DataService extends IntentService {
|
|||
} else {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("ADD: New treatment: " + trstring);
|
||||
Treatment treatment = new Treatment();
|
||||
InsulinInterface insulinInterface = MainApp.getConfigBuilder().getActiveInsulin();
|
||||
if (insulinInterface == null) insulinInterface = InsulinFastactingFragment.getPlugin();
|
||||
Treatment treatment = new Treatment(insulinInterface);
|
||||
treatment._id = _id;
|
||||
treatment.carbs = trJson.has("carbs") ? trJson.getDouble("carbs") : 0;
|
||||
treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d;
|
||||
|
@ -575,7 +579,9 @@ public class DataService extends IntentService {
|
|||
|
||||
if (Config.logIncommingData)
|
||||
log.debug("CHANGE: Adding new treatment: " + trstring);
|
||||
Treatment treatment = new Treatment();
|
||||
InsulinInterface insulinInterface = MainApp.getConfigBuilder().getActiveInsulin();
|
||||
if (insulinInterface == null) insulinInterface = InsulinFastactingFragment.getPlugin();
|
||||
Treatment treatment = new Treatment(insulinInterface);
|
||||
treatment._id = _id;
|
||||
treatment.carbs = trJson.has("carbs") ? trJson.getDouble("carbs") : 0;
|
||||
treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d;
|
||||
|
|
|
@ -41,7 +41,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
public static final String DATABASE_DANARHISTORY = "DanaRHistory";
|
||||
public static final String DATABASE_DBREQUESTS = "DBRequests";
|
||||
|
||||
private static final int DATABASE_VERSION = 5;
|
||||
private static final int DATABASE_VERSION = 6;
|
||||
|
||||
private long latestTreatmentChange = 0;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Date;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.data.Iob;
|
||||
import info.nightscout.androidaps.data.IobTotal;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
|
@ -55,6 +56,7 @@ public class TempBasal {
|
|||
public IobTotal iobCalc(Date time) {
|
||||
IobTotal result = new IobTotal(time.getTime());
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
InsulinInterface insulinInterface = MainApp.getConfigBuilder().getActiveInsulin();
|
||||
|
||||
if (profile == null)
|
||||
return result;
|
||||
|
@ -93,12 +95,12 @@ public class TempBasal {
|
|||
if (tempBolusCount > 0) {
|
||||
Long tempBolusSpacing = realDuration / tempBolusCount;
|
||||
for (Long j = 0l; j < tempBolusCount; j++) {
|
||||
Treatment tempBolusPart = new Treatment();
|
||||
Treatment tempBolusPart = new Treatment(insulinInterface);
|
||||
tempBolusPart.insulin = tempBolusSize;
|
||||
Long date = this.timeStart.getTime() + j * tempBolusSpacing * 60 * 1000;
|
||||
tempBolusPart.created_at = new Date(date);
|
||||
|
||||
Iob aIOB = tempBolusPart.iobCalc(time, profile.getDia());
|
||||
Iob aIOB = insulinInterface.iobCalc(tempBolusPart, time, profile.getDia());
|
||||
result.basaliob += aIOB.iobContrib;
|
||||
result.activity += aIOB.activityContrib;
|
||||
Double dia_ago = time.getTime() - profile.getDia() * 60 * 60 * 1000;
|
||||
|
|
|
@ -11,8 +11,10 @@ import org.slf4j.LoggerFactory;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.data.Iob;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
||||
|
@ -43,12 +45,34 @@ public class Treatment implements DataPointWithLabelInterface {
|
|||
@DatabaseField
|
||||
public Double insulin = 0d;
|
||||
|
||||
@DatabaseField
|
||||
public int insulinType = InsulinInterface.FASTACTINGINSULIN;
|
||||
|
||||
@DatabaseField
|
||||
public double dia = Constants.defaultDIA;
|
||||
|
||||
@DatabaseField
|
||||
public Double carbs = 0d;
|
||||
|
||||
@DatabaseField
|
||||
public boolean mealBolus = true; // true for meal bolus , false for correction bolus
|
||||
|
||||
public Treatment() {
|
||||
InsulinInterface insulin = MainApp.getConfigBuilder().getActiveInsulin();
|
||||
if (insulin != null) {
|
||||
insulinType = insulin.getId();
|
||||
dia = insulin.getDia();
|
||||
} else {
|
||||
insulinType = InsulinInterface.FASTACTINGINSULIN;
|
||||
dia = Constants.defaultDIA;
|
||||
}
|
||||
}
|
||||
|
||||
public Treatment(InsulinInterface insulin) {
|
||||
insulinType = insulin.getId();
|
||||
dia = insulin.getDia();
|
||||
}
|
||||
|
||||
public void copyFrom(Treatment t) {
|
||||
this._id = t._id;
|
||||
this.created_at = t.created_at;
|
||||
|
@ -57,32 +81,6 @@ public class Treatment implements DataPointWithLabelInterface {
|
|||
this.mealBolus = t.mealBolus;
|
||||
}
|
||||
|
||||
public Iob iobCalc(Date time, Double dia) {
|
||||
Iob result = new Iob();
|
||||
|
||||
Double scaleFactor = 3.0 / dia;
|
||||
Double peak = 75d;
|
||||
Double end = 180d;
|
||||
|
||||
if (this.insulin != 0d) {
|
||||
Long bolusTime = this.created_at.getTime();
|
||||
Double minAgo = scaleFactor * (time.getTime() - bolusTime) / 1000d / 60d;
|
||||
|
||||
if (minAgo < peak) {
|
||||
Double x1 = minAgo / 5d + 1;
|
||||
result.iobContrib = this.insulin * (1 - 0.001852 * x1 * x1 + 0.001852 * x1);
|
||||
// units: BG (mg/dL) = (BG/U) * U insulin * scalar
|
||||
result.activityContrib = this.insulin * (2 / dia / 60 / peak) * minAgo;
|
||||
|
||||
} else if (minAgo < end) {
|
||||
Double x2 = (minAgo - 75) / 5;
|
||||
result.iobContrib = this.insulin * (0.001323 * x2 * x2 - 0.054233 * x2 + 0.55556);
|
||||
result.activityContrib = this.insulin * (2 / dia / 60 - (minAgo - peak) * 2 / dia / 60 / (60 * 3 - peak));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public long getMillisecondsFromStart() {
|
||||
return new Date().getTime() - created_at.getTime();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package info.nightscout.androidaps.interfaces;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.data.Iob;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
|
||||
/**
|
||||
* Created by mike on 17.04.2017.
|
||||
*/
|
||||
|
||||
public interface InsulinInterface {
|
||||
final int FASTACTINGINSULIN = 0;
|
||||
|
||||
int getId();
|
||||
String getFriendlyName();
|
||||
String getComment();
|
||||
int getResourcePicture();
|
||||
double getDia();
|
||||
public Iob iobCalc(Treatment treatment, Date time, Double dia);
|
||||
}
|
|
@ -15,7 +15,8 @@ public interface PluginBase {
|
|||
int CONSTRAINTS = 7;
|
||||
int LOOP = 8;
|
||||
int BGSOURCE = 9;
|
||||
int LAST = 10; // keep always highest number
|
||||
int INSULIN = 10;
|
||||
int LAST = 11; // keep always highest number
|
||||
|
||||
int getType();
|
||||
String getFragmentClass();
|
||||
|
|
|
@ -39,7 +39,7 @@ public interface PumpInterface {
|
|||
TempBasal getTempBasal();
|
||||
TempBasal getExtendedBolus();
|
||||
|
||||
PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context);
|
||||
PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context);
|
||||
void stopBolusDelivering();
|
||||
PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes);
|
||||
PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes);
|
||||
|
|
|
@ -159,7 +159,7 @@ public class FillDialog extends DialogFragment implements OnClickListener {
|
|||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PumpEnactResult result = pump.deliverTreatment(finalInsulinAfterConstraints, 0, context, false);
|
||||
PumpEnactResult result = pump.deliverTreatment(MainApp.getConfigBuilder().getActiveInsulin(), finalInsulinAfterConstraints, 0, context, false);
|
||||
if (!result.success) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||
|
|
|
@ -129,7 +129,7 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
|||
|
||||
mgdl = SP.getBoolean(SETTINGS_PREFIX + "mgdl", true);
|
||||
mmol = SP.getBoolean(SETTINGS_PREFIX + "mmol", false);
|
||||
dia = SP.getDouble(SETTINGS_PREFIX + "dia", 3d);
|
||||
dia = SP.getDouble(SETTINGS_PREFIX + "dia", Constants.defaultDIA);
|
||||
targetLow = SP.getDouble(SETTINGS_PREFIX + "targetlow", 80d);
|
||||
targetHigh = SP.getDouble(SETTINGS_PREFIX + "targethigh", 120d);
|
||||
percentage = SP.getInt(SETTINGS_PREFIX + "percentage", 100);
|
||||
|
|
|
@ -21,6 +21,9 @@ import com.crashlytics.android.answers.CustomEvent;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventConfigBuilderChange;
|
||||
|
@ -29,9 +32,11 @@ import info.nightscout.androidaps.interfaces.APSInterface;
|
|||
import info.nightscout.androidaps.interfaces.BgSourceInterface;
|
||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||
import info.nightscout.androidaps.interfaces.FragmentBase;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.InsulinFastacting.InsulinFastactingPlugin;
|
||||
import info.nightscout.androidaps.plugins.NSProfile.NSProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.VirtualPump.VirtualPumpPlugin;
|
||||
import info.nightscout.utils.PasswordProtection;
|
||||
|
@ -45,23 +50,44 @@ public class ConfigBuilderFragment extends Fragment implements FragmentBase {
|
|||
return configBuilderPlugin;
|
||||
}
|
||||
|
||||
@BindView(R.id.configbuilder_insulinlistview)
|
||||
ListView insulinListView;
|
||||
@BindView(R.id.configbuilder_bgsourcelistview)
|
||||
ListView bgsourceListView;
|
||||
@BindView(R.id.configbuilder_pumplistview)
|
||||
ListView pumpListView;
|
||||
@BindView(R.id.configbuilder_pumplabel)
|
||||
TextView pumpLabel;
|
||||
@BindView(R.id.configbuilder_looplistview)
|
||||
ListView loopListView;
|
||||
@BindView(R.id.configbuilder_looplabel)
|
||||
TextView loopLabel;
|
||||
@BindView(R.id.configbuilder_treatmentslistview)
|
||||
ListView treatmentsListView;
|
||||
@BindView(R.id.configbuilder_tempslistview)
|
||||
ListView tempsListView;
|
||||
@BindView(R.id.configbuilder_tempslabel)
|
||||
TextView tempsLabel;
|
||||
@BindView(R.id.configbuilder_profilelistview)
|
||||
ListView profileListView;
|
||||
@BindView(R.id.configbuilder_apslistview)
|
||||
ListView apsListView;
|
||||
@BindView(R.id.configbuilder_apslabel)
|
||||
TextView apsLabel;
|
||||
@BindView(R.id.configbuilder_constraintslistview)
|
||||
ListView constraintsListView;
|
||||
@BindView(R.id.configbuilder_constraintslabel)
|
||||
TextView constraintsLabel;
|
||||
@BindView(R.id.configbuilder_generallistview)
|
||||
ListView generalListView;
|
||||
@BindView(R.id.configbuilder_nsclientversion)
|
||||
TextView nsclientVerView;
|
||||
@BindView(R.id.configbuilder_nightscoutversion)
|
||||
TextView nightscoutVerView;
|
||||
|
||||
private Unbinder unbinder;
|
||||
|
||||
PluginCustomAdapter insulinDataAdapter = null;
|
||||
PluginCustomAdapter bgsourceDataAdapter = null;
|
||||
PluginCustomAdapter pumpDataAdapter = null;
|
||||
PluginCustomAdapter loopDataAdapter = null;
|
||||
|
@ -72,7 +98,9 @@ public class ConfigBuilderFragment extends Fragment implements FragmentBase {
|
|||
PluginCustomAdapter constraintsDataAdapter = null;
|
||||
PluginCustomAdapter generalDataAdapter = null;
|
||||
|
||||
@BindView(R.id.configbuilder_mainlayout)
|
||||
LinearLayout mainLayout;
|
||||
@BindView(R.id.configbuilder_unlock)
|
||||
Button unlock;
|
||||
|
||||
// TODO: sorting
|
||||
|
@ -81,22 +109,8 @@ public class ConfigBuilderFragment extends Fragment implements FragmentBase {
|
|||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.configbuilder_fragment, container, false);
|
||||
bgsourceListView = (ListView) view.findViewById(R.id.configbuilder_bgsourcelistview);
|
||||
pumpListView = (ListView) view.findViewById(R.id.configbuilder_pumplistview);
|
||||
pumpLabel = (TextView) view.findViewById(R.id.configbuilder_pumplabel);
|
||||
loopListView = (ListView) view.findViewById(R.id.configbuilder_looplistview);
|
||||
loopLabel = (TextView) view.findViewById(R.id.configbuilder_looplabel);
|
||||
treatmentsListView = (ListView) view.findViewById(R.id.configbuilder_treatmentslistview);
|
||||
tempsListView = (ListView) view.findViewById(R.id.configbuilder_tempslistview);
|
||||
tempsLabel = (TextView) view.findViewById(R.id.configbuilder_tempslabel);
|
||||
profileListView = (ListView) view.findViewById(R.id.configbuilder_profilelistview);
|
||||
apsListView = (ListView) view.findViewById(R.id.configbuilder_apslistview);
|
||||
apsLabel = (TextView) view.findViewById(R.id.configbuilder_apslabel);
|
||||
constraintsListView = (ListView) view.findViewById(R.id.configbuilder_constraintslistview);
|
||||
constraintsLabel = (TextView) view.findViewById(R.id.configbuilder_constraintslabel);
|
||||
generalListView = (ListView) view.findViewById(R.id.configbuilder_generallistview);
|
||||
nsclientVerView = (TextView) view.findViewById(R.id.configbuilder_nsclientversion);
|
||||
nightscoutVerView = (TextView) view.findViewById(R.id.configbuilder_nightscoutversion);
|
||||
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
|
||||
nsclientVerView.setText(ConfigBuilderPlugin.nsClientVersionName);
|
||||
nightscoutVerView.setText(ConfigBuilderPlugin.nightscoutVersionName);
|
||||
|
@ -105,9 +119,6 @@ public class ConfigBuilderFragment extends Fragment implements FragmentBase {
|
|||
nightscoutVerView.setTextColor(Color.RED);
|
||||
setViews();
|
||||
|
||||
unlock = (Button) view.findViewById(R.id.configbuilder_unlock);
|
||||
mainLayout = (LinearLayout) view.findViewById(R.id.configbuilder_mainlayout);
|
||||
|
||||
if (PasswordProtection.isLocked("settings_password")) {
|
||||
mainLayout.setVisibility(View.GONE);
|
||||
unlock.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -128,7 +139,16 @@ public class ConfigBuilderFragment extends Fragment implements FragmentBase {
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
unbinder.unbind();
|
||||
}
|
||||
|
||||
void setViews() {
|
||||
insulinDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsListByInterface(InsulinInterface.class), PluginBase.INSULIN);
|
||||
insulinListView.setAdapter(insulinDataAdapter);
|
||||
setListViewHeightBasedOnChildren(insulinListView);
|
||||
bgsourceDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsListByInterface(BgSourceInterface.class), PluginBase.BGSOURCE);
|
||||
bgsourceListView.setAdapter(bgsourceDataAdapter);
|
||||
setListViewHeightBasedOnChildren(bgsourceListView);
|
||||
|
@ -253,7 +273,7 @@ public class ConfigBuilderFragment extends Fragment implements FragmentBase {
|
|||
}
|
||||
|
||||
// Hide enabled control and force enabled plugin if there is only one plugin available
|
||||
if (type == PluginBase.PUMP || type == PluginBase.TREATMENT || type == PluginBase.TEMPBASAL || type == PluginBase.PROFILE)
|
||||
if (type == PluginBase.INSULIN || type == PluginBase.PUMP || type == PluginBase.TREATMENT || type == PluginBase.TEMPBASAL || type == PluginBase.PROFILE)
|
||||
if (pluginList.size() < 2) {
|
||||
holder.checkboxEnabled.setEnabled(false);
|
||||
plugin.setFragmentEnabled(type, true);
|
||||
|
@ -299,6 +319,9 @@ public class ConfigBuilderFragment extends Fragment implements FragmentBase {
|
|||
case PluginBase.LOOP:
|
||||
break;
|
||||
// Single selection allowed
|
||||
case PluginBase.INSULIN:
|
||||
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(InsulinInterface.class);
|
||||
break;
|
||||
case PluginBase.APS:
|
||||
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(APSInterface.class);
|
||||
break;
|
||||
|
@ -328,6 +351,8 @@ public class ConfigBuilderFragment extends Fragment implements FragmentBase {
|
|||
} else { // enable first plugin in list
|
||||
if (type == PluginBase.PUMP)
|
||||
MainApp.getSpecificPlugin(VirtualPumpPlugin.class).setFragmentEnabled(type, true);
|
||||
else if (type == PluginBase.INSULIN)
|
||||
MainApp.getSpecificPlugin(InsulinFastactingPlugin.class).setFragmentEnabled(type, true);
|
||||
else if (type == PluginBase.PROFILE)
|
||||
MainApp.getSpecificPlugin(NSProfilePlugin.class).setFragmentEnabled(type, true);
|
||||
else
|
||||
|
|
|
@ -37,6 +37,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
|
|||
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||
import info.nightscout.androidaps.interfaces.BgSourceInterface;
|
||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||
|
@ -74,6 +75,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
static TempBasalsInterface activeTempBasals;
|
||||
static APSInterface activeAPS;
|
||||
static LoopPlugin activeLoop;
|
||||
static InsulinInterface activeInsulin;
|
||||
|
||||
static public String nightscoutVersionName = "";
|
||||
static public Integer nightscoutVersionCode = 0;
|
||||
|
@ -205,6 +207,10 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
return activeTempBasals;
|
||||
}
|
||||
|
||||
public static InsulinInterface getActiveInsulin() {
|
||||
return activeInsulin;
|
||||
}
|
||||
|
||||
public static APSInterface getActiveAPS() {
|
||||
return activeAPS;
|
||||
}
|
||||
|
@ -224,7 +230,8 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
(p.isEnabled(6) ? " PUMP" : "") +
|
||||
(p.isEnabled(7) ? " CONSTRAINTS" : "") +
|
||||
(p.isEnabled(8) ? " LOOP" : "") +
|
||||
(p.isEnabled(9) ? " BGSOURCE" : "")
|
||||
(p.isEnabled(9) ? " BGSOURCE" : "") +
|
||||
(p.isEnabled(10) ? " INSULIN" : "")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -245,6 +252,17 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
}
|
||||
}
|
||||
|
||||
// PluginBase.INSULIN
|
||||
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(InsulinInterface.class);
|
||||
activeInsulin = (InsulinInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.INSULIN);
|
||||
if (Config.logConfigBuilder)
|
||||
log.debug("Selected insulin interface: " + ((PluginBase) activeInsulin).getName());
|
||||
for (PluginBase p : pluginsInCategory) {
|
||||
if (!p.getName().equals(((PluginBase) activeInsulin).getName())) {
|
||||
p.setFragmentVisible(PluginBase.INSULIN, false);
|
||||
}
|
||||
}
|
||||
|
||||
// PluginBase.PROFILE
|
||||
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(ProfileInterface.class);
|
||||
activeProfile = (ProfileInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.PROFILE);
|
||||
|
@ -463,7 +481,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
return null;
|
||||
}
|
||||
|
||||
public PumpEnactResult deliverTreatmentFromBolusWizard(Context context, Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) {
|
||||
public PumpEnactResult deliverTreatmentFromBolusWizard(InsulinInterface insulinType, Context context, Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) {
|
||||
mWakeLock.acquire();
|
||||
PumpEnactResult result;
|
||||
if (activePump != null) {
|
||||
|
@ -479,14 +497,14 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
|
||||
MainApp.bus().post(new EventBolusRequested(insulin));
|
||||
|
||||
result = activePump.deliverTreatment(insulin, carbs, context);
|
||||
result = activePump.deliverTreatment(insulinType, insulin, carbs, context);
|
||||
|
||||
BolusProgressDialog.bolusEnded = true;
|
||||
|
||||
MainApp.bus().post(new EventDismissBolusprogressIfRunning(result));
|
||||
|
||||
if (result.success) {
|
||||
Treatment t = new Treatment();
|
||||
Treatment t = new Treatment(insulinType);
|
||||
t.insulin = result.bolusDelivered;
|
||||
if (carbTime == 0)
|
||||
t.carbs = (double) result.carbsDelivered; // with different carbTime record will come back from nightscout
|
||||
|
@ -500,7 +518,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
} else {
|
||||
if (Config.logCongigBuilderActions)
|
||||
log.debug("Creating treatment: " + insulin + " carbs: " + carbs);
|
||||
Treatment t = new Treatment();
|
||||
Treatment t = new Treatment(insulinType);
|
||||
t.insulin = insulin;
|
||||
t.carbs = (double) carbs;
|
||||
t.created_at = new Date();
|
||||
|
@ -518,11 +536,11 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context) {
|
||||
return deliverTreatment(insulin, carbs, context, true);
|
||||
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
|
||||
return deliverTreatment(insulinType, insulin, carbs, context, true);
|
||||
}
|
||||
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context, boolean createTreatment) {
|
||||
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context, boolean createTreatment) {
|
||||
mWakeLock.acquire();
|
||||
PumpEnactResult result;
|
||||
if (activePump != null) {
|
||||
|
@ -544,7 +562,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
|
||||
MainApp.bus().post(new EventBolusRequested(insulin));
|
||||
|
||||
result = activePump.deliverTreatment(insulin, carbs, context);
|
||||
result = activePump.deliverTreatment(insulinType, insulin, carbs, context);
|
||||
|
||||
BolusProgressDialog.bolusEnded = true;
|
||||
|
||||
|
@ -554,7 +572,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
log.debug("deliverTreatment insulin: " + insulin + " carbs: " + carbs + " success: " + result.success + " enacted: " + result.enacted + " bolusDelivered: " + result.bolusDelivered);
|
||||
|
||||
if (result.success && createTreatment) {
|
||||
Treatment t = new Treatment();
|
||||
Treatment t = new Treatment(insulinType);
|
||||
t.insulin = result.bolusDelivered;
|
||||
t.carbs = (double) result.carbsDelivered;
|
||||
t.created_at = new Date();
|
||||
|
@ -566,7 +584,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
} else {
|
||||
if (Config.logCongigBuilderActions)
|
||||
log.debug("Creating treatment: " + insulin + " carbs: " + carbs);
|
||||
Treatment t = new Treatment();
|
||||
Treatment t = new Treatment(insulinType);
|
||||
t.insulin = insulin;
|
||||
t.carbs = (double) carbs;
|
||||
t.created_at = new Date();
|
||||
|
|
|
@ -30,6 +30,7 @@ import info.nightscout.androidaps.db.Treatment;
|
|||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||
|
@ -357,11 +358,11 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context) {
|
||||
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
|
||||
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
||||
if (insulin > 0 || carbs > 0) {
|
||||
Treatment t = new Treatment();
|
||||
Treatment t = new Treatment(insulinType);
|
||||
boolean connectionOK = false;
|
||||
if (insulin > 0 || carbs > 0) connectionOK = sExecutionService.bolus(insulin, carbs, t);
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
|
|
|
@ -119,7 +119,7 @@ public class DanaRPump {
|
|||
// Evening / 17:00–21:59
|
||||
// Night / 22:00–5:59
|
||||
|
||||
double dia = SP.getDouble(R.string.key_danarprofile_dia, 3d);
|
||||
double dia = SP.getDouble(R.string.key_danarprofile_dia, Constants.defaultDIA);
|
||||
|
||||
try {
|
||||
json.put("defaultProfile", PROFILE_PREFIX + (activeProfile + 1));
|
||||
|
|
|
@ -30,6 +30,7 @@ import info.nightscout.androidaps.db.Treatment;
|
|||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||
|
@ -358,11 +359,11 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
|
|||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context) {
|
||||
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
|
||||
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
||||
if (insulin > 0 || carbs > 0) {
|
||||
Treatment t = new Treatment();
|
||||
Treatment t = new Treatment(insulinType);
|
||||
boolean connectionOK = false;
|
||||
if (insulin > 0 || carbs > 0) connectionOK = sExecutionService.bolus(insulin, carbs, t);
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
|
|
|
@ -114,7 +114,7 @@ public class DanaRKoreanPump {
|
|||
// Evening / 17:00–21:59
|
||||
// Night / 22:00–5:59
|
||||
|
||||
double dia = SP.getDouble(R.string.key_danarprofile_dia, 3d);
|
||||
double dia = SP.getDouble(R.string.key_danarprofile_dia, Constants.defaultDIA);
|
||||
|
||||
try {
|
||||
json.put("defaultProfile", PROFILE_PREFIX + (activeProfile + 1));
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package info.nightscout.androidaps.plugins.InsulinFastacting;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import info.nightscout.androidaps.interfaces.FragmentBase;
|
||||
|
||||
/**
|
||||
* Created by mike on 17.04.2017.
|
||||
*/
|
||||
|
||||
public class InsulinFastactingFragment extends Fragment implements FragmentBase {
|
||||
static InsulinFastactingPlugin insulinFastactingPlugin = new InsulinFastactingPlugin();
|
||||
|
||||
static public InsulinFastactingPlugin getPlugin() {
|
||||
return insulinFastactingPlugin;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package info.nightscout.androidaps.plugins.InsulinFastacting;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Iob;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
|
||||
/**
|
||||
* Created by mike on 17.04.2017.
|
||||
*/
|
||||
|
||||
public class InsulinFastactingPlugin implements PluginBase, InsulinInterface {
|
||||
|
||||
private static boolean fragmentEnabled = true;
|
||||
private static boolean fragmentVisible = false;
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return INSULIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFragmentClass() {
|
||||
return InsulinFastactingFragment.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return MainApp.sResources.getString(R.string.fastactinginsulin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameShort() {
|
||||
return MainApp.sResources.getString(R.string.insulin_shortname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int type) {
|
||||
return type == INSULIN && fragmentEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisibleInTabs(int type) {
|
||||
return type == INSULIN && fragmentVisible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeHidden(int type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
||||
if (type == INSULIN) this.fragmentEnabled = fragmentEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
||||
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
|
||||
}
|
||||
|
||||
// Insulin interface
|
||||
@Override
|
||||
public int getId() {
|
||||
return FASTACTINGINSULIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFriendlyName() {
|
||||
return MainApp.sResources.getString(R.string.fastactinginsulin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComment() {
|
||||
return MainApp.sResources.getString(R.string.fastactinginsulincomment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getResourcePicture() {
|
||||
return R.drawable.insulin0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDia() {
|
||||
ProfileInterface profileInterface = MainApp.getConfigBuilder().getActiveProfile();
|
||||
if (profileInterface.getProfile() != null)
|
||||
return profileInterface.getProfile().getDia();
|
||||
return Constants.defaultDIA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iob iobCalc(Treatment treatment, Date time, Double dia) {
|
||||
Iob result = new Iob();
|
||||
|
||||
Double scaleFactor = 3.0 / dia;
|
||||
Double peak = 75d;
|
||||
Double end = 180d;
|
||||
|
||||
if (treatment.insulin != 0d) {
|
||||
Long bolusTime = treatment.created_at.getTime();
|
||||
Double minAgo = scaleFactor * (time.getTime() - bolusTime) / 1000d / 60d;
|
||||
|
||||
if (minAgo < peak) {
|
||||
Double x1 = minAgo / 5d + 1;
|
||||
result.iobContrib = treatment.insulin * (1 - 0.001852 * x1 * x1 + 0.001852 * x1);
|
||||
// units: BG (mg/dL) = (BG/U) * U insulin * scalar
|
||||
result.activityContrib = treatment.insulin * (2 / dia / 60 / peak) * minAgo;
|
||||
|
||||
} else if (minAgo < end) {
|
||||
Double x2 = (minAgo - 75) / 5;
|
||||
result.iobContrib = treatment.insulin * (0.001323 * x2 * x2 - 0.054233 * x2 + 0.55556);
|
||||
result.activityContrib = treatment.insulin * (2 / dia / 60 - (minAgo - peak) * 2 / dia / 60 / (60 * 3 - peak));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -120,7 +120,7 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface {
|
|||
|
||||
mgdl = SP.getBoolean("LocalProfile" + "mgdl", false);
|
||||
mmol = SP.getBoolean("LocalProfile" + "mmol", true);
|
||||
dia = SP.getDouble("LocalProfile" + "dia", 3d);
|
||||
dia = SP.getDouble("LocalProfile" + "dia", Constants.defaultDIA);
|
||||
try {
|
||||
ic = new JSONArray(SP.getString("LocalProfile" + "ic", DEFAULTARRAY));
|
||||
} catch (JSONException e1) {
|
||||
|
|
|
@ -15,6 +15,7 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.TempBasal;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
|
@ -183,7 +184,7 @@ public class MDIPlugin implements PluginBase, PumpInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context) {
|
||||
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
result.success = true;
|
||||
result.bolusDelivered = insulin;
|
||||
|
|
|
@ -110,7 +110,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
|||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PumpEnactResult result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints, context);
|
||||
PumpEnactResult result = pump.deliverTreatment(MainApp.getConfigBuilder().getActiveInsulin(), finalInsulinAfterConstraints, finalCarbsAfterConstraints, context);
|
||||
if (!result.success) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||
|
|
|
@ -314,6 +314,7 @@ public class WizardDialog extends DialogFragment {
|
|||
@Override
|
||||
public void run() {
|
||||
PumpEnactResult result = pump.deliverTreatmentFromBolusWizard(
|
||||
MainApp.getConfigBuilder().getActiveInsulin(),
|
||||
context,
|
||||
finalInsulinAfterConstraints,
|
||||
finalCarbsAfterConstraints,
|
||||
|
|
|
@ -510,6 +510,7 @@ public class OverviewFragment extends Fragment {
|
|||
@Override
|
||||
public void run() {
|
||||
PumpEnactResult result = pump.deliverTreatmentFromBolusWizard(
|
||||
MainApp.getConfigBuilder().getActiveInsulin(),
|
||||
getContext(),
|
||||
finalInsulinAfterConstraints,
|
||||
finalCarbsAfterConstraints,
|
||||
|
|
|
@ -118,7 +118,7 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface {
|
|||
|
||||
mgdl = SP.getBoolean("SimpleProfile" + "mgdl", true);
|
||||
mmol = SP.getBoolean("SimpleProfile" + "mmol", false);
|
||||
dia = SP.getDouble("SimpleProfile" + "dia", 3d);
|
||||
dia = SP.getDouble("SimpleProfile" + "dia", Constants.defaultDIA);
|
||||
ic = SP.getDouble("SimpleProfile" + "ic", 20d);
|
||||
isf = SP.getDouble("SimpleProfile" + "isf", 200d);
|
||||
basal = SP.getDouble("SimpleProfile" + "basal", 1d);
|
||||
|
|
|
@ -442,7 +442,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
PumpInterface pumpInterface = MainApp.getConfigBuilder();
|
||||
if (pumpInterface != null) {
|
||||
danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class);
|
||||
PumpEnactResult result = pumpInterface.deliverTreatment(bolusWaitingForConfirmation.bolusRequested, 0, null);
|
||||
PumpEnactResult result = pumpInterface.deliverTreatment(MainApp.getConfigBuilder().getActiveInsulin() ,bolusWaitingForConfirmation.bolusRequested, 0, null);
|
||||
if (result.success) {
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusdelivered), result.bolusDelivered);
|
||||
if (danaRPlugin != null)
|
||||
|
|
|
@ -38,6 +38,7 @@ import info.nightscout.androidaps.data.Iob;
|
|||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
import info.nightscout.androidaps.interfaces.FragmentBase;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
|
@ -81,12 +82,13 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
|||
if (MainApp.getConfigBuilder() == null || MainApp.getConfigBuilder().getActiveProfile() == null) // app not initialized yet
|
||||
return;
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
if (profile == null)
|
||||
InsulinInterface insulinInterface = MainApp.getConfigBuilder().getActiveInsulin();
|
||||
if (profile == null || insulinInterface == null)
|
||||
return;
|
||||
holder.date.setText(DateUtil.dateAndTimeString(treatments.get(position).created_at));
|
||||
holder.insulin.setText(DecimalFormatter.to2Decimal(treatments.get(position).insulin) + " U");
|
||||
holder.carbs.setText(DecimalFormatter.to0Decimal(treatments.get(position).carbs) + " g");
|
||||
Iob iob = treatments.get(position).iobCalc(new Date(), profile.getDia());
|
||||
Iob iob = insulinInterface.iobCalc(treatments.get(position), new Date(), profile.getDia());
|
||||
holder.iob.setText(DecimalFormatter.to2Decimal(iob.iobContrib) + " U");
|
||||
holder.activity.setText(DecimalFormatter.to3Decimal(iob.activityContrib) + " U");
|
||||
holder.mealOrCorrection.setText(treatments.get(position).mealBolus ? MainApp.sResources.getString(R.string.mealbolus) : MainApp.sResources.getString(R.string.correctionbous));
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Iob;
|
||||
|
@ -15,6 +16,7 @@ import info.nightscout.androidaps.data.IobTotal;
|
|||
import info.nightscout.androidaps.data.MealData;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
|
@ -92,7 +94,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
}
|
||||
|
||||
public void initializeData() {
|
||||
double dia = 3;
|
||||
double dia = Constants.defaultDIA;
|
||||
if (MainApp.getConfigBuilder().getActiveProfile() != null && MainApp.getConfigBuilder().getActiveProfile().getProfile() != null)
|
||||
dia = MainApp.getConfigBuilder().getActiveProfile().getProfile().getDia();
|
||||
long fromMills = (long) (new Date().getTime() - 60 * 60 * 1000L * (24 + dia));
|
||||
|
@ -120,6 +122,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
if (MainApp.getConfigBuilder() == null || ConfigBuilderPlugin.getActiveProfile() == null) // app not initialized yet
|
||||
return total;
|
||||
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
|
||||
InsulinInterface insulinInterface = MainApp.getConfigBuilder().getActiveInsulin();
|
||||
if (profile == null)
|
||||
return total;
|
||||
|
||||
|
@ -129,10 +132,10 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
for (Integer pos = 0; pos < treatments.size(); pos++) {
|
||||
Treatment t = treatments.get(pos);
|
||||
if (t.created_at.getTime() > time) continue;
|
||||
Iob tIOB = t.iobCalc(now, dia);
|
||||
Iob tIOB = insulinInterface.iobCalc(t, now, dia);
|
||||
total.iob += tIOB.iobContrib;
|
||||
total.activity += tIOB.activityContrib;
|
||||
Iob bIOB = t.iobCalc(now, dia / SP.getInt("openapsama_bolussnooze_dia_divisor", 2));
|
||||
Iob bIOB = insulinInterface.iobCalc(t, now, dia / SP.getInt("openapsama_bolussnooze_dia_divisor", 2));
|
||||
total.bolussnooze += bIOB.iobContrib;
|
||||
}
|
||||
return total;
|
||||
|
|
|
@ -18,6 +18,7 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.TempBasal;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
|
@ -219,7 +220,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context) {
|
||||
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
result.success = true;
|
||||
result.bolusDelivered = insulin;
|
||||
|
|
|
@ -384,7 +384,7 @@ public class ActionStringHandler {
|
|||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PumpEnactResult result = MainApp.getConfigBuilder().deliverTreatment(amount, 0, null, false);
|
||||
PumpEnactResult result = MainApp.getConfigBuilder().deliverTreatment(MainApp.getConfigBuilder().getActiveInsulin(), amount, 0, null, false);
|
||||
if (!result.success) {
|
||||
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
|
||||
"\n" +
|
||||
|
@ -400,7 +400,7 @@ public class ActionStringHandler {
|
|||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PumpEnactResult result = MainApp.getConfigBuilder().deliverTreatment(amount, carbs, null, true);
|
||||
PumpEnactResult result = MainApp.getConfigBuilder().deliverTreatment(MainApp.getConfigBuilder().getActiveInsulin(), amount, carbs, null, true);
|
||||
if (!result.success) {
|
||||
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
|
||||
"\n" +
|
||||
|
|
BIN
app/src/main/res/drawable/insulin0.png
Normal file
BIN
app/src/main/res/drawable/insulin0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
|
@ -25,6 +25,23 @@
|
|||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:text="@string/configbuilder_insulin"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/configbuilder_insulinlistview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:background="@color/cardColorBackground" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -584,4 +584,8 @@
|
|||
<string name="ns_logappstartedevent">Log app start to NS</string>
|
||||
<string name="key_ns_logappstartedevent" translatable="false">ns_logappstartedevent</string>
|
||||
<string name="restartingapp">Exiting application to apply settings.</string>
|
||||
<string name="configbuilder_insulin">Insulin</string>
|
||||
<string name="fastactinginsulin">Fast Acting Insulin</string>
|
||||
<string name="fastactinginsulincomment">Novorapid, Novolog, Humalog</string>
|
||||
<string name="insulin_shortname">INS</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue