Improving pump status in the UI (combo tab)

This commit is contained in:
Johannes Mockenhaupt 2017-07-16 14:39:00 +02:00
parent f7586268c7
commit d619796019
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 35 additions and 56 deletions

View file

@ -11,7 +11,6 @@ public class PumpState {
public int tbrPercent = -1; public int tbrPercent = -1;
public double tbrRate = -1; public double tbrRate = -1;
public int tbrRemainingDuration = -1; public int tbrRemainingDuration = -1;
public boolean isErrorOrWarning = false;
public String errorMsg; public String errorMsg;
public PumpState tbrActive(boolean tbrActive) { public PumpState tbrActive(boolean tbrActive) {
@ -34,11 +33,6 @@ public class PumpState {
return this; return this;
} }
public PumpState isErrorOrWarning(boolean isErrorOrWarning) {
this.isErrorOrWarning = isErrorOrWarning;
return this;
}
public PumpState errorMsg(String errorMsg) { public PumpState errorMsg(String errorMsg) {
this.errorMsg = errorMsg; this.errorMsg = errorMsg;
return this; return this;
@ -51,7 +45,6 @@ public class PumpState {
", tbrPercent=" + tbrPercent + ", tbrPercent=" + tbrPercent +
", tbrRate=" + tbrRate + ", tbrRate=" + tbrRate +
", tbrRemainingDuration=" + tbrRemainingDuration + ", tbrRemainingDuration=" + tbrRemainingDuration +
", isErrorOrWarning=" + isErrorOrWarning +
", errorMsg=" + errorMsg + ", errorMsg=" + errorMsg +
", timestamp=" + timestamp + ", timestamp=" + timestamp +
'}'; '}';

View file

@ -99,28 +99,20 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
status.setText(getPlugin().statusSummary);
PumpState ps = getPlugin().pumpState; PumpState ps = getPlugin().pumpState;
status.setText(getPlugin().isBusy() ? "Busy" : "Idle");
if (getPlugin() != null && ps != null) {
boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100; boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100;
if (tbrActive) { if (tbrActive) {
tbrPercentage.setText("" + ps.tbrPercent + "%"); tbrPercentage.setText("" + ps.tbrPercent + "%");
tbrDurationRemaining.setText("" + ps.tbrRemainingDuration + " min"); tbrDurationRemaining.setText("" + ps.tbrRemainingDuration + " min");
tbrRate.setText("" + ps.tbrRate + " U/h"); tbrRate.setText("" + ps.tbrRate + " U/h");
} else { } else {
tbrPercentage.setText(""); tbrPercentage.setText("Default basal rate running");
tbrDurationRemaining.setText(""); tbrDurationRemaining.setText("");
tbrRate.setText(""); tbrRate.setText("" + getPlugin().getBaseBasalRate() + " U/h");
} }
errorMsg.setText(ps.errorMsg != null ? ps.errorMsg : ""); errorMsg.setText(ps.errorMsg != null ? ps.errorMsg : "");
lastUpdate.setText(ps.timestamp.toLocaleString()); lastUpdate.setText(ps.timestamp.toLocaleString());
} else {
tbrPercentage.setText("");
tbrRate.setText("");
tbrDurationRemaining.setText("");
errorMsg.setText("");
lastUpdate.setText("");
}
} }
}); });
} }

View file

@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.os.IBinder; import android.os.IBinder;
import android.os.SystemClock; import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
@ -58,10 +59,11 @@ public class ComboPlugin implements PluginBase, PumpInterface {
private Date lastCmdTime = new Date(0); private Date lastCmdTime = new Date(0);
private ServiceConnection mRuffyServiceConnection; private ServiceConnection mRuffyServiceConnection;
@Nullable @NonNull
volatile PumpState pumpState; 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(); 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 ... // TODO if there was some clue as to what refreshDataFromPump would do with the data ...
// that method calls NSUpload.uploadDeviceStatus(); in VirtualPump ... // that method calls NSUpload.uploadDeviceStatus(); in VirtualPump ...
public PumpState fetchPumpState() { void fetchPumpState() {
CommandResult commandResult = runCommand(new NoOpCommand()); runCommand(new NoOpCommand());
if (commandResult.success) {
pumpState = commandResult.state;
return commandResult.state;
} else {
return new PumpState().errorMsg("Failure reading state from pump: " + commandResult.message);
}
} }
private CommandResult runCommand(Command command) { private CommandResult runCommand(Command command) {
CommandResult commandResult; statusSummary = "Busy running command: " + command;
try {
statusSummary = "Busy running " + command;
pumpState = null;
MainApp.bus().post(new EventComboPumpUpdateGUI()); MainApp.bus().post(new EventComboPumpUpdateGUI());
commandResult = ruffyScripter.runCommand(command);
if (commandResult.success && commandResult.state != null) { CommandResult commandResult = ruffyScripter.runCommand(command);
pumpState = commandResult.state; log.debug("RuffyScripter returned from command invocation, result: " + commandResult);
}
return commandResult;
} finally {
lastCmdTime = new Date(); lastCmdTime = new Date();
if (commandResult.success) {
statusSummary = "Idle"; statusSummary = "Idle";
PumpState ps = pumpState; pumpState = commandResult.state;
if (ps != null) { } else {
if (ps.errorMsg != null) { // TODO this is where we want to raise a noisily-vibrating alarm
statusSummary = "Error: " + ps.errorMsg; statusSummary = "Command failed: " + command;
} else if (ps.isErrorOrWarning) { if (commandResult.message != null) {
statusSummary = "Error: pump is in error mode, please check pump display"; pumpState.errorMsg = commandResult.message;
} }
} }
MainApp.bus().post(new EventComboPumpUpdateGUI()); MainApp.bus().post(new EventComboPumpUpdateGUI());
} return commandResult;
} }
@Override @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 // cache as much as possible - every time we interact with the pump it vibrates at the end
@Override @Override
public JSONObject getJSONStatus() { public JSONObject getJSONStatus() {
/// TODO not doing that just yet
if (1==1) return null;
JSONObject pump = new JSONObject(); JSONObject pump = new JSONObject();
JSONObject status = new JSONObject(); JSONObject status = new JSONObject();
JSONObject extended = new JSONObject(); JSONObject extended = new JSONObject();