Improving pump status in the UI (combo tab)
This commit is contained in:
parent
f7586268c7
commit
d619796019
3 changed files with 35 additions and 56 deletions
|
@ -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 +
|
||||
'}';
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue