diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt index 9d5cfdb3ab..a5c5859775 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt @@ -248,6 +248,7 @@ class OmnipodFragment : DaggerFragment() { omnipod_pod_firmware_version.text = "-" omnipod_pod_expiry.text = "-" omnipod_basabasalrate.text = "-" + omnipod_total_delivered.text = "-" omnipod_reservoir.text = "-" omnipod_tempbasal.text = "-" omnipod_lastbolus.text = "-" @@ -279,6 +280,13 @@ class OmnipodFragment : DaggerFragment() { omnipod_tempbasal.text = activePlugin.activeTreatments .getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: "-" + // total delivered + omnipod_total_delivered.text = if (podStateManager.isPodActivationCompleted) { + resourceHelper.gs(R.string.omnipod_total_delivered, podStateManager.totalInsulinDelivered - OmnipodConst.POD_SETUP_UNITS); + } else { + "-" + } + // reservoir if (podStateManager.reservoirLevel == null) { omnipod_reservoir.text = resourceHelper.gs(R.string.omnipod_reservoir_over50) diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponse.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponse.java index ec99632553..3837bd833b 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponse.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponse.java @@ -20,6 +20,7 @@ public class StatusResponse extends MessageBlock { private final PodProgressStatus podProgressStatus; private final Duration timeActive; private final Double reservoirLevel; + private final int ticksDelivered; private final double insulinDelivered; private final double insulinNotDelivered; private final byte podMessageCounter; @@ -40,7 +41,8 @@ public class StatusResponse extends MessageBlock { int highInsulinBits = (encodedData[2] & 0xF) << 9; int middleInsulinBits = ByteUtil.convertUnsignedByteToInt(encodedData[3]) << 1; int lowInsulinBits = ByteUtil.convertUnsignedByteToInt(encodedData[4]) >>> 7; - insulinDelivered = OmnipodConst.POD_PULSE_SIZE * (highInsulinBits | middleInsulinBits | lowInsulinBits); + ticksDelivered = (highInsulinBits | middleInsulinBits | lowInsulinBits); + insulinDelivered = OmnipodConst.POD_PULSE_SIZE * ticksDelivered; podMessageCounter = (byte) ((encodedData[4] >>> 3) & 0xf); insulinNotDelivered = OmnipodConst.POD_PULSE_SIZE * (((encodedData[4] & 0x03) << 8) | ByteUtil.convertUnsignedByteToInt(encodedData[5])); @@ -75,6 +77,8 @@ public class StatusResponse extends MessageBlock { return reservoirLevel; } + public int getTicksDelivered() { return ticksDelivered; } + public double getInsulinDelivered() { return insulinDelivered; } diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodStateManager.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodStateManager.java index e9b27d8ec7..4eafecaa0c 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodStateManager.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodStateManager.java @@ -302,6 +302,8 @@ public abstract class PodStateManager { return getSafe(() -> podState.getReservoirLevel()); } + public final Double getTotalInsulinDelivered() { return getSafe(() -> podState.getTotalInsulinDelivered()); } + public final Duration getScheduleOffset() { DateTime now = getTime(); return new Duration(now.withTimeAtStartOfDay(), now); @@ -373,6 +375,7 @@ public abstract class PodStateManager { podState.setActiveAlerts(statusResponse.getAlerts()); podState.setLastDeliveryStatus(statusResponse.getDeliveryStatus()); podState.setReservoirLevel(statusResponse.getReservoirLevel()); + podState.setTotalTicksDelivered(statusResponse.getTicksDelivered()); podState.setPodProgressStatus(statusResponse.getPodProgressStatus()); podState.setLastUpdatedFromStatusResponse(DateTime.now()); }); @@ -469,6 +472,7 @@ public abstract class PodStateManager { private DateTime expiresAt; private PodInfoFaultEvent faultEvent; private Double reservoirLevel; + private Integer totalTicksDelivered; private boolean suspended; private NonceState nonceState; private PodProgressStatus podProgressStatus; @@ -602,6 +606,20 @@ public abstract class PodStateManager { this.reservoirLevel = reservoirLevel; } + public Integer getTotalTicksDelivered() { + return totalTicksDelivered; + } + + public Double getTotalInsulinDelivered() { + if (totalTicksDelivered != null) { + return totalTicksDelivered * OmnipodConst.POD_PULSE_SIZE; + } else { + return null; + } + } + + void setTotalTicksDelivered(Integer totalTicksDelivered) { this.totalTicksDelivered = totalTicksDelivered; } + public boolean isSuspended() { return suspended; } diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodConst.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodConst.java index 81bbf5d501..05d97e003a 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodConst.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodConst.java @@ -53,4 +53,5 @@ public class OmnipodConst { public static final double POD_PRIME_BOLUS_UNITS = 2.6; public static final double POD_CANNULA_INSERTION_BOLUS_UNITS = 0.5; + public static final double POD_SETUP_UNITS = POD_PRIME_BOLUS_UNITS + POD_CANNULA_INSERTION_BOLUS_UNITS; } diff --git a/omnipod/src/main/res/layout/omnipod_fragment.xml b/omnipod/src/main/res/layout/omnipod_fragment.xml index 72c3910ad9..bf4f6af6e5 100644 --- a/omnipod/src/main/res/layout/omnipod_fragment.xml +++ b/omnipod/src/main/res/layout/omnipod_fragment.xml @@ -517,6 +517,42 @@ android:layout_marginBottom="5dp" android:background="@color/listdelimiter" /> + + + + + + + + + + Moments ago Pod Mgmt Pod Status + Total Delivered + %1$.2f U %1$.2f U left Over 50 U Pod Address diff --git a/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponseTest.java b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponseTest.java index a931ad7b1d..6811b6d89c 100644 --- a/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponseTest.java +++ b/omnipod/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/StatusResponseTest.java @@ -45,6 +45,7 @@ public class StatusResponseTest { assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, statusResponse.getPodProgressStatus()); assertNull("Reservoir level should be null", statusResponse.getReservoirLevel()); assertEquals(Duration.standardMinutes(1307).getMillis(), statusResponse.getTimeActive().getMillis()); + assertEquals(1201, statusResponse.getTicksDelivered()); assertEquals(60.05, statusResponse.getInsulinDelivered(), 0.000001); assertEquals(15, statusResponse.getPodMessageCounter()); assertEquals(0, statusResponse.getInsulinNotDelivered(), 0.000001); @@ -62,6 +63,7 @@ public class StatusResponseTest { assertEquals(PodProgressStatus.FIFTY_OR_LESS_UNITS, statusResponse.getPodProgressStatus()); assertEquals(24.4, statusResponse.getReservoirLevel(), 0.000001); assertEquals(Duration.standardMinutes(4261).getMillis(), statusResponse.getTimeActive().getMillis()); + assertEquals(3134, statusResponse.getTicksDelivered()); assertEquals(156.7, statusResponse.getInsulinDelivered(), 0.000001); assertEquals(13, statusResponse.getPodMessageCounter()); assertEquals(0, statusResponse.getInsulinNotDelivered(), 0.000001); @@ -79,6 +81,7 @@ public class StatusResponseTest { assertEquals(Duration.standardMinutes(8191).getMillis(), statusResponse.getTimeActive().getMillis()); assertEquals(OmnipodConst.POD_PULSE_SIZE * 1023, statusResponse.getInsulinNotDelivered(), 0.000001); assertNull("Reservoir level should be null", statusResponse.getReservoirLevel()); + assertEquals(8191, statusResponse.getTicksDelivered()); assertEquals(OmnipodConst.POD_PULSE_SIZE * 8191, statusResponse.getInsulinDelivered(), 0.0000001); assertEquals(15, statusResponse.getPodMessageCounter()); assertEquals(8, statusResponse.getAlerts().getAlertSlots().size()); @@ -94,6 +97,7 @@ public class StatusResponseTest { assertTrue(Duration.standardMinutes(3547).isEqual(statusResponse.getTimeActive())); assertEquals(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus()); assertEquals(PodProgressStatus.FIFTY_OR_LESS_UNITS, statusResponse.getPodProgressStatus()); + assertEquals(2589, statusResponse.getTicksDelivered()); assertEquals(129.45, statusResponse.getInsulinDelivered(), 0.00001); assertEquals(46.00, statusResponse.getReservoirLevel(), 0.00001); assertEquals(2.2, statusResponse.getInsulinNotDelivered(), 0.0001);