diff --git a/app/src/main/java/de/jotomo/ruffyscripter/History.java b/app/src/main/java/de/jotomo/ruffyscripter/History.java index 49e34d438f..cfe514565b 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/History.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/History.java @@ -1,5 +1,7 @@ package de.jotomo.ruffyscripter; -/** The history data read from "My data" */ +/** + * The history data read from "My data" + */ public class History { } diff --git a/app/src/main/java/de/jotomo/ruffyscripter/PumpCapabilities.java b/app/src/main/java/de/jotomo/ruffyscripter/PumpCapabilities.java index 1270851ea0..50016db80e 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/PumpCapabilities.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/PumpCapabilities.java @@ -2,7 +2,7 @@ package de.jotomo.ruffyscripter; /** * Created by adrian on 26/07/17. - * + *

* Contains the capabilities of the current pump model. */ diff --git a/app/src/main/java/de/jotomo/ruffyscripter/PumpState.java b/app/src/main/java/de/jotomo/ruffyscripter/PumpState.java index 4d519b4669..51ffafe40f 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/PumpState.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/PumpState.java @@ -11,11 +11,12 @@ public class PumpState { public int tbrPercent = -1; public double tbrRate = -1; public int tbrRemainingDuration = -1; - /** This is the error message (if any) displayed by the pump if there is an alarm, - e.g. if a "TBR cancelled alarm" is active, the value will be "TBR CANCELLED". - Generally, an error code is also displayed, but it flashes and it might take - longer to read that and the pump connection gets interrupted if we're not - reacting quickly. + /** + * This is the error message (if any) displayed by the pump if there is an alarm, + * e.g. if a "TBR cancelled alarm" is active, the value will be "TBR CANCELLED". + * Generally, an error code is also displayed, but it flashes and it might take + * longer to read that and the pump connection gets interrupted if we're not + * reacting quickly. */ public String errorMsg; public boolean suspended; diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java index 33d10fc223..ac87486e77 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java @@ -7,12 +7,13 @@ import de.jotomo.ruffyscripter.RuffyScripter; /** * Interface for all commands to be executed by the pump. - * + *

* Note on cammond methods and timing: a method shall wait before and after executing * as necessary to not cause timing issues, so the caller can just call methods in * sequence, letting the methods take care of waits. */ public interface Command { CommandResult execute(RuffyScripter ruffyScripter, PumpState initialPumpState); + List validateArguments(); } diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandException.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandException.java index 5c25ba914c..d2f31cc8e2 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandException.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandException.java @@ -6,7 +6,8 @@ public class CommandException extends RuntimeException { public Exception exception = null; public String message = null; - public CommandException() {} + public CommandException() { + } public CommandException success(boolean success) { this.success = success; diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandResult.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandResult.java index 296f61f056..41b07e3ba2 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandResult.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandResult.java @@ -30,7 +30,7 @@ public class CommandResult { } public CommandResult completionTime(long completionTime) { - this.completionTime = completionTime ; + this.completionTime = completionTime; return this; } @@ -51,12 +51,12 @@ public class CommandResult { public CommandResult history(History history) { this.history = history; - return this; + return this; } public CommandResult capabilities(PumpCapabilities capabilities) { this.capabilities = capabilities; - return this; + return this; } @Override diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/DetermineCapabilitiesCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/DetermineCapabilitiesCommand.java index adc740c13e..cf704024c6 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/DetermineCapabilitiesCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/DetermineCapabilitiesCommand.java @@ -2,8 +2,6 @@ package de.jotomo.ruffyscripter.commands; 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.MenuType; 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.List; -import java.util.Locale; import de.jotomo.ruffyscripter.PumpCapabilities; import de.jotomo.ruffyscripter.PumpState; @@ -34,7 +31,7 @@ public class DetermineCapabilitiesCommand implements Command { try { //read main menu 100% or TBR? Read remaining duration. - long durationBefore = readDisplayedTbrDurationMainMenu(scripter); + long durationBefore = readDisplayedTbrDurationMainMenu(scripter); long percentageBefore = readDisplayedTbrPercentageMainMenu(scripter); enterTbrMenu(scripter); @@ -49,14 +46,14 @@ public class DetermineCapabilitiesCommand implements Command { //TODO: check if TBR is still the same or duration was less than 5 minutes - long durationAfter = readDisplayedTbrDurationMainMenu(scripter); + long durationAfter = readDisplayedTbrDurationMainMenu(scripter); long percentageAfter = readDisplayedTbrPercentageMainMenu(scripter); - if(Math.abs(durationBefore-durationAfter) > 5){ + if (Math.abs(durationBefore - durationAfter) > 5) { throw new CommandException().message("Duration jump during DetermineCapabilities"); } - if(percentageAfter != percentageBefore){ - if(durationBefore<5 && percentageAfter == 100){ + if (percentageAfter != percentageBefore) { + if (durationBefore < 5 && percentageAfter == 100) { log.debug("(percentageBefore != percentageAfter) - ignoring as tbr is now 100% and had a very short duration left"); } throw new CommandException().message("TBR changed while determining maxTBR."); @@ -99,7 +96,7 @@ public class DetermineCapabilitiesCommand implements Command { long percentageChange = maximumTempBasal - activeTempBasal; long percentageSteps = percentageChange / 10; - int retries= 0; + int retries = 0; while (percentageSteps > 0 && retries < RETRIES) { log.debug("Pressing down " + percentageSteps + " times to get to previous value. Retry " + retries); for (int i = 0; i < percentageSteps; i++) { @@ -139,7 +136,7 @@ public class DetermineCapabilitiesCommand implements Command { private int readDisplayedTbrDurationMainMenu(RuffyScripter scripter) { scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU); - if(scripter.currentMenu.attributes().contains(MenuAttribute.RUNTIME)){ + if (scripter.currentMenu.attributes().contains(MenuAttribute.RUNTIME)) { // TODO v2 add timeout? Currently the command execution timeout would trigger if exceeded Object durationObj = scripter.currentMenu.getAttribute(MenuAttribute.RUNTIME); MenuTime duration = (MenuTime) durationObj; @@ -151,8 +148,8 @@ public class DetermineCapabilitiesCommand implements Command { private int readDisplayedTbrPercentageMainMenu(RuffyScripter scripter) { scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU); - if(scripter.currentMenu.attributes().contains(MenuAttribute.TBR)){ - return (int)((Double) scripter.currentMenu.getAttribute(MenuAttribute.TBR)).doubleValue(); + if (scripter.currentMenu.attributes().contains(MenuAttribute.TBR)) { + return (int) ((Double) scripter.currentMenu.getAttribute(MenuAttribute.TBR)).doubleValue(); } else { return 100; } diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/GetBasalCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/GetBasalCommand.java index 09958f6bf1..264474d1cc 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/GetBasalCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/GetBasalCommand.java @@ -18,7 +18,8 @@ public class GetBasalCommand implements Command { private RuffyScripter scripter; - public GetBasalCommand() {} + public GetBasalCommand() { + } @Override public List validateArguments() { @@ -27,7 +28,7 @@ public class GetBasalCommand implements Command { return violations; } -// private void tick() + // private void tick() // { // switch (state) // { @@ -104,15 +105,14 @@ public class GetBasalCommand implements Command { @Override public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { try { - Map rate = new HashMap<>(); + Map rate = new HashMap<>(); - for(int i = 0; i < 24;i++) - { - Log.v("BASAL_RATE","BASAL_RATE from "+String.format("%02d",i)+":00 = "+rate.get(i)); + for (int i = 0; i < 24; i++) { + Log.v("BASAL_RATE", "BASAL_RATE from " + String.format("%02d", i) + ":00 = " + rate.get(i)); } } catch (Exception e) { - log.error("failed to get basal",e); - return new CommandResult().success(false).message("failed to get basal: "+e.getMessage()); + log.error("failed to get basal", e); + return new CommandResult().success(false).message("failed to get basal: " + e.getMessage()); } return new CommandResult().success(true).enacted(true).message("Basal Rate was read"); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index a0bc347ea9..3cd45b4953 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -124,7 +124,7 @@ public class ComboPlugin implements PluginBase, PumpInterface { * The alerter frequently checks the result of the last executed command via the lastCmdResult * field and shows a notification with sound and vibration if an error occurred. * More details on the error can then be looked up in the Combo tab. - * + *

* The alarm is re-raised every 5 minutes for as long as the error persist. As soon * as a command succeeds no more new alerts are raised. */ @@ -199,7 +199,7 @@ public class ComboPlugin implements PluginBase, PumpInterface { @Override public void onServiceConnected(ComponentName name, IBinder service) { - keepUnbound=false; + keepUnbound = false; ruffyScripter.start(IRuffyService.Stub.asInterface(service)); log.debug("ruffy serivce connected"); } @@ -210,7 +210,7 @@ public class ComboPlugin implements PluginBase, PumpInterface { log.debug("ruffy service disconnected"); // try to reconnect ruffy service unless unbind was explicitely requested // via unbindRuffyService - if(!keepUnbound) { + if (!keepUnbound) { SystemClock.sleep(250); bindRuffyService(); } @@ -228,6 +228,7 @@ public class ComboPlugin implements PluginBase, PumpInterface { } private boolean keepUnbound = false; + private void unbindRuffyService() { keepUnbound = true; ruffyScripter.unbind(); @@ -543,7 +544,7 @@ public class ComboPlugin implements PluginBase, PumpInterface { tempBasal.source = Source.USER; pumpEnactResult.isTempCancel = true; } - } else if ((activeTemp.percentRate >= 90 && activeTemp.percentRate <= 110) && activeTemp.getPlannedRemainingMinutes() <= 15 ) { + } else if ((activeTemp.percentRate >= 90 && activeTemp.percentRate <= 110) && activeTemp.getPlannedRemainingMinutes() <= 15) { // Let fake neutral temp keep running (see below) log.debug("cancelTempBasal: skipping changing tbr since it already is at " + activeTemp.percentRate + "% and running for another " + activeTemp.getPlannedRemainingMinutes() + " mins."); pumpEnactResult.comment = "cancelTempBasal skipping changing tbr since it already is at " + activeTemp.percentRate + "% and running for another " + activeTemp.getPlannedRemainingMinutes() + " mins."; @@ -556,7 +557,7 @@ public class ComboPlugin implements PluginBase, PumpInterface { } else { // Set a fake neutral temp to avoid TBR cancel alert. Decide 90% vs 110% based on // on whether the TBR we're cancelling is above or below 100%. - long percentage = (activeTemp.percentRate > 100) ? 110:90; + long percentage = (activeTemp.percentRate > 100) ? 110 : 90; log.debug("cancelTempBasal: changing tbr to " + percentage + "% for 15 mins."); commandResult = runCommand(new SetTbrCommand(percentage, 15)); if (commandResult.enacted) { @@ -670,12 +671,12 @@ public class ComboPlugin implements PluginBase, PumpInterface { ToastUtils.showToastInUiThread(MainApp.instance(), "Ruffy not initialized."); return; } - if (isBusy()){ + if (isBusy()) { ToastUtils.showToastInUiThread(MainApp.instance(), "Pump busy!"); return; } CommandResult result = runCommand(new DetermineCapabilitiesCommand()); - if (result.success){ + if (result.success) { pumpDescription.maxTempPercent = (int) result.capabilities.maxTempPercent; SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance()); SharedPreferences.Editor editor = preferences.edit();