Read reservoir level.

This commit is contained in:
Johannes Mockenhaupt 2018-01-07 11:16:43 +01:00
parent 3369d84de8
commit 836abd74ab
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 11 additions and 10 deletions

View file

@ -172,17 +172,16 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
} }
// reservoir // reservoir
int reservoirLevel = plugin.getPump().reservoirLevel;
reservoirView.setText(reservoirLevel == -1 ? "" : "" + reservoirLevel + " U");
if (ps.insulinState == PumpState.LOW) { if (ps.insulinState == PumpState.LOW) {
reservoirView.setTextColor(Color.YELLOW); reservoirView.setTextColor(Color.YELLOW);
reservoirView.setText(R.string.combo_reservoir_low);
reservoirView.setTypeface(null, Typeface.BOLD); reservoirView.setTypeface(null, Typeface.BOLD);
} else if (ps.insulinState == PumpState.EMPTY) { } else if (ps.insulinState == PumpState.EMPTY) {
reservoirView.setTextColor(Color.RED); reservoirView.setTextColor(Color.RED);
reservoirView.setText(R.string.combo_reservoir_empty);
reservoirView.setTypeface(null, Typeface.BOLD); reservoirView.setTypeface(null, Typeface.BOLD);
} else { } else {
reservoirView.setTextColor(Color.WHITE); reservoirView.setTextColor(Color.WHITE);
reservoirView.setText(R.string.combo_reservoir_normal);
reservoirView.setTypeface(null, Typeface.NORMAL); reservoirView.setTypeface(null, Typeface.NORMAL);
} }

View file

@ -339,7 +339,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (!pump.initialized) { if (!pump.initialized) {
initializePump(); initializePump();
} else { } else {
runCommand(MainApp.sResources.getString(R.string.combo_pump_action_refreshing), 1, ruffyScripter::readPumpState); runCommand(MainApp.sResources.getString(R.string.combo_pump_action_refreshing), 1, ruffyScripter::readReservoirLevelAndLastBolus);
} }
} }
@ -379,10 +379,13 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
MainApp.bus().post(new EventInitializationChanged()); MainApp.bus().post(new EventInitializationChanged());
// ComboFragment updates state fully only after the pump has initialized, so run this manually here // ComboFragment updates state fully only after the pump has initialized, so run this manually here
updateLocalData(readBasalResult); updateLocalData(runCommand(null, 1, ruffyScripter::readReservoirLevelAndLastBolus));
} }
private void updateLocalData(CommandResult result) { private void updateLocalData(CommandResult result) {
if (result.reservoirLevel != PumpState.UNKNOWN) {
pump.reservoirLevel = result.reservoirLevel;
}
if (result.state.menu != null) { if (result.state.menu != null) {
pump.state = result.state; pump.state = result.state;
} }
@ -1026,11 +1029,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
try { try {
JSONObject pumpJson = new JSONObject(); JSONObject pumpJson = new JSONObject();
pumpJson.put("clock", DateUtil.toISOString(pump.lastSuccessfulCmdTime)); pumpJson.put("clock", DateUtil.toISOString(pump.lastSuccessfulCmdTime));
if (pump.reservoirLevel != -1) {
int level = 150; pumpJson.put("reservoir", pump.reservoirLevel);
if (pump.state.insulinState == PumpState.LOW) level = 8; }
else if (pump.state.insulinState == PumpState.EMPTY) level = 0;
pumpJson.put("reservoir", level);
JSONObject statusJson = new JSONObject(); JSONObject statusJson = new JSONObject();
statusJson.put("status", getStateSummary()); statusJson.put("status", getStateSummary());

View file

@ -17,6 +17,7 @@ class ComboPump {
public volatile String activity; public volatile String activity;
@NonNull @NonNull
volatile PumpState state = new PumpState(); volatile PumpState state = new PumpState();
volatile int reservoirLevel = -1;
@NonNull @NonNull
volatile BasalProfile basalProfile = new BasalProfile(); volatile BasalProfile basalProfile = new BasalProfile();