combov2: Also limit TBR percentage when AAPS sets absolute TBR
Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
This commit is contained in:
parent
d50feec302
commit
cc26eb8ed8
1 changed files with 10 additions and 28 deletions
|
@ -95,6 +95,7 @@ import org.json.JSONObject
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@ -908,13 +909,11 @@ class ComboV2Plugin @Inject constructor (
|
||||||
// and the percentage must be an integer multiple
|
// and the percentage must be an integer multiple
|
||||||
// of 10, otherwise the Combo won't accept it.
|
// of 10, otherwise the Combo won't accept it.
|
||||||
|
|
||||||
val percentage = (absoluteRate / baseBasalRate * 100).toInt()
|
val percentage = absoluteRate / baseBasalRate * 100
|
||||||
val roundedPercentage = (absoluteRate / baseBasalRate * 10).roundToInt() * 10
|
val roundedPercentage = ((absoluteRate / baseBasalRate * 10).roundToInt() * 10)
|
||||||
|
val limitedPercentage = min(roundedPercentage, _pumpDescription.maxTempPercent)
|
||||||
|
|
||||||
if (percentage != roundedPercentage)
|
aapsLogger.debug(LTag.PUMP, "Calculated percentage of $percentage% out of absolute rate $absoluteRate; rounded to: $roundedPercentage%; limited to: $limitedPercentage%")
|
||||||
aapsLogger.debug(LTag.PUMP, "Calculated percentage of $percentage% out of absolute rate $absoluteRate; rounded percentage to $roundedPercentage%")
|
|
||||||
else
|
|
||||||
aapsLogger.debug(LTag.PUMP, "Calculated percentage of $percentage% out of absolute rate $absoluteRate")
|
|
||||||
|
|
||||||
val cctlTbrType = when (tbrType) {
|
val cctlTbrType = when (tbrType) {
|
||||||
PumpSync.TemporaryBasalType.NORMAL -> ComboCtlTbr.Type.NORMAL
|
PumpSync.TemporaryBasalType.NORMAL -> ComboCtlTbr.Type.NORMAL
|
||||||
|
@ -923,7 +922,7 @@ class ComboV2Plugin @Inject constructor (
|
||||||
PumpSync.TemporaryBasalType.SUPERBOLUS -> ComboCtlTbr.Type.SUPERBOLUS
|
PumpSync.TemporaryBasalType.SUPERBOLUS -> ComboCtlTbr.Type.SUPERBOLUS
|
||||||
}
|
}
|
||||||
|
|
||||||
setTbrInternal(roundedPercentage, durationInMinutes, cctlTbrType, force100Percent = false, pumpEnactResult)
|
setTbrInternal(limitedPercentage, durationInMinutes, cctlTbrType, force100Percent = false, pumpEnactResult)
|
||||||
|
|
||||||
return pumpEnactResult
|
return pumpEnactResult
|
||||||
}
|
}
|
||||||
|
@ -932,26 +931,9 @@ class ComboV2Plugin @Inject constructor (
|
||||||
val pumpEnactResult = PumpEnactResult(injector)
|
val pumpEnactResult = PumpEnactResult(injector)
|
||||||
pumpEnactResult.isPercent = true
|
pumpEnactResult.isPercent = true
|
||||||
|
|
||||||
val adjustedPercentage = percent
|
val roundedPercentage = ((percent + 5) / 10) * 10
|
||||||
.let {
|
val limitedPercentage = min(roundedPercentage, _pumpDescription.maxTempPercent)
|
||||||
if (it > _pumpDescription.maxTempPercent) {
|
aapsLogger.debug(LTag.PUMP, "Got percentage of $percent%; rounded to: $roundedPercentage%; limited to: $limitedPercentage%")
|
||||||
aapsLogger.debug(
|
|
||||||
LTag.PUMP,
|
|
||||||
"Reducing requested TBR to the maximum support " +
|
|
||||||
"by the pump: $percent -> ${_pumpDescription.maxTempPercent}"
|
|
||||||
)
|
|
||||||
_pumpDescription.maxTempPercent
|
|
||||||
} else
|
|
||||||
it
|
|
||||||
}
|
|
||||||
.let {
|
|
||||||
val roundedPercentage = ((it + 5) / 10) * 10
|
|
||||||
if (roundedPercentage != it) {
|
|
||||||
aapsLogger.debug(LTag.PUMP, "Rounded requested percentage:$it -> $roundedPercentage")
|
|
||||||
roundedPercentage
|
|
||||||
} else
|
|
||||||
it
|
|
||||||
}
|
|
||||||
|
|
||||||
val cctlTbrType = when (tbrType) {
|
val cctlTbrType = when (tbrType) {
|
||||||
PumpSync.TemporaryBasalType.NORMAL -> ComboCtlTbr.Type.NORMAL
|
PumpSync.TemporaryBasalType.NORMAL -> ComboCtlTbr.Type.NORMAL
|
||||||
|
@ -960,7 +942,7 @@ class ComboV2Plugin @Inject constructor (
|
||||||
PumpSync.TemporaryBasalType.SUPERBOLUS -> ComboCtlTbr.Type.SUPERBOLUS
|
PumpSync.TemporaryBasalType.SUPERBOLUS -> ComboCtlTbr.Type.SUPERBOLUS
|
||||||
}
|
}
|
||||||
|
|
||||||
setTbrInternal(adjustedPercentage, durationInMinutes, cctlTbrType, force100Percent = false, pumpEnactResult)
|
setTbrInternal(limitedPercentage, durationInMinutes, cctlTbrType, force100Percent = false, pumpEnactResult)
|
||||||
|
|
||||||
return pumpEnactResult
|
return pumpEnactResult
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue