MDT refactor pass 3
This commit is contained in:
parent
0d063ca73f
commit
331c1c3ab5
15 changed files with 173 additions and 165 deletions
|
@ -29,7 +29,10 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData
|
|||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOref1Thread
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobThread
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.*
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUITask
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment
|
||||
import info.nightscout.androidaps.queue.CommandQueue
|
||||
import info.nightscout.androidaps.queue.commands.*
|
||||
|
@ -187,6 +190,9 @@ interface AppComponent : AndroidInjector<MainApp> {
|
|||
fun injectGraphData(graphData: GraphData)
|
||||
|
||||
//Medtronic
|
||||
fun injectRileyLinkCommunicationManager(rileyLinkCommunicationManager: RileyLinkCommunicationManager)
|
||||
fun injectMedtronicCommunicationManager(medtronicCommunicationManager: MedtronicCommunicationManager)
|
||||
fun injectMedtronicUITask(medtronicUITask: MedtronicUITask)
|
||||
fun injectServiceTask(serviceTask: ServiceTask)
|
||||
fun injectPumpTask(pumpTask: PumpTask)
|
||||
fun injectDiscoverGattServicesTask(discoverGattServicesTask: DiscoverGattServicesTask)
|
||||
|
|
|
@ -46,7 +46,10 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData
|
|||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOref1Thread
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobThread
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.*
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUITask
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment
|
||||
import info.nightscout.androidaps.queue.CommandQueue
|
||||
import info.nightscout.androidaps.queue.commands.*
|
||||
|
@ -280,6 +283,9 @@ open class AppModule {
|
|||
@Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector
|
||||
|
||||
// Medtronic
|
||||
@ContributesAndroidInjector fun rileyLinkCommunicationManagerProvider(): RileyLinkCommunicationManager
|
||||
@ContributesAndroidInjector fun medtronicCommunicationManagerProvider(): MedtronicCommunicationManager
|
||||
@ContributesAndroidInjector fun medtronicUITaskProvider(): MedtronicUITask
|
||||
@ContributesAndroidInjector fun serviceTaskProvider(): ServiceTask
|
||||
@ContributesAndroidInjector fun pumpTaskProvider(): PumpTask
|
||||
@ContributesAndroidInjector fun discoverGattServicesTaskProvider(): DiscoverGattServicesTask
|
||||
|
|
|
@ -62,6 +62,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
|
|||
@Inject ResourceHelper resourceHelper;
|
||||
@Inject RileyLinkUtil rileyLinkUtil;
|
||||
@Inject MedtronicUtil medtronicUtil;
|
||||
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||
|
||||
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 30241; // arbitrary.
|
||||
private static final int REQUEST_ENABLE_BT = 30242; // arbitrary
|
||||
|
@ -112,8 +113,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
|
|||
|
||||
rileyLinkUtil.getRileyLinkSelectPreference().setSummary(bleAddress);
|
||||
|
||||
MedtronicPumpStatus pumpStatus = medtronicUtil.getPumpStatus();
|
||||
pumpStatus.verifyConfiguration(); // force reloading of address
|
||||
medtronicPumpStatus.verifyConfiguration(); // force reloading of address
|
||||
|
||||
rxBus.send(new EventMedtronicPumpConfigurationChanged());
|
||||
|
||||
|
|
|
@ -24,8 +24,9 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks
|
|||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask;
|
||||
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||
|
||||
/**
|
||||
* This is abstract class for RileyLink Communication, this one needs to be extended by specific "Pump" class.
|
||||
|
@ -34,6 +35,9 @@ import info.nightscout.androidaps.utils.SP;
|
|||
*/
|
||||
public abstract class RileyLinkCommunicationManager {
|
||||
|
||||
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||
@Inject protected SP sp;
|
||||
|
||||
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
|
||||
|
||||
private static final int SCAN_TIMEOUT = 1500;
|
||||
|
@ -44,7 +48,7 @@ public abstract class RileyLinkCommunicationManager {
|
|||
protected int receiverDeviceAwakeForMinutes = 1; // override this in constructor of specific implementation
|
||||
protected String receiverDeviceID; // String representation of receiver device (ex. Pump (xxxxxx) or Pod (yyyyyy))
|
||||
protected long lastGoodReceiverCommunicationTime = 0;
|
||||
protected PumpStatus pumpStatus;
|
||||
// protected PumpStatus pumpStatus;
|
||||
protected RileyLinkServiceData rileyLinkServiceData;
|
||||
private long nextWakeUpRequired = 0L;
|
||||
|
||||
|
@ -55,17 +59,13 @@ public abstract class RileyLinkCommunicationManager {
|
|||
|
||||
public RileyLinkCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) {
|
||||
this.injector = injector;
|
||||
injector.androidInjector().inject(this);
|
||||
this.rfspy = rfspy;
|
||||
this.rileyLinkServiceData = RileyLinkUtil.getInstance().getRileyLinkServiceData();
|
||||
RileyLinkUtil.getInstance().setRileyLinkCommunicationManager(this);
|
||||
|
||||
configurePumpSpecificSettings();
|
||||
}
|
||||
|
||||
|
||||
protected abstract void configurePumpSpecificSettings();
|
||||
|
||||
|
||||
// All pump communications go through this function.
|
||||
public <E extends RLMessage> E sendAndListen(RLMessage msg, int timeout_ms, Class<E> clazz)
|
||||
throws RileyLinkCommunicationException {
|
||||
|
@ -92,7 +92,7 @@ public abstract class RileyLinkCommunicationManager {
|
|||
}
|
||||
|
||||
RFSpyResponse rfSpyResponse = rfspy.transmitThenReceive(new RadioPacket(msg.getTxData()),
|
||||
(byte)0, (byte)repeatCount, (byte)0, (byte)0, timeout_ms, (byte)retryCount, extendPreamble_ms);
|
||||
(byte) 0, (byte) repeatCount, (byte) 0, (byte) 0, timeout_ms, (byte) retryCount, extendPreamble_ms);
|
||||
|
||||
RadioResponse radioResponse = rfSpyResponse.getRadioResponse();
|
||||
E response = createResponseMessage(radioResponse.getPayload(), clazz);
|
||||
|
@ -108,7 +108,7 @@ public abstract class RileyLinkCommunicationManager {
|
|||
if (hasTunning()) {
|
||||
timeoutCount++;
|
||||
|
||||
long diff = System.currentTimeMillis() - pumpStatus.lastConnection;
|
||||
long diff = System.currentTimeMillis() - getPumpStatus().lastConnection;
|
||||
|
||||
if (diff > ALLOWED_PUMP_UNREACHABLE) {
|
||||
LOG.warn("We reached max time that Pump can be unreachable. Starting Tuning.");
|
||||
|
@ -166,8 +166,8 @@ public abstract class RileyLinkCommunicationManager {
|
|||
LOG.info("Waking pump...");
|
||||
|
||||
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData); // simple
|
||||
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte)0, (byte)200,
|
||||
(byte)0, (byte)0, 25000, (byte)0);
|
||||
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 200,
|
||||
(byte) 0, (byte) 0, 25000, (byte) 0);
|
||||
if (isLogEnabled())
|
||||
LOG.info("wakeup: raw response is " + ByteUtil.shortHexString(resp.getRaw()));
|
||||
|
||||
|
@ -248,8 +248,8 @@ public abstract class RileyLinkCommunicationManager {
|
|||
for (int j = 0; j < tries; j++) {
|
||||
|
||||
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData);
|
||||
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte)0, (byte)0,
|
||||
(byte)0, (byte)0, 1250, (byte)0);
|
||||
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 0,
|
||||
(byte) 0, (byte) 0, 1250, (byte) 0);
|
||||
if (resp.wasTimeout()) {
|
||||
LOG.error("scanForPump: Failed to find pump at frequency {}", frequencies[i]);
|
||||
} else if (resp.looksLikeRadioPacket()) {
|
||||
|
@ -281,7 +281,7 @@ public abstract class RileyLinkCommunicationManager {
|
|||
trial.tries++;
|
||||
}
|
||||
sumRSSI += -99.0 * (trial.tries - trial.successes);
|
||||
trial.averageRSSI2 = (double)(sumRSSI) / (double)(trial.tries);
|
||||
trial.averageRSSI2 = (double) (sumRSSI) / (double) (trial.tries);
|
||||
|
||||
trial.calculateAverage();
|
||||
|
||||
|
@ -296,7 +296,7 @@ public abstract class RileyLinkCommunicationManager {
|
|||
FrequencyTrial one = results.trials.get(k);
|
||||
|
||||
stringBuilder.append(String.format("Scan Result[%s]: Freq=%s, avg RSSI = %s\n", "" + k, ""
|
||||
+ one.frequencyMHz, "" + one.averageRSSI + ", RSSIs =" + one.rssiList));
|
||||
+ one.frequencyMHz, "" + one.averageRSSI + ", RSSIs =" + one.rssiList));
|
||||
}
|
||||
|
||||
LOG.info(stringBuilder.toString());
|
||||
|
@ -338,7 +338,7 @@ public abstract class RileyLinkCommunicationManager {
|
|||
// RLMessage msg = makeRLMessage(RLMessageType.ReadSimpleData);
|
||||
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData);
|
||||
RadioPacket pkt = new RadioPacket(pumpMsgContent);
|
||||
RFSpyResponse resp = rfspy.transmitThenReceive(pkt, (byte)0, (byte)0, (byte)0, (byte)0, SCAN_TIMEOUT, (byte)0);
|
||||
RFSpyResponse resp = rfspy.transmitThenReceive(pkt, (byte) 0, (byte) 0, (byte) 0, (byte) 0, SCAN_TIMEOUT, (byte) 0);
|
||||
if (resp.wasTimeout()) {
|
||||
LOG.warn("tune_tryFrequency: no pump response at frequency {}", freqMHz);
|
||||
} else if (resp.looksLikeRadioPacket()) {
|
||||
|
@ -350,8 +350,8 @@ public abstract class RileyLinkCommunicationManager {
|
|||
LOG.warn("tune_tryFrequency: saw response level {} at frequency {}", radioResponse.rssi, freqMHz);
|
||||
return calculateRssi(radioResponse.rssi);
|
||||
} else {
|
||||
LOG.warn("tune_tryFrequency: invalid radio response:"
|
||||
+ ByteUtil.shortHexString(radioResponse.getPayload()));
|
||||
LOG.warn("tune_tryFrequency: invalid radio response:"
|
||||
+ ByteUtil.shortHexString(radioResponse.getPayload()));
|
||||
}
|
||||
|
||||
} catch (RileyLinkCommunicationException e) {
|
||||
|
@ -373,7 +373,7 @@ public abstract class RileyLinkCommunicationManager {
|
|||
// Try again at larger step size
|
||||
stepsize += 0.05;
|
||||
} else {
|
||||
if ((int)(evenBetterFrequency * 100) == (int)(betterFrequency * 100)) {
|
||||
if ((int) (evenBetterFrequency * 100) == (int) (betterFrequency * 100)) {
|
||||
// value did not change, so we're done.
|
||||
break;
|
||||
}
|
||||
|
@ -426,17 +426,15 @@ public abstract class RileyLinkCommunicationManager {
|
|||
protected void rememberLastGoodDeviceCommunicationTime() {
|
||||
lastGoodReceiverCommunicationTime = System.currentTimeMillis();
|
||||
|
||||
SP.putLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, lastGoodReceiverCommunicationTime);
|
||||
if(pumpStatus != null) {
|
||||
pumpStatus.setLastCommunicationToNow();
|
||||
}
|
||||
sp.putLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, lastGoodReceiverCommunicationTime);
|
||||
getPumpStatus().setLastCommunicationToNow();
|
||||
}
|
||||
|
||||
|
||||
private long getLastGoodReceiverCommunicationTime() {
|
||||
// If we have a value of zero, we need to load from prefs.
|
||||
if (lastGoodReceiverCommunicationTime == 0L) {
|
||||
lastGoodReceiverCommunicationTime = SP.getLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
|
||||
lastGoodReceiverCommunicationTime = sp.getLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
|
||||
// Might still be zero, but that's fine.
|
||||
}
|
||||
double minutesAgo = (System.currentTimeMillis() - lastGoodReceiverCommunicationTime) / (1000.0 * 60.0);
|
||||
|
@ -445,12 +443,6 @@ public abstract class RileyLinkCommunicationManager {
|
|||
return lastGoodReceiverCommunicationTime;
|
||||
}
|
||||
|
||||
|
||||
public PumpStatus getPumpStatus() {
|
||||
return pumpStatus;
|
||||
}
|
||||
|
||||
|
||||
public void clearNotConnectedCount() {
|
||||
if (rfspy != null) {
|
||||
rfspy.notConnectedCount = 0;
|
||||
|
@ -461,7 +453,5 @@ public abstract class RileyLinkCommunicationManager {
|
|||
return L.isEnabled(L.PUMPCOMM);
|
||||
}
|
||||
|
||||
public void setPumpStatus(PumpStatus pumpStatus) {
|
||||
this.pumpStatus = pumpStatus;
|
||||
}
|
||||
public abstract PumpStatus getPumpStatus();
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.util.Locale;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.support.DaggerFragment;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||
|
@ -24,6 +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.utils.resources.ResourceHelper;
|
||||
|
||||
/**
|
||||
* Created by andy on 5/19/18.
|
||||
|
@ -33,6 +33,8 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
|
|||
|
||||
@Inject RileyLinkUtil rileyLinkUtil;
|
||||
@Inject MedtronicUtil medtronicUtil;
|
||||
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||
@Inject ResourceHelper resourceHelper;
|
||||
|
||||
TextView connectionStatus;
|
||||
TextView configuredAddress;
|
||||
|
@ -100,15 +102,15 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
|
|||
RileyLinkTargetDevice targetDevice = rileyLinkUtil.getTargetDevice();
|
||||
|
||||
if (rileyLinkUtil.getServiceState() == null)
|
||||
this.connectionStatus.setText(MainApp.gs(RileyLinkServiceState.NotStarted.getResourceId(targetDevice)));
|
||||
this.connectionStatus.setText(resourceHelper.gs(RileyLinkServiceState.NotStarted.getResourceId(targetDevice)));
|
||||
else
|
||||
this.connectionStatus.setText(MainApp.gs(rileyLinkUtil.getServiceState().getResourceId(targetDevice)));
|
||||
this.connectionStatus.setText(resourceHelper.gs(rileyLinkUtil.getServiceState().getResourceId(targetDevice)));
|
||||
|
||||
if (rileyLinkServiceData != null) {
|
||||
this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress);
|
||||
this.connectionError.setText(rileyLinkServiceData.errorCode == null ? //
|
||||
"-"
|
||||
: MainApp.gs(rileyLinkServiceData.errorCode.getResourceId(targetDevice)));
|
||||
: resourceHelper.gs(rileyLinkServiceData.errorCode.getResourceId(targetDevice)));
|
||||
|
||||
|
||||
RileyLinkFirmwareVersion firmwareVersion = rileyLinkServiceData.versionCC110;
|
||||
|
@ -123,13 +125,12 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
|
|||
}
|
||||
|
||||
// TODO add handling for Omnipod pump status
|
||||
MedtronicPumpStatus medtronicPumpStatus = medtronicUtil.getPumpStatus();
|
||||
|
||||
if (medtronicPumpStatus != null) {
|
||||
this.deviceType.setText(MainApp.gs(RileyLinkTargetDevice.MedtronicPump.getResourceId()));
|
||||
this.deviceType.setText(resourceHelper.gs(RileyLinkTargetDevice.MedtronicPump.getResourceId()));
|
||||
this.deviceModel.setText(medtronicPumpStatus.pumpType.getDescription());
|
||||
this.serialNumber.setText(medtronicPumpStatus.serialNumber);
|
||||
this.pumpFrequency.setText(MainApp.gs(medtronicPumpStatus.pumpFrequency.equals("medtronic_pump_frequency_us_ca") ? R.string.medtronic_pump_frequency_us_ca : R.string.medtronic_pump_frequency_worldwide));
|
||||
this.pumpFrequency.setText(resourceHelper.gs(medtronicPumpStatus.pumpFrequency.equals("medtronic_pump_frequency_us_ca") ? R.string.medtronic_pump_frequency_us_ca : R.string.medtronic_pump_frequency_worldwide));
|
||||
|
||||
// TODO extend when Omnipod used
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@ class MedtronicFragment : DaggerFragment() {
|
|||
@Inject lateinit var warnColors: WarnColors
|
||||
@Inject lateinit var rileyLinkUtil: RileyLinkUtil
|
||||
@Inject lateinit var medtronicUtil: MedtronicUtil
|
||||
@Inject lateinit var medtronicPumpStatus: MedtronicPumpStatus
|
||||
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
|
@ -87,7 +88,7 @@ class MedtronicFragment : DaggerFragment() {
|
|||
medtronic_pump_status.text = "{fa-bed}"
|
||||
|
||||
medtronic_history.setOnClickListener {
|
||||
if (medtronicUtil.getPumpStatus().verifyConfiguration()) {
|
||||
if (medtronicPumpStatus.verifyConfiguration()) {
|
||||
startActivity(Intent(context, MedtronicHistoryActivity::class.java))
|
||||
} else {
|
||||
displayNotConfiguredDialog()
|
||||
|
@ -95,7 +96,7 @@ class MedtronicFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
medtronic_refresh.setOnClickListener {
|
||||
if (!medtronicUtil.getPumpStatus().verifyConfiguration()) {
|
||||
if (!medtronicPumpStatus.verifyConfiguration()) {
|
||||
displayNotConfiguredDialog()
|
||||
} else {
|
||||
medtronic_refresh.isEnabled = false
|
||||
|
@ -109,7 +110,7 @@ class MedtronicFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
medtronic_stats.setOnClickListener {
|
||||
if (medtronicUtil.getPumpStatus().verifyConfiguration()) {
|
||||
if (medtronicPumpStatus.verifyConfiguration()) {
|
||||
startActivity(Intent(context, RileyLinkStatusActivity::class.java))
|
||||
} else {
|
||||
displayNotConfiguredDialog()
|
||||
|
@ -149,7 +150,7 @@ class MedtronicFragment : DaggerFragment() {
|
|||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
aapsLogger.debug(LTag.PUMP, "EventMedtronicPumpConfigurationChanged triggered")
|
||||
medtronicUtil.getPumpStatus().verifyConfiguration()
|
||||
medtronicPumpStatus.verifyConfiguration()
|
||||
updateGUI()
|
||||
}, { fabricPrivacy.logException(it) })
|
||||
disposable += rxBus
|
||||
|
@ -173,33 +174,32 @@ class MedtronicFragment : DaggerFragment() {
|
|||
|
||||
@Synchronized
|
||||
private fun setDeviceStatus() {
|
||||
val pumpStatus: MedtronicPumpStatus = medtronicUtil.getPumpStatus()
|
||||
pumpStatus.rileyLinkServiceState = checkStatusSet(pumpStatus.rileyLinkServiceState,
|
||||
medtronicPumpStatus.rileyLinkServiceState = checkStatusSet(medtronicPumpStatus.rileyLinkServiceState,
|
||||
rileyLinkUtil.getServiceState()) as RileyLinkServiceState?
|
||||
|
||||
val resourceId = pumpStatus.rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.MedtronicPump)
|
||||
val resourceId = medtronicPumpStatus.rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.MedtronicPump)
|
||||
val rileyLinkError = rileyLinkUtil.getError()
|
||||
medtronic_rl_status.text =
|
||||
when {
|
||||
pumpStatus.rileyLinkServiceState == RileyLinkServiceState.NotStarted -> resourceHelper.gs(resourceId)
|
||||
pumpStatus.rileyLinkServiceState.isConnecting -> "{fa-bluetooth-b spin} " + resourceHelper.gs(resourceId)
|
||||
pumpStatus.rileyLinkServiceState.isError && rileyLinkError == null -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
|
||||
pumpStatus.rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump))
|
||||
medtronicPumpStatus.rileyLinkServiceState == RileyLinkServiceState.NotStarted -> resourceHelper.gs(resourceId)
|
||||
medtronicPumpStatus.rileyLinkServiceState.isConnecting -> "{fa-bluetooth-b spin} " + resourceHelper.gs(resourceId)
|
||||
medtronicPumpStatus.rileyLinkServiceState.isError && rileyLinkError == null -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
|
||||
medtronicPumpStatus.rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump))
|
||||
else -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
|
||||
}
|
||||
medtronic_rl_status.setTextColor(if (rileyLinkError != null) Color.RED else Color.WHITE)
|
||||
|
||||
pumpStatus.rileyLinkError = checkStatusSet(pumpStatus.rileyLinkError, rileyLinkUtil.getError()) as RileyLinkError?
|
||||
medtronicPumpStatus.rileyLinkError = checkStatusSet(medtronicPumpStatus.rileyLinkError, rileyLinkUtil.getError()) as RileyLinkError?
|
||||
|
||||
medtronic_errors.text =
|
||||
pumpStatus.rileyLinkError?.let {
|
||||
medtronicPumpStatus.rileyLinkError?.let {
|
||||
resourceHelper.gs(it.getResourceId(RileyLinkTargetDevice.MedtronicPump))
|
||||
} ?: "-"
|
||||
|
||||
pumpStatus.pumpDeviceState = checkStatusSet(pumpStatus.pumpDeviceState,
|
||||
medtronicUtil.getPumpDeviceState()) as PumpDeviceState?
|
||||
medtronicPumpStatus.pumpDeviceState = checkStatusSet(medtronicPumpStatus.pumpDeviceState,
|
||||
medtronicUtil.pumpDeviceState) as PumpDeviceState?
|
||||
|
||||
when (pumpStatus.pumpDeviceState) {
|
||||
when (medtronicPumpStatus.pumpDeviceState) {
|
||||
null,
|
||||
PumpDeviceState.Sleeping -> medtronic_pump_status.text = "{fa-bed} " // + pumpStatus.pumpDeviceState.name());
|
||||
PumpDeviceState.NeverContacted,
|
||||
|
@ -207,12 +207,12 @@ class MedtronicFragment : DaggerFragment() {
|
|||
PumpDeviceState.PumpUnreachable,
|
||||
PumpDeviceState.ErrorWhenCommunicating,
|
||||
PumpDeviceState.TimeoutWhenCommunicating,
|
||||
PumpDeviceState.InvalidConfiguration -> medtronic_pump_status.text = " " + resourceHelper.gs(pumpStatus.pumpDeviceState.resourceId)
|
||||
PumpDeviceState.InvalidConfiguration -> medtronic_pump_status.text = " " + resourceHelper.gs(medtronicPumpStatus.pumpDeviceState.resourceId)
|
||||
|
||||
PumpDeviceState.Active -> {
|
||||
val cmd = medtronicUtil.getCurrentCommand()
|
||||
if (cmd == null)
|
||||
medtronic_pump_status.text = " " + resourceHelper.gs(pumpStatus.pumpDeviceState.resourceId)
|
||||
medtronic_pump_status.text = " " + resourceHelper.gs(medtronicPumpStatus.pumpDeviceState.resourceId)
|
||||
else {
|
||||
aapsLogger.debug(LTag.PUMP, "Command: " + cmd)
|
||||
val cmdResourceId = cmd.resourceId
|
||||
|
@ -228,7 +228,7 @@ class MedtronicFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
else -> aapsLogger.warn(LTag.PUMP, "Unknown pump state: " + pumpStatus.pumpDeviceState)
|
||||
else -> aapsLogger.warn(LTag.PUMP, "Unknown pump state: " + medtronicPumpStatus.pumpDeviceState)
|
||||
}
|
||||
|
||||
val status = commandQueue.spannedStatus()
|
||||
|
@ -262,18 +262,17 @@ class MedtronicFragment : DaggerFragment() {
|
|||
@Synchronized
|
||||
fun updateGUI() {
|
||||
if (medtronic_rl_status == null) return
|
||||
val pumpStatus = medtronicUtil.getPumpStatus()
|
||||
|
||||
setDeviceStatus()
|
||||
|
||||
// last connection
|
||||
if (pumpStatus.lastConnection != 0L) {
|
||||
val minAgo = DateUtil.minAgo(resourceHelper, pumpStatus.lastConnection)
|
||||
val min = (System.currentTimeMillis() - pumpStatus.lastConnection) / 1000 / 60
|
||||
if (pumpStatus.lastConnection + 60 * 1000 > System.currentTimeMillis()) {
|
||||
if (medtronicPumpStatus.lastConnection != 0L) {
|
||||
val minAgo = DateUtil.minAgo(resourceHelper, medtronicPumpStatus.lastConnection)
|
||||
val min = (System.currentTimeMillis() - medtronicPumpStatus.lastConnection) / 1000 / 60
|
||||
if (medtronicPumpStatus.lastConnection + 60 * 1000 > System.currentTimeMillis()) {
|
||||
medtronic_lastconnection.setText(R.string.combo_pump_connected_now)
|
||||
medtronic_lastconnection.setTextColor(Color.WHITE)
|
||||
} else if (pumpStatus.lastConnection + 30 * 60 * 1000 < System.currentTimeMillis()) {
|
||||
} else if (medtronicPumpStatus.lastConnection + 30 * 60 * 1000 < System.currentTimeMillis()) {
|
||||
|
||||
if (min < 60) {
|
||||
medtronic_lastconnection.text = resourceHelper.gs(R.string.minago, min)
|
||||
|
@ -296,19 +295,19 @@ class MedtronicFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
// last bolus
|
||||
val bolus = pumpStatus.lastBolusAmount
|
||||
val bolusTime = pumpStatus.lastBolusTime
|
||||
val bolus = medtronicPumpStatus.lastBolusAmount
|
||||
val bolusTime = medtronicPumpStatus.lastBolusTime
|
||||
if (bolus != null && bolusTime != null) {
|
||||
val agoMsc = System.currentTimeMillis() - pumpStatus.lastBolusTime.time
|
||||
val agoMsc = System.currentTimeMillis() - medtronicPumpStatus.lastBolusTime.time
|
||||
val bolusMinAgo = agoMsc.toDouble() / 60.0 / 1000.0
|
||||
val unit = resourceHelper.gs(R.string.insulin_unit_shortname)
|
||||
val ago: String
|
||||
if (agoMsc < 60 * 1000) {
|
||||
ago = resourceHelper.gs(R.string.combo_pump_connected_now)
|
||||
} else if (bolusMinAgo < 60) {
|
||||
ago = DateUtil.minAgo(resourceHelper, pumpStatus.lastBolusTime.time)
|
||||
ago = DateUtil.minAgo(resourceHelper, medtronicPumpStatus.lastBolusTime.time)
|
||||
} else {
|
||||
ago = DateUtil.hourAgo(pumpStatus.lastBolusTime.time, resourceHelper)
|
||||
ago = DateUtil.hourAgo(medtronicPumpStatus.lastBolusTime.time, resourceHelper)
|
||||
}
|
||||
medtronic_lastbolus.text = resourceHelper.gs(R.string.combo_last_bolus, bolus, unit, ago)
|
||||
} else {
|
||||
|
@ -316,24 +315,24 @@ class MedtronicFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
// base basal rate
|
||||
medtronic_basabasalrate.text = ("(" + pumpStatus.activeProfileName + ") "
|
||||
medtronic_basabasalrate.text = ("(" + medtronicPumpStatus.activeProfileName + ") "
|
||||
+ resourceHelper.gs(R.string.pump_basebasalrate, medtronicPumpPlugin.baseBasalRate))
|
||||
|
||||
medtronic_tempbasal.text = activePlugin.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull()
|
||||
?: ""
|
||||
|
||||
// battery
|
||||
if (medtronicUtil.getBatteryType() == BatteryType.None || pumpStatus.batteryVoltage == null) {
|
||||
medtronic_pumpstate_battery.text = "{fa-battery-" + pumpStatus.batteryRemaining / 25 + "} "
|
||||
if (medtronicUtil.getBatteryType() == BatteryType.None || medtronicPumpStatus.batteryVoltage == null) {
|
||||
medtronic_pumpstate_battery.text = "{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} "
|
||||
} else {
|
||||
medtronic_pumpstate_battery.text = "{fa-battery-" + pumpStatus.batteryRemaining / 25 + "} " + pumpStatus.batteryRemaining + "%" + String.format(" (%.2f V)", pumpStatus.batteryVoltage)
|
||||
medtronic_pumpstate_battery.text = "{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} " + medtronicPumpStatus.batteryRemaining + "%" + String.format(" (%.2f V)", medtronicPumpStatus.batteryVoltage)
|
||||
}
|
||||
warnColors.setColorInverse(medtronic_pumpstate_battery, pumpStatus.batteryRemaining.toDouble(), 25.0, 10.0)
|
||||
warnColors.setColorInverse(medtronic_pumpstate_battery, medtronicPumpStatus.batteryRemaining.toDouble(), 25.0, 10.0)
|
||||
|
||||
// reservoir
|
||||
medtronic_reservoir.text = resourceHelper.gs(R.string.reservoirvalue, pumpStatus.reservoirRemainingUnits, pumpStatus.reservoirFullUnits)
|
||||
warnColors.setColorInverse(medtronic_reservoir, pumpStatus.reservoirRemainingUnits, 50.0, 20.0)
|
||||
medtronic_reservoir.text = resourceHelper.gs(R.string.reservoirvalue, medtronicPumpStatus.reservoirRemainingUnits, medtronicPumpStatus.reservoirFullUnits)
|
||||
warnColors.setColorInverse(medtronic_reservoir, medtronicPumpStatus.reservoirRemainingUnits, 50.0, 20.0)
|
||||
|
||||
medtronic_errors.text = pumpStatus.errorInfo
|
||||
medtronic_errors.text = medtronicPumpStatus.errorInfo
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,10 +99,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
private final RileyLinkUtil rileyLinkUtil;
|
||||
private final MedtronicUtil medtronicUtil;
|
||||
private final MedtronicPumpStatus medtronicPumpStatus;
|
||||
private final MedtronicUIComm medtronicUIComm;
|
||||
|
||||
protected static MedtronicPumpPlugin plugin = null;
|
||||
private RileyLinkMedtronicService rileyLinkMedtronicService;
|
||||
private MedtronicUIComm medtronicUIComm;
|
||||
|
||||
// variables for handling statuses and history
|
||||
private boolean firstRun = true;
|
||||
|
@ -131,7 +131,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
FabricPrivacy fabricPrivacy,
|
||||
RileyLinkUtil rileyLinkUtil,
|
||||
MedtronicUtil medtronicUtil,
|
||||
MedtronicPumpStatus medtronicPumpStatus
|
||||
MedtronicPumpStatus medtronicPumpStatus,
|
||||
MedtronicUIComm medtronicUIComm
|
||||
) {
|
||||
|
||||
super(new PluginDescription() //
|
||||
|
@ -150,6 +151,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
this.medtronicUtil = medtronicUtil;
|
||||
this.sp = sp;
|
||||
this.medtronicPumpStatus = medtronicPumpStatus;
|
||||
this.medtronicUIComm = medtronicUIComm;
|
||||
|
||||
displayConnectionMessages = false;
|
||||
|
||||
|
@ -170,11 +172,9 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
for (int i = 0; i < 20; i++) {
|
||||
SystemClock.sleep(5000);
|
||||
|
||||
if (medtronicUtil.getPumpStatus() != null) {
|
||||
aapsLogger.debug(LTag.PUMP, "Starting Medtronic-RileyLink service");
|
||||
if (medtronicUtil.getPumpStatus().setNotInPreInit()) {
|
||||
break;
|
||||
}
|
||||
aapsLogger.debug(LTag.PUMP, "Starting Medtronic-RileyLink service");
|
||||
if (medtronicPumpStatus.setNotInPreInit()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
@ -186,7 +186,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
medtronicUIComm = new MedtronicUIComm(aapsLogger, rxBus, getResourceHelper(), rileyLinkUtil, medtronicUtil);
|
||||
medtronicHistoryData = new MedtronicHistoryData(aapsLogger, sp, activePlugin);
|
||||
}
|
||||
|
||||
|
@ -211,8 +210,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
@Override
|
||||
public void initPumpStatusData() {
|
||||
|
||||
medtronicUtil.setPumpStatus(medtronicPumpStatus);
|
||||
|
||||
medtronicPumpStatus.lastConnection = sp.getLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
|
||||
medtronicPumpStatus.lastDataTime = medtronicPumpStatus.lastConnection;
|
||||
medtronicPumpStatus.previousConnection = medtronicPumpStatus.lastConnection;
|
||||
|
@ -1532,7 +1529,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
switch (mcat) {
|
||||
|
||||
case WakeUpAndTune: {
|
||||
if (medtronicUtil.getPumpStatus().verifyConfiguration()) {
|
||||
if (medtronicPumpStatus.verifyConfiguration()) {
|
||||
ServiceTaskExecutor.startTask(new WakeAndTuneTask(getInjector()));
|
||||
} else {
|
||||
Intent i = new Intent(context, ErrorHelperActivity.class);
|
||||
|
@ -1583,5 +1580,9 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
refreshCustomActionsList();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public MedtronicPumpStatus getMedtronicPumpStatus() {
|
||||
return medtronicPumpStatus;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,9 +10,12 @@ import java.util.GregorianCalendar;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
||||
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy;
|
||||
|
@ -45,8 +48,8 @@ import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.TempBasalPair;
|
|||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
/**
|
||||
* Original file created by geoff on 5/30/16.
|
||||
|
@ -57,6 +60,8 @@ import info.nightscout.androidaps.utils.SP;
|
|||
*/
|
||||
public class MedtronicCommunicationManager extends RileyLinkCommunicationManager {
|
||||
|
||||
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||
|
||||
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
|
||||
private static final int MAX_COMMAND_TRIES = 3;
|
||||
private static final int DEFAULT_TIMEOUT = 2000;
|
||||
|
@ -76,7 +81,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
medtronicCommunicationManager = this;
|
||||
this.medtronicConverter = new MedtronicConverter();
|
||||
this.pumpHistoryDecoder = new MedtronicPumpHistoryDecoder();
|
||||
MedtronicUtil.getInstance().getPumpStatus().previousConnection = SP.getLong(
|
||||
medtronicPumpStatus.previousConnection = sp.getLong(
|
||||
RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
|
||||
}
|
||||
|
||||
|
@ -85,13 +90,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
return medtronicCommunicationManager;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void configurePumpSpecificSettings() {
|
||||
pumpStatus = MedtronicUtil.getInstance().getPumpStatus();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <E extends RLMessage> E createResponseMessage(byte[] payload, Class<E> clazz) {
|
||||
PumpMessage pumpMessage = new PumpMessage(payload);
|
||||
|
@ -141,7 +139,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
|
||||
if (!canPreventTuneUp) {
|
||||
|
||||
long diff = System.currentTimeMillis() - MedtronicUtil.getInstance().getPumpStatus().lastConnection;
|
||||
long diff = System.currentTimeMillis() - medtronicPumpStatus.lastConnection;
|
||||
|
||||
if (diff > RILEYLINK_TIMEOUT) {
|
||||
ServiceTaskExecutor.startTask(new WakeAndTuneTask(injector));
|
||||
|
@ -962,5 +960,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
return L.isEnabled(L.PUMPCOMM);
|
||||
}
|
||||
|
||||
|
||||
@Override public PumpStatus getPumpStatus() {
|
||||
return medtronicPumpStatus;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,10 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.ui;
|
|||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||
|
@ -15,27 +19,32 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
|||
/**
|
||||
* Created by andy on 6/14/18.
|
||||
*/
|
||||
@Singleton
|
||||
public class MedtronicUIComm {
|
||||
|
||||
@NotNull private final HasAndroidInjector injector;
|
||||
@NotNull private final AAPSLogger aapsLogger;
|
||||
@NotNull private final RileyLinkUtil rileyLinkUtil;
|
||||
@NotNull private final MedtronicUtil medtronicUtil;
|
||||
|
||||
MedtronicCommunicationManager mcmInstance = null;
|
||||
MedtronicUIPostprocessor uiPostprocessor;
|
||||
@NotNull private final MedtronicUIPostprocessor medtronicUIPostprocessor;
|
||||
|
||||
@Inject
|
||||
public MedtronicUIComm(
|
||||
HasAndroidInjector injector,
|
||||
AAPSLogger aapsLogger,
|
||||
RxBusWrapper rxBus,
|
||||
ResourceHelper resourceHelper,
|
||||
RileyLinkUtil rileyLinkUtil,
|
||||
MedtronicUtil medtronicUtil
|
||||
MedtronicUtil medtronicUtil,
|
||||
MedtronicUIPostprocessor medtronicUIPostprocessor
|
||||
) {
|
||||
this.injector = injector;
|
||||
this.aapsLogger = aapsLogger;
|
||||
this.rileyLinkUtil = rileyLinkUtil;
|
||||
this.medtronicUtil = medtronicUtil;
|
||||
|
||||
uiPostprocessor = new MedtronicUIPostprocessor(aapsLogger, rxBus, resourceHelper, medtronicUtil);
|
||||
this.medtronicUIPostprocessor = medtronicUIPostprocessor;
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,7 +61,7 @@ public class MedtronicUIComm {
|
|||
|
||||
aapsLogger.warn(LTag.PUMP, "Execute Command: " + commandType.name());
|
||||
|
||||
MedtronicUITask task = new MedtronicUITask(commandType, parameters);
|
||||
MedtronicUITask task = new MedtronicUITask(injector, commandType, parameters);
|
||||
|
||||
medtronicUtil.setCurrentCommand(commandType);
|
||||
|
||||
|
@ -88,7 +97,7 @@ public class MedtronicUIComm {
|
|||
aapsLogger.warn(LTag.PUMP, "Reply not received for " + commandType);
|
||||
}
|
||||
|
||||
task.postProcess(uiPostprocessor);
|
||||
task.postProcess(medtronicUIPostprocessor);
|
||||
|
||||
return task;
|
||||
|
||||
|
|
|
@ -7,6 +7,9 @@ import org.joda.time.Duration;
|
|||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||
|
@ -26,18 +29,22 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
|||
* Created by andy on 6/15/18.
|
||||
*/
|
||||
|
||||
@Singleton
|
||||
class MedtronicUIPostprocessor {
|
||||
|
||||
@NotNull private final AAPSLogger aapsLogger;
|
||||
@NotNull private final RxBusWrapper rxBus;
|
||||
@NotNull private final ResourceHelper resourceHelper;
|
||||
@NotNull private final MedtronicUtil medtronicUtil;
|
||||
@NotNull private final MedtronicPumpStatus medtronicPumpStatus;
|
||||
|
||||
public MedtronicUIPostprocessor(AAPSLogger aapsLogger, RxBusWrapper rxBus, ResourceHelper resourceHelper, MedtronicUtil medtronicUtil) {
|
||||
@Inject
|
||||
public MedtronicUIPostprocessor(AAPSLogger aapsLogger, RxBusWrapper rxBus, ResourceHelper resourceHelper, MedtronicUtil medtronicUtil, MedtronicPumpStatus medtronicPumpStatus) {
|
||||
this.aapsLogger = aapsLogger;
|
||||
this.rxBus = rxBus;
|
||||
this.resourceHelper = resourceHelper;
|
||||
this.medtronicUtil = medtronicUtil;
|
||||
this.medtronicPumpStatus = medtronicPumpStatus;
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,7 +60,7 @@ class MedtronicUIPostprocessor {
|
|||
if (response) {
|
||||
BasalProfile basalProfile = (BasalProfile) uiTask.getParameter(0);
|
||||
|
||||
medtronicUtil.getPumpStatus().basalsByHour = basalProfile.getProfilesByHour();
|
||||
medtronicPumpStatus.basalsByHour = basalProfile.getProfilesByHour();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -65,8 +72,8 @@ class MedtronicUIPostprocessor {
|
|||
Double[] profilesByHour = basalProfile.getProfilesByHour();
|
||||
|
||||
if (profilesByHour != null) {
|
||||
medtronicUtil.getPumpStatus().basalsByHour = profilesByHour;
|
||||
medtronicUtil.getPumpStatus().basalProfileStatus = BasalProfileStatus.ProfileOK;
|
||||
medtronicPumpStatus.basalsByHour = profilesByHour;
|
||||
medtronicPumpStatus.basalProfileStatus = BasalProfileStatus.ProfileOK;
|
||||
} else {
|
||||
uiTask.responseType = MedtronicUIResponseType.Error;
|
||||
uiTask.errorDescription = "No profile found.";
|
||||
|
@ -81,20 +88,20 @@ class MedtronicUIPostprocessor {
|
|||
break;
|
||||
|
||||
case SetBolus: {
|
||||
medtronicUtil.getPumpStatus().lastBolusAmount = uiTask.getDoubleFromParameters(0);
|
||||
medtronicUtil.getPumpStatus().lastBolusTime = new Date();
|
||||
medtronicPumpStatus.lastBolusAmount = uiTask.getDoubleFromParameters(0);
|
||||
medtronicPumpStatus.lastBolusTime = new Date();
|
||||
}
|
||||
break;
|
||||
|
||||
case GetRemainingInsulin: {
|
||||
medtronicUtil.getPumpStatus().reservoirRemainingUnits = (Float) uiTask.returnData;
|
||||
medtronicPumpStatus.reservoirRemainingUnits = (Float) uiTask.returnData;
|
||||
}
|
||||
break;
|
||||
|
||||
case CancelTBR: {
|
||||
medtronicUtil.getPumpStatus().tempBasalStart = null;
|
||||
medtronicUtil.getPumpStatus().tempBasalAmount = null;
|
||||
medtronicUtil.getPumpStatus().tempBasalLength = null;
|
||||
medtronicPumpStatus.tempBasalStart = null;
|
||||
medtronicPumpStatus.tempBasalAmount = null;
|
||||
medtronicPumpStatus.tempBasalLength = null;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -118,10 +125,10 @@ class MedtronicUIPostprocessor {
|
|||
case GetBatteryStatus: {
|
||||
BatteryStatusDTO batteryStatusDTO = (BatteryStatusDTO) uiTask.returnData;
|
||||
|
||||
medtronicUtil.getPumpStatus().batteryRemaining = batteryStatusDTO.getCalculatedPercent(medtronicUtil.getPumpStatus().batteryType);
|
||||
medtronicPumpStatus.batteryRemaining = batteryStatusDTO.getCalculatedPercent(medtronicPumpStatus.batteryType);
|
||||
|
||||
if (batteryStatusDTO.voltage != null) {
|
||||
medtronicUtil.getPumpStatus().batteryVoltage = batteryStatusDTO.voltage;
|
||||
medtronicPumpStatus.batteryVoltage = batteryStatusDTO.voltage;
|
||||
}
|
||||
|
||||
aapsLogger.debug(LTag.PUMP, "BatteryStatus: {}", batteryStatusDTO.toString());
|
||||
|
@ -130,7 +137,7 @@ class MedtronicUIPostprocessor {
|
|||
break;
|
||||
|
||||
case PumpModel: {
|
||||
if (medtronicUtil.getPumpStatus().medtronicDeviceType != medtronicUtil.getMedtronicPumpModel()) {
|
||||
if (medtronicPumpStatus.medtronicDeviceType != medtronicUtil.getMedtronicPumpModel()) {
|
||||
aapsLogger.warn(LTag.PUMP, "Configured pump is different then pump detected !");
|
||||
medtronicUtil.sendNotification(MedtronicNotificationType.PumpTypeNotSame, resourceHelper, rxBus);
|
||||
}
|
||||
|
@ -190,11 +197,7 @@ class MedtronicUIPostprocessor {
|
|||
|
||||
PumpSettingDTO checkValue = null;
|
||||
|
||||
if (medtronicUtil.getPumpStatus() == null) {
|
||||
aapsLogger.debug(LTag.PUMP, "Pump Status: was null");
|
||||
}
|
||||
|
||||
medtronicUtil.getPumpStatus().verifyConfiguration();
|
||||
medtronicPumpStatus.verifyConfiguration();
|
||||
|
||||
// check profile
|
||||
if (!"Yes".equals(settings.get("PCFG_BASAL_PROFILES_ENABLED").value)) {
|
||||
|
@ -223,16 +226,16 @@ class MedtronicUIPostprocessor {
|
|||
|
||||
checkValue = settings.get("PCFG_MAX_BOLUS");
|
||||
|
||||
if (!medtronicUtil.isSame(Double.parseDouble(checkValue.value), medtronicUtil.getPumpStatus().maxBolus)) {
|
||||
aapsLogger.error("Wrong Max Bolus set on Pump (current={}, required={}).", checkValue.value, medtronicUtil.getPumpStatus().maxBolus);
|
||||
medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongMaxBolusSet, resourceHelper, rxBus, medtronicUtil.getPumpStatus().maxBolus);
|
||||
if (!medtronicUtil.isSame(Double.parseDouble(checkValue.value), medtronicPumpStatus.maxBolus)) {
|
||||
aapsLogger.error("Wrong Max Bolus set on Pump (current={}, required={}).", checkValue.value, medtronicPumpStatus.maxBolus);
|
||||
medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongMaxBolusSet, resourceHelper, rxBus, medtronicPumpStatus.maxBolus);
|
||||
}
|
||||
|
||||
checkValue = settings.get("PCFG_MAX_BASAL");
|
||||
|
||||
if (!medtronicUtil.isSame(Double.parseDouble(checkValue.value), medtronicUtil.getPumpStatus().maxBasal)) {
|
||||
aapsLogger.error("Wrong Max Basal set on Pump (current={}, required={}).", checkValue.value, medtronicUtil.getPumpStatus().maxBasal);
|
||||
medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongMaxBasalSet, resourceHelper, rxBus, medtronicUtil.getPumpStatus().maxBasal);
|
||||
if (!medtronicUtil.isSame(Double.parseDouble(checkValue.value), medtronicPumpStatus.maxBasal)) {
|
||||
aapsLogger.error("Wrong Max Basal set on Pump (current={}, required={}).", checkValue.value, medtronicPumpStatus.maxBasal);
|
||||
medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongMaxBasalSet, resourceHelper, rxBus, medtronicPumpStatus.maxBasal);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package info.nightscout.androidaps.plugins.pump.medtronic.comm.ui;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
|
@ -15,6 +17,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.TempBasalPair;
|
|||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicUIResponseType;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicDeviceStatusChange;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpValuesChanged;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||
|
@ -25,6 +28,10 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
|||
|
||||
public class MedtronicUITask {
|
||||
|
||||
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||
|
||||
@NotNull private final HasAndroidInjector injector;
|
||||
|
||||
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMP);
|
||||
|
||||
public MedtronicCommandType commandType;
|
||||
|
@ -36,12 +43,16 @@ public class MedtronicUITask {
|
|||
MedtronicUIResponseType responseType;
|
||||
|
||||
|
||||
public MedtronicUITask(MedtronicCommandType commandType) {
|
||||
public MedtronicUITask(HasAndroidInjector injector, MedtronicCommandType commandType) {
|
||||
this.injector = injector;
|
||||
injector.androidInjector().inject(this);
|
||||
this.commandType = commandType;
|
||||
}
|
||||
|
||||
|
||||
public MedtronicUITask(MedtronicCommandType commandType, Object... parameters) {
|
||||
public MedtronicUITask(HasAndroidInjector injector, MedtronicCommandType commandType, Object... parameters) {
|
||||
this.injector = injector;
|
||||
injector.androidInjector().inject(this);
|
||||
this.commandType = commandType;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
@ -200,7 +211,7 @@ public class MedtronicUITask {
|
|||
errorDescription));
|
||||
} else {
|
||||
RxBus.Companion.getINSTANCE().send(new EventMedtronicPumpValuesChanged());
|
||||
MedtronicUtil.getInstance().getPumpStatus().setLastCommunicationToNow();
|
||||
medtronicPumpStatus.setLastCommunicationToNow();
|
||||
}
|
||||
|
||||
MedtronicUtil.getInstance().setCurrentCommand(null);
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.google.gson.annotations.Expose;
|
|||
|
||||
import org.joda.time.Instant;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -13,6 +12,7 @@ import info.nightscout.androidaps.logging.L;
|
|||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||
|
||||
/**
|
||||
|
@ -305,7 +305,7 @@ public class BasalProfile {
|
|||
|
||||
Double[] basalByHour = new Double[24];
|
||||
|
||||
PumpType pumpType = MedtronicUtil.getInstance().getPumpStatus().pumpType;
|
||||
PumpType pumpType = MedtronicPumpPlugin.getPlugin().getMedtronicPumpStatus().pumpType;
|
||||
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
BasalProfileEntry current = entries.get(i);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package info.nightscout.androidaps.plugins.pump.medtronic.driver;
|
||||
|
||||
import org.joda.time.LocalDateTime;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
@ -44,10 +42,10 @@ public class MedtronicPumpStatus extends PumpStatus {
|
|||
private final ResourceHelper resourceHelper;
|
||||
private final SP sp;
|
||||
|
||||
public String errorDescription = null;
|
||||
private String errorDescription = null;
|
||||
public String serialNumber;
|
||||
public String pumpFrequency = null;
|
||||
public String rileyLinkAddress = null;
|
||||
private String rileyLinkAddress = null;
|
||||
public Double maxBolus;
|
||||
public Double maxBasal;
|
||||
private boolean inPreInit = true;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package info.nightscout.androidaps.plugins.pump.medtronic.service;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Configuration;
|
||||
|
@ -10,11 +9,9 @@ import android.os.IBinder;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkEncodingType;
|
||||
|
@ -22,15 +19,12 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLin
|
|||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTask;
|
||||
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||
|
||||
/**
|
||||
* RileyLinkMedtronicService is intended to stay running when the gui-app is closed.
|
||||
|
@ -41,12 +35,8 @@ public class RileyLinkMedtronicService extends RileyLinkService {
|
|||
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
|
||||
@Inject MedtronicUtil medtronicUtil;
|
||||
|
||||
@Deprecated // TEDO remove this reference
|
||||
private static ServiceTask currentTask = null;
|
||||
|
||||
// cache of most recently received set of pump history pages. Probably shouldn't be here.
|
||||
public MedtronicCommunicationManager medtronicCommunicationManager;
|
||||
MedtronicPumpStatus pumpStatus = null;
|
||||
private MedtronicCommunicationManager medtronicCommunicationManager;
|
||||
private IBinder mBinder = new LocalBinder();
|
||||
|
||||
|
||||
|
@ -100,8 +90,6 @@ public class RileyLinkMedtronicService extends RileyLinkService {
|
|||
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkMedtronicService newly constructed");
|
||||
medtronicUtil.setMedtronicService(this);
|
||||
pumpStatus = (MedtronicPumpStatus) medtronicPumpPlugin.getPumpStatusData();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ public class MedtronicUtil {
|
|||
private MedtronicDeviceType medtronicPumpModel;
|
||||
private RileyLinkMedtronicService medtronicService;
|
||||
@Deprecated // TODO remove this reference
|
||||
private MedtronicPumpStatus medtronicPumpStatus;
|
||||
private MedtronicCommandType currentCommand;
|
||||
private Map<String, PumpSettingDTO> settings;
|
||||
private int BIG_FRAME_LENGTH = 65;
|
||||
|
@ -69,17 +68,20 @@ public class MedtronicUtil {
|
|||
@NotNull private final AAPSLogger aapsLogger;
|
||||
@NotNull private final RxBusWrapper rxBus;
|
||||
@NotNull private final RileyLinkUtil rileyLinkUtil;
|
||||
@NotNull private final MedtronicPumpStatus medtronicPumpStatus;
|
||||
|
||||
@Inject
|
||||
public MedtronicUtil(
|
||||
AAPSLogger aapsLogger,
|
||||
RxBusWrapper rxBus,
|
||||
RileyLinkUtil rileyLinkUtil
|
||||
RileyLinkUtil rileyLinkUtil,
|
||||
MedtronicPumpStatus medtronicPumpStatus
|
||||
|
||||
) {
|
||||
this.aapsLogger = aapsLogger;
|
||||
this.rxBus = rxBus;
|
||||
this.rileyLinkUtil = rileyLinkUtil;
|
||||
this.medtronicPumpStatus = medtronicPumpStatus;
|
||||
instance = this;
|
||||
}
|
||||
|
||||
|
@ -465,16 +467,10 @@ public class MedtronicUtil {
|
|||
|
||||
|
||||
@Deprecated // TODO use singleton
|
||||
public MedtronicPumpStatus getPumpStatus() {
|
||||
public MedtronicPumpStatus getPumpStatus1() {
|
||||
return medtronicPumpStatus;
|
||||
}
|
||||
|
||||
@Deprecated // TODO use singleton
|
||||
public void setPumpStatus(MedtronicPumpStatus medtronicPumpStatus) {
|
||||
this.medtronicPumpStatus = medtronicPumpStatus;
|
||||
}
|
||||
|
||||
|
||||
public MedtronicCommandType getCurrentCommand() {
|
||||
return this.currentCommand;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue