Formatting.

This commit is contained in:
Johannes Mockenhaupt 2017-08-17 10:56:33 +02:00
parent b000824b8a
commit f41d597c07
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
9 changed files with 42 additions and 39 deletions

View file

@ -1,5 +1,7 @@
package de.jotomo.ruffyscripter; package de.jotomo.ruffyscripter;
/** The history data read from "My data" */ /**
* The history data read from "My data"
*/
public class History { public class History {
} }

View file

@ -2,7 +2,7 @@ package de.jotomo.ruffyscripter;
/** /**
* Created by adrian on 26/07/17. * Created by adrian on 26/07/17.
* * <p>
* Contains the capabilities of the current pump model. * Contains the capabilities of the current pump model.
*/ */

View file

@ -11,11 +11,12 @@ 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;
/** 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". * This is the error message (if any) displayed by the pump if there is an alarm,
Generally, an error code is also displayed, but it flashes and it might take * e.g. if a "TBR cancelled alarm" is active, the value will be "TBR CANCELLED".
longer to read that and the pump connection gets interrupted if we're not * Generally, an error code is also displayed, but it flashes and it might take
reacting quickly. * longer to read that and the pump connection gets interrupted if we're not
* reacting quickly.
*/ */
public String errorMsg; public String errorMsg;
public boolean suspended; public boolean suspended;

View file

@ -7,12 +7,13 @@ import de.jotomo.ruffyscripter.RuffyScripter;
/** /**
* Interface for all commands to be executed by the pump. * Interface for all commands to be executed by the pump.
* * <p>
* Note on cammond methods and timing: a method shall wait before and after executing * 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 * as necessary to not cause timing issues, so the caller can just call methods in
* 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(RuffyScripter ruffyScripter, PumpState initialPumpState);
List<String> validateArguments(); List<String> validateArguments();
} }

View file

@ -6,7 +6,8 @@ public class CommandException extends RuntimeException {
public Exception exception = null; public Exception exception = null;
public String message = null; public String message = null;
public CommandException() {} public CommandException() {
}
public CommandException success(boolean success) { public CommandException success(boolean success) {
this.success = success; this.success = success;

View file

@ -30,7 +30,7 @@ public class CommandResult {
} }
public CommandResult completionTime(long completionTime) { public CommandResult completionTime(long completionTime) {
this.completionTime = completionTime ; this.completionTime = completionTime;
return this; return this;
} }
@ -51,12 +51,12 @@ public class CommandResult {
public CommandResult history(History history) { public CommandResult history(History history) {
this.history = history; this.history = history;
return this; return this;
} }
public CommandResult capabilities(PumpCapabilities capabilities) { public CommandResult capabilities(PumpCapabilities capabilities) {
this.capabilities = capabilities; this.capabilities = capabilities;
return this; return this;
} }
@Override @Override

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;
@ -34,7 +31,7 @@ public class DetermineCapabilitiesCommand implements Command {
try { try {
//read main menu 100% or TBR? Read remaining duration. //read main menu 100% or TBR? Read remaining duration.
long durationBefore = readDisplayedTbrDurationMainMenu(scripter); long durationBefore = readDisplayedTbrDurationMainMenu(scripter);
long percentageBefore = readDisplayedTbrPercentageMainMenu(scripter); long percentageBefore = readDisplayedTbrPercentageMainMenu(scripter);
enterTbrMenu(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 //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); long percentageAfter = readDisplayedTbrPercentageMainMenu(scripter);
if(Math.abs(durationBefore-durationAfter) > 5){ if (Math.abs(durationBefore - durationAfter) > 5) {
throw new CommandException().message("Duration jump during DetermineCapabilities"); throw new CommandException().message("Duration jump during DetermineCapabilities");
} }
if(percentageAfter != percentageBefore){ if (percentageAfter != percentageBefore) {
if(durationBefore<5 && percentageAfter == 100){ if (durationBefore < 5 && percentageAfter == 100) {
log.debug("(percentageBefore != percentageAfter) - ignoring as tbr is now 100% and had a very short duration left"); 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."); throw new CommandException().message("TBR changed while determining maxTBR.");
@ -99,7 +96,7 @@ public class DetermineCapabilitiesCommand implements Command {
long percentageChange = maximumTempBasal - activeTempBasal; long percentageChange = maximumTempBasal - activeTempBasal;
long percentageSteps = percentageChange / 10; long percentageSteps = percentageChange / 10;
int retries= 0; int retries = 0;
while (percentageSteps > 0 && retries < RETRIES) { while (percentageSteps > 0 && retries < RETRIES) {
log.debug("Pressing down " + percentageSteps + " times to get to previous value. Retry " + retries); log.debug("Pressing down " + percentageSteps + " times to get to previous value. Retry " + retries);
for (int i = 0; i < percentageSteps; i++) { for (int i = 0; i < percentageSteps; i++) {
@ -139,7 +136,7 @@ public class DetermineCapabilitiesCommand implements Command {
private int readDisplayedTbrDurationMainMenu(RuffyScripter scripter) { private int readDisplayedTbrDurationMainMenu(RuffyScripter scripter) {
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU); 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 // TODO v2 add timeout? Currently the command execution timeout would trigger if exceeded
Object durationObj = scripter.currentMenu.getAttribute(MenuAttribute.RUNTIME); Object durationObj = scripter.currentMenu.getAttribute(MenuAttribute.RUNTIME);
MenuTime duration = (MenuTime) durationObj; MenuTime duration = (MenuTime) durationObj;
@ -151,8 +148,8 @@ public class DetermineCapabilitiesCommand implements Command {
private int readDisplayedTbrPercentageMainMenu(RuffyScripter scripter) { private int readDisplayedTbrPercentageMainMenu(RuffyScripter scripter) {
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU); scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
if(scripter.currentMenu.attributes().contains(MenuAttribute.TBR)){ if (scripter.currentMenu.attributes().contains(MenuAttribute.TBR)) {
return (int)((Double) scripter.currentMenu.getAttribute(MenuAttribute.TBR)).doubleValue(); return (int) ((Double) scripter.currentMenu.getAttribute(MenuAttribute.TBR)).doubleValue();
} else { } else {
return 100; return 100;
} }

View file

@ -18,7 +18,8 @@ public class GetBasalCommand implements Command {
private RuffyScripter scripter; private RuffyScripter scripter;
public GetBasalCommand() {} public GetBasalCommand() {
}
@Override @Override
public List<String> validateArguments() { public List<String> validateArguments() {
@ -27,7 +28,7 @@ public class GetBasalCommand implements Command {
return violations; return violations;
} }
// private void tick() // private void tick()
// { // {
// switch (state) // switch (state)
// { // {
@ -104,15 +105,14 @@ public class GetBasalCommand implements Command {
@Override @Override
public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) { public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) {
try { try {
Map<Integer,Double> rate = new HashMap<>(); Map<Integer, Double> rate = new HashMap<>();
for(int i = 0; i < 24;i++) for (int i = 0; i < 24; i++) {
{ Log.v("BASAL_RATE", "BASAL_RATE from " + String.format("%02d", i) + ":00 = " + rate.get(i));
Log.v("BASAL_RATE","BASAL_RATE from "+String.format("%02d",i)+":00 = "+rate.get(i));
} }
} catch (Exception e) { } catch (Exception e) {
log.error("failed to get basal",e); log.error("failed to get basal", e);
return new CommandResult().success(false).message("failed to get basal: "+e.getMessage()); return new CommandResult().success(false).message("failed to get basal: " + e.getMessage());
} }
return new CommandResult().success(true).enacted(true).message("Basal Rate was read"); return new CommandResult().success(true).enacted(true).message("Basal Rate was read");
} }

View file

@ -124,7 +124,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
* The alerter frequently checks the result of the last executed command via the lastCmdResult * 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. * 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. * More details on the error can then be looked up in the Combo tab.
* * <p>
* The alarm is re-raised every 5 minutes for as long as the error persist. As soon * 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. * as a command succeeds no more new alerts are raised.
*/ */
@ -199,7 +199,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
@Override @Override
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
keepUnbound=false; keepUnbound = false;
ruffyScripter.start(IRuffyService.Stub.asInterface(service)); ruffyScripter.start(IRuffyService.Stub.asInterface(service));
log.debug("ruffy serivce connected"); log.debug("ruffy serivce connected");
} }
@ -210,7 +210,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
log.debug("ruffy service disconnected"); log.debug("ruffy service disconnected");
// try to reconnect ruffy service unless unbind was explicitely requested // try to reconnect ruffy service unless unbind was explicitely requested
// via unbindRuffyService // via unbindRuffyService
if(!keepUnbound) { if (!keepUnbound) {
SystemClock.sleep(250); SystemClock.sleep(250);
bindRuffyService(); bindRuffyService();
} }
@ -228,6 +228,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
} }
private boolean keepUnbound = false; private boolean keepUnbound = false;
private void unbindRuffyService() { private void unbindRuffyService() {
keepUnbound = true; keepUnbound = true;
ruffyScripter.unbind(); ruffyScripter.unbind();
@ -543,7 +544,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
tempBasal.source = Source.USER; tempBasal.source = Source.USER;
pumpEnactResult.isTempCancel = true; 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) // 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."); 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."; 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 { } else {
// Set a fake neutral temp to avoid TBR cancel alert. Decide 90% vs 110% based on // 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%. // 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."); log.debug("cancelTempBasal: changing tbr to " + percentage + "% for 15 mins.");
commandResult = runCommand(new SetTbrCommand(percentage, 15)); commandResult = runCommand(new SetTbrCommand(percentage, 15));
if (commandResult.enacted) { if (commandResult.enacted) {
@ -670,12 +671,12 @@ public class ComboPlugin implements PluginBase, PumpInterface {
ToastUtils.showToastInUiThread(MainApp.instance(), "Ruffy not initialized."); ToastUtils.showToastInUiThread(MainApp.instance(), "Ruffy not initialized.");
return; return;
} }
if (isBusy()){ if (isBusy()) {
ToastUtils.showToastInUiThread(MainApp.instance(), "Pump busy!"); ToastUtils.showToastInUiThread(MainApp.instance(), "Pump busy!");
return; return;
} }
CommandResult result = runCommand(new DetermineCapabilitiesCommand()); CommandResult result = runCommand(new DetermineCapabilitiesCommand());
if (result.success){ if (result.success) {
pumpDescription.maxTempPercent = (int) result.capabilities.maxTempPercent; pumpDescription.maxTempPercent = (int) result.capabilities.maxTempPercent;
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance()); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance());
SharedPreferences.Editor editor = preferences.edit(); SharedPreferences.Editor editor = preferences.edit();