diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.java index 1bb22614e8..d68cdd0296 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.java @@ -481,7 +481,7 @@ public class MedtronicFragment extends SubscriberFragment { } // battery - batteryView.setText("{fa-battery-" + (pumpStatus.batteryRemaining / 25) + "}"); + batteryView.setText("{fa-battery-" + (pumpStatus.batteryRemaining / 25) + "} " + pumpStatus.batteryRemaining + "%"); SetWarnColor.setColorInverse(batteryView, pumpStatus.batteryRemaining, 51d, 26d); // reservoir diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java index 8b521f9324..527de8c68c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java @@ -135,7 +135,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter medtronicService = null; } - public void onServiceConnected(ComponentName name, IBinder service) { if (isLoggingEnabled()) LOG.debug("RileyLinkMedtronicService is connected"); @@ -285,7 +284,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter @Override public boolean isInitialized() { - // TODO remove if (isLoggingEnabled() && displayConnectionMessages) LOG.debug("MedtronicPumpPlugin::isInitialized"); return isServiceSet() && isInitialized; @@ -532,8 +530,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter readPumpHistory(); - // TODO rewrite reading of data to be done in background or different thread perhaps ?? - // remaining insulin (>50 = 4h; 50-20 = 1h; 15m) medtronicUIComm.executeCommand(MedtronicCommandType.GetRemainingInsulin); scheduleNextRefresh(MedtronicStatusRefreshType.RemainingInsulin, 10); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverter.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverter.java index 2e83649b4a..132221b527 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverter.java @@ -172,7 +172,7 @@ public class MedtronicConverter { // if response in 3 bytes then we add additional information // double d = MedtronicUtil.makeUnsignedShort(rawData[2], rawData[1]) / 100.0d; - double d = ByteUtil.toInt(rawData[1], rawData[2]) / 100.0d; + double d = (ByteUtil.toInt(rawData[1], rawData[2])*1.0d) / 100.0d; batteryStatus.voltage = d; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.java index 38e6c0dd44..ca637030a8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.java @@ -100,10 +100,14 @@ public class MedtronicUIPostprocessor { case GetBatteryStatus: { BatteryStatusDTO batteryStatusDTO = (BatteryStatusDTO)uiTask.returnData; - if (batteryStatusDTO.batteryStatusType == BatteryStatusDTO.BatteryStatusType.Low) - pumpStatus.batteryRemaining = 18; - else - pumpStatus.batteryRemaining = 70; + pumpStatus.batteryRemaining = (batteryStatusDTO.getCalculatedPercent(pumpStatus.batteryType)); + + LOG.info("BatteryStatus: {}", batteryStatusDTO.toString()); + +// if (batteryStatusDTO.batteryStatusType == BatteryStatusDTO.BatteryStatusType.Low) +// pumpStatus.batteryRemaining = 18; +// else +// pumpStatus.batteryRemaining = 70; } break; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java index 587c3ec8f5..067041fce4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java @@ -12,15 +12,29 @@ public class BatteryStatusDTO { @Expose public BatteryStatusType batteryStatusType; - public double voltage; + public Double voltage; public int getCalculatedPercent(BatteryType batteryType) { + if (voltage==null || batteryType==BatteryType.None) { + return (batteryStatusType==BatteryStatusType.Low || batteryStatusType==BatteryStatusType.Unknown) ? 18 : 70; + } + double percent = (voltage - batteryType.lowVoltage) / (batteryType.highVoltage - batteryType.lowVoltage); return (int)(percent * 100.0d); } + + public String toString() { + return String.format("BatteryStatusDTO [voltage=%.2f, alkaline=%d, lithium=%d]", + voltage==null? 0.0f : voltage, + getCalculatedPercent(BatteryType.Alkaline), + getCalculatedPercent(BatteryType.Lithium)); + } + + + public enum BatteryStatusType { Normal, Low, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java index 10b73778e6..53cc93a955 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java @@ -144,8 +144,15 @@ public class TempBasalPair { return MedtronicUtil.createByteArray(list); } + public boolean isCancelTBR() { + return (MedtronicUtil.isSame(insulinRate, 0.0d) && durationMinutes==0); + } + public String getDescription() { + if (isCancelTBR()) { + return "Cancel TBR"; + } if (isPercent) { return String.format(Locale.ENGLISH, "Rate: %.0f%%, Duration: %d min", insulinRate, durationMinutes); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/BatteryType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/BatteryType.java index bbc4e52f93..339f7311d5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/BatteryType.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/BatteryType.java @@ -1,20 +1,45 @@ package info.nightscout.androidaps.plugins.pump.medtronic.defs; +import java.util.HashMap; +import java.util.Map; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; + /** * Created by andy on 6/4/18. */ public enum BatteryType { - Alkaline(1.20f, 1.47f), // - Lithium(1.32f, 1.58f); + None(R.string.medtronic_pump_battery_no, 0, 0), + Alkaline(R.string.medtronic_pump_battery_alkaline,1.20f, 1.47f), // + Lithium(R.string.medtronic_pump_battery_lithium,1.32f, 1.58f); + private final String description; public float lowVoltage; public float highVoltage; + static Map mapByDescription; - BatteryType(float lowVoltage, float highVoltage) { + static { + mapByDescription = new HashMap<>(); + + for (BatteryType value : values()) { + mapByDescription.put(value.description, value); + } + } + + BatteryType(int resId, float lowVoltage, float highVoltage) { + this.description = MainApp.gs(resId); this.lowVoltage = lowVoltage; this.highVoltage = highVoltage; } + + public static BatteryType getByDescription(String batteryTypeStr) { + if (mapByDescription.containsKey(batteryTypeStr)) { + return mapByDescription.get(batteryTypeStr); + } + return BatteryType.None; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicStatusRefreshType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicStatusRefreshType.java index f678699700..8db905b5c8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicStatusRefreshType.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicStatusRefreshType.java @@ -11,7 +11,7 @@ public enum MedtronicStatusRefreshType { PumpHistory(5, null), // Configuration(0, null), // RemainingInsulin(-1, MedtronicCommandType.GetRemainingInsulin), // - BatteryStatus(60, MedtronicCommandType.GetBatteryStatus), // + BatteryStatus(55, MedtronicCommandType.GetBatteryStatus), // PumpTime(60, MedtronicCommandType.RealTimeClock) // ; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java index d7f95c1676..0a6c366a27 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java @@ -23,6 +23,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.Rile import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState; import info.nightscout.androidaps.plugins.pump.medtronic.defs.BasalProfileStatus; +import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst; @@ -75,6 +76,7 @@ public class MedtronicPumpStatus extends PumpStatus { private Map medtronicDeviceTypeMap = null; private RileyLinkTargetFrequency targetFrequency; public BasalProfileStatus basalProfileStatus; + public BatteryType batteryType = BatteryType.None; public MedtronicPumpStatus(PumpDescription pumpDescription) { @@ -262,6 +264,14 @@ public class MedtronicPumpStatus extends PumpStatus { this.encodingChanged = true; } + String batteryTypeStr = SP.getString(MedtronicConst.Prefs.BatteryType, null); + + BatteryType batteryType = BatteryType.getByDescription(batteryTypeStr); + + if (this.batteryType != batteryType) { + this.batteryType = batteryType; + } + reconfigureService(); } catch (Exception ex) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicConst.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicConst.java index 63a9b440bb..1be9e2f478 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicConst.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicConst.java @@ -18,6 +18,7 @@ public class MedtronicConst { public static final String MaxBasal = PrefPrefix + "max_basal"; public static final String BolusDelay = PrefPrefix + "bolus_delay"; public static final String Encoding = PrefPrefix + "encoding"; + public static final String BatteryType = PrefPrefix + "battery_type"; } public class Statistics { diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index e6d467563b..e348e32aa7 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -175,4 +175,10 @@ @string/medtronic_pump_encoding_4b6b_rileylink + + @string/medtronic_pump_battery_no + @string/medtronic_pump_battery_alkaline + @string/medtronic_pump_battery_lithium + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0b03da8b1b..4c8dbefa1e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1360,6 +1360,10 @@ Wake and Tune Up Clear Bolus Block Reset RileyLink + Battery Type (Power View) + Not selected (Simple view) + Alkaline (Extended view) + Lithium (Extended view) SCAN diff --git a/app/src/main/res/xml/pref_medtronic.xml b/app/src/main/res/xml/pref_medtronic.xml index 5835f7514a..3791fa574e 100644 --- a/app/src/main/res/xml/pref_medtronic.xml +++ b/app/src/main/res/xml/pref_medtronic.xml @@ -60,6 +60,14 @@ android:selectable="true" android:title="@string/medtronic_pump_encoding" /> + + - - - - - \ No newline at end of file