MedtronicPumpPlugin -> kt
This commit is contained in:
parent
88072ea752
commit
ad89d54319
1 changed files with 8 additions and 46 deletions
|
@ -201,9 +201,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
do {
|
do {
|
||||||
SystemClock.sleep(60000)
|
SystemClock.sleep(60000)
|
||||||
if (this.isInitialized) {
|
if (this.isInitialized) {
|
||||||
val statusRefresh = workWithStatusRefresh(
|
val statusRefresh = synchronized(statusRefreshMap) { HashMap(statusRefreshMap) }
|
||||||
StatusRefreshAction.GetData, null, null
|
|
||||||
)!!
|
|
||||||
if (doWeHaveAnyStatusNeededRefreshing(statusRefresh)) {
|
if (doWeHaveAnyStatusNeededRefreshing(statusRefresh)) {
|
||||||
if (!commandQueue.statusInQueue()) {
|
if (!commandQueue.statusInQueue()) {
|
||||||
commandQueue.readStatus(rh.gs(R.string.scheduled_status_refresh), null)
|
commandQueue.readStatus(rh.gs(R.string.scheduled_status_refresh), null)
|
||||||
|
@ -316,10 +314,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshAnyStatusThatNeedsToBeRefreshed() {
|
private fun refreshAnyStatusThatNeedsToBeRefreshed() {
|
||||||
val statusRefresh = workWithStatusRefresh(
|
val statusRefresh = synchronized(statusRefreshMap) { HashMap(statusRefreshMap) }
|
||||||
StatusRefreshAction.GetData, null,
|
|
||||||
null
|
|
||||||
)!!
|
|
||||||
if (!doWeHaveAnyStatusNeededRefreshing(statusRefresh)) {
|
if (!doWeHaveAnyStatusNeededRefreshing(statusRefresh)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -659,19 +654,9 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
@Suppress("SameParameterValue")
|
@Suppress("SameParameterValue")
|
||||||
private fun setNotReachable(isBolus: Boolean, success: Boolean): PumpEnactResult {
|
private fun setNotReachable(isBolus: Boolean, success: Boolean): PumpEnactResult {
|
||||||
setRefreshButtonEnabled(true)
|
setRefreshButtonEnabled(true)
|
||||||
if (isBolus) {
|
if (isBolus) bolusDeliveryType = BolusDeliveryType.Idle
|
||||||
bolusDeliveryType = BolusDeliveryType.Idle
|
return if (success) PumpEnactResult(injector).success(true).enacted(false)
|
||||||
}
|
else PumpEnactResult(injector).success(false).enacted(false).comment(R.string.medtronic_pump_status_pump_unreachable)
|
||||||
return if (success) {
|
|
||||||
PumpEnactResult(injector) //
|
|
||||||
.success(true) //
|
|
||||||
.enacted(false)
|
|
||||||
} else {
|
|
||||||
PumpEnactResult(injector) //
|
|
||||||
.success(false) //
|
|
||||||
.enacted(false) //
|
|
||||||
.comment(R.string.medtronic_pump_status_pump_unreachable)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun stopBolusDelivering() {
|
override fun stopBolusDelivering() {
|
||||||
|
@ -688,7 +673,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
// if enforceNew===true current temp basal is canceled and new TBR set (duration is prolonged),
|
// if enforceNew===true current temp basal is canceled and new TBR set (duration is prolonged),
|
||||||
// if false and the same rate is requested enacted=false and success=true is returned and TBR is not changed
|
// if false and the same rate is requested enacted=false and success=true is returned and TBR is not changed
|
||||||
@Synchronized
|
@Synchronized
|
||||||
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: TemporaryBasalType): PumpEnactResult {
|
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: TemporaryBasalType): PumpEnactResult {
|
||||||
setRefreshButtonEnabled(false)
|
setRefreshButtonEnabled(false)
|
||||||
|
@ -975,38 +960,15 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
MedtronicStatusRefreshType.RemainingInsulin -> {
|
MedtronicStatusRefreshType.RemainingInsulin -> {
|
||||||
val remaining = medtronicPumpStatus.reservoirRemainingUnits
|
val remaining = medtronicPumpStatus.reservoirRemainingUnits
|
||||||
val min: Int = if (remaining > 50) 4 * 60 else if (remaining > 20) 60 else 15
|
val min: Int = if (remaining > 50) 4 * 60 else if (remaining > 20) 60 else 15
|
||||||
workWithStatusRefresh(StatusRefreshAction.Add, refreshType, getTimeInFutureFromMinutes(min))
|
synchronized(statusRefreshMap) { statusRefreshMap[refreshType] = getTimeInFutureFromMinutes(min) }
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicStatusRefreshType.PumpTime, MedtronicStatusRefreshType.Configuration, MedtronicStatusRefreshType.BatteryStatus, MedtronicStatusRefreshType.PumpHistory -> {
|
MedtronicStatusRefreshType.PumpTime, MedtronicStatusRefreshType.Configuration, MedtronicStatusRefreshType.BatteryStatus, MedtronicStatusRefreshType.PumpHistory -> {
|
||||||
workWithStatusRefresh(
|
synchronized(statusRefreshMap) { statusRefreshMap[refreshType] = getTimeInFutureFromMinutes(refreshType.refreshTime + additionalTimeInMinutes) }
|
||||||
StatusRefreshAction.Add, refreshType,
|
|
||||||
getTimeInFutureFromMinutes(refreshType.refreshTime + additionalTimeInMinutes)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum class StatusRefreshAction {
|
|
||||||
Add, //
|
|
||||||
GetData
|
|
||||||
}
|
|
||||||
|
|
||||||
@Synchronized
|
|
||||||
private fun workWithStatusRefresh(action: StatusRefreshAction, statusRefreshType: MedtronicStatusRefreshType?, time: Long?): Map<MedtronicStatusRefreshType, Long>? {
|
|
||||||
return when (action) {
|
|
||||||
StatusRefreshAction.Add -> {
|
|
||||||
statusRefreshMap[statusRefreshType!!] = time!!
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
StatusRefreshAction.GetData -> {
|
|
||||||
HashMap(statusRefreshMap)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getTimeInFutureFromMinutes(minutes: Int): Long {
|
private fun getTimeInFutureFromMinutes(minutes: Int): Long {
|
||||||
return System.currentTimeMillis() + getTimeInMs(minutes)
|
return System.currentTimeMillis() + getTimeInMs(minutes)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue