Added play test beep mechanism

This commit is contained in:
Artiom Kenibasov 2020-11-21 15:44:32 +01:00
parent d66ccfc041
commit 86d6fbc615
11 changed files with 120 additions and 6 deletions

View file

@ -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));

View file

@ -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;

View file

@ -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<Integer, PodHistoryEntryType> instanceMap;

View file

@ -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<StatusResponse> {
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));
}
}

View file

@ -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)));

View file

@ -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;
}

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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:

View file

@ -255,6 +255,8 @@
<string name="omnipod_less_than_a_minute_ago">Less than a minute ago</string>
<string name="omnipod_composite_time">%1$s and %2$s</string>
<string name="omnipod_time_ago">%1$s ago</string>
<string name="omnipod_cmd_beep_config">Beep config</string>
<string name="omnipod_cmd_play_test_beep">Play test beep</string>
<plurals name="omnipod_minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>