Inject scripter into commands.

This commit is contained in:
Johannes Mockenhaupt 2017-08-23 12:10:50 +02:00
parent 04a03dedc3
commit fe7f831429
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
10 changed files with 13 additions and 16 deletions

View file

@ -304,7 +304,8 @@ public class RuffyScripter {
PumpState pumpState = readPumpState(); PumpState pumpState = readPumpState();
log.debug("Pump state before running command: " + pumpState); log.debug("Pump state before running command: " + pumpState);
long cmdStartTime = System.currentTimeMillis(); long cmdStartTime = System.currentTimeMillis();
returnable.cmdResult = cmd.execute(scripter, pumpState); cmd.setScripter(scripter);
returnable.cmdResult = cmd.execute(pumpState);
long cmdEndTime = System.currentTimeMillis(); long cmdEndTime = System.currentTimeMillis();
returnable.cmdResult.completionTime = cmdEndTime; returnable.cmdResult.completionTime = cmdEndTime;
log.debug("Executing " + cmd + " took " + (cmdEndTime - cmdStartTime) + "ms"); log.debug("Executing " + cmd + " took " + (cmdEndTime - cmdStartTime) + "ms");

View file

@ -5,7 +5,7 @@ import de.jotomo.ruffyscripter.RuffyScripter;
public abstract class BaseCommand implements Command { public abstract class BaseCommand implements Command {
// RS will inject itself here // RS will inject itself here
protected RuffyScripter scripter; protected RuffyScripter scripter;
public void setScripter(RuffyScripter scripter) { this.scripter = scripter; } @Override public void setScripter(RuffyScripter scripter) { this.scripter = scripter; }
// TODO upcoming // TODO upcoming
protected volatile boolean cancelRequested = false; protected volatile boolean cancelRequested = false;

View file

@ -35,7 +35,7 @@ public class BolusCommand extends BaseCommand {
} }
@Override @Override
public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { public CommandResult execute(PumpState initialPumpState) {
try { try {
enterBolusMenu(scripter); enterBolusMenu(scripter);

View file

@ -8,7 +8,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import de.jotomo.ruffyscripter.PumpState; import de.jotomo.ruffyscripter.PumpState;
import de.jotomo.ruffyscripter.RuffyScripter;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
// TODO robustness: can a TBR run out, whilst we're trying to cancel it? // TODO robustness: can a TBR run out, whilst we're trying to cancel it?
@ -23,7 +22,7 @@ public class CancelTbrCommand extends BaseCommand {
} }
@Override @Override
public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { public CommandResult execute(PumpState initialPumpState) {
try { try {
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU); scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
if (!initialPumpState.tbrActive) { if (!initialPumpState.tbrActive) {
@ -49,7 +48,7 @@ public class CancelTbrCommand extends BaseCommand {
} }
log.debug("Cancelling active TBR of " + initialPumpState.tbrPercent log.debug("Cancelling active TBR of " + initialPumpState.tbrPercent
+ "% with " + initialPumpState.tbrRemainingDuration + " min remaining"); + "% with " + initialPumpState.tbrRemainingDuration + " min remaining");
return new SetTbrCommand(100, 0).execute(scripter, initialPumpState); return new SetTbrCommand(100, 0).execute(initialPumpState);
} catch (CommandException e) { } catch (CommandException e) {
return e.toCommandResult(); return e.toCommandResult();
} }

View file

@ -13,6 +13,7 @@ import de.jotomo.ruffyscripter.RuffyScripter;
* sequence, letting the methods take care of waits. * sequence, letting the methods take care of waits.
*/ */
public interface Command { public interface Command {
CommandResult execute(RuffyScripter ruffyScripter, PumpState initialPumpState); CommandResult execute(PumpState initialPumpState);
List<String> validateArguments(); List<String> validateArguments();
void setScripter(RuffyScripter scripter);
} }

View file

@ -2,8 +2,6 @@ package de.jotomo.ruffyscripter.commands;
import android.os.SystemClock; import android.os.SystemClock;
import com.j256.ormlite.stmt.query.In;
import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute; import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute;
import org.monkey.d.ruffy.ruffy.driver.display.MenuType; import org.monkey.d.ruffy.ruffy.driver.display.MenuType;
import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime; import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime;
@ -12,7 +10,6 @@ import org.slf4j.LoggerFactory;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale;
import de.jotomo.ruffyscripter.PumpCapabilities; import de.jotomo.ruffyscripter.PumpCapabilities;
import de.jotomo.ruffyscripter.PumpState; import de.jotomo.ruffyscripter.PumpState;
@ -30,7 +27,7 @@ public class DetermineCapabilitiesCommand extends BaseCommand {
} }
@Override @Override
public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { public CommandResult execute(PumpState initialPumpState) {
try { try {
//read main menu 100% or TBR? Read remaining duration. //read main menu 100% or TBR? Read remaining duration.

View file

@ -102,7 +102,7 @@ public class GetBasalCommand extends BaseCommand {
// } // }
// } // }
@Override @Override
public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { public CommandResult execute(PumpState initialPumpState) {
try { try {
Map<Integer,Double> rate = new HashMap<>(); Map<Integer,Double> rate = new HashMap<>();

View file

@ -4,11 +4,10 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import de.jotomo.ruffyscripter.PumpState; import de.jotomo.ruffyscripter.PumpState;
import de.jotomo.ruffyscripter.RuffyScripter;
public class ReadPumpStateCommand extends BaseCommand { public class ReadPumpStateCommand extends BaseCommand {
@Override @Override
public CommandResult execute(RuffyScripter ruffyScripter, PumpState initialPumpState) { public CommandResult execute(PumpState initialPumpState) {
return new CommandResult().success(true).enacted(false).message("Returning pump state only"); return new CommandResult().success(true).enacted(false).message("Returning pump state only");
} }

View file

@ -60,7 +60,7 @@ public class SetTbrCommand extends BaseCommand {
} }
@Override @Override
public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { public CommandResult execute(PumpState initialPumpState) {
try { try {
log.debug("1. going from " + scripter.currentMenu + " to TBR_MENU"); log.debug("1. going from " + scripter.currentMenu + " to TBR_MENU");
int retries = 5; int retries = 5;

View file

@ -54,7 +54,7 @@ public class SetTbrCommandAlt extends BaseCommand {
} }
@Override @Override
public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { public CommandResult execute(PumpState initialPumpState) {
try { try {
enterTbrMenu(scripter); enterTbrMenu(scripter);
inputTbrPercentage(scripter); inputTbrPercentage(scripter);