diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/PumpState.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/PumpState.java index 47260dc5f7..c8ff08a130 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/PumpState.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/PumpState.java @@ -11,7 +11,6 @@ public class PumpState { public int tbrPercent = -1; public double tbrRate = -1; public int tbrRemainingDuration = -1; - public boolean isErrorOrWarning = false; public String errorMsg; public PumpState tbrActive(boolean tbrActive) { @@ -34,11 +33,6 @@ public class PumpState { return this; } - public PumpState isErrorOrWarning(boolean isErrorOrWarning) { - this.isErrorOrWarning = isErrorOrWarning; - return this; - } - public PumpState errorMsg(String errorMsg) { this.errorMsg = errorMsg; return this; @@ -51,7 +45,6 @@ public class PumpState { ", tbrPercent=" + tbrPercent + ", tbrRate=" + tbrRate + ", tbrRemainingDuration=" + tbrRemainingDuration + - ", isErrorOrWarning=" + isErrorOrWarning + ", errorMsg=" + errorMsg + ", timestamp=" + timestamp + '}'; 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 e00838fc0e..e759b44ba3 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 @@ -99,28 +99,20 @@ public class ComboFragment extends Fragment implements View.OnClickListener { activity.runOnUiThread(new Runnable() { @Override public void run() { + status.setText(getPlugin().statusSummary); PumpState ps = getPlugin().pumpState; - status.setText(getPlugin().isBusy() ? "Busy" : "Idle"); - if (getPlugin() != null && ps != null) { - boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100; - if (tbrActive) { - tbrPercentage.setText("" + ps.tbrPercent + "%"); - tbrDurationRemaining.setText("" + ps.tbrRemainingDuration + " min"); - tbrRate.setText("" + ps.tbrRate + " U/h"); - } else { - tbrPercentage.setText(""); - tbrDurationRemaining.setText(""); - tbrRate.setText(""); - } - errorMsg.setText(ps.errorMsg != null ? ps.errorMsg : ""); - lastUpdate.setText(ps.timestamp.toLocaleString()); + boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100; + if (tbrActive) { + tbrPercentage.setText("" + ps.tbrPercent + "%"); + tbrDurationRemaining.setText("" + ps.tbrRemainingDuration + " min"); + tbrRate.setText("" + ps.tbrRate + " U/h"); } else { - tbrPercentage.setText(""); - tbrRate.setText(""); + tbrPercentage.setText("Default basal rate running"); tbrDurationRemaining.setText(""); - errorMsg.setText(""); - lastUpdate.setText(""); + tbrRate.setText("" + getPlugin().getBaseBasalRate() + " U/h"); } + errorMsg.setText(ps.errorMsg != null ? ps.errorMsg : ""); + lastUpdate.setText(ps.timestamp.toLocaleString()); } }); } 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 85a2203d07..ae1328c680 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 @@ -6,6 +6,7 @@ import android.content.Intent; import android.content.ServiceConnection; import android.os.IBinder; import android.os.SystemClock; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.squareup.otto.Subscribe; @@ -58,10 +59,11 @@ public class ComboPlugin implements PluginBase, PumpInterface { private Date lastCmdTime = new Date(0); private ServiceConnection mRuffyServiceConnection; - @Nullable - volatile PumpState pumpState; + @NonNull + volatile PumpState pumpState = new PumpState(); - volatile String statusSummary = "No state received yet"; + @NonNull + volatile String statusSummary = "Initializing"; private static PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult(); @@ -308,40 +310,30 @@ public class ComboPlugin implements PluginBase, PumpInterface { // TODO if there was some clue as to what refreshDataFromPump would do with the data ... // that method calls NSUpload.uploadDeviceStatus(); in VirtualPump ... - public PumpState fetchPumpState() { - CommandResult commandResult = runCommand(new NoOpCommand()); - if (commandResult.success) { - pumpState = commandResult.state; - return commandResult.state; - } else { - return new PumpState().errorMsg("Failure reading state from pump: " + commandResult.message); - } + void fetchPumpState() { + runCommand(new NoOpCommand()); } private CommandResult runCommand(Command command) { - CommandResult commandResult; - try { - statusSummary = "Busy running " + command; - pumpState = null; - MainApp.bus().post(new EventComboPumpUpdateGUI()); - commandResult = ruffyScripter.runCommand(command); - if (commandResult.success && commandResult.state != null) { - pumpState = commandResult.state; - } - return commandResult; - } finally { - lastCmdTime = new Date(); + statusSummary = "Busy running command: " + command; + MainApp.bus().post(new EventComboPumpUpdateGUI()); + + CommandResult commandResult = ruffyScripter.runCommand(command); + log.debug("RuffyScripter returned from command invocation, result: " + commandResult); + + lastCmdTime = new Date(); + if (commandResult.success) { statusSummary = "Idle"; - PumpState ps = pumpState; - if (ps != null) { - if (ps.errorMsg != null) { - statusSummary = "Error: " + ps.errorMsg; - } else if (ps.isErrorOrWarning) { - statusSummary = "Error: pump is in error mode, please check pump display"; - } + pumpState = commandResult.state; + } else { + // TODO this is where we want to raise a noisily-vibrating alarm + statusSummary = "Command failed: " + command; + if (commandResult.message != null) { + pumpState.errorMsg = commandResult.message; } - MainApp.bus().post(new EventComboPumpUpdateGUI()); } + MainApp.bus().post(new EventComboPumpUpdateGUI()); + return commandResult; } @Override @@ -436,6 +428,8 @@ public class ComboPlugin implements PluginBase, PumpInterface { // cache as much as possible - every time we interact with the pump it vibrates at the end @Override public JSONObject getJSONStatus() { + /// TODO not doing that just yet + if (1==1) return null; JSONObject pump = new JSONObject(); JSONObject status = new JSONObject(); JSONObject extended = new JSONObject();