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 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 +
|
||||||
'}';
|
'}';
|
||||||
|
|
|
@ -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");
|
boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100;
|
||||||
if (getPlugin() != null && ps != null) {
|
if (tbrActive) {
|
||||||
boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100;
|
tbrPercentage.setText("" + ps.tbrPercent + "%");
|
||||||
if (tbrActive) {
|
tbrDurationRemaining.setText("" + ps.tbrRemainingDuration + " min");
|
||||||
tbrPercentage.setText("" + ps.tbrPercent + "%");
|
tbrRate.setText("" + ps.tbrRate + " U/h");
|
||||||
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());
|
|
||||||
} else {
|
} else {
|
||||||
tbrPercentage.setText("");
|
tbrPercentage.setText("Default basal rate running");
|
||||||
tbrRate.setText("");
|
|
||||||
tbrDurationRemaining.setText("");
|
tbrDurationRemaining.setText("");
|
||||||
errorMsg.setText("");
|
tbrRate.setText("" + getPlugin().getBaseBasalRate() + " U/h");
|
||||||
lastUpdate.setText("");
|
|
||||||
}
|
}
|
||||||
|
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.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 {
|
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
||||||
statusSummary = "Busy running " + command;
|
|
||||||
pumpState = null;
|
CommandResult commandResult = ruffyScripter.runCommand(command);
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
log.debug("RuffyScripter returned from command invocation, result: " + commandResult);
|
||||||
commandResult = ruffyScripter.runCommand(command);
|
|
||||||
if (commandResult.success && commandResult.state != null) {
|
lastCmdTime = new Date();
|
||||||
pumpState = commandResult.state;
|
if (commandResult.success) {
|
||||||
}
|
|
||||||
return commandResult;
|
|
||||||
} finally {
|
|
||||||
lastCmdTime = new Date();
|
|
||||||
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();
|
||||||
|
|
Loading…
Reference in a new issue