RileyLinkPumpDevice -> kt
This commit is contained in:
parent
e8928e554f
commit
40d1c0c9bc
5 changed files with 124 additions and 99 deletions
|
@ -91,7 +91,8 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
aapsSchedulers: AapsSchedulers,
|
aapsSchedulers: AapsSchedulers,
|
||||||
pumpSync: PumpSync,
|
pumpSync: PumpSync,
|
||||||
pumpSyncStorage: info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage
|
pumpSyncStorage: info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage
|
||||||
) : PumpPluginAbstract(PluginDescription() //
|
) : PumpPluginAbstract(
|
||||||
|
PluginDescription() //
|
||||||
.mainType(PluginType.PUMP) //
|
.mainType(PluginType.PUMP) //
|
||||||
.fragmentClass(MedtronicFragment::class.java.name) //
|
.fragmentClass(MedtronicFragment::class.java.name) //
|
||||||
.pluginIcon(R.drawable.ic_veo_128)
|
.pluginIcon(R.drawable.ic_veo_128)
|
||||||
|
@ -234,18 +235,16 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
// Pump Plugin
|
// Pump Plugin
|
||||||
private var isServiceSet: Boolean = false
|
private var isServiceSet: Boolean = false
|
||||||
|
|
||||||
override fun getRileyLinkService(): RileyLinkMedtronicService? = rileyLinkMedtronicService
|
override val rileyLinkService: RileyLinkMedtronicService? = rileyLinkMedtronicService
|
||||||
|
|
||||||
override fun getPumpInfo(): RileyLinkPumpInfo {
|
override val pumpInfo: RileyLinkPumpInfo
|
||||||
val frequency = rh.gs(if (medtronicPumpStatus.pumpFrequency == "medtronic_pump_frequency_us_ca") R.string.medtronic_pump_frequency_us_ca else R.string.medtronic_pump_frequency_worldwide)
|
get() = RileyLinkPumpInfo(
|
||||||
val model = if (!medtronicUtil.isModelSet) "???" else "Medtronic " + medtronicPumpStatus.medtronicDeviceType.pumpModel
|
rh.gs(if (medtronicPumpStatus.pumpFrequency == "medtronic_pump_frequency_us_ca") R.string.medtronic_pump_frequency_us_ca else R.string.medtronic_pump_frequency_worldwide),
|
||||||
val serialNumber = medtronicPumpStatus.serialNumber
|
if (!medtronicUtil.isModelSet) "???" else "Medtronic " + medtronicPumpStatus.medtronicDeviceType.pumpModel,
|
||||||
return RileyLinkPumpInfo(frequency, model, serialNumber)
|
medtronicPumpStatus.serialNumber
|
||||||
}
|
)
|
||||||
|
|
||||||
override fun getLastConnectionTimeMillis(): Long {
|
override val lastConnectionTimeMillis: Long = medtronicPumpStatus.lastConnection
|
||||||
return medtronicPumpStatus.lastConnection
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setLastCommunicationToNow() {
|
override fun setLastCommunicationToNow() {
|
||||||
medtronicPumpStatus.setLastCommunicationToNow()
|
medtronicPumpStatus.setLastCommunicationToNow()
|
||||||
|
@ -326,7 +325,8 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
if (rileyLinkServiceState != RileyLinkServiceState.PumpConnectorReady //
|
if (rileyLinkServiceState != RileyLinkServiceState.PumpConnectorReady //
|
||||||
&& rileyLinkServiceState != RileyLinkServiceState.RileyLinkReady //
|
&& rileyLinkServiceState != RileyLinkServiceState.RileyLinkReady //
|
||||||
&& rileyLinkServiceState != RileyLinkServiceState.TuneUpDevice) {
|
&& rileyLinkServiceState != RileyLinkServiceState.TuneUpDevice
|
||||||
|
) {
|
||||||
aapsLogger.debug(LTag.PUMP, "RileyLink unreachable.")
|
aapsLogger.debug(LTag.PUMP, "RileyLink unreachable.")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -334,8 +334,10 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshAnyStatusThatNeedsToBeRefreshed() {
|
private fun refreshAnyStatusThatNeedsToBeRefreshed() {
|
||||||
val statusRefresh = workWithStatusRefresh(StatusRefreshAction.GetData, null,
|
val statusRefresh = workWithStatusRefresh(
|
||||||
null)!!
|
StatusRefreshAction.GetData, null,
|
||||||
|
null
|
||||||
|
)!!
|
||||||
if (!doWeHaveAnyStatusNeededRefreshing(statusRefresh)) {
|
if (!doWeHaveAnyStatusNeededRefreshing(statusRefresh)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -594,9 +596,13 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
return PumpEnactResult(injector) //
|
return PumpEnactResult(injector) //
|
||||||
.success(false) //
|
.success(false) //
|
||||||
.enacted(false) //
|
.enacted(false) //
|
||||||
.comment(rh.gs(R.string.medtronic_cmd_bolus_could_not_be_delivered_no_insulin,
|
.comment(
|
||||||
|
rh.gs(
|
||||||
|
R.string.medtronic_cmd_bolus_could_not_be_delivered_no_insulin,
|
||||||
medtronicPumpStatus.reservoirRemainingUnits,
|
medtronicPumpStatus.reservoirRemainingUnits,
|
||||||
detailedBolusInfo.insulin))
|
detailedBolusInfo.insulin
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
bolusDeliveryType = BolusDeliveryType.DeliveryPrepared
|
bolusDeliveryType = BolusDeliveryType.DeliveryPrepared
|
||||||
if (isPumpNotReachable) {
|
if (isPumpNotReachable) {
|
||||||
|
@ -619,8 +625,10 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
bolusDeliveryType = BolusDeliveryType.Delivering
|
bolusDeliveryType = BolusDeliveryType.Delivering
|
||||||
|
|
||||||
// LOG.debug("MedtronicPumpPlugin::deliverBolus - Start delivery");
|
// LOG.debug("MedtronicPumpPlugin::deliverBolus - Start delivery");
|
||||||
val responseTask = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(MedtronicCommandType.SetBolus,
|
val responseTask = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(
|
||||||
arrayListOf(detailedBolusInfo.insulin))
|
MedtronicCommandType.SetBolus,
|
||||||
|
arrayListOf(detailedBolusInfo.insulin)
|
||||||
|
)
|
||||||
val response = responseTask?.result as Boolean?
|
val response = responseTask?.result as Boolean?
|
||||||
setRefreshButtonEnabled(true)
|
setRefreshButtonEnabled(true)
|
||||||
|
|
||||||
|
@ -757,8 +765,10 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
// now start new TBR
|
// now start new TBR
|
||||||
val responseTask = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(MedtronicCommandType.SetTemporaryBasal,
|
val responseTask = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(
|
||||||
arrayListOf(absoluteRate, durationInMinutes))
|
MedtronicCommandType.SetTemporaryBasal,
|
||||||
|
arrayListOf(absoluteRate, durationInMinutes)
|
||||||
|
)
|
||||||
val response = responseTask?.result as Boolean?
|
val response = responseTask?.result as Boolean?
|
||||||
aapsLogger.info(LTag.PUMP, logPrefix + "setTempBasalAbsolute - setTBR. Response: " + response)
|
aapsLogger.info(LTag.PUMP, logPrefix + "setTempBasalAbsolute - setTBR. Response: " + response)
|
||||||
return if (response == null || !response) {
|
return if (response == null || !response) {
|
||||||
|
@ -784,13 +794,13 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
|
|
||||||
@Deprecated("Not used, TBRs fixed in history, should be removed.")
|
@Deprecated("Not used, TBRs fixed in history, should be removed.")
|
||||||
private fun cancelTBRWithTemporaryId() {
|
private fun cancelTBRWithTemporaryId() {
|
||||||
val tbrs : MutableList<PumpDbEntryTBR> = pumpSyncStorage.getTBRs()
|
val tbrs: MutableList<PumpDbEntryTBR> = pumpSyncStorage.getTBRs()
|
||||||
if (tbrs.size > 0 && medtronicPumpStatus.runningTBRWithTemp!=null) {
|
if (tbrs.size > 0 && medtronicPumpStatus.runningTBRWithTemp != null) {
|
||||||
aapsLogger.info(LTag.PUMP, logPrefix + "cancelTBRWithTemporaryId - TBR items: ${tbrs.size}")
|
aapsLogger.info(LTag.PUMP, logPrefix + "cancelTBRWithTemporaryId - TBR items: ${tbrs.size}")
|
||||||
|
|
||||||
var item : PumpDbEntryTBR? = null
|
var item: PumpDbEntryTBR? = null
|
||||||
|
|
||||||
if (tbrs.size==1) {
|
if (tbrs.size == 1) {
|
||||||
item = tbrs[0]
|
item = tbrs[0]
|
||||||
} else {
|
} else {
|
||||||
for (tbr in tbrs) {
|
for (tbr in tbrs) {
|
||||||
|
@ -801,7 +811,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item!=null) {
|
if (item != null) {
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, "DD: cancelTBRWithTemporaryId: tempIdEntry=${item}")
|
aapsLogger.debug(LTag.PUMP, "DD: cancelTBRWithTemporaryId: tempIdEntry=${item}")
|
||||||
|
|
||||||
|
@ -814,18 +824,20 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
"duration=${differenceS} s, " +
|
"duration=${differenceS} s, " +
|
||||||
"isAbsolute=${!item.isAbsolute}, temporaryId=${item.temporaryId}, " +
|
"isAbsolute=${!item.isAbsolute}, temporaryId=${item.temporaryId}, " +
|
||||||
"pumpId=NO, pumpType=${medtronicPumpStatus.pumpType}, " +
|
"pumpId=NO, pumpType=${medtronicPumpStatus.pumpType}, " +
|
||||||
"pumpSerial=${medtronicPumpStatus.serialNumber}]")
|
"pumpSerial=${medtronicPumpStatus.serialNumber}]"
|
||||||
|
)
|
||||||
|
|
||||||
val result = pumpSync.syncTemporaryBasalWithTempId(
|
val result = pumpSync.syncTemporaryBasalWithTempId(
|
||||||
timestamp = item.date,
|
timestamp = item.date,
|
||||||
rate = item.rate,
|
rate = item.rate,
|
||||||
duration= differenceS * 1000L,
|
duration = differenceS * 1000L,
|
||||||
isAbsolute = item.isAbsolute,
|
isAbsolute = item.isAbsolute,
|
||||||
temporaryId = item.temporaryId,
|
temporaryId = item.temporaryId,
|
||||||
type = item.tbrType,
|
type = item.tbrType,
|
||||||
pumpId = null,
|
pumpId = null,
|
||||||
pumpType = medtronicPumpStatus.pumpType,
|
pumpType = medtronicPumpStatus.pumpType,
|
||||||
pumpSerial = medtronicPumpStatus.serialNumber)
|
pumpSerial = medtronicPumpStatus.serialNumber
|
||||||
|
)
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithTempId - Result: $result")
|
aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithTempId - Result: $result")
|
||||||
}
|
}
|
||||||
|
@ -834,7 +846,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
aapsLogger.info(LTag.PUMP, logPrefix + "cancelTBRWithTemporaryId - TBR items: ${tbrs.size}, runningTBRWithTemp=${medtronicPumpStatus.runningTBRWithTemp}")
|
aapsLogger.info(LTag.PUMP, logPrefix + "cancelTBRWithTemporaryId - TBR items: ${tbrs.size}, runningTBRWithTemp=${medtronicPumpStatus.runningTBRWithTemp}")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (medtronicPumpStatus.runningTBRWithTemp!=null) {
|
if (medtronicPumpStatus.runningTBRWithTemp != null) {
|
||||||
medtronicPumpStatus.runningTBRWithTemp = null
|
medtronicPumpStatus.runningTBRWithTemp = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -846,7 +858,10 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
} else {
|
} else {
|
||||||
var absoluteValue = profile.getBasal() * (percent / 100.0)
|
var absoluteValue = profile.getBasal() * (percent / 100.0)
|
||||||
absoluteValue = pumpDescription.pumpType.determineCorrectBasalSize(absoluteValue)
|
absoluteValue = pumpDescription.pumpType.determineCorrectBasalSize(absoluteValue)
|
||||||
aapsLogger.warn(LTag.PUMP, "setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% ($percent). This will start setTempBasalAbsolute, with calculated value ($absoluteValue). Result might not be 100% correct.")
|
aapsLogger.warn(
|
||||||
|
LTag.PUMP,
|
||||||
|
"setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% ($percent). This will start setTempBasalAbsolute, with calculated value ($absoluteValue). Result might not be 100% correct."
|
||||||
|
)
|
||||||
setTempBasalAbsolute(absoluteValue, durationInMinutes, profile, enforceNew, tbrType)
|
setTempBasalAbsolute(absoluteValue, durationInMinutes, profile, enforceNew, tbrType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -870,7 +885,8 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
scheduleNextRefresh(MedtronicStatusRefreshType.PumpTime, -1)
|
scheduleNextRefresh(MedtronicStatusRefreshType.PumpTime, -1)
|
||||||
}
|
}
|
||||||
if (medtronicPumpStatus.basalProfileStatus !== BasalProfileStatus.NotInitialized
|
if (medtronicPumpStatus.basalProfileStatus !== BasalProfileStatus.NotInitialized
|
||||||
&& medtronicHistoryData.hasBasalProfileChanged()) {
|
&& medtronicHistoryData.hasBasalProfileChanged()
|
||||||
|
) {
|
||||||
medtronicHistoryData.processLastBasalProfileChange(pumpDescription.pumpType, medtronicPumpStatus)
|
medtronicHistoryData.processLastBasalProfileChange(pumpDescription.pumpType, medtronicPumpStatus)
|
||||||
}
|
}
|
||||||
val previousState = pumpState
|
val previousState = pumpState
|
||||||
|
@ -890,7 +906,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
private fun readPumpHistoryLogic() {
|
private fun readPumpHistoryLogic() {
|
||||||
|
|
||||||
val debugHistory = false
|
val debugHistory = false
|
||||||
var targetDate: LocalDateTime? = null
|
val targetDate: LocalDateTime?
|
||||||
if (lastPumpHistoryEntry == null) { // first read
|
if (lastPumpHistoryEntry == null) { // first read
|
||||||
if (debugHistory) aapsLogger.debug(LTag.PUMP, logPrefix + "readPumpHistoryLogic(): lastPumpHistoryEntry: null")
|
if (debugHistory) aapsLogger.debug(LTag.PUMP, logPrefix + "readPumpHistoryLogic(): lastPumpHistoryEntry: null")
|
||||||
val lastPumpHistoryEntryTime = lastPumpEntryTime
|
val lastPumpHistoryEntryTime = lastPumpEntryTime
|
||||||
|
@ -898,13 +914,11 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
timeMinus36h = timeMinus36h.minusHours(36)
|
timeMinus36h = timeMinus36h.minusHours(36)
|
||||||
medtronicHistoryData.setIsInInit(true)
|
medtronicHistoryData.setIsInInit(true)
|
||||||
if (lastPumpHistoryEntryTime == 0L) {
|
if (lastPumpHistoryEntryTime == 0L) {
|
||||||
if (debugHistory) aapsLogger.debug(
|
if (debugHistory) aapsLogger.debug(LTag.PUMP, logPrefix + "readPumpHistoryLogic(): lastPumpHistoryEntryTime: 0L")
|
||||||
LTag.PUMP, logPrefix + "readPumpHistoryLogic(): lastPumpHistoryEntryTime: 0L - targetDate: "
|
|
||||||
+ targetDate)
|
|
||||||
targetDate = timeMinus36h
|
targetDate = timeMinus36h
|
||||||
} else {
|
} else {
|
||||||
// LocalDateTime lastHistoryRecordTime = DateTimeUtil.toLocalDateTime(lastPumpHistoryEntryTime);
|
// LocalDateTime lastHistoryRecordTime = DateTimeUtil.toLocalDateTime(lastPumpHistoryEntryTime);
|
||||||
if (debugHistory) aapsLogger.debug(LTag.PUMP, logPrefix + "readPumpHistoryLogic(): lastPumpHistoryEntryTime: " + lastPumpHistoryEntryTime + " - targetDate: " + targetDate)
|
if (debugHistory) aapsLogger.debug(LTag.PUMP, logPrefix + "readPumpHistoryLogic(): lastPumpHistoryEntryTime: " + lastPumpHistoryEntryTime)
|
||||||
//medtronicHistoryData.setLastHistoryRecordTime(lastPumpHistoryEntryTime)
|
//medtronicHistoryData.setLastHistoryRecordTime(lastPumpHistoryEntryTime)
|
||||||
var lastHistoryRecordTime = DateTimeUtil.toLocalDateTime(lastPumpHistoryEntryTime)
|
var lastHistoryRecordTime = DateTimeUtil.toLocalDateTime(lastPumpHistoryEntryTime)
|
||||||
lastHistoryRecordTime = lastHistoryRecordTime.minusHours(12) // we get last 12 hours of history to
|
lastHistoryRecordTime = lastHistoryRecordTime.minusHours(12) // we get last 12 hours of history to
|
||||||
|
@ -922,8 +936,10 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
|
|
||||||
//aapsLogger.debug(LTag.PUMP, "HST: Target Date: " + targetDate);
|
//aapsLogger.debug(LTag.PUMP, "HST: Target Date: " + targetDate);
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val responseTask2 = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(MedtronicCommandType.GetHistoryData,
|
val responseTask2 = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(
|
||||||
arrayListOf(/*lastPumpHistoryEntry*/ null, targetDate) as? ArrayList<Any>?)
|
MedtronicCommandType.GetHistoryData,
|
||||||
|
arrayListOf(/*lastPumpHistoryEntry*/ null, targetDate) as? ArrayList<Any>?
|
||||||
|
)
|
||||||
if (debugHistory) aapsLogger.debug(LTag.PUMP, "HST: After task")
|
if (debugHistory) aapsLogger.debug(LTag.PUMP, "HST: After task")
|
||||||
val historyResult = responseTask2?.result as PumpHistoryResult?
|
val historyResult = responseTask2?.result as PumpHistoryResult?
|
||||||
if (debugHistory) aapsLogger.debug(LTag.PUMP, "HST: History Result: " + historyResult.toString())
|
if (debugHistory) aapsLogger.debug(LTag.PUMP, "HST: History Result: " + historyResult.toString())
|
||||||
|
@ -981,8 +997,10 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicStatusRefreshType.PumpTime, MedtronicStatusRefreshType.Configuration, MedtronicStatusRefreshType.BatteryStatus, MedtronicStatusRefreshType.PumpHistory -> {
|
MedtronicStatusRefreshType.PumpTime, MedtronicStatusRefreshType.Configuration, MedtronicStatusRefreshType.BatteryStatus, MedtronicStatusRefreshType.PumpHistory -> {
|
||||||
workWithStatusRefresh(StatusRefreshAction.Add, refreshType,
|
workWithStatusRefresh(
|
||||||
getTimeInFutureFromMinutes(refreshType.refreshTime + additionalTimeInMinutes))
|
StatusRefreshAction.Add, refreshType,
|
||||||
|
getTimeInFutureFromMinutes(refreshType.refreshTime + additionalTimeInMinutes)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -993,9 +1011,11 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun workWithStatusRefresh(action: StatusRefreshAction, //
|
private fun workWithStatusRefresh(
|
||||||
|
action: StatusRefreshAction, //
|
||||||
statusRefreshType: MedtronicStatusRefreshType?, //
|
statusRefreshType: MedtronicStatusRefreshType?, //
|
||||||
time: Long?): Map<MedtronicStatusRefreshType, Long>? {
|
time: Long?
|
||||||
|
): Map<MedtronicStatusRefreshType, Long>? {
|
||||||
return when (action) {
|
return when (action) {
|
||||||
StatusRefreshAction.Add -> {
|
StatusRefreshAction.Add -> {
|
||||||
statusRefreshMap[statusRefreshType!!] = time!!
|
statusRefreshMap[statusRefreshType!!] = time!!
|
||||||
|
@ -1086,14 +1106,16 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
runningTBR.tbrType,
|
runningTBR.tbrType,
|
||||||
runningTBR.pumpId!!,
|
runningTBR.pumpId!!,
|
||||||
runningTBR.pumpType,
|
runningTBR.pumpType,
|
||||||
runningTBR.serialNumber)
|
runningTBR.serialNumber
|
||||||
|
)
|
||||||
|
|
||||||
val differenceTimeMin = floor(differenceTime / (60.0 * 1000.0))
|
val differenceTimeMin = floor(differenceTime / (60.0 * 1000.0))
|
||||||
|
|
||||||
aapsLogger.debug(
|
aapsLogger.debug(
|
||||||
LTag.PUMP, "canceling running TBR - syncTemporaryBasalWithPumpId [date=${runningTBR.date}, " +
|
LTag.PUMP, "canceling running TBR - syncTemporaryBasalWithPumpId [date=${runningTBR.date}, " +
|
||||||
"pumpId=${runningTBR.pumpId}, rate=${runningTBR.rate} U, duration=${differenceTimeMin.toInt()}, " +
|
"pumpId=${runningTBR.pumpId}, rate=${runningTBR.rate} U, duration=${differenceTimeMin.toInt()}, " +
|
||||||
"pumpSerial=${medtronicPumpStatus.serialNumber}] - Result: $result")
|
"pumpSerial=${medtronicPumpStatus.serialNumber}] - Result: $result"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1145,8 +1167,10 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
.enacted(false) //
|
.enacted(false) //
|
||||||
.comment(rh.gs(R.string.medtronic_cmd_set_profile_pattern_overflow, profileInvalid))
|
.comment(rh.gs(R.string.medtronic_cmd_set_profile_pattern_overflow, profileInvalid))
|
||||||
}
|
}
|
||||||
val responseTask = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(MedtronicCommandType.SetBasalProfileSTD,
|
val responseTask = rileyLinkMedtronicService?.medtronicUIComm?.executeCommand(
|
||||||
arrayListOf(basalProfile))
|
MedtronicCommandType.SetBasalProfileSTD,
|
||||||
|
arrayListOf(basalProfile)
|
||||||
|
)
|
||||||
val response = responseTask?.result as Boolean?
|
val response = responseTask?.result as Boolean?
|
||||||
aapsLogger.info(LTag.PUMP, logPrefix + "Basal Profile was set: " + response)
|
aapsLogger.info(LTag.PUMP, logPrefix + "Basal Profile was set: " + response)
|
||||||
return if (response == null || !response) {
|
return if (response == null || !response) {
|
||||||
|
@ -1184,18 +1208,24 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
|
|
||||||
// OPERATIONS not supported by Pump or Plugin
|
// OPERATIONS not supported by Pump or Plugin
|
||||||
private var customActions: List<CustomAction>? = null
|
private var customActions: List<CustomAction>? = null
|
||||||
private val customActionWakeUpAndTune = CustomAction(R.string.medtronic_custom_action_wake_and_tune,
|
private val customActionWakeUpAndTune = CustomAction(
|
||||||
MedtronicCustomActionType.WakeUpAndTune)
|
R.string.medtronic_custom_action_wake_and_tune,
|
||||||
|
MedtronicCustomActionType.WakeUpAndTune
|
||||||
|
)
|
||||||
private val customActionClearBolusBlock = CustomAction(
|
private val customActionClearBolusBlock = CustomAction(
|
||||||
R.string.medtronic_custom_action_clear_bolus_block, MedtronicCustomActionType.ClearBolusBlock, false)
|
R.string.medtronic_custom_action_clear_bolus_block, MedtronicCustomActionType.ClearBolusBlock, false
|
||||||
|
)
|
||||||
private val customActionResetRLConfig = CustomAction(
|
private val customActionResetRLConfig = CustomAction(
|
||||||
R.string.medtronic_custom_action_reset_rileylink, MedtronicCustomActionType.ResetRileyLinkConfiguration, true)
|
R.string.medtronic_custom_action_reset_rileylink, MedtronicCustomActionType.ResetRileyLinkConfiguration, true
|
||||||
|
)
|
||||||
|
|
||||||
override fun getCustomActions(): List<CustomAction>? {
|
override fun getCustomActions(): List<CustomAction>? {
|
||||||
if (customActions == null) {
|
if (customActions == null) {
|
||||||
customActions = listOf(customActionWakeUpAndTune, //
|
customActions = listOf(
|
||||||
|
customActionWakeUpAndTune, //
|
||||||
customActionClearBolusBlock, //
|
customActionClearBolusBlock, //
|
||||||
customActionResetRLConfig)
|
customActionResetRLConfig
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return customActions
|
return customActions
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ class RileyLinkBLEConfigActivity : DaggerAppCompatActivity() {
|
||||||
sp.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress)
|
sp.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress)
|
||||||
sp.putString(RileyLinkConst.Prefs.RileyLinkName, deviceName)
|
sp.putString(RileyLinkConst.Prefs.RileyLinkName, deviceName)
|
||||||
val rileyLinkPump = activePlugin.activePump as RileyLinkPumpDevice
|
val rileyLinkPump = activePlugin.activePump as RileyLinkPumpDevice
|
||||||
rileyLinkPump.rileyLinkService.verifyConfiguration(true) // force reloading of address to assure that the RL gets reconnected (even if the address didn't change)
|
rileyLinkPump.rileyLinkService?.verifyConfiguration(true) // force reloading of address to assure that the RL gets reconnected (even if the address didn't change)
|
||||||
rileyLinkPump.triggerPumpConfigurationChangedEvent()
|
rileyLinkPump.triggerPumpConfigurationChangedEvent()
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService;
|
|
||||||
|
|
||||||
public interface RileyLinkPumpDevice {
|
|
||||||
|
|
||||||
void setBusy(boolean busy);
|
|
||||||
|
|
||||||
void triggerPumpConfigurationChangedEvent();
|
|
||||||
|
|
||||||
RileyLinkService getRileyLinkService();
|
|
||||||
|
|
||||||
RileyLinkPumpInfo getPumpInfo();
|
|
||||||
|
|
||||||
long getLastConnectionTimeMillis();
|
|
||||||
|
|
||||||
void setLastCommunicationToNow();
|
|
||||||
}
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService
|
||||||
|
|
||||||
|
interface RileyLinkPumpDevice {
|
||||||
|
|
||||||
|
fun setBusy(busy: Boolean)
|
||||||
|
fun triggerPumpConfigurationChangedEvent()
|
||||||
|
val rileyLinkService: RileyLinkService?
|
||||||
|
val pumpInfo: RileyLinkPumpInfo
|
||||||
|
val lastConnectionTimeMillis: Long
|
||||||
|
fun setLastCommunicationToNow()
|
||||||
|
}
|
|
@ -40,7 +40,7 @@ class RileyLinkBroadcastReceiver : DaggerBroadcastReceiver() {
|
||||||
createBroadcastIdentifiers()
|
createBroadcastIdentifiers()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val rileyLinkService: RileyLinkService
|
private val rileyLinkService: RileyLinkService?
|
||||||
get() = (activePlugin.activePump as RileyLinkPumpDevice).rileyLinkService
|
get() = (activePlugin.activePump as RileyLinkPumpDevice).rileyLinkService
|
||||||
|
|
||||||
private fun createBroadcastIdentifiers() {
|
private fun createBroadcastIdentifiers() {
|
||||||
|
@ -102,13 +102,13 @@ class RileyLinkBroadcastReceiver : DaggerBroadcastReceiver() {
|
||||||
RileyLinkConst.Intents.RileyLinkReady -> {
|
RileyLinkConst.Intents.RileyLinkReady -> {
|
||||||
aapsLogger.warn(LTag.PUMPBTCOMM, "RileyLinkConst.Intents.RileyLinkReady")
|
aapsLogger.warn(LTag.PUMPBTCOMM, "RileyLinkConst.Intents.RileyLinkReady")
|
||||||
// sendIPCNotification(RT2Const.IPC.MSG_note_WakingPump);
|
// sendIPCNotification(RT2Const.IPC.MSG_note_WakingPump);
|
||||||
rileyLinkService.rileyLinkBLE.enableNotifications()
|
rileyLinkService?.rileyLinkBLE?.enableNotifications()
|
||||||
rileyLinkService.rfSpy.startReader() // call startReader from outside?
|
rileyLinkService?.rfSpy?.startReader() // call startReader from outside?
|
||||||
rileyLinkService.rfSpy.initializeRileyLink()
|
rileyLinkService?.rfSpy?.initializeRileyLink()
|
||||||
val bleVersion = rileyLinkService.rfSpy.bleVersionCached
|
val bleVersion = rileyLinkService?.rfSpy?.bleVersionCached
|
||||||
val rlVersion = rileyLinkServiceData.firmwareVersion
|
val rlVersion = rileyLinkServiceData.firmwareVersion
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "RfSpy version (BLE113): $bleVersion")
|
aapsLogger.debug(LTag.PUMPBTCOMM, "RfSpy version (BLE113): $bleVersion")
|
||||||
rileyLinkService.rileyLinkServiceData.versionBLE113 = bleVersion
|
rileyLinkService?.rileyLinkServiceData?.versionBLE113 = bleVersion
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "RfSpy Radio version (CC110): " + rlVersion.name)
|
aapsLogger.debug(LTag.PUMPBTCOMM, "RfSpy Radio version (CC110): " + rlVersion.name)
|
||||||
rileyLinkServiceData.firmwareVersion = rlVersion
|
rileyLinkServiceData.firmwareVersion = rlVersion
|
||||||
|
@ -122,12 +122,12 @@ class RileyLinkBroadcastReceiver : DaggerBroadcastReceiver() {
|
||||||
val rileylinkBLEAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "")
|
val rileylinkBLEAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "")
|
||||||
if (rileylinkBLEAddress == "") {
|
if (rileylinkBLEAddress == "") {
|
||||||
aapsLogger.error("No Rileylink BLE Address saved in app")
|
aapsLogger.error("No Rileylink BLE Address saved in app")
|
||||||
} else rileyLinkService.reconfigureRileyLink(rileylinkBLEAddress)
|
} else rileyLinkService?.reconfigureRileyLink(rileylinkBLEAddress)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
RileyLinkConst.Intents.RileyLinkDisconnect -> {
|
RileyLinkConst.Intents.RileyLinkDisconnect -> {
|
||||||
rileyLinkService.disconnectRileyLink()
|
rileyLinkService?.disconnectRileyLink()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ class RileyLinkBroadcastReceiver : DaggerBroadcastReceiver() {
|
||||||
|
|
||||||
RileyLinkConst.Intents.BluetoothReconnected -> {
|
RileyLinkConst.Intents.BluetoothReconnected -> {
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "Bluetooth - Reconnecting")
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Bluetooth - Reconnecting")
|
||||||
rileyLinkService.bluetoothInit()
|
rileyLinkService?.bluetoothInit()
|
||||||
serviceTaskExecutor.startTask(DiscoverGattServicesTask(injector, true))
|
serviceTaskExecutor.startTask(DiscoverGattServicesTask(injector, true))
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ class RileyLinkBroadcastReceiver : DaggerBroadcastReceiver() {
|
||||||
|
|
||||||
private fun processTuneUpBroadcasts(action: String): Boolean =
|
private fun processTuneUpBroadcasts(action: String): Boolean =
|
||||||
if (broadcastIdentifiers["TuneUp"]?.contains(action) == true) {
|
if (broadcastIdentifiers["TuneUp"]?.contains(action) == true) {
|
||||||
if (rileyLinkService.rileyLinkTargetDevice.isTuneUpEnabled) serviceTaskExecutor.startTask(WakeAndTuneTask(injector))
|
if (rileyLinkService?.rileyLinkTargetDevice?.isTuneUpEnabled == true) serviceTaskExecutor.startTask(WakeAndTuneTask(injector))
|
||||||
true
|
true
|
||||||
} else false
|
} else false
|
||||||
}
|
}
|
Loading…
Reference in a new issue