Some Omnipod cleanup after merge

This commit is contained in:
Bart Sopers 2020-08-16 17:05:32 +02:00
parent 5d3426dc70
commit 100f8fe235
11 changed files with 66 additions and 250 deletions

View file

@ -17,16 +17,17 @@ import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState 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.defs.RileyLinkTargetDevice
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodStatusRequest import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodStatusRequest
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodManagementActivity import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodManagementActivity
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodAcknowledgeAlertsChanged import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodAcknowledgeAlertsChanged
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.EventOmnipodPumpValuesChanged
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefreshButtonState import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefreshButtonState
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst
@ -78,7 +79,7 @@ class OmnipodFragment : DaggerFragment() {
init { init {
refreshLoop = Runnable { refreshLoop = Runnable {
activity?.runOnUiThread { updateGUI() } activity?.runOnUiThread { updateUi() }
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs()) loopHandler.postDelayed(refreshLoop, T.mins(1).msecs())
} }
} }
@ -155,27 +156,24 @@ class OmnipodFragment : DaggerFragment() {
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ omnipod_refresh.isEnabled = it.newState }, { fabricPrivacy.logException(it) }) .subscribe({ omnipod_refresh.isEnabled = it.newState }, { fabricPrivacy.logException(it) })
disposable += rxBus disposable += rxBus
.toObservable(EventOmnipodDeviceStatusChange::class.java) .toObservable(EventRileyLinkDeviceStatusChange::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({ updateRileyLinkUiElements() }, { fabricPrivacy.logException(it) })
aapsLogger.info(LTag.PUMP, "onStatusEvent(EventOmnipodDeviceStatusChange): {}", it)
setDeviceStatus()
}, { fabricPrivacy.logException(it) })
disposable += rxBus disposable += rxBus
.toObservable(EventOmnipodPumpValuesChanged::class.java) .toObservable(EventOmnipodPumpValuesChanged::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }, { fabricPrivacy.logException(it) }) .subscribe({ updateOmipodUiElements() }, { fabricPrivacy.logException(it) })
disposable += rxBus disposable += rxBus
.toObservable(EventOmnipodAcknowledgeAlertsChanged::class.java) .toObservable(EventOmnipodAcknowledgeAlertsChanged::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateAcknowledgeAlerts() }, { fabricPrivacy.logException(it) }) .subscribe({ updateAcknowledgeAlertsUiElements() }, { fabricPrivacy.logException(it) })
disposable += rxBus disposable += rxBus
.toObservable(EventPreferenceChange::class.java) .toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io()) .observeOn(Schedulers.io())
.subscribe({ .subscribe({
setVisibilityOfPodDebugButton() setVisibilityOfPodDebugButton()
}, { fabricPrivacy.logException(it) }) }, { fabricPrivacy.logException(it) })
updateGUI() updateUi()
} }
fun setVisibilityOfPodDebugButton() { fun setVisibilityOfPodDebugButton() {
@ -200,11 +198,14 @@ class OmnipodFragment : DaggerFragment() {
loopHandler.removeCallbacks(refreshLoop) loopHandler.removeCallbacks(refreshLoop)
} }
@Synchronized fun updateUi() {
private fun setDeviceStatus() { updateRileyLinkUiElements()
aapsLogger.info(LTag.PUMP, "OmnipodFragment.setDeviceStatus") updateOmipodUiElements()
}
val errors = ArrayList<String>(); @Synchronized
private fun updateRileyLinkUiElements() {
aapsLogger.info(LTag.PUMP, "OmnipodFragment.setDeviceStatus")
val rileyLinkServiceState = rileyLinkServiceData.rileyLinkServiceState val rileyLinkServiceState = rileyLinkServiceData.rileyLinkServiceState
@ -220,7 +221,14 @@ class OmnipodFragment : DaggerFragment() {
else -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId) else -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
} }
omnipod_rl_status.setTextColor(if (rileyLinkServiceState.isError || rileyLinkError != null) Color.RED else Color.WHITE) omnipod_rl_status.setTextColor(if (rileyLinkServiceState.isError || rileyLinkError != null) Color.RED else Color.WHITE)
}
fun updateOmipodUiElements() {
updateLastConnectionUiElements()
updateAcknowledgeAlertsUiElements()
setVisibilityOfPodDebugButton()
val errors = ArrayList<String>();
val rileyLinkErrorInfo = omnipodPumpStatus.errorInfo val rileyLinkErrorInfo = omnipodPumpStatus.errorInfo
if (rileyLinkErrorInfo != null) { if (rileyLinkErrorInfo != null) {
errors.add(rileyLinkErrorInfo) errors.add(rileyLinkErrorInfo)
@ -236,6 +244,11 @@ class OmnipodFragment : DaggerFragment() {
omnipod_pod_tid.text = "-" omnipod_pod_tid.text = "-"
omnipod_pod_fw_version.text = "-" omnipod_pod_fw_version.text = "-"
omnipod_pod_expiry.text = "-" omnipod_pod_expiry.text = "-"
omnipod_basabasalrate.text = "-"
omnipod_reservoir.text = "-"
omnipod_tempbasal.text = "-"
omnipod_lastbolus.text = "-"
omnipod_lastconnection.setTextColor(Color.WHITE)
if (podStateManager.hasPodState()) { if (podStateManager.hasPodState()) {
omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_not_initalized) omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_not_initalized)
} else { } else {
@ -249,7 +262,6 @@ class OmnipodFragment : DaggerFragment() {
omnipod_pod_expiry.text = podStateManager.expiryDateAsString omnipod_pod_expiry.text = podStateManager.expiryDateAsString
val stateText: String val stateText: String
when { when {
podStateManager.hasFaultEvent() -> { podStateManager.hasFaultEvent() -> {
val faultEventCode = podStateManager.faultEvent.faultEventCode val faultEventCode = podStateManager.faultEvent.faultEventCode
@ -265,28 +277,9 @@ class OmnipodFragment : DaggerFragment() {
stateText = resourceHelper.gs(R.string.omnipod_pod_setup_in_progress, podStateManager.podProgressStatus.name) stateText = resourceHelper.gs(R.string.omnipod_pod_setup_in_progress, podStateManager.podProgressStatus.name)
} }
} }
omnipod_pod_status.text = stateText omnipod_pod_status.text = stateText
}
omnipod_pod_status.setTextColor(if (podStateManager.hasFaultEvent()) Color.RED else Color.WHITE) updateLastConnectionUiElements()
omnipod_errors.text = if (errors.size == 0) "-" else StringUtils.join(errors, System.lineSeparator())
val status = commandQueue.spannedStatus()
if (status.toString() == "") {
omnipod_queue.visibility = View.GONE
} else {
omnipod_queue.visibility = View.VISIBLE
omnipod_queue.text = status
}
}
// GUI functions
fun updateGUI() {
setDeviceStatus()
if (podStateManager.isPodRunning) {
updateLastConnection()
// last bolus // last bolus
if (podStateManager.lastBolusStartTime != null && podStateManager.lastBolusAmount != null) { if (podStateManager.lastBolusStartTime != null && podStateManager.lastBolusAmount != null) {
@ -310,24 +303,24 @@ class OmnipodFragment : DaggerFragment() {
omnipod_reservoir.text = resourceHelper.gs(R.string.omnipod_reservoir_left, podStateManager.reservoirLevel) omnipod_reservoir.text = resourceHelper.gs(R.string.omnipod_reservoir_left, podStateManager.reservoirLevel)
warnColors.setColorInverse(omnipod_reservoir, podStateManager.reservoirLevel, 50.0, 20.0) warnColors.setColorInverse(omnipod_reservoir, podStateManager.reservoirLevel, 50.0, 20.0)
} }
}
omnipod_pod_status.setTextColor(if (podStateManager.hasFaultEvent()) Color.RED else Color.WHITE)
omnipod_errors.text = if (errors.size == 0) "-" else StringUtils.join(errors, System.lineSeparator())
val status = commandQueue.spannedStatus()
if (status.toString() == "") {
omnipod_queue.visibility = View.GONE
} else { } else {
updateLastConnection() omnipod_queue.visibility = View.VISIBLE
omnipod_basabasalrate.text = "-" omnipod_queue.text = status
omnipod_reservoir.text = "-"
omnipod_tempbasal.text = "-"
omnipod_lastbolus.text = "-"
omnipod_lastconnection.setTextColor(Color.WHITE)
} }
updateAcknowledgeAlerts() omnipod_refresh.isEnabled = podStateManager.isPodInitialized && podStateManager.podProgressStatus.isAtLeast(PodProgressStatus.PAIRING_COMPLETED)
setVisibilityOfPodDebugButton()
omnipod_refresh.isEnabled = podStateManager.isPodInitialized
} }
private fun updateLastConnection() { private fun updateLastConnectionUiElements() {
if (podStateManager.isPodRunning && podStateManager.lastSuccessfulCommunication != null) { // Null check for backwards compatibility if (podStateManager.isPodInitialized && podStateManager.lastSuccessfulCommunication != null) { // Null check for backwards compatibility
omnipod_lastconnection.text = readableDuration(podStateManager.lastSuccessfulCommunication) omnipod_lastconnection.text = readableDuration(podStateManager.lastSuccessfulCommunication)
if (omnipodPumpPlugin.isUnreachableAlertTimeoutExceeded(localAlertUtils.pumpUnreachableThreshold())) { if (omnipodPumpPlugin.isUnreachableAlertTimeoutExceeded(localAlertUtils.pumpUnreachableThreshold())) {
omnipod_lastconnection.setTextColor(Color.RED) omnipod_lastconnection.setTextColor(Color.RED)
@ -344,6 +337,16 @@ class OmnipodFragment : DaggerFragment() {
} }
} }
private fun updateAcknowledgeAlertsUiElements() {
if (podStateManager.isPodInitialized && podStateManager.hasActiveAlerts()) {
omnipod_pod_active_alerts_ack.isEnabled = true
omnipod_pod_active_alerts.text = TextUtils.join(System.lineSeparator(), omnipodUtil.getTranslatedActiveAlerts(podStateManager))
} else {
omnipod_pod_active_alerts_ack.isEnabled = false
omnipod_pod_active_alerts.text = "-"
}
}
private fun readableDuration(dateTime: DateTime): String { private fun readableDuration(dateTime: DateTime): String {
val min = Duration(dateTime, DateTime.now()).standardMinutes val min = Duration(dateTime, DateTime.now()).standardMinutes
when { when {
@ -368,14 +371,4 @@ class OmnipodFragment : DaggerFragment() {
} }
} }
private fun updateAcknowledgeAlerts() {
if (podStateManager.hasPodState() && podStateManager.hasActiveAlerts()) {
omnipod_pod_active_alerts_ack.isEnabled = true
omnipod_pod_active_alerts.text = TextUtils.join(System.lineSeparator(), omnipodUtil.getTranslatedActiveAlerts(podStateManager))
} else {
omnipod_pod_active_alerts_ack.isEnabled = false
omnipod_pod_active_alerts.text = "-"
}
}
} }

View file

@ -354,7 +354,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
private void doPodCheck() { private void doPodCheck() {
if (System.currentTimeMillis() > this.nextPodCheck) { if (System.currentTimeMillis() > this.nextPodCheck) {
if (omnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod) { if (!podStateManager.isPodRunning()) {
Notification notification = new Notification(Notification.OMNIPOD_POD_NOT_ATTACHED, resourceHelper.gs(R.string.omnipod_error_pod_not_attached), Notification.NORMAL); Notification notification = new Notification(Notification.OMNIPOD_POD_NOT_ATTACHED, resourceHelper.gs(R.string.omnipod_error_pod_not_attached), Notification.NORMAL);
rxBus.send(new EventNewNotification(notification)); rxBus.send(new EventNewNotification(notification));
} else { } else {
@ -498,8 +498,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override @Override
public boolean isSuspended() { public boolean isSuspended() {
return omnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod || return !podStateManager.isPodRunning() || podStateManager.isSuspended();
!podStateManager.isPodRunning() || podStateManager.isSuspended();
} }
@Override @Override

View file

@ -1,40 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.defs;
import info.nightscout.androidaps.R;
/**
* Created by andy on 4.8.2019
*/
// TODO remove this class and use PumpDeviceState instead
// BS: Actually, don't use PumpDeviceState in Omnipod driver at all; use PodStateManager
// If PumpDeviceState is Omnipod specific; also remove that
public enum PodDeviceState {
// FIXME
NeverContacted(R.string.medtronic_pump_status_never_contacted), //
Sleeping(R.string.medtronic_pump_status_sleeping), //
WakingUp(R.string.medtronic_pump_status_waking_up), //
Active(R.string.medtronic_pump_status_active), //
ErrorWhenCommunicating(R.string.medtronic_pump_status_error_comm), //
TimeoutWhenCommunicating(R.string.medtronic_pump_status_timeout_comm), //
// ProblemContacting(R.string.medtronic_pump_status_problem_contacting), //
PumpUnreachable(R.string.medtronic_pump_status_pump_unreachable), //
InvalidConfiguration(R.string.medtronic_pump_status_invalid_config);
Integer resourceId = null;
PodDeviceState() {
}
PodDeviceState(int resourceId) {
this.resourceId = resourceId;
}
public Integer getResourceId() {
return resourceId;
}
}

View file

@ -14,7 +14,6 @@ import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDevic
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; 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.common.hw.rileylink.data.RLHistoryItem;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -23,6 +22,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
* Created by andy on 4.8.2019 * Created by andy on 4.8.2019
*/ */
@Singleton @Singleton
@Deprecated
public class OmnipodPumpStatus extends PumpStatus { public class OmnipodPumpStatus extends PumpStatus {
// TODO remove all fields that can also be obtained via PodStateManager // TODO remove all fields that can also be obtained via PodStateManager
// We can probably get rid of this class altogether // We can probably get rid of this class altogether
@ -47,7 +47,6 @@ public class OmnipodPumpStatus extends PumpStatus {
public String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}"; public String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}";
public PodDeviceState podDeviceState = PodDeviceState.NeverContacted;
public boolean ackAlertsAvailable = false; public boolean ackAlertsAvailable = false;
public String ackAlertsText = null; public String ackAlertsText = null;
@ -146,7 +145,6 @@ public class OmnipodPumpStatus extends PumpStatus {
", tempBasalAmount=" + tempBasalAmount + ", tempBasalAmount=" + tempBasalAmount +
", tempBasalLength=" + tempBasalLength + ", tempBasalLength=" + tempBasalLength +
", regexMac='" + regexMac + '\'' + ", regexMac='" + regexMac + '\'' +
", podDeviceState=" + podDeviceState +
", lastDataTime=" + lastDataTime + ", lastDataTime=" + lastDataTime +
", lastConnection=" + lastConnection + ", lastConnection=" + lastConnection +
", previousConnection=" + previousConnection + ", previousConnection=" + previousConnection +

View file

@ -25,6 +25,7 @@ import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
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.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
@ -151,6 +152,9 @@ public class AapsOmnipodManager implements IOmnipodManager {
} }
Disposable disposable = delegate.insertCannula(basalSchedule).subscribe(res -> // Disposable disposable = delegate.insertCannula(basalSchedule).subscribe(res -> //
handleSetupActionResult(podInitActionType, podInitReceiver, res, time, profile)); handleSetupActionResult(podInitActionType, podInitReceiver, res, time, profile));
rxBus.send(new EventDismissNotification(Notification.OMNIPOD_POD_NOT_ATTACHED));
return new PumpEnactResult(injector).success(true).enacted(true); return new PumpEnactResult(injector).success(true).enacted(true);
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);

View file

@ -4,9 +4,8 @@ import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.defs.DeviceCommandExecutor; import info.nightscout.androidaps.plugins.pump.common.defs.DeviceCommandExecutor;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.IOmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.defs.IOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
/** /**
* Created by andy on 4.8.2019 * Created by andy on 4.8.2019
@ -15,20 +14,17 @@ public class OmnipodUIComm implements DeviceCommandExecutor {
private final HasAndroidInjector injector; private final HasAndroidInjector injector;
private final AAPSLogger aapsLogger; private final AAPSLogger aapsLogger;
private final OmnipodUtil omnipodUtil;
private final IOmnipodManager omnipodCommunicationManager; private final IOmnipodManager omnipodCommunicationManager;
private final OmnipodUIPostprocessor omnipodUIPostprocessor; private final OmnipodUIPostprocessor omnipodUIPostprocessor;
public OmnipodUIComm( public OmnipodUIComm(
HasAndroidInjector injector, HasAndroidInjector injector,
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
OmnipodUtil omnipodUtil,
OmnipodUIPostprocessor omnipodUIPostprocessor, OmnipodUIPostprocessor omnipodUIPostprocessor,
IOmnipodManager omnipodCommunicationManager IOmnipodManager omnipodCommunicationManager
) { ) {
this.injector = injector; this.injector = injector;
this.aapsLogger = aapsLogger; this.aapsLogger = aapsLogger;
this.omnipodUtil = omnipodUtil;
this.omnipodUIPostprocessor = omnipodUIPostprocessor; this.omnipodUIPostprocessor = omnipodUIPostprocessor;
this.omnipodCommunicationManager = omnipodCommunicationManager; this.omnipodCommunicationManager = omnipodCommunicationManager;
} }
@ -40,8 +36,6 @@ public class OmnipodUIComm implements DeviceCommandExecutor {
OmnipodUITask task = new OmnipodUITask(injector, commandType, parameters); OmnipodUITask task = new OmnipodUITask(injector, commandType, parameters);
omnipodUtil.setCurrentCommand(commandType);
// new Thread(() -> { // new Thread(() -> {
// LOG.warn("@@@ Start Thread"); // LOG.warn("@@@ Start Thread");
// //

View file

@ -19,6 +19,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
/** /**
* Created by andy on 4.8.2019 * Created by andy on 4.8.2019
*/ */
// TODO remove once OmnipodPumpStatus has been removed
@Singleton @Singleton
public class OmnipodUIPostprocessor { public class OmnipodUIPostprocessor {
@ -36,7 +37,6 @@ public class OmnipodUIPostprocessor {
this.rxBus = plugin.getRxBus(); this.rxBus = plugin.getRxBus();
} }
// this is mostly intended for command that return certain statuses (Remaining Insulin, ...), and // this is mostly intended for command that return certain statuses (Remaining Insulin, ...), and
// where responses won't be directly used // where responses won't be directly used
public void postProcessData(OmnipodUITask uiTask) { public void postProcessData(OmnipodUITask uiTask) {

View file

@ -10,15 +10,12 @@ import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.IOmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.defs.IOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType; 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.PodInitReceiver;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodResponseType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodResponseType;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
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; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
/** /**
@ -191,11 +188,9 @@ public class OmnipodUITask {
} }
// FIXME a lot of this is not needed anymore since introducing PodStateManager // FIXME remove once OmnipodPumpStatus has been removed
public void postProcess(OmnipodUIPostprocessor postprocessor) { public void postProcess(OmnipodUIPostprocessor postprocessor) {
EventOmnipodDeviceStatusChange statusChange;
aapsLogger.debug(LTag.PUMP, "OmnipodUITask: @@@ postProcess. {}", commandType); aapsLogger.debug(LTag.PUMP, "OmnipodUITask: @@@ postProcess. {}", commandType);
aapsLogger.debug(LTag.PUMP, "OmnipodUITask: @@@ postProcess. responseType={}", responseType); aapsLogger.debug(LTag.PUMP, "OmnipodUITask: @@@ postProcess. responseType={}", responseType);
@ -206,22 +201,12 @@ public class OmnipodUITask {
aapsLogger.debug(LTag.PUMP, "OmnipodUITask: @@@ postProcess. responseType={}", responseType); aapsLogger.debug(LTag.PUMP, "OmnipodUITask: @@@ postProcess. responseType={}", responseType);
if (responseType == PodResponseType.Invalid) { if (responseType == PodResponseType.Invalid) {
statusChange = new EventOmnipodDeviceStatusChange(PodDeviceState.ErrorWhenCommunicating,
"Unsupported command in OmnipodUITask");
omnipodPumpStatus.setLastFailedCommunicationToNow(); omnipodPumpStatus.setLastFailedCommunicationToNow();
rxBus.send(statusChange);
} else if (responseType == PodResponseType.Error) { } else if (responseType == PodResponseType.Error) {
statusChange = new EventOmnipodDeviceStatusChange(PodDeviceState.ErrorWhenCommunicating,
errorDescription);
omnipodPumpStatus.setLastFailedCommunicationToNow(); omnipodPumpStatus.setLastFailedCommunicationToNow();
rxBus.send(statusChange);
} else { } else {
omnipodPumpStatus.setLastCommunicationToNow(); omnipodPumpStatus.setLastCommunicationToNow();
rxBus.send(new EventOmnipodPumpValuesChanged());
} }
omnipodUtil.setPodDeviceState(PodDeviceState.Sleeping);
omnipodUtil.setCurrentCommand(null);
} }

View file

@ -1,56 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.events
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState
import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange
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.OmnipodCommandType
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager
/**
* Created by andy on 4.8.2019
*/
// FIXME Remove in favor of EventRileyLinkDeviceStatusChange and EventOmnipodPumpValuesChanged
class EventOmnipodDeviceStatusChange : EventRileyLinkDeviceStatusChange {
var podStateManager: PodStateManager? = null
var podDeviceState: PodDeviceState? = null
@JvmOverloads
constructor(rileyLinkServiceState: RileyLinkServiceState?, rileyLinkError: RileyLinkError? = null) : super(rileyLinkServiceState, rileyLinkError) {
}
constructor(commandType: OmnipodCommandType?) {
}
constructor(podStateManager: PodStateManager?) {
this.podStateManager = podStateManager
}
constructor(errorDescription: String?) {
this.errorDescription = errorDescription
}
constructor(podDeviceState: PodDeviceState?, errorDescription: String?) {
this.podDeviceState = podDeviceState
this.errorDescription = errorDescription
}
constructor(pumpDeviceState: PumpDeviceState?) {
this.pumpDeviceState = pumpDeviceState
}
constructor(pumpDeviceState: PumpDeviceState?, errorDescription: String?) {
this.pumpDeviceState = pumpDeviceState
this.errorDescription = errorDescription
}
override fun toString(): String {
return ("EventOmnipodDeviceStatusChange [" //
+ "rileyLinkServiceState=" + rileyLinkServiceState
+ ", rileyLinkError=" + rileyLinkError //
+ ", podStateManager=" + podStateManager //
+ ", podDeviceState=" + podDeviceState + "]")
}
}

View file

@ -27,7 +27,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIComm; import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIComm;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIPostprocessor; import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIPostprocessor;
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.OmnipodConst; 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.util.OmnipodUtil;
@ -113,12 +113,12 @@ public class RileyLinkOmnipodService extends RileyLinkService {
aapsOmnipodManager = new AapsOmnipodManager(omnipodCommunicationService, podStateManager, omnipodPumpStatus, aapsOmnipodManager = new AapsOmnipodManager(omnipodCommunicationService, podStateManager, omnipodPumpStatus,
omnipodUtil, aapsLogger, rxBus, sp, resourceHelper, injector, activePlugin, this); omnipodUtil, aapsLogger, rxBus, sp, resourceHelper, injector, activePlugin, this);
omnipodUIComm = new OmnipodUIComm(injector, aapsLogger, omnipodUtil, omnipodUIPostprocessor, aapsOmnipodManager); omnipodUIComm = new OmnipodUIComm(injector, aapsLogger, omnipodUIPostprocessor, aapsOmnipodManager);
} else { } else {
aapsOmnipodManager = instance; aapsOmnipodManager = instance;
} }
rxBus.send(new EventOmnipodDeviceStatusChange(podStateManager)); rxBus.send(new EventOmnipodPumpValuesChanged());
} }

View file

@ -17,17 +17,10 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.data.RLHistoryItemOmnipod;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSet; import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSet;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSlot; import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSlot;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertType;
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.PodStateManager; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
@ -41,53 +34,24 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
public class OmnipodUtil { public class OmnipodUtil {
private final AAPSLogger aapsLogger; private final AAPSLogger aapsLogger;
private final RxBusWrapper rxBus;
private final RileyLinkUtil rileyLinkUtil;
private final OmnipodPumpStatus omnipodPumpStatus; private final OmnipodPumpStatus omnipodPumpStatus;
private final ResourceHelper resourceHelper; private final ResourceHelper resourceHelper;
private final ActivePluginProvider activePlugins;
private final SP sp; private final SP sp;
private boolean lowLevelDebug = true;
private OmnipodCommandType currentCommand;
private Gson gsonInstance = createGson(); private Gson gsonInstance = createGson();
private OmnipodDriverState driverState = OmnipodDriverState.NotInitalized; private OmnipodDriverState driverState = OmnipodDriverState.NotInitalized;
@Inject @Inject
public OmnipodUtil( public OmnipodUtil(
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
RxBusWrapper rxBus,
RileyLinkUtil rileyLinkUtil,
OmnipodPumpStatus omnipodPumpStatus, OmnipodPumpStatus omnipodPumpStatus,
SP sp, SP sp,
ResourceHelper resourceHelper, ResourceHelper resourceHelper
ActivePluginProvider activePlugins
) { ) {
this.aapsLogger = aapsLogger; this.aapsLogger = aapsLogger;
this.rxBus = rxBus;
this.rileyLinkUtil = rileyLinkUtil;
this.omnipodPumpStatus = omnipodPumpStatus; this.omnipodPumpStatus = omnipodPumpStatus;
this.sp = sp; this.sp = sp;
this.resourceHelper = resourceHelper; this.resourceHelper = resourceHelper;
this.activePlugins = activePlugins;
}
public boolean isLowLevelDebug() {
return lowLevelDebug;
}
public void setLowLevelDebug(boolean lowLevelDebug) {
this.lowLevelDebug = lowLevelDebug;
}
public OmnipodCommandType getCurrentCommand() {
return currentCommand;
}
public void setCurrentCommand(OmnipodCommandType currentCommand) {
this.currentCommand = currentCommand;
if (currentCommand != null)
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItemOmnipod(currentCommand));
} }
public OmnipodDriverState getDriverState() { public OmnipodDriverState getDriverState() {
@ -100,15 +64,6 @@ public class OmnipodUtil {
driverState = state; driverState = state;
omnipodPumpStatus.driverState = state; omnipodPumpStatus.driverState = state;
// TODO maybe remove
// if (OmnipodUtil.omnipodPumpStatus != null) {
// OmnipodUtil.omnipodPumpStatus.driverState = state;
// }
//
// if (OmnipodUtil.omnipodPumpPlugin != null) {
// OmnipodUtil.omnipodPumpPlugin.setDriverState(state);
// }
} }
private Gson createGson() { private Gson createGson() {
@ -125,22 +80,6 @@ public class OmnipodUtil {
return gsonBuilder.create(); return gsonBuilder.create();
} }
public void setPodDeviceState(PodDeviceState podDeviceState) {
omnipodPumpStatus.podDeviceState = podDeviceState;
}
public PodDeviceState getPodDeviceState() {
return omnipodPumpStatus.podDeviceState;
}
public void setPumpType(PumpType pumpType_) {
omnipodPumpStatus.pumpType = pumpType_;
}
public PumpType getPumpType() {
return omnipodPumpStatus.pumpType;
}
public Gson getGsonInstance() { public Gson getGsonInstance() {
return this.gsonInstance; return this.gsonInstance;
} }