diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneral.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneral.java index a2d487d696..b8618470f0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneral.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneral.java @@ -23,7 +23,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.Riley import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil; import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; -import info.nightscout.androidaps.plugins.pump.omnipod.service.OmnipodPumpStatus; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; /** 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 c67217cbe9..3354af21be 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 @@ -10,9 +10,6 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R -import info.nightscout.androidaps.events.EventExtendedBolusChange -import info.nightscout.androidaps.events.EventPumpStatusChanged -import info.nightscout.androidaps.events.EventTempBasalChange import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin @@ -23,15 +20,15 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLin import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodStatusRequest 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.dialogs.PodManagementActivity 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.events.EventOmnipodRefreshButtonState -import info.nightscout.androidaps.plugins.pump.omnipod.service.OmnipodPumpStatus +import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.queue.Callback -import info.nightscout.androidaps.queue.events.EventQueueChanged import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.SetWarnColor @@ -208,8 +205,8 @@ class OmnipodFragment : Fragment() { omnipod_pod_address.text = pumpStatus.podSessionState.address.toString() omnipod_pod_expiry.text = pumpStatus.podSessionState.expiryDateAsString - pumpStatus.podDeviceState = checkStatusSet(pumpStatus.podDeviceState, - OmnipodUtil.getPodDeviceState()) as PodDeviceState? + //pumpStatus.podSessionState = checkStatusSet(pumpStatus.podSessionState, + // OmnipodUtil.getPodSessionState()) as PodSessionState? var podDeviceState = pumpStatus.podDeviceState 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 3e19f45658..19a339260a 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 @@ -56,7 +56,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType; 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; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService; import info.nightscout.androidaps.plugins.pump.omnipod.util.LogReceiver; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/AapsOmnipodManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/AapsOmnipodManager.java index 671e858cee..3510aa2684 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/AapsOmnipodManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/AapsOmnipodManager.java @@ -10,21 +10,22 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; -import info.nightscout.androidaps.plugins.pump.omnipod.service.OmnipodPumpStatus; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.OmnipodManagerAAPS; +import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface { - private final OmnipodManager delegate; + private final OmnipodManagerAAPS delegate; private static AapsOmnipodManager instance; private OmnipodPumpStatus pumpStatus; - // FIXME this is dirty public static AapsOmnipodManager getInstance() { return instance; } public AapsOmnipodManager(OmnipodCommunicationService communicationService, PodSessionState podState) { - delegate = new OmnipodManager(communicationService, podState); + delegate = new OmnipodManagerAAPS(communicationService, podState); instance = this; } @@ -39,6 +40,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface // FIXME we need a basal profile here PumpEnactResult result = delegate.insertCannula(profile); podInitReceiver.returnInitTaskStatus(podInitActionType, result.success, (result.success ? null : result.comment)); + OmnipodUtil.setPodSessionState(delegate.podState); return result; } return new PumpEnactResult().success(false).enacted(false).comment("Illegal PodInitActionType: " + podInitActionType.name()); @@ -50,8 +52,8 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface } @Override - public PumpEnactResult deactivatePod() { - return delegate.deactivatePod(); + public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) { + return delegate.deactivatePod(podInitReceiver); } @Override @@ -61,7 +63,6 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface @Override public PumpEnactResult resetPodStatus() { - pumpStatus.podDeviceState = null; return delegate.resetPodState(); } @@ -100,12 +101,10 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface return delegate.getPodInfo(podInfoType); } - // TODO should we add this to the OmnipodCommunicationManager interface? public PumpEnactResult suspendDelivery() { return delegate.suspendDelivery(); } - // TODO should we add this to the OmnipodCommunicationManager interface? public PumpEnactResult resumeDelivery() { return delegate.resumeDelivery(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java index 8527a104f6..a3ab492ca9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.comm; +import android.os.SystemClock; + import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.Duration; @@ -37,12 +39,15 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress; import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalScheduleMapper; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodDbEntry; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodDbEntryType; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; +import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.utils.SP; public class OmnipodManager { - private final OmnipodCommunicationService communicationService; - private PodSessionState podState; + protected final OmnipodCommunicationService communicationService; + protected PodSessionState podState; public OmnipodManager(OmnipodCommunicationService communicationService, PodSessionState podState) { if (communicationService == null) { @@ -181,6 +186,10 @@ public class OmnipodManager { podState = null; SP.remove(OmnipodConst.Prefs.PodState); + addToHistory(System.currentTimeMillis(), PodDbEntryType.ResetPodState, null, null, null, null); + + OmnipodUtil.setPodSessionState(null); + return new PumpEnactResult().success(true).enacted(true); } @@ -352,8 +361,27 @@ public class OmnipodManager { return new PumpEnactResult().success(false).enacted(false).comment("Pod should be initialized first"); } - private void addToHistory(long requestTime, OmnipodAction omnipodAction, long responseTime) { + private void addToHistory(long requestTime, PodDbEntryType entryType, String shortDescription, OmnipodAction omnipodAction, Long responseTime, Object response) { // TODO andy + + PodDbEntry entry = new PodDbEntry(requestTime, entryType); + + if (shortDescription!=null) { + entry.setShortDescription(shortDescription); + } + + if (omnipodAction!=null) { + + } + + if (responseTime!=null) { + + } + + if (response!=null) { + + } + } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodCommunicationManagerInterface.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodCommunicationManagerInterface.java index 8a89fb2eab..5805fc550e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodCommunicationManagerInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodCommunicationManagerInterface.java @@ -3,7 +3,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.defs; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; -import info.nightscout.androidaps.plugins.pump.omnipod.service.OmnipodPumpStatus; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; public interface OmnipodCommunicationManagerInterface { @@ -23,7 +23,7 @@ public interface OmnipodCommunicationManagerInterface { /** * Deactivate Pod */ - PumpEnactResult deactivatePod(); + PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver); /** * Set Basal Profile diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/PodInitActionType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/PodInitActionType.java index 60e8234529..c0a92ed2d7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/PodInitActionType.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/PodInitActionType.java @@ -12,9 +12,16 @@ public enum PodInitActionType { PairPod(R.string.omnipod_init_pod_pair_pod, PairAndPrimeWizardStep), // PrimePod(R.string.omnipod_init_pod_prime_pod, PairAndPrimeWizardStep), // - FillCannulaSetBasalProfileWizardStep(), - FillCannula(R.string.omnipod_init_pod_fill_cannula, FillCannulaSetBasalProfileWizardStep), - SetBasalProfile(R.string.omnipod_init_pod_set_basal_profile, FillCannulaSetBasalProfileWizardStep); + FillCannulaSetBasalProfileWizardStep(), // + FillCannula(R.string.omnipod_init_pod_fill_cannula, FillCannulaSetBasalProfileWizardStep), // + SetBasalProfile(R.string.omnipod_init_pod_set_basal_profile, FillCannulaSetBasalProfileWizardStep), // + + DeactivatePodWizardStep(), // + CancelDelivery(R.string.omnipod_deactivate_pod_cancel_delivery, DeactivatePodWizardStep), // + DeactivatePod(R.string.omnipod_deactivate_pod_deactivate_pod, DeactivatePodWizardStep) // + ; + + private int resourceId; private PodInitActionType parent; @@ -22,12 +29,6 @@ public enum PodInitActionType { private static Map> stepsForWizardStep; - static { - // TODO - - } - - PodInitActionType(int resourceId, PodInitActionType parent) { this.resourceId = resourceId; this.parent = parent; @@ -38,6 +39,11 @@ public enum PodInitActionType { } + public boolean isParent() { + return this.parent == null; + } + + public List getChildren() { List outList = new ArrayList<>(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/PodManagementActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/PodManagementActivity.kt index 26871e2d31..4e8acdef24 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/PodManagementActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/PodManagementActivity.kt @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dialogs import android.content.Intent import android.os.Bundle +import android.os.SystemClock import com.atech.android.library.wizardpager.WizardPagerActivity import com.atech.android.library.wizardpager.WizardPagerContext import com.atech.android.library.wizardpager.data.WizardPagerSettings @@ -9,8 +10,14 @@ import com.atech.android.library.wizardpager.defs.WizardStepsWayType import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.NoSplashActivity +import info.nightscout.androidaps.plugins.bus.RxBus +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin +import info.nightscout.androidaps.plugins.pump.omnipod.comm.AapsOmnipodManager import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod.InitPodCancelAction import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod.InitPodWizardModel +import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.OmnipodManagerAAPS +import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged +import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefreshButtonState import info.nightscout.androidaps.utils.OKDialog import kotlinx.android.synthetic.main.omnipod_pod_mgmt.* @@ -77,8 +84,9 @@ class PodManagementActivity : NoSplashActivity() { fun resetPodAction() { OKDialog.showConfirmation(this, - MainApp.gs(R.string.omnipod_cmd_reset_pod_na), null) - + MainApp.gs(R.string.omnipod_cmd_reset_pod_desc), Thread { + AapsOmnipodManager.getInstance().resetPodStatus() + }) } fun showPodHistory() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitActionFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitActionFragment.java index 4fd5c3488a..4fda8fff75 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitActionFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitActionFragment.java @@ -25,24 +25,29 @@ import java.util.List; import java.util.Map; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.pump.omnipod.comm.AapsOmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver; /** * Created by TechFreak on 04/09/2014. */ -public class InitActionFragment extends Fragment { +public class InitActionFragment extends Fragment implements PodInitReceiver { private static final String ARG_KEY = "key"; private PageFragmentCallbacks mCallbacks; private String mKey; private InitActionPage mPage; - ProgressBar progressBar; - TextView errorView; + private ProgressBar progressBar; + private TextView errorView; - PodInitActionType podInitActionType; - List children; - Map mapCheckBoxes; + private PodInitActionType podInitActionType; + //private List children; + private Map mapCheckBoxes; + private InitActionFragment instance; public static InitActionFragment create(String key, PodInitActionType podInitActionType) { Bundle args = new Bundle(); @@ -55,7 +60,7 @@ public class InitActionFragment extends Fragment { } public InitActionFragment() { - + this.instance = this; } @Override @@ -80,7 +85,7 @@ public class InitActionFragment extends Fragment { LinearLayout linearLayout = rootView.findViewById(R.id.initAction_ItemsHolder); - children = podInitActionType.getChildren(); + List children = podInitActionType.getChildren(); mapCheckBoxes = new HashMap<>(); for (PodInitActionType child : children) { @@ -118,20 +123,20 @@ public class InitActionFragment extends Fragment { mCallbacks = null; } - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); +// @Override +// public void onViewCreated(View view, Bundle savedInstanceState) { +// super.onViewCreated(view, savedInstanceState); +// +// } - } - - @Override - public void setMenuVisibility(boolean menuVisible) { - super.setMenuVisibility(menuVisible); - - // In a future update to the support library, this should override setUserVisibleHint - // instead of setMenuVisibility. - - } +// @Override +// public void setMenuVisibility(boolean menuVisible) { +// super.setMenuVisibility(menuVisible); +// +// // In a future update to the support library, this should override setUserVisibleHint +// // instead of setMenuVisibility. +// +// } public PodInitActionType getPodInitActionType() { return podInitActionType; @@ -152,22 +157,31 @@ public class InitActionFragment extends Fragment { new AsyncTask() { - protected void onPreExecute() { - //progressBar.setVisibility(View.VISIBLE); - } + PumpEnactResult callResult; - ; + protected void onPreExecute() { + progressBar.setVisibility(View.VISIBLE); + } @Override protected String doInBackground(Void... params) { - System.out.println("ACTION: doInBackground Started: "); - SystemClock.sleep(5000); - mPage.setActionCompleted(true); + if (podInitActionType == PodInitActionType.PairAndPrimeWizardStep) { + this.callResult = AapsOmnipodManager.getInstance().initPod( + podInitActionType, + instance, + null + ); + } else if (podInitActionType == PodInitActionType.FillCannulaSetBasalProfileWizardStep) { + this.callResult = AapsOmnipodManager.getInstance().initPod( + podInitActionType, + instance, + ProfileFunctions.getInstance().getProfile() + ); + } else if (podInitActionType == PodInitActionType.DeactivatePodWizardStep) { + this.callResult = AapsOmnipodManager.getInstance().deactivatePod(instance); + } - System.out.println("ACTION: doInBackground Finished: "); - - - return "Test"; + return "OK"; } @Override @@ -176,20 +190,17 @@ public class InitActionFragment extends Fragment { System.out.println("ACTION: onPostExecute: " + result); - boolean isOk = false; - - for (PodInitActionType actionType : mapCheckBoxes.keySet()) { - mapCheckBoxes.get(actionType).setChecked(true); - mapCheckBoxes.get(actionType).setTextColor(isOk ? Color.rgb(34, 135, 91) : Color.rgb(168, 36, 15)); - } + boolean isOk = callResult.success; progressBar.setVisibility(View.GONE); if (!isOk) { errorView.setVisibility(View.VISIBLE); - errorView.setText("Error containg pod."); + errorView.setText(callResult.comment); } + mPage.setActionCompleted(isOk); + mPage.getData().putString(Page.SIMPLE_DATA_KEY, "ddd"); mPage.notifyDataChanged(); } @@ -199,4 +210,28 @@ public class InitActionFragment extends Fragment { System.out.println("ACTION: Not visible"); } } + + @Override + public void returnInitTaskStatus(PodInitActionType podInitActionType, boolean isSuccess, String errorMessage) { + if (podInitActionType.isParent()) { + for (PodInitActionType actionType : mapCheckBoxes.keySet()) { + setCheckBox(actionType, isSuccess); + } + } else { + setCheckBox(podInitActionType, isSuccess); + } + } + + + public void setCheckBox(PodInitActionType podInitActionType, boolean isSuccess) { + getActivity().runOnUiThread(() -> { + mapCheckBoxes.get(podInitActionType).setChecked(true); + mapCheckBoxes.get(podInitActionType).setTextColor(isSuccess ? Color.rgb(34, 135, 91) : + Color.rgb(168, 36, 15)); + }); + } + + + + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/PodInfoFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/PodInfoFragment.java index e4625df76b..ddcd1cb129 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/PodInfoFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/PodInfoFragment.java @@ -32,6 +32,7 @@ import java.util.List; import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.pump.omnipod.defs.FirmwareVersion; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; +import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; public class PodInfoFragment extends Fragment { @@ -77,31 +78,35 @@ public class PodInfoFragment extends Fragment { if (isInitPod) { - createDataOfPod(); + if (createDataOfPod()) { - ListView listView = (ListView) rootView.findViewById(R.id.podInfoList); - listView.setAdapter(new PodInfoAdapter(mCurrentReviewItems, getContext())); - listView.setChoiceMode(ListView.CHOICE_MODE_NONE); + ListView listView = (ListView) rootView.findViewById(R.id.podInfoList); + listView.setAdapter(new PodInfoAdapter(mCurrentReviewItems, getContext())); + listView.setChoiceMode(ListView.CHOICE_MODE_NONE); + } } return rootView; } - private void createDataOfPod() { + private boolean createDataOfPod() { - // TODO + PodSessionState podSessionState = OmnipodUtil.getPodSessionState(); - PodSessionState podSessionState = new PodSessionState(DateTimeZone.UTC, - 483748738, - new DateTime(), - new FirmwareVersion(1,0,0), - new FirmwareVersion(1,0,0), - 574875, - 5487584, - 1, - 1 - ); +// PodSessionState podSessionState = new PodSessionState(DateTimeZone.UTC, +// 483748738, +// new DateTime(), +// new FirmwareVersion(1,0,0), +// new FirmwareVersion(1,0,0), +// 574875, +// 5487584, +// 1, +// 1 +// ); + + if (podSessionState==null) + return false; mCurrentReviewItems = new ArrayList<>(); mCurrentReviewItems.add(new ReviewItem("Pod Address", "" + podSessionState.getAddress(), "33")); @@ -109,6 +114,7 @@ public class PodInfoFragment extends Fragment { mCurrentReviewItems.add(new ReviewItem("Firmware Version", podSessionState.getPiVersion().toString(), "35")); mCurrentReviewItems.add(new ReviewItem("LOT", "" + podSessionState.getLot(), "36")); + return true; } @Override 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/driver/OmnipodPumpStatus.java similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/OmnipodPumpStatus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodPumpStatus.java index 15e8e99cb8..19831042eb 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/driver/OmnipodPumpStatus.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.service; +package info.nightscout.androidaps.plugins.pump.omnipod.driver; import org.jetbrains.annotations.Nullable; import org.joda.time.LocalDateTime; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/OmnipodManagerAAPS.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/OmnipodManagerAAPS.java new file mode 100644 index 0000000000..84d3f88ab2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/OmnipodManagerAAPS.java @@ -0,0 +1,95 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.driver.comm; + + +import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.plugins.bus.RxBus; +import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService; +import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodManager; +import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.DeactivatePodAction; +import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.OmnipodAction; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodDbEntry; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodDbEntryType; +import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged; +import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; +import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; +import info.nightscout.androidaps.utils.SP; + +/** + * Created by andy on 24.11.2019 + */ + +// TODO this should be used instead of AapsOmnipodManager +public class OmnipodManagerAAPS extends OmnipodManager //implements OmnipodCommunicationManagerInterface +{ + + public OmnipodManagerAAPS(OmnipodCommunicationService communicationService, PodSessionState podState) { + super(communicationService, podState); + } + + + public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) { + + if (podState == null) { + // TODO use string resource + podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, false, "Pod should be paired and primed first"); + + return new PumpEnactResult().success(false).enacted(false).comment("Pod should be paired and primed first"); + } + + try { + communicationService.executeAction(new DeactivatePodAction(podState, true)); + resetPodStateInternal(); + podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, true, null); + + } catch (Exception ex) { + // TODO distinguish between certain and uncertain failures + // TODO user friendly error messages (string resources) + podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, false, "Error communicating with Pod [msg=" + ex.getMessage() + "]"); + + return new PumpEnactResult().success(false).enacted(false).comment(ex.getMessage()); + } + + return new PumpEnactResult().success(true).enacted(true); + } + + + public PumpEnactResult resetPodState() { + resetPodStateInternal(); + + addToHistory(System.currentTimeMillis(), PodDbEntryType.ResetPodState, null, null, null, true); + + return new PumpEnactResult().success(true).enacted(true); + } + + private void resetPodStateInternal() { + podState = null; + SP.remove(OmnipodConst.Prefs.PodState); + + OmnipodUtil.setPodSessionState(null); + RxBus.INSTANCE.send(new EventOmnipodPumpValuesChanged()); + } + + + private void addToHistory(long requestTime, PodDbEntryType entryType, OmnipodAction omnipodAction, Long responseTime, Object response, boolean success) { + // TODO andy + + PodDbEntry entry = new PodDbEntry(requestTime, entryType); + + if (omnipodAction!=null) { + + } + + if (responseTime!=null) { + entry.setDateTimeResponse(responseTime); + } + + if (response!=null) { + + } + + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodDbEntry.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodDbEntry.java new file mode 100644 index 0000000000..215a12eb75 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodDbEntry.java @@ -0,0 +1,104 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.driver.db; + +import info.nightscout.androidaps.db.DbObjectBase; + +/** + * Created by andy on 24.11.2019 + */ +public class PodDbEntry implements DbObjectBase { + + private long dateTime; + private PodDbEntryType podDbEntryType; + private String shortDescription; + private String request; + private long dateTimeResponse; + private String response; + private boolean success; + private long pumpId; + + public PodDbEntry(PodDbEntryType podDbEntryType) { + this.dateTime = System.currentTimeMillis(); + this.podDbEntryType = podDbEntryType; + generatePumpId(); + } + + + public PodDbEntry(long requestTime, PodDbEntryType podDbEntryType) { + this.dateTime = requestTime; + this.podDbEntryType = podDbEntryType; + generatePumpId(); + } + + public PodDbEntry(long requestTime, PodDbEntryType podDbEntryType, String shortDescription, String request, Long dateTimeResponse, String response) { + this.dateTime = requestTime; + this.podDbEntryType = podDbEntryType; + this.shortDescription = shortDescription; + this.request = request; + this.dateTimeResponse = dateTimeResponse; + this.response = response; + generatePumpId(); + } + + + public long getDateTime() { + return dateTime; + } + + public void setDateTime(long dateTime) { + this.dateTime = dateTime; + } + + public PodDbEntryType getPodDbEntryType() { + return podDbEntryType; + } + + public void setPodDbEntryType(PodDbEntryType podDbEntryType) { + this.podDbEntryType = podDbEntryType; + } + + public String getRequest() { + return request; + } + + public void setRequest(String request) { + this.request = request; + } + + public long getDateTimeResponse() { + return dateTimeResponse; + } + + public void setDateTimeResponse(long dateTimeResponse) { + this.dateTimeResponse = dateTimeResponse; + } + + public String getResponse() { + return response; + } + + public void setResponse(String response) { + this.response = response; + } + + @Override + public long getDate() { + return this.dateTime; + } + + @Override + public long getPumpId() { + return pumpId; + } + + private void generatePumpId() { + // TODO + } + + public String getShortDescription() { + return shortDescription; + } + + public void setShortDescription(String shortDescription) { + this.shortDescription = shortDescription; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodDbEntryType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodDbEntryType.java new file mode 100644 index 0000000000..1c9ce1af62 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodDbEntryType.java @@ -0,0 +1,41 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.driver.db; + +/** + * Created by andy on 24.11.2019 + */ +public enum PodDbEntryType { + + PairAndPrime(1), + InsertCannula(2), + DeactivatePod(3), + ResetPodState(4), + + SetTemporaryBasal(10), + CancelTemporaryBasal(11), + + SetBasalSchedule(20), + + GetPodStatus(30), + GetPodInfo(31), + + SetBolus(40), + CancelBolus(41), + + ConfigureAlerts(50), + AcknowledgeAlerts(51), + + SuspendDelivery(60), + ResumeDelivery(61) + ; + + private int code; + + PodDbEntryType(int code) { + + this.code = code; + } + + public int getCode() { + return code; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIComm.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIComm.java index 2e3e764528..f7e6167101 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIComm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIComm.java @@ -7,7 +7,7 @@ import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin; 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.service.OmnipodPumpStatus; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; /** diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java index f6ed9c5244..91da9b1d1c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java @@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCustomActionType; -import info.nightscout.androidaps.plugins.pump.omnipod.service.OmnipodPumpStatus; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; /** * Created by andy on 4.8.2019 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUITask.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUITask.java index c1b3706b3d..b92ffdf2f5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUITask.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUITask.java @@ -66,7 +66,7 @@ public class OmnipodUITask { break; case DeactivatePod: - returnData = communicationManager.deactivatePod(); + returnData = communicationManager.deactivatePod((PodInitReceiver) parameters[0]); break; case ResetPodStatus: diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/RileyLinkOmnipodService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/RileyLinkOmnipodService.java index f6a96cbb63..a5e565d081 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/RileyLinkOmnipodService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/RileyLinkOmnipodService.java @@ -28,6 +28,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService; 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.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.utils.SP; 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 9d32748437..337e7c389c 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 @@ -31,7 +31,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPumpPluginInt 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.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService; import info.nightscout.androidaps.utils.OKDialog; @@ -48,8 +48,8 @@ public class OmnipodUtil extends RileyLinkUtil { private static OmnipodPumpStatus omnipodPumpStatus; private static OmnipodCommandType currentCommand; private static Gson gsonInstance = createGson(); - private static PodSessionState podSessionState; - private static PodDeviceState podDeviceState; + //private static PodSessionState podSessionState; + //private static PodDeviceState podDeviceState; private static OmnipodPumpPluginInterface omnipodPumpPlugin; private static OmnipodPodType omnipodPodType; @@ -170,14 +170,9 @@ public class OmnipodUtil extends RileyLinkUtil { RxBus.INSTANCE.send(new EventOmnipodDeviceStatusChange(podSessionState)); } - @Nullable - public static PodDeviceState getPodDeviceState() { - return null; - } - - public static void setPodDeviceState(PodDeviceState podDeviceState) { - OmnipodUtil.podDeviceState = podDeviceState; + public static void setPodDeviceState(PodDeviceState podSessionState) { + omnipodPumpStatus.podDeviceState = podSessionState; } @@ -200,4 +195,13 @@ public class OmnipodUtil extends RileyLinkUtil { public static OmnipodPodType getOmnipodPodType() { return omnipodPodType; } + + public static PodDeviceState getPodDeviceState() { + return omnipodPumpStatus.podDeviceState; + } + + + public static PodSessionState getPodSessionState() { + return omnipodPumpStatus.podSessionState; + } } 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 index a67bf944d7..f03a3b056b 100644 --- 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 @@ -15,7 +15,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunication import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; -import info.nightscout.androidaps.plugins.pump.omnipod.service.OmnipodPumpStatus; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.utils.SP; @@ -73,7 +73,7 @@ public class OmnipodDashCommunicationManager implements OmnipodCommunicationMana } - public PumpEnactResult deactivatePod() { + public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) { return null; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3c5fde662f..e91968f83b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1654,6 +1654,7 @@ Init Pod not available at the moment. Deactivate Pod not available at the moment. Reset Pod not available at the moment. + If you press "OK" Pod will be forcefully removed. Do this only if Deactivate Pod fails. Pod History not available at the moment. Omnipod @@ -1676,6 +1677,8 @@ Prime Pod Fill Cannula Set Basal Profile + Cancel Delivery + Deactivate Pod