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 b3f1aebab7..bf8d91bac1 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 @@ -370,7 +370,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } // trigger a connect, which will update state and check history - CommandResult stateResult = runCommand(null,1, ruffyScripter::readPumpState); + CommandResult stateResult = runCommand(null, 1, ruffyScripter::readPumpState); if (!stateResult.success) { return; } @@ -404,7 +404,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // ComboFragment updates state fully only after the pump has initialized, // so force an update after initialization completed - updateLocalData(runCommand(null, 1, ruffyScripter::readQuickInfo)); + updateLocalData(runCommand(null, 1, () -> ruffyScripter.readQuickInfo(1))); } /** Updates local cache with state (reservoir level, last bolus ...) returned from the pump */ @@ -542,7 +542,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // history below to see what was actually delivered // get last bolus from pump history for verification - CommandResult postBolusStateResult = runCommand(null, 3, ruffyScripter::readQuickInfo); + CommandResult postBolusStateResult = runCommand(null, 3, () -> ruffyScripter.readQuickInfo(1)); if (!postBolusStateResult.success) { return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed)); @@ -552,7 +552,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf : null; // no bolus delivered? - if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus) ) { + if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus)) { if (cancelBolus) { return new PumpEnactResult().success(true).enacted(false); } else { @@ -855,7 +855,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // turn benign warnings into notifications notifyAboutPumpWarning(activeAlert); ruffyScripter.confirmAlert(activeAlert.warningCode); - } else if (activeAlert.errorCode != null){ + } else if (activeAlert.errorCode != null) { Notification notification = new Notification(); notification.date = new Date(); notification.id = Notification.COMBO_PUMP_ALARM; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java index 80f57774ce..5918023d1e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java @@ -32,7 +32,7 @@ public interface RuffyCommands { CommandResult readPumpState(); /** Read reservoir level and last bolus via Quick Info */ - CommandResult readQuickInfo(); + CommandResult readQuickInfo(int numberOfBolusRecordsToRetrieve); /** Reads pump history via the My Data menu. The {@link PumpHistoryRequest} specifies * what types of data and how far back data is returned. */ diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java index cdbb40c413..4112306fdd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java @@ -48,8 +48,6 @@ import info.nightscout.androidaps.BuildConfig; * operations and are cleanly separated from the thread management, connection management etc */ public class RuffyScripter implements RuffyCommands { - private final boolean readQuickInfo = true; - private static final Logger log = LoggerFactory.getLogger(RuffyScripter.class); private IRuffyService ruffyService; @@ -225,17 +223,11 @@ public class RuffyScripter implements RuffyCommands { } @Override - public CommandResult readQuickInfo() { - if (readQuickInfo) { - Answers.getInstance().logCustom(new CustomEvent("ComboReadQuickInfoCmd") - .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) - .putCustomAttribute("version", BuildConfig.VERSION)); - return runCommand(new ReadQuickInfoCommand()); - } - Answers.getInstance().logCustom(new CustomEvent("ComboReadHistoryCmd") + public CommandResult readQuickInfo(int numberOfBolusRecordsToRetrieve) { + Answers.getInstance().logCustom(new CustomEvent("ComboReadQuickInfoCmd") .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) .putCustomAttribute("version", BuildConfig.VERSION)); - return runCommand(new ReadHistoryCommand(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST))); + return runCommand(new ReadQuickInfoCommand(numberOfBolusRecordsToRetrieve)); } public void returnToRootMenu() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java index b1e80c4e61..2973091c67 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java @@ -2,26 +2,58 @@ package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute; import org.monkey.d.ruffy.ruffy.driver.display.MenuType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; +import java.util.Date; import java.util.List; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory; public class ReadQuickInfoCommand extends BaseCommand { + private static final Logger log = LoggerFactory.getLogger(ReadQuickInfoCommand.class); + + private final int numberOfBolusRecordsToRetrieve; + + public ReadQuickInfoCommand(int numberOfBolusRecordsToRetrieve) { + this.numberOfBolusRecordsToRetrieve = numberOfBolusRecordsToRetrieve; + } + @Override public void execute() { scripter.verifyRootMenuIsDisplayed(); + // navigate to reservoir menu scripter.pressCheckKey(); scripter.waitForMenuToBeLeft(MenuType.MAIN_MENU); scripter.waitForMenuToBeLeft(MenuType.STOP); scripter.verifyMenuIsDisplayed(MenuType.QUICK_INFO); result.reservoirLevel = ((Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.REMAINING_INSULIN)).intValue(); - scripter.pressCheckKey(); - List bolusHistory = new ArrayList<>(1); - bolusHistory.add(readBolusRecord()); - result.history = new PumpHistory().bolusHistory(bolusHistory); + if (numberOfBolusRecordsToRetrieve > 0) { + // navigate to bolus data menu + scripter.pressCheckKey(); + scripter.verifyMenuIsDisplayed(MenuType.BOLUS_DATA); + List bolusHistory = new ArrayList<>(numberOfBolusRecordsToRetrieve); + result.history = new PumpHistory().bolusHistory(bolusHistory); + for(int recordsLeftToRead = numberOfBolusRecordsToRetrieve; recordsLeftToRead > 0; recordsLeftToRead--) { + scripter.verifyMenuIsDisplayed(MenuType.BOLUS_DATA); + bolusHistory.add(readBolusRecord()); + int record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD); + scripter.pressDownKey(); + while (record == (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD)) { + scripter.waitForScreenUpdate(); + } + } + if (log.isDebugEnabled()) { + if (!result.history.bolusHistory.isEmpty()) { + log.debug("Read bolus history (" + result.history.bolusHistory.size() + "):"); + for (Bolus bolus : result.history.bolusHistory) { + log.debug(new Date(bolus.timestamp) + ": " + bolus.toString()); + } + } + } + } scripter.returnToRootMenu(); result.success = true; }