From c8f7b535c2b7d2fb8ba7ca0d09ef76d8b3e49656 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 27 Aug 2017 13:39:29 +0200 Subject: [PATCH] Remove code to determine pump capabilities for the time being. --- .../ruffyscripter/PumpCapabilities.java | 23 --- .../ruffyscripter/commands/CommandResult.java | 7 - .../DetermineCapabilitiesCommand.java | 160 ------------------ .../plugins/PumpCombo/ComboFragment.java | 32 ---- .../plugins/PumpCombo/ComboPlugin.java | 26 --- .../main/res/layout/combopump_fragment.xml | 54 ------ 6 files changed, 302 deletions(-) delete mode 100644 app/src/main/java/de/jotomo/ruffyscripter/PumpCapabilities.java diff --git a/app/src/main/java/de/jotomo/ruffyscripter/PumpCapabilities.java b/app/src/main/java/de/jotomo/ruffyscripter/PumpCapabilities.java deleted file mode 100644 index 50016db80e..0000000000 --- a/app/src/main/java/de/jotomo/ruffyscripter/PumpCapabilities.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.jotomo.ruffyscripter; - -/** - * Created by adrian on 26/07/17. - *

- * Contains the capabilities of the current pump model. - */ - -public class PumpCapabilities { - public long maxTempPercent; - - public PumpCapabilities maxTempPercent(long maxTempPercent) { - this.maxTempPercent = maxTempPercent; - return this; - } - - @Override - public String toString() { - return "PumpCapabilities{" + - "maxTempPercent=" + maxTempPercent + - '}'; - } -} 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 b759eb32dc..9d1bbb321e 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandResult.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandResult.java @@ -3,7 +3,6 @@ package de.jotomo.ruffyscripter.commands; import java.util.Date; import de.jotomo.ruffyscripter.History; -import de.jotomo.ruffyscripter.PumpCapabilities; import de.jotomo.ruffyscripter.PumpState; public class CommandResult { @@ -14,7 +13,6 @@ public class CommandResult { public String message; public PumpState state; public History history; - public PumpCapabilities capabilities; public String duration; public CommandResult() { @@ -60,11 +58,6 @@ public class CommandResult { return this; } - public CommandResult capabilities(PumpCapabilities capabilities) { - this.capabilities = capabilities; - return this; - } - @Override public String toString() { return "CommandResult{" + 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 172a7742e1..e69de29bb2 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/DetermineCapabilitiesCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/DetermineCapabilitiesCommand.java @@ -1,160 +0,0 @@ -package de.jotomo.ruffyscripter.commands; - -import android.os.SystemClock; - -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; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collections; -import java.util.List; - -import de.jotomo.ruffyscripter.PumpCapabilities; - - -public class DetermineCapabilitiesCommand extends BaseCommand { - private static final Logger log = LoggerFactory.getLogger(DetermineCapabilitiesCommand.class); - public static final int UP_STEPS = 75; - public static final int RETRIES = 5; - - @Override - public List validateArguments() { - return Collections.emptyList(); - } - - @Override - public CommandResult execute() { - try { - - //read main menu 100% or TBR? Read remaining duration. - long durationBefore = readDisplayedTbrDurationMainMenu(); - long percentageBefore = readDisplayedTbrPercentageMainMenu(); - - enterTbrMenu(); - long maxTbrPercentage = findMaxTbrPercentage(); - - // TODO v2 this can probably be removed by now - SystemClock.sleep(750); - - scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU, - "Pump did not return to MAIN_MEU after finding max tbr. " + - "Check pump manually, the TBR might be wrong."); - - - //TODO: check if TBR is still the same or duration was less than 5 minutes - long durationAfter = readDisplayedTbrDurationMainMenu(); - long percentageAfter = readDisplayedTbrPercentageMainMenu(); - - if(Math.abs(durationBefore-durationAfter) > 5){ - throw new CommandException().message("Duration jump during DetermineCapabilities"); - } - 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."); - } - - //TODO return Result - return new CommandResult().success(true).enacted(false).message("Capablities: {maxTbrPercentage = " + maxTbrPercentage + ", success=" + "success }").capabilities((new PumpCapabilities()).maxTempPercent(maxTbrPercentage)); - } catch (CommandException e) { - return e.toCommandResult(); - } - } - - private void enterTbrMenu() { - scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU); - scripter.navigateToMenu(MenuType.TBR_MENU); - scripter.verifyMenuIsDisplayed(MenuType.TBR_MENU); - scripter.pressCheckKey(); - scripter.waitForMenuUpdate(); - scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); - } - - private long findMaxTbrPercentage() { - scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); - long activeTempBasal = readDisplayedTbrPercentage(); - - // pretend to increase the TBR to more than 500% - log.debug("Pressing up " + UP_STEPS + " times to get to maximum"); - for (int i = 0; i < UP_STEPS; i++) { - scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); - scripter.pressUpKey(); - SystemClock.sleep(200); - log.debug("Push #" + (i + 1)); - } - - //read the displayed maximum value - scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); - long maximumTempBasal = readDisplayedTbrPercentage(); - - //reset the TBR in a controlled manner - long percentageChange = maximumTempBasal - activeTempBasal; - long percentageSteps = percentageChange / 10; - - 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++) { - scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); - scripter.pressDownKey(); - SystemClock.sleep(200); - log.debug("Push #" + (i + 1)); - } - //do the rest if button-presses failed. - scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); - long currentPercentage = readDisplayedTbrPercentage(); - percentageChange = currentPercentage - activeTempBasal; - percentageSteps = percentageChange / 10; - retries++; - } - - - //exit menu - scripter.pressCheckKey(); - scripter.waitForMenuToBeLeft(MenuType.TBR_SET); - return maximumTempBasal; - } - - - private long readDisplayedTbrPercentage() { - SystemClock.sleep(1000); - // TODO v2 add timeout? Currently the command execution timeout would trigger if exceeded - Object percentageObj = scripter.getCurrentMenu().getAttribute(MenuAttribute.BASAL_RATE); - // this as a bit hacky, the display value is blinking, so we might catch that, so - // keep trying till we get the Double we want - while (!(percentageObj instanceof Double)) { - scripter.waitForMenuUpdate(); - percentageObj = scripter.getCurrentMenu().getAttribute(MenuAttribute.BASAL_RATE); - } - return ((Double) percentageObj).longValue(); - } - - private int readDisplayedTbrDurationMainMenu() { - scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU); - if(scripter.getCurrentMenu().attributes().contains(MenuAttribute.RUNTIME)){ - // TODO v2 add timeout? Currently the command execution timeout would trigger if exceeded - Object durationObj = scripter.getCurrentMenu().getAttribute(MenuAttribute.RUNTIME); - MenuTime duration = (MenuTime) durationObj; - return duration.getHour() * 60 + duration.getMinute(); - } else { - return 0; - } - } - - private int readDisplayedTbrPercentageMainMenu() { - scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU); - if(scripter.getCurrentMenu().attributes().contains(MenuAttribute.TBR)){ - return (int)((Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.TBR)).doubleValue(); - } else { - return 100; - } - } - - @Override - public String toString() { - return "DetermineCapabilitiesCommand{}"; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index 855ac662ae..f4d49c0a94 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -34,7 +34,6 @@ public class ComboFragment extends Fragment implements View.OnClickListener { } private Button refresh; - private TextView updateCapabilities; private TextView statusText; @@ -48,7 +47,6 @@ public class ComboFragment extends Fragment implements View.OnClickListener { private TextView lastCmdResultText; private TextView lastCmdDurationText; - private TextView tbrCapabilityText; private TextView pumpstateBatteryText; private TextView insulinstateText; @@ -59,7 +57,6 @@ public class ComboFragment extends Fragment implements View.OnClickListener { View view = inflater.inflate(R.layout.combopump_fragment, container, false); refresh = (Button) view.findViewById(R.id.combo_refresh); - updateCapabilities = (TextView) view.findViewById(R.id.combo_update_capabilities); statusText = (TextView) view.findViewById(R.id.combo_status); @@ -72,12 +69,10 @@ public class ComboFragment extends Fragment implements View.OnClickListener { lastCmdTimeText = (TextView) view.findViewById(R.id.combo_last_command_time); lastCmdResultText = (TextView) view.findViewById(R.id.combo_last_command_result); lastCmdDurationText = (TextView) view.findViewById(R.id.combo_last_command_duration); - tbrCapabilityText = (TextView) view.findViewById(R.id.combo_tbr_capability); pumpstateBatteryText = (TextView) view.findViewById(R.id.combo_pumpstate_battery); insulinstateText = (TextView) view.findViewById(R.id.combo_insulinstate); refresh.setOnClickListener(this); - updateCapabilities.setOnClickListener(this); updateGUI(); return view; @@ -113,32 +108,6 @@ public class ComboFragment extends Fragment implements View.OnClickListener { }); thread.start(); break; - case R.id.combo_update_capabilities: - (new Thread(new Runnable() { - @Override - public void run() { - Activity activity = getActivity(); - if (activity != null) - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - updateCapabilities.setText("{fa-bluetooth spin}"); - } - }); - - getPlugin().updateCapabilities(); - - if (activity != null) - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - updateCapabilities.setText("{fa-bluetooth-b}"); - } - }); - - } - })).start(); - break; } } @@ -201,7 +170,6 @@ public class ComboFragment extends Fragment implements View.OnClickListener { lastCmdDurationText.setText(""); } } - tbrCapabilityText.setText(getPlugin().getPumpDescription().maxTempPercent + "%"); } }); } 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 9f0e227cc5..e0b9b4c632 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 @@ -31,7 +31,6 @@ import de.jotomo.ruffyscripter.commands.BolusCommand; import de.jotomo.ruffyscripter.commands.CancelTbrCommand; import de.jotomo.ruffyscripter.commands.Command; import de.jotomo.ruffyscripter.commands.CommandResult; -import de.jotomo.ruffyscripter.commands.DetermineCapabilitiesCommand; import de.jotomo.ruffyscripter.commands.GetPumpStateCommand; import de.jotomo.ruffyscripter.commands.SetTbrCommand; import de.jotomo.ruffyscripter.commands.SetTbrCommandAlt; @@ -695,29 +694,4 @@ public class ComboPlugin implements PluginBase, PumpInterface { public void onStatusEvent(final EventAppExit ignored) { unbindRuffyService(); } - - - public void updateCapabilities() { - // if Android is sluggish this might get called before ruffy is bound - if (ruffyScripter == null) { - log.warn("Rejecting call to RefreshDataFromPump: ruffy service not bound (yet)"); - ToastUtils.showToastInUiThread(MainApp.instance(), "Ruffy not initialized."); - return; - } - if (isBusy()) { - ToastUtils.showToastInUiThread(MainApp.instance(), "Pump busy!"); - return; - } - CommandResult result = runCommand(new DetermineCapabilitiesCommand()); - if (result.success) { - pumpDescription.maxTempPercent = (int) result.capabilities.maxTempPercent; - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance()); - SharedPreferences.Editor editor = preferences.edit(); - editor.putInt(COMBO_MAX_TEMP_PERCENT_SP, pumpDescription.maxTempPercent); - editor.commit(); - MainApp.bus().post(new EventComboPumpUpdateGUI()); - } else { - ToastUtils.showToastInUiThread(MainApp.instance(), "No success."); - } - } } \ No newline at end of file diff --git a/app/src/main/res/layout/combopump_fragment.xml b/app/src/main/res/layout/combopump_fragment.xml index a4270240ef..b515ceda2f 100644 --- a/app/src/main/res/layout/combopump_fragment.xml +++ b/app/src/main/res/layout/combopump_fragment.xml @@ -418,60 +418,6 @@ - - - - - - - - - - - - -