From 5de588b540a5accb2f7edbcd64aad9025b196cdc Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 20 Jan 2018 15:25:06 +0100 Subject: [PATCH] Enable reading reservoir level units. This partially reverts commit b4998feee11d63418ed1ce288eed7a820529e723. --- .../androidaps/plugins/PumpCombo/ComboFragment.java | 6 +++--- .../androidaps/plugins/PumpCombo/ComboPlugin.java | 13 +++++++++---- .../androidaps/plugins/PumpCombo/ComboPump.java | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index 6abb40dcec..ee023e23cc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -164,17 +164,17 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis } // reservoir + int reservoirLevel = plugin.getPump().reservoirLevel; + reservoirView.setText(reservoirLevel == -1 ? "" : "" + reservoirLevel + " " + + MainApp.sResources.getString(R.string.treatments_wizard_unit_label)); if (ps.insulinState == PumpState.LOW) { reservoirView.setTextColor(Color.YELLOW); - reservoirView.setText(R.string.combo_reservoir_low); reservoirView.setTypeface(null, Typeface.BOLD); } else if (ps.insulinState == PumpState.EMPTY) { reservoirView.setTextColor(Color.RED); - reservoirView.setText(R.string.combo_reservoir_empty); reservoirView.setTypeface(null, Typeface.BOLD); } else { reservoirView.setTextColor(Color.WHITE); - reservoirView.setText(R.string.combo_reservoir_normal); reservoirView.setTypeface(null, Typeface.NORMAL); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index f960312235..3f5075b007 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -354,7 +354,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (!pump.initialized) { initializePump(); } else { - runCommand(MainApp.gs(R.string.combo_pump_action_refreshing), 1, ruffyScripter::readPumpState); + runCommand(MainApp.gs(R.string.combo_pump_action_refreshing), 1, ruffyScripter::readReservoirLevelAndLastBolus); // note that since the history is checked upon every connect, the above already updated // the DB with any changed history records } @@ -406,10 +406,13 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf MainApp.bus().post(new EventInitializationChanged()); // ComboFragment updates state fully only after the pump has initialized, so read full state here - updateLocalData(readBasalResult); + updateLocalData(runCommand(null, 1, ruffyScripter::readReservoirLevelAndLastBolus)); } private void updateLocalData(CommandResult result) { + if (result.reservoirLevel != PumpState.UNKNOWN) { + pump.reservoirLevel = result.reservoirLevel; + } if (result.state.menu != null) { pump.state = result.state; } @@ -1111,9 +1114,11 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf JSONObject pumpJson = new JSONObject(); pumpJson.put("clock", DateUtil.toISOString(pump.lastSuccessfulCmdTime)); - int level = 150; - if (pump.state.insulinState == PumpState.LOW) level = 8; + int level; + if (pump.reservoirLevel != -1) level = pump.reservoirLevel; + else if (pump.state.insulinState == PumpState.LOW) level = 8; else if (pump.state.insulinState == PumpState.EMPTY) level = 0; + else level = 150; pumpJson.put("reservoir", level); JSONObject statusJson = new JSONObject(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java index 5980cf11eb..0455fa3ada 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java @@ -17,6 +17,7 @@ class ComboPump { public volatile String activity; @NonNull volatile PumpState state = new PumpState(); + volatile int reservoirLevel = -1; @NonNull volatile BasalProfile basalProfile = new BasalProfile();