From 21a2c688c64bf2cc5d8e7281b9a7e7e3e96833b6 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 13 Nov 2017 22:55:48 +0100 Subject: [PATCH] Cleanups. --- TODO-Combo.md | 10 ++-- Testing-Combo.md | 4 ++ .../plugins/PumpCombo/ComboPlugin.java | 2 +- .../jotomo/ruffyscripter/RuffyScripter.java | 50 ++++--------------- .../ruffyscripter/commands/BolusCommand.java | 2 +- .../commands/ReadHistoryCommand.java | 8 +-- .../ruffyscripter/commands/SetTbrCommand.java | 4 +- 7 files changed, 28 insertions(+), 52 deletions(-) diff --git a/TODO-Combo.md b/TODO-Combo.md index 4d7fd04d1a..4b3d0657a7 100644 --- a/TODO-Combo.md +++ b/TODO-Combo.md @@ -12,10 +12,10 @@ - [ ] Reading history - [x] Bolus - [x] Read - - [x] Sync DB + - [x] Update DB - [ ] TBRs - [x] Read - - [x] Sync DB + - [x] Update DB - [ ] Issue of creating TBR start date from main menu time, which might be off by a minute when we read it as a history record. End date time might be slightly off, unless CancelTempBasal is updated to read from history (probably not worth it). @@ -26,13 +26,13 @@ from 59.9999 to 0) - [ ] Alerts - [x] Read - - [ ] Sync DB? No, but raise an alert if new ones are found beyond those read at startup + - [ ] Update DB? No, but raise an alert if new ones are found beyond those read at startup (Those that occurred while AAPS was not active needn't be turned into alarms, the user had to deal with them on the pump already). - [x] Display in UI - - [ ] TDD + - [x] TDD - [x] Read - - [ ] Sync DB? + - [x] Update DB? No, just write to plugin cache - [x] Display in UI - [ ] Taking over alerts - [ ] On connect diff --git a/Testing-Combo.md b/Testing-Combo.md index 36e79f9aab..55c3329e3c 100644 --- a/Testing-Combo.md +++ b/Testing-Combo.md @@ -49,6 +49,10 @@ by AAPS and result in the pump's time being updated the next time communication with the pump takes place, so disabling automatic time updates on the phone and changing the phone clock manually should allow testing this + - [ ] XXX test year change, reading history + Set phone time to 31.12, 23:55, press Refresh in Combo tab to sync time to pump, + enter bolus + - [ ] XXX daylight saving time changes (2am twice) - [ ] Disconnected pump ... - [ ] Refilling cartridge 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 ea61029379..fa41f609d0 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 @@ -277,7 +277,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } // ComboFragment updates state fully only after the pump has initialized, - // this fetches state again and updates the ui proper + // this fetches state again and updates the UI proper runCommand(null, 0, ruffyScripter::readPumpState); } diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index cdfff9b3c2..d15351c979 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -219,7 +219,7 @@ public class RuffyScripter implements RuffyCommands { while (menuType != MenuType.MAIN_MENU && menuType != MenuType.STOP && menuType != MenuType.WARNING_OR_ERROR) { log.debug("Going back to main menu, currently at " + menuType); pressBackKey(); - waitForMenuUpdate(); + waitForScreenUpdate(); menuType = getCurrentMenu().getType(); } } @@ -570,42 +570,22 @@ public class RuffyScripter implements RuffyCommands { } } - // TODO sort out usages of this method and waitForMenu update, which have the same intent, - // but approach things differently; - private void waitForScreenUpdate() { + /** + * Wait until the menu is updated + */ + public void waitForScreenUpdate() { if (Thread.currentThread().isInterrupted()) throw new CommandException("Interrupted"); synchronized (screenlock) { try { - screenlock.wait((long) 2000); // updates usually come in every ~500, occasionally up to 1100ms + // updates usually come in every ~500, occasionally up to 1100ms + screenlock.wait((long) 2000); } catch (InterruptedException e) { throw new CommandException("Interrupted"); } } } - // TODO v2, rework these two methods: waitForMenuUpdate shoud only be used by commands - // then anything longer than a few seconds is an error; - // only ensureConnected() uses the method with the timeout parameter; inline that code, - // so we can use a custom timeout and give a better error message in case of failure - - // TODO confirmAlarms? and report back which were cancelled? - - /** - * Wait until the menu is updated - */ - public void waitForMenuUpdate() { - waitForScreenUpdate(); -// long timeoutExpired = System.currentTimeMillis() + 60 * 1000; -// long initialUpdateTime = menuLastUpdated; -// while (initialUpdateTime == menuLastUpdated) { -// if (System.currentTimeMillis() > timeoutExpired) { -// throw new CommandException("Timeout waiting for menu update"); -// } -// SystemClock.sleep(10); -// } - } - private void pressKey(final byte key) { if (Thread.currentThread().isInterrupted()) throw new CommandException("Interrupted"); @@ -619,25 +599,17 @@ public class RuffyScripter implements RuffyCommands { } public void navigateToMenu(MenuType desiredMenu) { -// MenuType startedFrom = getCurrentMenu().getType(); -// boolean movedOnce = false; - int retries = 20; + int moviesLeft = 20; while (getCurrentMenu().getType() != desiredMenu) { - retries--; + moviesLeft--; MenuType currentMenuType = getCurrentMenu().getType(); log.debug("Navigating to menu " + desiredMenu + ", current menu: " + currentMenuType); -// if (movedOnce && currentMenuType == startedFrom) { -// throw new CommandException().message("Menu not found searching for " + desiredMenu -// + ". Check menu settings on your pump to ensure it's not hidden."); -// } - if (retries == 0) { + if (moviesLeft == 0) { throw new CommandException("Menu not found searching for " + desiredMenu + ". Check menu settings on your pump to ensure it's not hidden."); } pressMenuKey(); -// waitForMenuToBeLeft(currentMenuType); - SystemClock.sleep(200); -// movedOnce = true; + waitForScreenUpdate(); } } diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java index b046c4ac2a..4634f405a9 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java @@ -161,7 +161,7 @@ public class BolusCommand extends BaseCommand { scripter.navigateToMenu(MenuType.BOLUS_MENU); scripter.verifyMenuIsDisplayed(MenuType.BOLUS_MENU); scripter.pressCheckKey(); - scripter.waitForMenuUpdate(); + scripter.waitForScreenUpdate(); scripter.verifyMenuIsDisplayed(MenuType.BOLUS_ENTER); } diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java index 1115edb4e8..83e2ead50f 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java @@ -149,7 +149,7 @@ public class ReadHistoryCommand extends BaseCommand { break; } scripter.pressDownKey(); - scripter.waitForMenuUpdate(); + scripter.waitForScreenUpdate(); record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD); } } @@ -185,7 +185,7 @@ public class ReadHistoryCommand extends BaseCommand { break; } scripter.pressDownKey(); - scripter.waitForMenuUpdate(); + scripter.waitForScreenUpdate(); record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD); } } @@ -215,7 +215,7 @@ public class ReadHistoryCommand extends BaseCommand { break; } scripter.pressDownKey(); - scripter.waitForMenuUpdate(); + scripter.waitForScreenUpdate(); record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD); } } @@ -245,7 +245,7 @@ public class ReadHistoryCommand extends BaseCommand { break; } scripter.pressDownKey(); - scripter.waitForMenuUpdate(); + scripter.waitForScreenUpdate(); record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD); } } diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java index c88e490105..b82e73177f 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java @@ -70,7 +70,7 @@ public class SetTbrCommand extends BaseCommand { // switch to TBR_DURATION menu by pressing menu key scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); scripter.pressMenuKey(); - scripter.waitForMenuUpdate(); + scripter.waitForScreenUpdate(); scripter.verifyMenuIsDisplayed(MenuType.TBR_DURATION); boolean increasingDuration = inputTbrDuration(); @@ -88,7 +88,7 @@ public class SetTbrCommand extends BaseCommand { scripter.navigateToMenu(MenuType.TBR_MENU); scripter.verifyMenuIsDisplayed(MenuType.TBR_MENU); scripter.pressCheckKey(); - scripter.waitForMenuUpdate(); + scripter.waitForScreenUpdate(); scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); }