Merge pull request #2531 from jbr7rr/dash-fix-long-0temp
Dash: Workaround for long 0temp
This commit is contained in:
commit
4a1ed1f584
|
@ -22,10 +22,15 @@ object ProgramTempBasalUtil {
|
|||
fun mapTempBasalToTenthPulsesPerSlot(durationInSlots: Int, rateInUnitsPerHour: Double): ShortArray {
|
||||
val pulsesPerHour = (rateInUnitsPerHour * 20).roundToInt().toShort()
|
||||
val tenthPulsesPerSlot = ShortArray(durationInSlots)
|
||||
var i = 0
|
||||
while (durationInSlots > i) {
|
||||
tenthPulsesPerSlot[i] = (roundToHalf(pulsesPerHour / 2.0) * 10).toInt().toShort()
|
||||
i++
|
||||
val tenthPulsesPerSlotShort = if (pulsesPerHour == 0.toShort() && durationInSlots > 4) {
|
||||
// Workaround for 0.0 U/h long temp basals being cancelled by pod
|
||||
// This will result in a 0.01 U/h temp basal for 0temps > 120 minutes
|
||||
1.toShort()
|
||||
} else {
|
||||
(roundToHalf(pulsesPerHour / 2.0) * 10).toInt().toShort()
|
||||
}
|
||||
for (i in tenthPulsesPerSlot.indices) {
|
||||
tenthPulsesPerSlot[i] = tenthPulsesPerSlotShort
|
||||
}
|
||||
return tenthPulsesPerSlot
|
||||
}
|
||||
|
|
|
@ -35,7 +35,39 @@ class ProgramTempBasalCommandTest {
|
|||
.build()
|
||||
|
||||
Assert.assertArrayEquals(
|
||||
Hex.decodeHex("024200011C201A0E494E532E0100820A384000009000160EC000000A6B49D200000AEB49D20001DE"),
|
||||
Hex.decodeHex("024200011C201A0E494E532E0100820A384000009000160EC000000A6B49D200000A6B49D20001E3"),
|
||||
command.encoded
|
||||
)
|
||||
}
|
||||
|
||||
@Test @Throws(DecoderException::class) fun testZeroTempBasalShort() {
|
||||
val command = ProgramTempBasalCommand.Builder()
|
||||
.setUniqueId(37879809)
|
||||
.setNonce(1229869870)
|
||||
.setSequenceNumber(7.toShort())
|
||||
.setRateInUnitsPerHour(0.0)
|
||||
.setDurationInMinutes(30.toShort())
|
||||
.setProgramReminder(ProgramReminder(true, true, 0.toByte()))
|
||||
.build()
|
||||
|
||||
Assert.assertArrayEquals(
|
||||
Hex.decodeHex("024200011C201A0E494E532E01007901384000000000160EC00000016B49D2000001EB49D200815B"),
|
||||
command.encoded
|
||||
)
|
||||
}
|
||||
|
||||
@Test @Throws(DecoderException::class) fun testZeroTempBasalVeryLong() {
|
||||
val command = ProgramTempBasalCommand.Builder()
|
||||
.setUniqueId(37879809)
|
||||
.setNonce(1229869870)
|
||||
.setSequenceNumber(7.toShort())
|
||||
.setRateInUnitsPerHour(0.0)
|
||||
.setDurationInMinutes(720.toShort())
|
||||
.setProgramReminder(ProgramReminder(true, true, 0.toByte()))
|
||||
.build()
|
||||
|
||||
Assert.assertArrayEquals(
|
||||
Hex.decodeHex("024200011C221A10494E532E0100901838400000F0007000160EC00000186B49D20000186B49D2000132"),
|
||||
command.encoded
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue