From 00b9379b8c388274ae33005e302995ea73ee07dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20M=C3=BCthing?= Date: Sat, 22 Aug 2020 17:08:07 +0200 Subject: [PATCH 1/7] Make delivered ticks available in status response --- .../pump/omnipod/comm/message/response/StatusResponse.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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; } From 61d6c638b73aa5f12d4bcefca725b4244ca51c32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20M=C3=BCthing?= Date: Sat, 22 Aug 2020 17:08:30 +0200 Subject: [PATCH 2/7] Provide total insulin delivered from Pod available in PodStateManager --- .../omnipod/defs/state/PodStateManager.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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; } From e66033ab1e29281db039100f31ad6b9c5cbcee5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20M=C3=BCthing?= Date: Sat, 22 Aug 2020 17:09:05 +0200 Subject: [PATCH 3/7] Show total dose delivered by pod in OmnipodFragment This includes the units delivered during priming and cannula insertion, but it gives a nice approximation of the remaining insulin if you remember what you injected. --- .../plugins/pump/omnipod/OmnipodFragment.kt | 4 +++ .../src/main/res/layout/omnipod_fragment.xml | 36 +++++++++++++++++++ omnipod/src/main/res/values/strings.xml | 2 ++ 3 files changed, 42 insertions(+) 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..e9b059c89b 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,9 @@ class OmnipodFragment : DaggerFragment() { omnipod_tempbasal.text = activePlugin.activeTreatments .getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: "-" + // total delivered + omnipod_total_delivered.text = resourceHelper.gs(R.string.omnipod_total_delivered,podStateManager.totalInsulinDelivered); + // reservoir if (podStateManager.reservoirLevel == null) { omnipod_reservoir.text = resourceHelper.gs(R.string.omnipod_reservoir_over50) 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 From 9ccee886c637f7e033e9c6eba7babca08e303f4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20M=C3=BCthing?= Date: Sun, 23 Aug 2020 18:01:20 +0200 Subject: [PATCH 4/7] Add tests for getTicksDelivered() --- .../omnipod/comm/message/response/StatusResponseTest.java | 4 ++++ 1 file changed, 4 insertions(+) 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); From f3a7a5a39333401e8b27c69170388be32ea7c604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20M=C3=BCthing?= Date: Sun, 23 Aug 2020 18:01:40 +0200 Subject: [PATCH 5/7] Add constant POD_SETUP_UNITS for the total number of units delivered during pod setup --- .../androidaps/plugins/pump/omnipod/util/OmnipodConst.java | 1 + 1 file changed, 1 insertion(+) 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; } From 633767ad3d030979e6e66079e8db119412b785e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20M=C3=BCthing?= Date: Sun, 23 Aug 2020 18:02:38 +0200 Subject: [PATCH 6/7] Subtract setup units from displayed total insulin delivered --- .../androidaps/plugins/pump/omnipod/OmnipodFragment.kt | 8 +++++++- omnipod/src/main/res/values/strings.xml | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) 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 e9b059c89b..2d9d3b82d1 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 @@ -281,7 +281,13 @@ class OmnipodFragment : DaggerFragment() { .getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: "-" // total delivered - omnipod_total_delivered.text = resourceHelper.gs(R.string.omnipod_total_delivered,podStateManager.totalInsulinDelivered); + omnipod_total_delivered.text = podStateManager.totalInsulinDelivered.let { + when { + it == null -> "-" + it < OmnipodConst.POD_SETUP_UNITS -> resourceHelper.gs(R.string.omnipod_total_delivered_pod_preparing) + else -> resourceHelper.gs(R.string.omnipod_total_delivered, it - OmnipodConst.POD_SETUP_UNITS); + } + } // reservoir if (podStateManager.reservoirLevel == null) { diff --git a/omnipod/src/main/res/values/strings.xml b/omnipod/src/main/res/values/strings.xml index 5107c443c1..2abe3fc797 100644 --- a/omnipod/src/main/res/values/strings.xml +++ b/omnipod/src/main/res/values/strings.xml @@ -27,6 +27,7 @@ Pod Mgmt Pod Status Total Delivered + Pod Preparing %1$.2f U %1$.2f U left Over 50 U From 85048c9a02e825686619089aca6e2f7a75a2ff81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20M=C3=BCthing?= Date: Sun, 23 Aug 2020 19:27:34 +0200 Subject: [PATCH 7/7] Simplify total delivered insulin display as suggested by Bart --- .../androidaps/plugins/pump/omnipod/OmnipodFragment.kt | 10 ++++------ omnipod/src/main/res/values/strings.xml | 1 - 2 files changed, 4 insertions(+), 7 deletions(-) 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 2d9d3b82d1..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 @@ -281,12 +281,10 @@ class OmnipodFragment : DaggerFragment() { .getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: "-" // total delivered - omnipod_total_delivered.text = podStateManager.totalInsulinDelivered.let { - when { - it == null -> "-" - it < OmnipodConst.POD_SETUP_UNITS -> resourceHelper.gs(R.string.omnipod_total_delivered_pod_preparing) - else -> resourceHelper.gs(R.string.omnipod_total_delivered, it - OmnipodConst.POD_SETUP_UNITS); - } + omnipod_total_delivered.text = if (podStateManager.isPodActivationCompleted) { + resourceHelper.gs(R.string.omnipod_total_delivered, podStateManager.totalInsulinDelivered - OmnipodConst.POD_SETUP_UNITS); + } else { + "-" } // reservoir diff --git a/omnipod/src/main/res/values/strings.xml b/omnipod/src/main/res/values/strings.xml index 2abe3fc797..5107c443c1 100644 --- a/omnipod/src/main/res/values/strings.xml +++ b/omnipod/src/main/res/values/strings.xml @@ -27,7 +27,6 @@ Pod Mgmt Pod Status Total Delivered - Pod Preparing %1$.2f U %1$.2f U left Over 50 U