diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java index 06b7c963a5..c7afc04cf1 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java @@ -76,6 +76,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.mess import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.ActivationProgress; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertConfiguration; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertSet; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.BeepConfigType; import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager; import info.nightscout.androidaps.plugins.pump.omnipod.driver.util.TimeUtil; import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodActiveAlertsChanged; @@ -85,6 +86,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodTbrChan import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.CommandAcknowledgeAlerts; import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.CommandHandleTimeChange; +import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.CommandPlayTestBeep; import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.CommandUpdateAlertConfiguration; import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.OmnipodCustomCommand; import info.nightscout.androidaps.plugins.pump.omnipod.queue.command.OmnipodCustomCommandType; @@ -794,6 +796,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, return handleTimeChange(((CommandHandleTimeChange) command).isRequestedByUser()); case UPDATE_ALERT_CONFIGURATION: return updateAlertConfiguration(); + case PLAY_TEST_BEEP: + return executeCommand(OmnipodCommandType.PLAY_TEST_BEEP, () -> aapsOmnipodManager.playTestBeep(((CommandPlayTestBeep)command).getBeepType())); default: aapsLogger.warn(LTag.PUMP, "Unknown custom command: " + commandType); return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(resourceHelper.gs(R.string.omnipod_error_unknown_custom_command, commandType)); diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/definition/OmnipodCommandType.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/definition/OmnipodCommandType.java index 8d9b250ac4..7cbc3c8a11 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/definition/OmnipodCommandType.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/definition/OmnipodCommandType.java @@ -21,7 +21,8 @@ public enum OmnipodCommandType { ACKNOWLEDGE_ALERTS(R.string.omnipod_cmd_acknowledge_alerts), // READ_POD_PULSE_LOG(R.string.omnipod_cmd_read_pulse_log), // SUSPEND_DELIVERY(R.string.omnipod_cmd_suspend_delivery), - RESUME_DELIVERY(R.string.omnipod_cmd_resume_delivery); + RESUME_DELIVERY(R.string.omnipod_cmd_resume_delivery), + PLAY_TEST_BEEP(R.string.omnipod_cmd_play_test_beep); private int resourceId; diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/definition/PodHistoryEntryType.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/definition/PodHistoryEntryType.java index 89560786e0..366e675b20 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/definition/PodHistoryEntryType.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/definition/PodHistoryEntryType.java @@ -35,12 +35,14 @@ public enum PodHistoryEntryType { CONFIGURE_ALERTS(50, R.string.omnipod_cmd_configure_alerts, PumpHistoryEntryGroup.Alarm), ACKNOWLEDGE_ALERTS(51, R.string.omnipod_cmd_acknowledge_alerts, PumpHistoryEntryGroup.Alarm), + PLAY_TEST_BEEP(52, R.string.omnipod_cmd_play_test_beep, PumpHistoryEntryGroup.Alarm), SUSPEND_DELIVERY(60, R.string.omnipod_cmd_suspend_delivery, PumpHistoryEntryGroup.Basal), RESUME_DELIVERY(61, R.string.omnipod_cmd_resume_delivery, PumpHistoryEntryGroup.Basal), UNKNOWN_ENTRY_TYPE(99, R.string.omnipod_cmd_unknown_entry); + private int code; private static final Map instanceMap; diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/communication/action/ConfigureBeepAction.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/communication/action/ConfigureBeepAction.java new file mode 100644 index 0000000000..f75c2b652c --- /dev/null +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/communication/action/ConfigureBeepAction.java @@ -0,0 +1,49 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.action; + +import org.joda.time.Duration; + +import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.command.BeepConfigCommand; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.StatusResponse; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.BeepConfigType; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager; +import info.nightscout.androidaps.plugins.pump.omnipod.rileylink.manager.OmnipodRileyLinkCommunicationManager; + +public class ConfigureBeepAction implements OmnipodAction { + private final PodStateManager podStateManager; + private final BeepConfigType beepType; + private final boolean basalCompletionBeep; + private final Duration basalIntervalBeep; + private final boolean tempBasalCompletionBeep; + private final Duration tempBasalIntervalBeep; + private final boolean bolusCompletionBeep; + private final Duration bolusIntervalBeep; + + public ConfigureBeepAction(PodStateManager podState, BeepConfigType beepType, boolean basalCompletionBeep, Duration basalIntervalBeep, boolean tempBasalCompletionBeep, Duration tempBasalIntervalBeep, boolean bolusCompletionBeep, Duration bolusIntervalBeep) { + if (podState == null || beepType == null) { + throw new IllegalArgumentException("Pod state manager cannot be null"); + } + + this.beepType = beepType; + this.basalCompletionBeep = basalCompletionBeep; + this.basalIntervalBeep = basalIntervalBeep; + this.tempBasalCompletionBeep = tempBasalCompletionBeep; + this.tempBasalIntervalBeep = tempBasalIntervalBeep; + this.bolusCompletionBeep = bolusCompletionBeep; + this.bolusIntervalBeep = bolusIntervalBeep; + this.podStateManager = podState; + } + + + public ConfigureBeepAction(PodStateManager podState, BeepConfigType beepType) { + this(podState, beepType, false, Duration.ZERO, false, Duration.ZERO, false, Duration.ZERO); + } + + @Override + public StatusResponse execute(OmnipodRileyLinkCommunicationManager communicationService) { + return communicationService.sendCommand( + StatusResponse.class, podStateManager + , new BeepConfigCommand(beepType, basalCompletionBeep, basalIntervalBeep, + tempBasalCompletionBeep, tempBasalIntervalBeep, + bolusCompletionBeep, bolusIntervalBeep)); + } +} diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/communication/message/command/BeepConfigCommand.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/communication/message/command/BeepConfigCommand.java index fc36e68eab..47cf4533ba 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/communication/message/command/BeepConfigCommand.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/communication/message/command/BeepConfigCommand.java @@ -30,10 +30,6 @@ public class BeepConfigCommand extends MessageBlock { encode(); } - public BeepConfigCommand(BeepConfigType beepType) { - this(beepType, false, Duration.ZERO, false, Duration.ZERO, false, Duration.ZERO); - } - private void encode() { encodedData = new byte[]{beepType.getValue()}; encodedData = ByteUtil.concat(encodedData, (byte) ((basalCompletionBeep ? (1 << 6) : 0) + (basalIntervalBeep.getStandardMinutes() & 0x3f))); diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/OmnipodManager.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/OmnipodManager.java index 7158e9f98d..d4cf973d15 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/OmnipodManager.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/OmnipodManager.java @@ -18,6 +18,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.acti import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.action.BolusAction; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.action.CancelDeliveryAction; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.action.ConfigureAlertsAction; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.action.ConfigureBeepAction; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.action.DeactivatePodAction; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.action.GetPodInfoAction; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.action.GetStatusAction; @@ -33,6 +34,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.mess import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoResponse; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.ActivationProgress; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertConfiguration; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.BeepConfigType; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.BeepType; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.DeliveryStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.DeliveryType; @@ -427,6 +429,23 @@ public class OmnipodManager { podStateManager.discardState(); } + public synchronized void configureBeeps(BeepConfigType beepType, boolean basalCompletionBeep, Duration basalIntervalBeep, + boolean tempBasalCompletionBeep, Duration tempBasalIntervalBeep, + boolean bolusCompletionBeep, Duration bolusIntervalBeep) { + if (!podStateManager.isPodInitialized()) { + throw new IllegalPodProgressException(PodProgressStatus.REMINDER_INITIALIZED, null); + } + communicationService.executeAction(new ConfigureBeepAction(podStateManager, beepType, false, Duration.ZERO, false, Duration.ZERO, false, Duration.ZERO)); + } + + public synchronized void playTestBeep(BeepConfigType beepType) { + if (!podStateManager.isPodInitialized()) { + throw new IllegalPodProgressException(PodProgressStatus.REMINDER_INITIALIZED, null); + } + communicationService.executeAction(new ConfigureBeepAction(podStateManager, beepType)); + } + + public OmnipodRileyLinkCommunicationManager getCommunicationService() { return communicationService; } diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/manager/AapsOmnipodManager.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/manager/AapsOmnipodManager.java index fec5c84cac..9f5333330c 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/manager/AapsOmnipodManager.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/manager/AapsOmnipodManager.java @@ -46,6 +46,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.mess import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoRecentPulseLog; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoResponse; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.AlertConfiguration; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.BeepConfigType; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.FaultEventCode; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.OmnipodConstants; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodInfoType; @@ -232,6 +233,21 @@ public class AapsOmnipodManager { return new PumpEnactResult(injector).success(true).enacted(false); } + public PumpEnactResult playTestBeep(BeepConfigType beepType) { + try { + executeCommand(() -> delegate.playTestBeep(beepType)); + } catch (Exception ex) { + String errorMessage = translateException(ex); + addFailureToHistory(PodHistoryEntryType.PLAY_TEST_BEEP, errorMessage); + return new PumpEnactResult(injector).success(false).enacted(false).comment(errorMessage); + } + + addSuccessToHistory(PodHistoryEntryType.PLAY_TEST_BEEP, beepType); + return new PumpEnactResult(injector).success(true).enacted(false); + } + + + public PumpEnactResult getPodStatus() { StatusResponse statusResponse; diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/queue/command/CommandPlayTestBeep.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/queue/command/CommandPlayTestBeep.java new file mode 100644 index 0000000000..94ff4996c0 --- /dev/null +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/queue/command/CommandPlayTestBeep.java @@ -0,0 +1,16 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.queue.command; + +import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.BeepConfigType; + +public class CommandPlayTestBeep extends OmnipodCustomCommand { + private BeepConfigType beepType; + + public CommandPlayTestBeep(BeepConfigType beepType) { + super(OmnipodCustomCommandType.PLAY_TEST_BEEP); + this.beepType = beepType; + } + + public BeepConfigType getBeepType() { + return beepType; + } +} diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/queue/command/OmnipodCustomCommandType.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/queue/command/OmnipodCustomCommandType.java index e6df62c47b..ab7cb38b39 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/queue/command/OmnipodCustomCommandType.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/queue/command/OmnipodCustomCommandType.java @@ -8,7 +8,9 @@ public enum OmnipodCustomCommandType { RESUME_DELIVERY("RESUME DELIVERY"), DEACTIVATE_POD("DEACTIVATE POD"), HANDLE_TIME_CHANGE("HANDLE TIME CHANGE"), - UPDATE_ALERT_CONFIGURATION("UPDATE ALERT CONFIGURATION"); + UPDATE_ALERT_CONFIGURATION("UPDATE ALERT CONFIGURATION"), + PLAY_TEST_BEEP("EMIT BEEP") + ; private final String description; diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/PodHistoryActivity.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/PodHistoryActivity.java index ff8319a557..74aded32fb 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/PodHistoryActivity.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/PodHistoryActivity.java @@ -35,6 +35,7 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.utils.ProfileUtil; import info.nightscout.androidaps.plugins.pump.omnipod.R; import info.nightscout.androidaps.plugins.pump.omnipod.definition.PodHistoryEntryType; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.BeepConfigType; import info.nightscout.androidaps.plugins.pump.omnipod.util.AapsOmnipodUtil; import info.nightscout.androidaps.utils.resources.ResourceHelper; @@ -272,6 +273,12 @@ public class PodHistoryActivity extends NoSplashAppCompatActivity { } break; + case PLAY_TEST_BEEP: { + if (historyEntry.getData() != null) { + valueView.setText(historyEntry.getData()); + } + } + break; case GET_POD_STATUS: case GET_POD_INFO: case SET_TIME: diff --git a/omnipod/src/main/res/values/strings.xml b/omnipod/src/main/res/values/strings.xml index 6cfea07b2b..6bc4cc2b11 100644 --- a/omnipod/src/main/res/values/strings.xml +++ b/omnipod/src/main/res/values/strings.xml @@ -255,6 +255,8 @@ Less than a minute ago %1$s and %2$s %1$s ago + Beep config + Play test beep %1$d minute %1$d minutes