Handle the pump being stopped: don't treat it like an error, but don't execute commands either.

This commit is contained in:
Johannes Mockenhaupt 2017-07-17 17:26:19 +02:00
parent 222ad0a527
commit 36966c8907
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 17 additions and 2 deletions

View file

@ -12,6 +12,7 @@ public class PumpState {
public double tbrRate = -1; public double tbrRate = -1;
public int tbrRemainingDuration = -1; public int tbrRemainingDuration = -1;
public String errorMsg; public String errorMsg;
public boolean suspended;
public PumpState tbrActive(boolean tbrActive) { public PumpState tbrActive(boolean tbrActive) {
this.tbrActive = tbrActive; this.tbrActive = tbrActive;
@ -38,6 +39,11 @@ public class PumpState {
return this; return this;
} }
public PumpState suspended(boolean suspended) {
this.suspended = suspended;
return this;
}
@Override @Override
public String toString() { public String toString() {
return "PumpState{" + return "PumpState{" +
@ -46,6 +52,7 @@ public class PumpState {
", tbrRate=" + tbrRate + ", tbrRate=" + tbrRate +
", tbrRemainingDuration=" + tbrRemainingDuration + ", tbrRemainingDuration=" + tbrRemainingDuration +
", errorMsg=" + errorMsg + ", errorMsg=" + errorMsg +
", suspended=" + suspended +
", timestamp=" + timestamp + ", timestamp=" + timestamp +
'}'; '}';
} }

View file

@ -195,6 +195,11 @@ public class RuffyScripter {
return; return;
} }
} }
// don't execute anything if STOP menu is shown (pump is noisy already and user is probably changing the cartridge)
if (currentMenu == null || currentMenu.getType() == MenuType.STOP) {
returnable.cmdResult = new CommandResult().success(true).enacted(false);
return;
}
log.debug("Cmd execution: connection ready, executing cmd " + cmd); log.debug("Cmd execution: connection ready, executing cmd " + cmd);
returnable.cmdResult = cmd.execute(scripter); returnable.cmdResult = cmd.execute(scripter);
} catch (CommandException e) { } catch (CommandException e) {
@ -401,6 +406,8 @@ public class RuffyScripter {
} }
} else if (menuType == MenuType.WARNING_OR_ERROR) { } else if (menuType == MenuType.WARNING_OR_ERROR) {
state.errorMsg = (String) menu.getAttribute(MenuAttribute.MESSAGE); state.errorMsg = (String) menu.getAttribute(MenuAttribute.MESSAGE);
} else if (menuType == MenuType.STOP) {
state.suspended = true;
} else { } else {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (MenuAttribute menuAttribute : menu.attributes()) { for (MenuAttribute menuAttribute : menu.attributes()) {

View file

@ -129,7 +129,8 @@ public class ComboPlugin implements PluginBase, PumpInterface {
int id = 1000; int id = 1000;
long lastAlarmTime = 0; long lastAlarmTime = 0;
while (true) { while (true) {
String errorMsg = pumpState.errorMsg; PumpState ps = ComboPlugin.this.pumpState;
String errorMsg = ps.errorMsg;
if (errorMsg != null) { if (errorMsg != null) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long fiveMinutesSinceLastAlarm = lastAlarmTime + (5 * 60 * 1000) + (15 * 1000); long fiveMinutesSinceLastAlarm = lastAlarmTime + (5 * 60 * 1000) + (15 * 1000);
@ -155,7 +156,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
log.warn("Pump still in error state, but alarm raised recently, so not triggering again: " + errorMsg); log.warn("Pump still in error state, but alarm raised recently, so not triggering again: " + errorMsg);
} }
} else { } else {
log.trace("Pump state normal"); log.trace("Pump state: " + (ps.suspended ? "suspended" : "normal"));
} }
SystemClock.sleep(5 * 1000); SystemClock.sleep(5 * 1000);
} }