diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java index dab8446c49..5badf23adc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java @@ -82,9 +82,11 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter @Override protected void onStart() { - Context context = MainApp.instance().getApplicationContext(); - Intent intent = new Intent(context, getServiceClass()); - context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE); + if (getServiceClass()!=null) { + Context context = MainApp.instance().getApplicationContext(); + Intent intent = new Intent(context, getServiceClass()); + context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE); + } serviceRunning = true; @@ -96,8 +98,10 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter @Override protected void onStop() { - Context context = MainApp.instance().getApplicationContext(); - context.unbindService(serviceConnection); + if (serviceConnection!=null) { + Context context = MainApp.instance().getApplicationContext(); + context.unbindService(serviceConnection); + } serviceRunning = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java index e031cdde9e..105d430435 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java @@ -97,6 +97,12 @@ public enum PumpType { new DoseSettings(0.05d, 30, 12 * 60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, // cannot exceed max basal rate 30u/hr 0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), + Insulet_Omnipod_Dash("Insulet Omnipod Dash", ManufacturerType.Insulet, "Omnipod Dash", 0.05d, null, // + new DoseSettings(0.05d, 30, 8 * 60, 0.05d), // + PumpTempBasalType.Absolute, // + new DoseSettings(0.05d, 30, 12 * 60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, // cannot exceed max basal rate 30u/hr + 0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), + // Medtronic Medtronic_512_712("Medtronic 512/712", ManufacturerType.Medtronic, "512/712", 0.1d, null, // new DoseSettings(0.05d, 30, 8 * 60, 0.05d), // diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt index 88a3043b8d..ea6226c18b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt @@ -22,6 +22,8 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLin import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity +import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState +import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged @@ -83,17 +85,17 @@ class OmnipodFragment : Fragment() { } omnipod_refresh.setOnClickListener { -// if (!OmnipodUtil.getPumpStatus().verifyConfiguration()) { -// OmnipodUtil.displayNotConfiguredDialog(context) -// } else { -// omnipod_refresh.isEnabled = false -// MedtronicPumpPlugin.getPlugin().resetStatusState() -// ConfigBuilderPlugin.getPlugin().commandQueue.readStatus("Clicked refresh", object : Callback() { -// override fun run() { -// activity?.runOnUiThread { omnipod_refresh.isEnabled = true } -// } -// }) -// } + if (!OmnipodUtil.getPumpStatus().verifyConfiguration()) { + OmnipodUtil.displayNotConfiguredDialog(context) + } else { + omnipod_refresh.isEnabled = false + OmnipodUtil.getPlugin().resetStatusState() + ConfigBuilderPlugin.getPlugin().commandQueue.readStatus("Clicked refresh", object : Callback() { + override fun run() { + activity?.runOnUiThread { omnipod_refresh.isEnabled = true } + } + }) + } } omnipod_stats.setOnClickListener { @@ -163,7 +165,7 @@ class OmnipodFragment : Fragment() { pumpStatus.rileyLinkServiceState = checkStatusSet(pumpStatus.rileyLinkServiceState, RileyLinkUtil.getServiceState()) as RileyLinkServiceState? - val resourceId = pumpStatus.rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.MedtronicPump) + val resourceId = pumpStatus.rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.Omnipod) val rileyLinkError = RileyLinkUtil.getError() omnipod_rl_status.text = when { @@ -182,6 +184,62 @@ class OmnipodFragment : Fragment() { MainApp.gs(it.getResourceId(RileyLinkTargetDevice.Omnipod)) } ?: "-" + if (pumpStatus.podNumber==null) { + + } + + + if (pumpStatus.podSessionState==null) { + omnipod_pod_address.text = MainApp.gs(R.string.omnipod_pod_name_no_info) + omnipod_pod_expiry.text = "-" + omnipod_pod_status.text = "{fa-bed} " + } else { + + omnipod_pod_address.text = pumpStatus.podSessionState.address.toString() + omnipod_pod_expiry.text = pumpStatus.podSessionState.expiryDateAsString + + pumpStatus.podDeviceState = checkStatusSet(pumpStatus.podDeviceState, + OmnipodUtil.getPodDeviceState()) as PodDeviceState? + + var podDeviceState = pumpStatus.podDeviceState + + when (podDeviceState) { + null, + PumpDeviceState.Sleeping -> omnipod_pod_status.text = "{fa-bed} " // + pumpStatus.pumpDeviceState.name()); + PumpDeviceState.NeverContacted, + PumpDeviceState.WakingUp, + PumpDeviceState.PumpUnreachable, + PumpDeviceState.ErrorWhenCommunicating, + PumpDeviceState.TimeoutWhenCommunicating, + PumpDeviceState.InvalidConfiguration -> omnipod_pod_status.text = " " + MainApp.gs(podDeviceState.resourceId) + PumpDeviceState.Active -> { + + omnipod_pod_status.text = "Active"; +// val cmd = OmnipodUtil.getCurrentCommand() +// if (cmd == null) +// omnipod_pod_status.text = " " + MainApp.gs(pumpStatus.pumpDeviceState.resourceId) +// else { +// log.debug("Command: " + cmd) +// val cmdResourceId = cmd.resourceId +// if (cmd == MedtronicCommandType.GetHistoryData) { +// omnipod_pod_status.text = OmnipodUtil.frameNumber?.let { +// MainApp.gs(cmdResourceId, OmnipodUtil.pageNumber, OmnipodUtil.frameNumber) +// } +// ?: MainApp.gs(R.string.medtronic_cmd_desc_get_history_request, OmnipodUtil.pageNumber) +// } else { +// omnipod_pod_status.text = " " + (cmdResourceId?.let { MainApp.gs(it) } +// ?: cmd.getCommandDescription()) +// } +// } + } + else -> log.warn("Unknown pump state: " + pumpStatus.podDeviceState) + } + + + + } + + // pumpStatus.pumpDeviceState = checkStatusSet(pumpStatus.pumpDeviceState, // OmnipodUtil.getPumpDeviceState()) as PumpDeviceState? // diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java index 7b699667c4..e601a7ab59 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java @@ -43,12 +43,13 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkConfigurationTask; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor; -import info.nightscout.androidaps.plugins.pump.medtronic.events.EventRefreshButtonState; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager; import info.nightscout.androidaps.plugins.pump.omnipod.comm.ui.OmnipodUIComm; import info.nightscout.androidaps.plugins.pump.omnipod.comm.ui.OmnipodUITask; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCustomActionType; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged; import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefreshButtonState; import info.nightscout.androidaps.plugins.pump.omnipod.service.OmnipodPumpStatus; @@ -67,22 +68,23 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa private static final Logger LOG = LoggerFactory.getLogger(L.PUMP); - protected static OmnipodPumpPlugin plugin = null; + private static OmnipodPumpPlugin plugin = null; private RileyLinkOmnipodService omnipodService; - private OmnipodPumpStatus pumpStatusLocal = null; - private OmnipodUIComm omnipodUIComm = new OmnipodUIComm(); + protected OmnipodPumpStatus pumpStatusLocal = null; + protected OmnipodUIComm omnipodUIComm; // variables for handling statuses and history - private boolean firstRun = true; - private boolean isRefresh = false; + protected boolean firstRun = true; + protected boolean isRefresh = false; private boolean isBasalProfileInvalid = false; private boolean basalProfileChanged = false; private boolean isInitialized = false; - private OmnipodCommunicationManager omnipodCommunicationManager; + protected OmnipodCommunicationManagerInterface omnipodCommunicationManager; public static boolean isBusy = false; - private List busyTimestamps = new ArrayList<>(); - private boolean sentIdToFirebase = false; + protected List busyTimestamps = new ArrayList<>(); + protected boolean sentIdToFirebase = false; + private boolean hasTimeDateOrTimeZoneChanged = false; private Profile currentProfile; @@ -102,6 +104,14 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa displayConnectionMessages = false; + if (omnipodCommunicationManager == null) { + omnipodCommunicationManager = OmnipodCommunicationManager.getInstance(); + } + + omnipodUIComm = new OmnipodUIComm(omnipodCommunicationManager); + + OmnipodUtil.setPlugin(this); + serviceConnection = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { @@ -135,6 +145,11 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa } + protected OmnipodPumpPlugin(PluginDescription pluginDescription, PumpType pumpType) { + super(pluginDescription, pumpType); + } + + public static OmnipodPumpPlugin getPlugin() { if (plugin == null) plugin = new OmnipodPumpPlugin(); @@ -288,17 +303,18 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa if (firstRun) { initializePump(!isRefresh); + } else { + getPodPumpStatus(); } -// getPodPumpStatus(); -// -// if (firstRun) { -// initializePump(!isRefresh); -// } else { -// refreshAnyStatusThatNeedsToBeRefreshed(); -// } -// -// MainApp.bus().post(new EventMedtronicPumpValuesChanged()); + triggerUIChange(); + } + + private void getPodPumpStatus() { + // TODO read pod status + LOG.error("getPodPumpStatus() NOT IMPLEMENTED"); + + // we would probably need to read Basal Profile here too } @@ -318,34 +334,29 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa if (isLoggingEnabled()) LOG.info(getLogPrefix() + "initializePump - start"); - if (omnipodCommunicationManager == null) { - omnipodCommunicationManager = OmnipodCommunicationManager.getInstance(); + + setRefreshButtonEnabled(false); + + String podState = SP.getString(OmnipodConst.Prefs.PodState, null); + + if (podState != null) { + PodSessionState podSessionState = OmnipodUtil.getGsonInstance().fromJson(podState, PodSessionState.class); + OmnipodUtil.setPodSessionState(podSessionState); + + LOG.debug("PodSessionState (saved): " + podSessionState); + + // TODO handle if session state too old + + // TODO handle basal + + // TODO handle time + + getPodPumpStatus(); + } else { + LOG.debug("No PodSessionState found. Pod probably not running."); } -// setRefreshButtonEnabled(false); -// -// getPodPumpStatus(); -// -// if (isRefresh) { -// if (isPumpNotReachable()) { -// if (isLoggingEnabled()) -// LOG.error(getLogPrefix() + "initializePump::Pump unreachable."); -// MedtronicUtil.sendNotification(MedtronicNotificationType.PumpUnreachable); -// -// setRefreshButtonEnabled(true); -// -// return; -// } -// -// MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable); -// } -// -// this.pumpState = PumpDriverState.Connected; -// -// pumpStatusLocal.setLastCommunicationToNow(); -// setRefreshButtonEnabled(true); - - // TODO need to read status and BasalProfile if pod inited and pod status and set correct commands enabled + setRefreshButtonEnabled(true); if (!isRefresh) { pumpState = PumpDriverState.Initialized; @@ -360,7 +371,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa } isInitialized = true; - // this.pumpState = PumpDriverState.Initialized; this.firstRun = false; } @@ -369,7 +379,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa @Override public boolean isThisProfileSet(Profile profile) { - // status was not yet read from pod + // TODO status was not yet read from pod if (currentProfile == null) { return true; } @@ -404,19 +414,17 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa @Override public double getReservoirLevel() { - // TODO return getPodPumpStatusObject().reservoirRemainingUnits; } @Override public int getBatteryLevel() { - // TODO - return getPodPumpStatusObject().batteryRemaining; + return 75; } - private OmnipodPumpStatus getPodPumpStatusObject() { + protected OmnipodPumpStatus getPodPumpStatusObject() { if (pumpStatusLocal == null) { // FIXME I don't know why this happens if (isLoggingEnabled()) @@ -429,7 +437,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa protected void triggerUIChange() { - MainApp.bus().post(new EventOmnipodPumpValuesChanged()); + RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged()); } @@ -445,7 +453,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa OmnipodUITask responseTask = omnipodUIComm.executeCommand(OmnipodCommandType.SetBolus, detailedBolusInfo.insulin); - Boolean response = (Boolean) responseTask.returnData; + Boolean response = responseTask.wasCommandSuccessful(); setRefreshButtonEnabled(true); @@ -454,7 +462,9 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); // we subtract insulin, exact amount will be visible with next remainingInsulin update. - getPodPumpStatusObject().reservoirRemainingUnits -= detailedBolusInfo.insulin; + if (getPodPumpStatusObject().reservoirRemainingUnits != 0) { + getPodPumpStatusObject().reservoirRemainingUnits -= detailedBolusInfo.insulin; + } incrementStatistics(detailedBolusInfo.isSMB ? OmnipodConst.Statistics.SMBBoluses : OmnipodConst.Statistics.StandardBoluses); @@ -484,22 +494,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa } - private PumpEnactResult setNotReachable(boolean isBolus, boolean success) { - setRefreshButtonEnabled(true); - - if (success) { - return new PumpEnactResult() // - .success(true) // - .enacted(false); - } else { - return new PumpEnactResult() // - .success(false) // - .enacted(false) // - .comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable)); - } - } - - public void stopBolusDelivering() { LOG.info(getLogPrefix() + "stopBolusDelivering"); @@ -510,7 +504,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa OmnipodUITask responseTask = omnipodUIComm.executeCommand(OmnipodCommandType.CancelBolus); - Boolean response = (Boolean) responseTask.returnData; + Boolean response = responseTask.wasCommandSuccessful(); setRefreshButtonEnabled(true); @@ -575,7 +569,8 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa // CANCEL OmnipodUITask responseTask2 = omnipodUIComm.executeCommand(OmnipodCommandType.CancelTemporaryBasal); - Boolean response = (Boolean) responseTask2.returnData; + Boolean response = responseTask2.wasCommandSuccessful(); + ; if (response) { if (isLoggingEnabled()) @@ -595,7 +590,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa OmnipodUITask responseTask = omnipodUIComm.executeCommand(OmnipodCommandType.SetTemporaryBasal, absoluteRate, durationInMinutes); - Boolean response = (Boolean) responseTask.returnData; + Boolean response = responseTask.wasCommandSuccessful(); if (isLoggingEnabled()) LOG.info(getLogPrefix() + "setTempBasalAbsolute - setTBR. Response: " + response); @@ -630,7 +625,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa } - private TempBasalPair readTBR() { + protected TempBasalPair readTBR() { // TODO we can do it like this or read status from pod ?? if (pumpStatusLocal.tempBasalEnd < System.currentTimeMillis()) { // TBR done @@ -643,7 +638,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa } - private void finishAction(String overviewKey) { + protected void finishAction(String overviewKey) { if (overviewKey != null) MainApp.bus().post(new EventRefreshOverview(overviewKey)); @@ -653,16 +648,16 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa } - private long getTimeInFutureFromMinutes(int minutes) { + protected long getTimeInFutureFromMinutes(int minutes) { return System.currentTimeMillis() + getTimeInMs(minutes); } - private long getTimeInMs(int minutes) { + protected long getTimeInMs(int minutes) { return getTimeInS(minutes) * 1000L; } - private int getTimeInS(int minutes) { + protected int getTimeInS(int minutes) { return minutes * 60; } @@ -688,7 +683,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa OmnipodUITask responseTask2 = omnipodUIComm.executeCommand(OmnipodCommandType.CancelTemporaryBasal); - Boolean response = (Boolean) responseTask2.returnData; + Boolean response = responseTask2.wasCommandSuccessful(); finishAction("TBR"); @@ -738,7 +733,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa OmnipodUITask responseTask = omnipodUIComm.executeCommand(OmnipodCommandType.SetBasalProfile, profile); - Boolean response = (Boolean) responseTask.returnData; + Boolean response = responseTask.wasCommandSuccessful(); if (isLoggingEnabled()) LOG.info(getLogPrefix() + "Basal Profile was set: " + response); @@ -756,18 +751,18 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa // OPERATIONS not supported by Pump or Plugin - private List customActions = null; + protected List customActions = null; private CustomAction customActionResetRLConfig = new CustomAction( R.string.medtronic_custom_action_reset_rileylink, OmnipodCustomActionType.ResetRileyLinkConfiguration, true); - private CustomAction customActionInitPod = new CustomAction( + protected CustomAction customActionInitPod = new CustomAction( R.string.omnipod_cmd_init_pod, OmnipodCustomActionType.InitPod, true); - private CustomAction customActionDeactivatePod = new CustomAction( + protected CustomAction customActionDeactivatePod = new CustomAction( R.string.omnipod_cmd_deactivate_pod, OmnipodCustomActionType.DeactivatePod, false); - private CustomAction customActionResetPod = new CustomAction( + protected CustomAction customActionResetPod = new CustomAction( R.string.omnipod_cmd_reset_pod, OmnipodCustomActionType.ResetPodStatus, true); @@ -776,7 +771,10 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa if (customActions == null) { this.customActions = Arrays.asList( - customActionResetRLConfig); + customActionResetRLConfig, // + customActionInitPod, // + customActionDeactivatePod, // + customActionResetPod); } return this.customActions; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodCommunicationManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodCommunicationManager.java index d8dc63bb75..e08a399090 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodCommunicationManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodCommunicationManager.java @@ -14,8 +14,8 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RLMessage; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RLMessageType; import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodManager; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.PairAction; import info.nightscout.androidaps.plugins.pump.omnipod.comm.data.PodCommResponse; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.utils.SP; @@ -45,14 +45,11 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager i private PodSessionState getPodSessionState() { - - return null; } - public static OmnipodCommunicationManager getInstance() { return omnipodCommunicationManager; } @@ -102,7 +99,6 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager i omnipodManager.pairAndPrime(); - return null; } @@ -140,4 +136,9 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager i return null; } + @Override + public PodCommResponse acknowledgeAlerts() { + return null; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/data/PodCommResponse.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/data/PodCommResponse.java index ebc7ccf966..625168bac0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/data/PodCommResponse.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/data/PodCommResponse.java @@ -10,6 +10,10 @@ public class PodCommResponse { Object customData; Object errorResponse; + public boolean isAcknowledged() { + return (acknowledged != null && acknowledged); + } + // some status data if it can be returned (battery, reservoir, etc) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/ui/OmnipodUIComm.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/ui/OmnipodUIComm.java index 09647186f7..2d91deec37 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/ui/OmnipodUIComm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/ui/OmnipodUIComm.java @@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; @@ -15,18 +16,18 @@ public class OmnipodUIComm { private static final Logger LOG = LoggerFactory.getLogger(L.PUMP); - OmnipodCommunicationManager ocmInstance = null; + OmnipodCommunicationManagerInterface ocmInstance = null; OmnipodUIPostprocessor uiPostprocessor = new OmnipodUIPostprocessor(); - private OmnipodCommunicationManager getCommunicationManager() { - if (ocmInstance == null) { - ocmInstance = OmnipodCommunicationManager.getInstance(); - } - + private OmnipodCommunicationManagerInterface getCommunicationManager() { return ocmInstance; } + public OmnipodUIComm(OmnipodCommunicationManagerInterface communicationManager) { + ocmInstance = communicationManager; + } + public synchronized OmnipodUITask executeCommand(OmnipodCommandType commandType, Object... parameters) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/ui/OmnipodUITask.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/ui/OmnipodUITask.java index 350ea34f15..5a831e1e19 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/ui/OmnipodUITask.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/ui/OmnipodUITask.java @@ -3,17 +3,18 @@ package info.nightscout.androidaps.plugins.pump.omnipod.comm.ui; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.TempBasalPair; -import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState; -import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpValuesChanged; -import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager; +import info.nightscout.androidaps.plugins.bus.RxBus; +import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; +import info.nightscout.androidaps.plugins.pump.omnipod.comm.data.PodCommResponse; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodResponseType; import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange; +import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged; +import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; /** * Created by andy on 4.8.2019 @@ -24,7 +25,7 @@ public class OmnipodUITask { private static final Logger LOG = LoggerFactory.getLogger(L.PUMP); public OmnipodCommandType commandType; - public Object returnData; + public PodCommResponse returnData; private String errorDescription; private Object[] parameters; private PodResponseType responseType; @@ -41,7 +42,7 @@ public class OmnipodUITask { } - public void execute(OmnipodCommunicationManager communicationManager) { + public void execute(OmnipodCommunicationManagerInterface communicationManager) { if (isLogEnabled()) LOG.debug("OmnipodUITask: @@@ In execute. {}", commandType); @@ -100,6 +101,8 @@ public class OmnipodUITask { } + // TODO response + } @@ -146,19 +149,19 @@ public class OmnipodUITask { } if (responseType == PodResponseType.Invalid) { - statusChange = new EventOmnipodDeviceStatusChange(PumpDeviceState.ErrorWhenCommunicating, + statusChange = new EventOmnipodDeviceStatusChange(PodDeviceState.ErrorWhenCommunicating, "Unsupported command in OmnipodUITask"); - MainApp.bus().post(statusChange); + RxBus.INSTANCE.send(statusChange); } else if (responseType == PodResponseType.Error) { - statusChange = new EventOmnipodDeviceStatusChange(PumpDeviceState.ErrorWhenCommunicating, + statusChange = new EventOmnipodDeviceStatusChange(PodDeviceState.ErrorWhenCommunicating, errorDescription); - MainApp.bus().post(statusChange); + RxBus.INSTANCE.send(statusChange); } else { - MainApp.bus().post(new EventMedtronicPumpValuesChanged()); - MedtronicUtil.getPumpStatus().setLastCommunicationToNow(); + OmnipodUtil.getPumpStatus().setLastCommunicationToNow(); + RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged()); } - MedtronicUtil.setCurrentCommand(null); + OmnipodUtil.setPodDeviceState(PodDeviceState.Sleeping); } @@ -181,4 +184,12 @@ public class OmnipodUITask { return this.responseType; } + public boolean wasCommandSuccessful() { + if (returnData == null) { + return false; + } + return returnData.isAcknowledged(); + } + + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodCommunicationManagerInterface.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodCommunicationManagerInterface.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodCommunicationManagerInterface.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodCommunicationManagerInterface.java index 25c55bca6a..48baf9e815 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodCommunicationManagerInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodCommunicationManagerInterface.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.comm; +package info.nightscout.androidaps.plugins.pump.omnipod.defs; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; @@ -57,5 +57,10 @@ public interface OmnipodCommunicationManagerInterface { */ PodCommResponse cancelTemporaryBasal(); + /** + * Acknowledge alerts + */ + PodCommResponse acknowledgeAlerts(); + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodSessionState.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodSessionState.java index 97e646b717..6bd82435bc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodSessionState.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/state/PodSessionState.java @@ -18,6 +18,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.FirmwareVersion; import info.nightscout.androidaps.plugins.pump.omnipod.defs.NonceState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress; import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule; +import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmniCRC; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; @@ -202,8 +203,16 @@ public class PodSessionState extends PodState { private void store() { Gson gson = OmnipodUtil.getGsonInstance(); SP.putString(OmnipodConst.Prefs.PodState, gson.toJson(this)); + OmnipodUtil.setPodSessionState(this); } + public String getExpiryDateAsString() { + // TODO + return "???"; + } + + + @Override public String toString() { return "PodSessionState{" + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodDeviceStatusChange.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodDeviceStatusChange.java index 30be8cdb71..f0b7a98a60 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodDeviceStatusChange.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodDeviceStatusChange.java @@ -3,7 +3,8 @@ package info.nightscout.androidaps.plugins.pump.omnipod.events; import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState; -import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; /** * Created by andy on 4.8.2019 @@ -13,8 +14,9 @@ public class EventOmnipodDeviceStatusChange extends Event { public RileyLinkServiceState rileyLinkServiceState; public RileyLinkError rileyLinkError; - public PumpDeviceState pumpDeviceState; + public PodSessionState podSessionState; public String errorDescription; + public PodDeviceState podDeviceState; public EventOmnipodDeviceStatusChange(RileyLinkServiceState rileyLinkServiceState) { @@ -28,20 +30,27 @@ public class EventOmnipodDeviceStatusChange extends Event { } - public EventOmnipodDeviceStatusChange(PumpDeviceState pumpDeviceState) { - this.pumpDeviceState = pumpDeviceState; + public EventOmnipodDeviceStatusChange(PodSessionState podSessionState) { + this.podSessionState = podSessionState; } - public EventOmnipodDeviceStatusChange(PumpDeviceState pumpDeviceState, String errorDescription) { - this.pumpDeviceState = pumpDeviceState; + public EventOmnipodDeviceStatusChange(String errorDescription) { + this.errorDescription = errorDescription; + } + + public EventOmnipodDeviceStatusChange(PodDeviceState podDeviceState, String errorDescription) { + this.podDeviceState = podDeviceState; this.errorDescription = errorDescription; } @Override public String toString() { - return "EventOmnipodDeviceStatusChange [" + "rileyLinkServiceState=" + rileyLinkServiceState - + ", rileyLinkError=" + rileyLinkError + ", pumpDeviceState=" + pumpDeviceState + ']'; + return "EventOmnipodDeviceStatusChange [" // + + "rileyLinkServiceState=" + rileyLinkServiceState + + ", rileyLinkError=" + rileyLinkError // + + ", podSessionState=" + podSessionState // + + ", podDeviceState=" + podDeviceState + "]"; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/OmnipodPumpStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/OmnipodPumpStatus.java index af1b95c956..184ce358e8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/OmnipodPumpStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/OmnipodPumpStatus.java @@ -1,5 +1,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.service; +import org.jetbrains.annotations.Nullable; import org.joda.time.LocalDateTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,6 +15,8 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.utils.SP; @@ -37,12 +40,14 @@ public class OmnipodPumpStatus extends PumpStatus { public long tempBasalEnd; public Double tempBasalAmount = 0.0d; public Integer tempBasalLength; + public PodSessionState podSessionState; private boolean rileyLinkAddressChanged = false; private String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}"; public String podNumber; + public PodDeviceState podDeviceState = PodDeviceState.NeverContacted; public OmnipodPumpStatus(PumpDescription pumpDescription) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodUtil.java index 70de575737..eb3921a8f2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodUtil.java @@ -8,6 +8,8 @@ import com.google.gson.JsonDeserializer; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.format.ISODateTimeFormat; @@ -19,14 +21,15 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; -import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem; -import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicNotificationType; +import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; +import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange; import info.nightscout.androidaps.plugins.pump.omnipod.service.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService; import info.nightscout.androidaps.utils.OKDialog; @@ -44,6 +47,9 @@ public class OmnipodUtil extends RileyLinkUtil { private static OmnipodPumpStatus omnipodPumpStatus; private static OmnipodCommandType currentCommand; private static Gson gsonInstance = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); + private static PodSessionState podSessionState; + private static PodDeviceState podDeviceState; + private static OmnipodPumpPlugin omnipodPumpPlugin; public static Gson getGsonInstance() { return gsonInstance; @@ -84,29 +90,6 @@ public class OmnipodUtil extends RileyLinkUtil { } - public static void sendNotification(MedtronicNotificationType notificationType) { - Notification notification = new Notification( // - notificationType.getNotificationType(), // - MainApp.gs(notificationType.getResourceId()), // - notificationType.getNotificationUrgency()); - MainApp.bus().post(new EventNewNotification(notification)); - } - - - public static void sendNotification(MedtronicNotificationType notificationType, Object... parameters) { - Notification notification = new Notification( // - notificationType.getNotificationType(), // - MainApp.gs(notificationType.getResourceId(), parameters), // - notificationType.getNotificationUrgency()); - MainApp.bus().post(new EventNewNotification(notification)); - } - - - public static void dismissNotification(MedtronicNotificationType notificationType) { - MainApp.bus().post(new EventDismissNotification(notificationType.getNotificationType())); - } - - public static boolean isLowLevelDebug() { return lowLevelDebug; } @@ -179,4 +162,33 @@ public class OmnipodUtil extends RileyLinkUtil { return gsonBuilder.create(); } + + public static void setPodSessionState(PodSessionState podSessionState) { + omnipodPumpStatus.podSessionState = podSessionState; + RxBus.INSTANCE.send(new EventOmnipodDeviceStatusChange(podSessionState)); + } + + @Nullable + public static PodDeviceState getPodDeviceState() { + return null; + } + + + public static void setPodDeviceState(PodDeviceState podDeviceState) { + OmnipodUtil.podDeviceState = podDeviceState; + } + + + @NotNull + public static OmnipodPumpPlugin getPlugin() { + return OmnipodUtil.omnipodPumpPlugin; + } + + + @NotNull + public static void setPlugin(OmnipodPumpPlugin pumpPlugin) { + OmnipodUtil.omnipodPumpPlugin = pumpPlugin; + } + + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/OmnipodDashPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/OmnipodDashPumpPlugin.java new file mode 100644 index 0000000000..59a7a3baff --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/OmnipodDashPumpPlugin.java @@ -0,0 +1,325 @@ +package info.nightscout.androidaps.plugins.pump.omnipod_dash; + +import android.content.ComponentName; +import android.content.ServiceConnection; +import android.os.Bundle; +import android.os.IBinder; +import android.os.SystemClock; + +import androidx.annotation.NonNull; + +import org.joda.time.LocalDateTime; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import info.nightscout.androidaps.BuildConfig; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.DetailedBolusInfo; +import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.db.Source; +import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.events.EventRefreshOverview; +import info.nightscout.androidaps.interfaces.PluginDescription; +import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.bus.RxBus; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; +import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract; +import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState; +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkConfigurationTask; +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor; +import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodFragment; +import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin; +import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager; +import info.nightscout.androidaps.plugins.pump.omnipod.comm.ui.OmnipodUIComm; +import info.nightscout.androidaps.plugins.pump.omnipod.comm.ui.OmnipodUITask; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCustomActionType; +import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged; +import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefreshButtonState; +import info.nightscout.androidaps.plugins.pump.omnipod.service.OmnipodPumpStatus; +import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService; +import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; +import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; +import info.nightscout.androidaps.plugins.pump.omnipod_dash.comm.OmnipodDashCommunicationManager; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; +import info.nightscout.androidaps.utils.SP; + +/** + * Created by andy on 23.04.18. + * + * @author Andy Rozman (andy.rozman@gmail.com) + */ +public class OmnipodDashPumpPlugin extends OmnipodPumpPlugin implements PumpInterface { + + private static final Logger LOG = LoggerFactory.getLogger(L.PUMP); + + protected static OmnipodDashPumpPlugin plugin = null; + private RileyLinkOmnipodService omnipodService; + private OmnipodPumpStatus pumpStatusLocal = null; + + // variables for handling statuses and history + private boolean firstRun = true; + private boolean isRefresh = false; + private boolean isBasalProfileInvalid = false; + private boolean basalProfileChanged = false; + private boolean isInitialized = false; + + public static boolean isBusy = false; + private List busyTimestamps = new ArrayList<>(); + private boolean sentIdToFirebase = false; + private boolean hasTimeDateOrTimeZoneChanged = false; + + private Profile currentProfile; + + + private OmnipodDashPumpPlugin() { + + super(new PluginDescription() // + .mainType(PluginType.PUMP) // + .fragmentClass(OmnipodFragment.class.getName()) // + .pluginName(R.string.omnipod_dash_name) // + .shortName(R.string.omnipod_dash_name_short) // + .preferencesId(R.xml.pref_omnipod) // + .description(R.string.description_pump_omnipod_dash), // + PumpType.Insulet_Omnipod_Dash + ); + + displayConnectionMessages = false; + + if (omnipodCommunicationManager == null) { + omnipodCommunicationManager = OmnipodDashCommunicationManager.getInstance(); + } + + omnipodUIComm = new OmnipodUIComm(omnipodCommunicationManager); + + OmnipodUtil.setPlugin(this); + + // FIXME +// serviceConnection = new ServiceConnection() { +// +// public void onServiceDisconnected(ComponentName name) { +// if (isLoggingEnabled()) +// LOG.debug("RileyLinkOmnipodService is disconnected"); +// omnipodService = null; +// } +// +// public void onServiceConnected(ComponentName name, IBinder service) { +// if (isLoggingEnabled()) +// LOG.debug("RileyLinkOmnipodService is connected"); +// RileyLinkOmnipodService.LocalBinder mLocalBinder = (RileyLinkOmnipodService.LocalBinder) service; +// omnipodService = mLocalBinder.getServiceInstance(); +// +// new Thread(() -> { +// +// for (int i = 0; i < 20; i++) { +// SystemClock.sleep(5000); +// +// if (OmnipodUtil.getPumpStatus() != null) { +// if (isLoggingEnabled()) +// LOG.debug("Starting OmniPod-RileyLink service"); +// if (OmnipodUtil.getPumpStatus().setNotInPreInit()) { +// break; +// } +// } +// } +// }).start(); +// } +// }; + } + + + public static OmnipodDashPumpPlugin getPlugin() { + if (plugin == null) + plugin = new OmnipodDashPumpPlugin(); + return plugin; + } + + + private String getLogPrefix() { + return "OmnipodPlugin::"; + } + + + + // FIXME + public Class getServiceClass() { + return RileyLinkOmnipodService.class; + } + + + @Override + public String deviceID() { + return "Omnipod Dash"; + } + + + // Pump Plugin + + private boolean isServiceSet() { + return omnipodService != null; + } + + + @Override + public boolean isInitialized() { + if (isLoggingEnabled() && displayConnectionMessages) + LOG.debug(getLogPrefix() + "isInitialized"); + return isServiceSet() && isInitialized; + } + + + @Override + public boolean isConnected() { + if (isLoggingEnabled() && displayConnectionMessages) + LOG.debug(getLogPrefix() + "isConnected"); + return isServiceSet() && omnipodService.isInitialized(); + } + + + @Override + public boolean isConnecting() { + if (isLoggingEnabled() && displayConnectionMessages) + LOG.debug(getLogPrefix() + "isConnecting"); + return !isServiceSet() || !omnipodService.isInitialized(); + } + + + @Override + public void getPumpStatus() { + + if (firstRun) { + initializePump(!isRefresh); + } + +// getPodPumpStatus(); +// +// if (firstRun) { +// initializePump(!isRefresh); +// } else { +// refreshAnyStatusThatNeedsToBeRefreshed(); +// } +// +// MainApp.bus().post(new EventMedtronicPumpValuesChanged()); + } + + + void resetStatusState() { + firstRun = true; + isRefresh = true; + } + + + private void setRefreshButtonEnabled(boolean enabled) { + RxBus.INSTANCE.send(new EventOmnipodRefreshButtonState(enabled)); + } + + + private void initializePump(boolean realInit) { + + if (isLoggingEnabled()) + LOG.info(getLogPrefix() + "initializePump - start"); + + if (omnipodCommunicationManager == null) { + omnipodCommunicationManager = OmnipodDashCommunicationManager.getInstance(); + } + +// setRefreshButtonEnabled(false); +// +// getPodPumpStatus(); +// +// if (isRefresh) { +// if (isPumpNotReachable()) { +// if (isLoggingEnabled()) +// LOG.error(getLogPrefix() + "initializePump::Pump unreachable."); +// MedtronicUtil.sendNotification(MedtronicNotificationType.PumpUnreachable); +// +// setRefreshButtonEnabled(true); +// +// return; +// } +// +// MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable); +// } +// +// this.pumpState = PumpDriverState.Connected; +// +// pumpStatusLocal.setLastCommunicationToNow(); +// setRefreshButtonEnabled(true); + + // TODO need to read status and BasalProfile if pod inited and pod status and set correct commands enabled + + if (!isRefresh) { + pumpState = PumpDriverState.Initialized; + } + + if (!sentIdToFirebase) { + Bundle params = new Bundle(); + params.putString("version", BuildConfig.VERSION); + MainApp.getFirebaseAnalytics().logEvent("OmnipodPumpInit", params); + + sentIdToFirebase = true; + } + + isInitialized = true; + // this.pumpState = PumpDriverState.Initialized; + + this.firstRun = false; + } + + + protected void triggerUIChange() { + MainApp.bus().post(new EventOmnipodPumpValuesChanged()); + } + + + + + + // OPERATIONS not supported by Pump or Plugin + + //private List customActions = null; + + + @Override + public List getCustomActions() { + + if (customActions == null) { + this.customActions = Arrays.asList( + customActionInitPod, // + customActionDeactivatePod, // + customActionResetPod); + } + + return this.customActions; + } + + + @Override + public void timeDateOrTimeZoneChanged() { + +// if (isLoggingEnabled()) +// LOG.warn(getLogPrefix() + "Time, Date and/or TimeZone changed. "); +// +// this.hasTimeDateOrTimeZoneChanged = true; + } + + + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/comm/OmnipodDashCommunicationManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/comm/OmnipodDashCommunicationManager.java new file mode 100644 index 0000000000..c0593759a4 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/comm/OmnipodDashCommunicationManager.java @@ -0,0 +1,113 @@ +package info.nightscout.androidaps.plugins.pump.omnipod_dash.comm; + +import android.content.Context; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy; +import info.nightscout.androidaps.plugins.pump.omnipod.comm.data.PodCommResponse; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; +import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; +import info.nightscout.androidaps.utils.SP; + +/** + * Created by andy on 4.8.2019 + */ +public class OmnipodDashCommunicationManager implements OmnipodCommunicationManagerInterface { + + private static final Logger LOG = LoggerFactory.getLogger(L.PUMPCOMM); + + private static OmnipodDashCommunicationManager omnipodCommunicationManager; + String errorMessage; + + + public OmnipodDashCommunicationManager(Context context, RFSpy rfspy) { + omnipodCommunicationManager = this; + OmnipodUtil.getPumpStatus().previousConnection = SP.getLong( + RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L); + } + + + private PodSessionState getPodSessionState() { + + + return null; + } + + + public static OmnipodDashCommunicationManager getInstance() { + return omnipodCommunicationManager; + } + + + //@Override + protected void configurePumpSpecificSettings() { + //pumpStatus = OmnipodUtil.getPumpStatus(); + } + + + public String getErrorResponse() { + return this.errorMessage; + } + + + private boolean isLogEnabled() { + return L.isEnabled(L.PUMPCOMM); + } + + + // This are just skeleton methods, we need to see what we can get returned and act accordingly + + public PodCommResponse initPod() { + //omnipodManager.pairAndPrime(); + + + return null; + } + + + public PodCommResponse getPodStatus() { + return null; + } + + + public PodCommResponse deactivatePod() { + return null; + } + + public PodCommResponse setBasalProfile(Profile profile) { + return null; + } + + public PodCommResponse resetPodStatus() { + return null; + } + + public PodCommResponse setBolus(Double parameter) { + return null; + } + + public PodCommResponse cancelBolus() { + return null; + } + + public PodCommResponse setTemporaryBasal(TempBasalPair tbr) { + return null; + } + + public PodCommResponse cancelTemporaryBasal() { + return null; + } + + @Override + public PodCommResponse acknowledgeAlerts() { + return null; + } + +} diff --git a/app/src/main/res/layout/omnipod_fragment.xml b/app/src/main/res/layout/omnipod_fragment.xml index 868f48e276..165c7ed410 100644 --- a/app/src/main/res/layout/omnipod_fragment.xml +++ b/app/src/main/res/layout/omnipod_fragment.xml @@ -99,6 +99,83 @@ android:layout_marginTop="5dp" android:background="@color/listdelimiter" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -466,6 +589,17 @@ android:paddingRight="0dp" android:text="@string/omnipod_pod_mgmt" /> +