- fixes for Bolus problems

This commit is contained in:
Andy Rozman 2019-04-12 21:20:09 +01:00
parent ad17c66b1b
commit c7f6eb79f0
7 changed files with 210 additions and 355 deletions

View file

@ -65,7 +65,7 @@ android {
multiDexEnabled true
versionCode 1500
// dev_version: 2.2.3-dev
version "medtronic-0.9.2-SNAPSHOT"
version "medtronic-0.9.3-SNAPSHOT"
buildConfigField "String", "VERSION", '"' + version + '"'
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'

View file

@ -19,17 +19,14 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin;
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin;
import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin;
import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin;
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin;
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin;
import info.nightscout.androidaps.plugins.general.wear.WearPlugin;
import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin;
import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin;
import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
@ -42,16 +39,17 @@ import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin;
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin;
import info.nightscout.androidaps.plugins.source.SourceDexcomG5Plugin;
import info.nightscout.androidaps.plugins.general.wear.WearPlugin;
import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin;
import info.nightscout.androidaps.utils.LocaleHelper;
import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.SP;
public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
MyPreferenceFragment myPreferenceFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -63,7 +61,6 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
MainApp.bus().post(new EventPreferenceChange(key));
@ -77,15 +74,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
if (key.equals("short_tabtitles")) {
MainApp.bus().post(new EventRefreshGui());
}
if (key.equals(MainApp.gs(R.string.key_openapsama_useautosens))
&& SP.getBoolean(R.string.key_openapsama_useautosens, false)) {
OKDialog.show(this, MainApp.gs(R.string.configbuilder_sensitivity),
MainApp.gs(R.string.sensitivity_warning), null);
if (key.equals(MainApp.gs(R.string.key_openapsama_useautosens)) && SP.getBoolean(R.string.key_openapsama_useautosens, false)) {
OKDialog.show(this, MainApp.gs(R.string.configbuilder_sensitivity), MainApp.gs(R.string.sensitivity_warning), null);
}
updatePrefSummary(myPreferenceFragment.getPreference(key));
}
private static void updatePrefSummary(Preference pref) {
if (pref instanceof ListPreference) {
ListPreference listPref = (ListPreference) pref;
@ -100,14 +94,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
} else if (editTextPref.getText() != null) {
((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage());
pref.setSummary(editTextPref.getText());
} else if (pref.getKey().contains("smscommunicator_allowednumbers")
&& TextUtils.isEmpty(editTextPref.getText().trim())) {
} else if (pref.getKey().contains("smscommunicator_allowednumbers") && TextUtils.isEmpty(editTextPref.getText().trim())) {
pref.setSummary(MainApp.gs(R.string.smscommunicator_allowednumbers_summary));
}
}
}
public static void initSummary(Preference p) {
if (p instanceof PreferenceGroup) {
PreferenceGroup pGrp = (PreferenceGroup) p;
@ -120,23 +112,19 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
}
public static class MyPreferenceFragment extends PreferenceFragment {
private Integer id;
@Override
public void setArguments(Bundle args) {
super.setArguments(args);
id = args.getInt("id");
}
void addPreferencesFromResourceIfEnabled(PluginBase p, PluginType type) {
if (p.isEnabled(type) && p.getPreferencesId() != -1)
addPreferencesFromResource(p.getPreferencesId());
}
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -168,8 +156,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
}
addPreferencesFromResourceIfEnabled(SensitivityAAPSPlugin.getPlugin(), PluginType.SENSITIVITY);
addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(),
PluginType.SENSITIVITY);
addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(), PluginType.SENSITIVITY);
addPreferencesFromResourceIfEnabled(SensitivityOref0Plugin.getPlugin(), PluginType.SENSITIVITY);
addPreferencesFromResourceIfEnabled(SensitivityOref1Plugin.getPlugin(), PluginType.SENSITIVITY);
@ -209,14 +196,10 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
if (Config.NSCLIENT) {
PreferenceScreen scrnAdvancedSettings = (PreferenceScreen)findPreference(getString(R.string.key_advancedsettings));
if (scrnAdvancedSettings != null) {
scrnAdvancedSettings
.removePreference(getPreference(getString(R.string.key_statuslights_res_warning)));
scrnAdvancedSettings
.removePreference(getPreference(getString(R.string.key_statuslights_res_critical)));
scrnAdvancedSettings
.removePreference(getPreference(getString(R.string.key_statuslights_bat_warning)));
scrnAdvancedSettings
.removePreference(getPreference(getString(R.string.key_statuslights_bat_critical)));
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_res_warning)));
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_res_critical)));
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_bat_warning)));
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_bat_critical)));
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_show_statuslights)));
}
}
@ -224,14 +207,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
initSummary(getPreferenceScreen());
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("id", id);
}
public Preference getPreference(String key) {
return findPreference(key);
}

View file

@ -1,12 +1,12 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
@ -23,7 +23,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
/**
* This file was taken from GGC - GNU Gluco Control and modified/extended for AAPS.
*
* <p>
* Author: Andy {andy.rozman@gmail.com}
*/
@ -631,13 +631,13 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
if (MedtronicDeviceType.isSameDevice(MedtronicUtil.getMedtronicPumpModel(),
MedtronicDeviceType.Medtronic_523andHigher)) {
bolus.setRequestedAmount(ByteUtil.toInt(data[0], data[1]) / 40.0f);
bolus.setDeliveredAmount(ByteUtil.toInt(data[2], data[3]) / 40.0f);
bolus.setInsulinOnBoard(ByteUtil.toInt(data[4], data[5]) / 40.0f);
bolus.setRequestedAmount(ByteUtil.toInt(data[0], data[1]) / 40.0d);
bolus.setDeliveredAmount(ByteUtil.toInt(data[2], data[3]) / 40.0d);
bolus.setInsulinOnBoard(ByteUtil.toInt(data[4], data[5]) / 40.0d);
bolus.setDuration(data[6] * 30);
} else {
bolus.setRequestedAmount(ByteUtil.asUINT8(data[0]) / 10.0f);
bolus.setDeliveredAmount(ByteUtil.asUINT8(data[1]) / 10.0f);
bolus.setRequestedAmount(ByteUtil.asUINT8(data[0]) / 10.0d);
bolus.setDeliveredAmount(ByteUtil.asUINT8(data[1]) / 10.0d);
bolus.setDuration(ByteUtil.asUINT8(data[2]) * 30);
}

View file

@ -605,8 +605,6 @@ public class MedtronicHistoryData {
switch (bolusDTO.getBolusType()) {
case Normal: {
// DetailedBolusInfo normalBolus = new DetailedBolusInfo();
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.date = tryToGetByLocalTime(bolus.atechDateTime);
@ -618,10 +616,6 @@ public class MedtronicHistoryData {
bolus.setLinkedObject(detailedBolusInfo);
// bolus.setLinkedObject(normalBolus);
// TreatmentsPlugin.getPlugin().addToHistoryTreatment(normalBolus, false);
if (L.isEnabled(L.PUMPCOMM))
LOG.debug("addBolus - [date={},pumpId={}, insulin={}, newRecord={}]", detailedBolusInfo.date,
detailedBolusInfo.pumpId, detailedBolusInfo.insulin, newRecord);
@ -652,23 +646,6 @@ public class MedtronicHistoryData {
} else {
boolean old = false;
// if (old) {
// treatment.insulin = bolusDTO.getDeliveredAmount();
// treatment.pumpId = bolus.getPumpId();
// treatment.source = Source.PUMP;
//
// bolus.setLinkedObject(treatment);
//
// TreatmentsPlugin.getPlugin().getService().createOrUpdate(treatment);
//
// LOG.debug("editBolus - [date={},pumpId={}, insulin={}]", treatment.date, treatment.pumpId,
// treatment.insulin);
//
// MainApp.bus().post(new EventTreatmentChange(treatment));
// } else {
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(treatment.date);
if (detailedBolusInfo == null) {
detailedBolusInfo = new DetailedBolusInfo();
@ -678,6 +655,7 @@ public class MedtronicHistoryData {
detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = bolus.getPumpId();
detailedBolusInfo.insulin = bolusDTO.getDeliveredAmount();
detailedBolusInfo.carbs = treatment.carbs;
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);

View file

@ -29,16 +29,16 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpBolusType;
public class BolusDTO extends PumpTimeStampedRecord {
@Expose
private Float requestedAmount;
private Double requestedAmount;
@Expose
private Float deliveredAmount;
private Double deliveredAmount;
@Expose
private Float immediateAmount; // when Multiwave this is used
private Double immediateAmount; // when Multiwave this is used
@Expose
private Integer duration;
@Expose
private PumpBolusType bolusType;
private Float insulinOnBoard;
private Double insulinOnBoard;
public BolusDTO() {
@ -46,22 +46,22 @@ public class BolusDTO extends PumpTimeStampedRecord {
}
public Float getRequestedAmount() {
public Double getRequestedAmount() {
return requestedAmount;
}
public void setRequestedAmount(Float requestedAmount) {
public void setRequestedAmount(Double requestedAmount) {
this.requestedAmount = requestedAmount;
}
public Float getDeliveredAmount() {
public Double getDeliveredAmount() {
return deliveredAmount;
}
public void setDeliveredAmount(Float deliveredAmount) {
public void setDeliveredAmount(Double deliveredAmount) {
this.deliveredAmount = deliveredAmount;
}
@ -86,12 +86,12 @@ public class BolusDTO extends PumpTimeStampedRecord {
}
public Float getInsulinOnBoard() {
public Double getInsulinOnBoard() {
return insulinOnBoard;
}
public void setInsulinOnBoard(Float insulinOnBoard) {
public void setInsulinOnBoard(Double insulinOnBoard) {
this.insulinOnBoard = insulinOnBoard;
}
@ -131,12 +131,12 @@ public class BolusDTO extends PumpTimeStampedRecord {
}
public Float getImmediateAmount() {
public Double getImmediateAmount() {
return immediateAmount;
}
public void setImmediateAmount(Float immediateAmount) {
public void setImmediateAmount(Double immediateAmount) {
this.immediateAmount = immediateAmount;
}

View file

@ -108,9 +108,9 @@ public class Treatment implements DataPointWithLabelInterface {
public boolean isDataChanging(Treatment other) {
if (date != other.date)
return true;
if (insulin != other.insulin)
if (!isSame(insulin, other.insulin))
return true;
if (carbs != other.carbs)
if (!isSame(carbs, other.carbs))
return true;
return false;
}
@ -118,9 +118,9 @@ public class Treatment implements DataPointWithLabelInterface {
public boolean isEqual(Treatment other) {
if (date != other.date)
return false;
if (insulin != other.insulin)
if (!isSame(insulin, other.insulin))
return false;
if (carbs != other.carbs)
if (!isSame(carbs, other.carbs))
return false;
if (mealBolus != other.mealBolus)
return false;
@ -136,9 +136,9 @@ public class Treatment implements DataPointWithLabelInterface {
public boolean isEqualWithoutPumpId(Treatment other) {
if (date != other.date)
return false;
if (insulin != other.insulin)
if (!isSame(insulin, other.insulin))
return false;
if (carbs != other.carbs)
if (!isSame(carbs, other.carbs))
return false;
if (mealBolus != other.mealBolus)
return false;
@ -149,6 +149,11 @@ public class Treatment implements DataPointWithLabelInterface {
return true;
}
public boolean isSame(Double d1, Double d2) {
double diff = d1 - d2;
return (Math.abs(diff) <= 0.000001);
}
@Nullable
public JSONObject getBoluscalc() {
@ -168,12 +173,13 @@ public class Treatment implements DataPointWithLabelInterface {
if (date != other.date) {
return false;
}
if (insulin != other.insulin) {
if (!isSame(insulin, other.insulin))
return false;
}
if (carbs != other.carbs) {
if (!isSame(carbs, other.carbs))
return false;
}
return true;
}