comboctl-parser: Support main screens with ext/multiwave and TBR symbols

Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
This commit is contained in:
Carlos Rafael Giani 2022-11-13 20:12:31 +01:00
parent e9294c59a0
commit 8d6171db49
3 changed files with 73 additions and 5 deletions

View file

@ -70,6 +70,7 @@ sealed class MainScreenContent {
val remainingBolusDurationInMinutes: Int, val remainingBolusDurationInMinutes: Int,
val isExtendedBolus: Boolean, val isExtendedBolus: Boolean,
val remainingBolusAmount: Int, val remainingBolusAmount: Int,
val tbrIsActive: Boolean,
val activeBasalProfileNumber: Int, val activeBasalProfileNumber: Int,
val currentBasalRateFactor: Int, val currentBasalRateFactor: Int,
val batteryState: BatteryState val batteryState: BatteryState
@ -1381,6 +1382,7 @@ class ExtendedAndMultiwaveBolusMainScreenParser : Parser() {
SingleGlyphParser(Glyph.SmallSymbol(SmallSymbol.ARROW)), SingleGlyphParser(Glyph.SmallSymbol(SmallSymbol.ARROW)),
TimeParser(), // Remaining extended/multiwave bolus duration TimeParser(), // Remaining extended/multiwave bolus duration
SingleGlyphTypeParser(Glyph.LargeSymbol::class), // Extended / multiwave symbol SingleGlyphTypeParser(Glyph.LargeSymbol::class), // Extended / multiwave symbol
OptionalParser(SingleGlyphTypeParser(Glyph.SmallSymbol::class)), // TBR arrow up/down symbol (only present if TBR is active)
DecimalParser(), // Remaining bolus amount DecimalParser(), // Remaining bolus amount
SingleGlyphParser(Glyph.LargeCharacter('u')), SingleGlyphParser(Glyph.LargeCharacter('u')),
SingleGlyphTypeParser(Glyph.SmallDigit::class), // Active basal rate number SingleGlyphTypeParser(Glyph.SmallDigit::class), // Active basal rate number
@ -1395,7 +1397,7 @@ class ExtendedAndMultiwaveBolusMainScreenParser : Parser() {
return ParseResult.Failed return ParseResult.Failed
parseResult as ParseResult.Sequence parseResult as ParseResult.Sequence
if (parseResult.size < 5) if (parseResult.size < 6)
return ParseResult.Failed return ParseResult.Failed
// At that location, only the extended and multiwave bolus symbols // At that location, only the extended and multiwave bolus symbols
@ -1406,8 +1408,15 @@ class ExtendedAndMultiwaveBolusMainScreenParser : Parser() {
else -> return ParseResult.Failed else -> return ParseResult.Failed
} }
val tbrIsActive = when (parseResult.valueAtOrNull<Glyph.SmallSymbol>(2)?.symbol) {
SmallSymbol.UP,
SmallSymbol.DOWN -> true
null -> false
else -> return ParseResult.Failed
}
val batteryState = batteryStateFromSymbol( val batteryState = batteryStateFromSymbol(
if (parseResult.size >= 6) parseResult.valueAt<Glyph.SmallSymbol>(5).symbol else null if (parseResult.size >= 7) parseResult.valueAt<Glyph.SmallSymbol>(5).symbol else null
) )
val remainingBolusDuration = parseResult.valueAt<LocalDateTime>(0) val remainingBolusDuration = parseResult.valueAt<LocalDateTime>(0)
@ -1418,9 +1427,10 @@ class ExtendedAndMultiwaveBolusMainScreenParser : Parser() {
currentTime = parseContext.topLeftTime!!, currentTime = parseContext.topLeftTime!!,
remainingBolusDurationInMinutes = remainingBolusDuration.hour * 60 + remainingBolusDuration.minute, remainingBolusDurationInMinutes = remainingBolusDuration.hour * 60 + remainingBolusDuration.minute,
isExtendedBolus = isExtendedBolus, isExtendedBolus = isExtendedBolus,
remainingBolusAmount = parseResult.valueAt<Int>(2), remainingBolusAmount = parseResult.valueAt<Int>(3),
activeBasalProfileNumber = parseResult.valueAt<Glyph.SmallDigit>(3).digit, tbrIsActive = tbrIsActive,
currentBasalRateFactor = parseResult.valueAt<Int>(4), activeBasalProfileNumber = parseResult.valueAt<Glyph.SmallDigit>(4).digit,
currentBasalRateFactor = parseResult.valueAt<Int>(5),
batteryState = batteryState batteryState = batteryState
) )
) )

View file

@ -480,6 +480,7 @@ class ParserTest {
remainingBolusDurationInMinutes = 3 * 60 + 0, remainingBolusDurationInMinutes = 3 * 60 + 0,
isExtendedBolus = true, isExtendedBolus = true,
remainingBolusAmount = 2300, remainingBolusAmount = 2300,
tbrIsActive = false,
activeBasalProfileNumber = 1, activeBasalProfileNumber = 1,
currentBasalRateFactor = 790, currentBasalRateFactor = 790,
batteryState = BatteryState.FULL_BATTERY batteryState = BatteryState.FULL_BATTERY
@ -488,6 +489,27 @@ class ParserTest {
) )
} }
@Test
fun checkExtendedBolusWithTbrMainScreenParsing() {
val testContext = TestContext(testFrameMainScreenWithExtendedBolusInfoAndTbr, 1, parseTopLeftTime = true)
val result = ExtendedAndMultiwaveBolusMainScreenParser().parse(testContext.parseContext)
assertEquals(ParseResult.Value::class, result::class)
val screen = (result as ParseResult.Value<*>).value as ParsedScreen.MainScreen
assertEquals(
MainScreenContent.ExtendedOrMultiwaveBolus(
currentTime = testContext.parseContext.topLeftTime!!,
remainingBolusDurationInMinutes = 1 * 60 + 31,
isExtendedBolus = true,
remainingBolusAmount = 1300,
tbrIsActive = true,
activeBasalProfileNumber = 1,
currentBasalRateFactor = 384,
batteryState = BatteryState.FULL_BATTERY
),
screen.content
)
}
@Test @Test
fun checkMultiwaveBolusMainScreenParsing() { fun checkMultiwaveBolusMainScreenParsing() {
val testContext = TestContext(testFrameMainScreenWithMultiwaveBolusInfo, 1, parseTopLeftTime = true) val testContext = TestContext(testFrameMainScreenWithMultiwaveBolusInfo, 1, parseTopLeftTime = true)
@ -501,6 +523,7 @@ class ParserTest {
remainingBolusDurationInMinutes = 1 * 60 + 30, remainingBolusDurationInMinutes = 1 * 60 + 30,
isExtendedBolus = false, isExtendedBolus = false,
remainingBolusAmount = 1700, remainingBolusAmount = 1700,
tbrIsActive = false,
activeBasalProfileNumber = 1, activeBasalProfileNumber = 1,
currentBasalRateFactor = 790, currentBasalRateFactor = 790,
batteryState = BatteryState.FULL_BATTERY batteryState = BatteryState.FULL_BATTERY

View file

@ -195,6 +195,41 @@ val testFrameMainScreenWithExtendedBolusInfo = makeDisplayFrame(arrayOf(
" ███ ██ █ ██ ███ ██ █ █ █ " " ███ ██ █ ██ ███ ██ █ █ █ "
)) ))
val testFrameMainScreenWithExtendedBolusInfoAndTbr = makeDisplayFrame(arrayOf(
" ███ █ █████ █ █ █ ███ █ █████ █ ",
" █ █ █ ██ █ ██ ██ ██ █ █ ██ ██ █ ██ ",
"█ █ █ █ ████ █ █ █ ███████ █ ██ █ ██ █ █ ",
"█ ██ █ █ █ █ █ █ ████████ █ █ █ █ █ █ ",
"█ █ █ █ █████ █ ███████ ██ █ █ ██ █ █ ",
" █ █ █ █ █ █ █ ██ █ █ █ ██ █ █ █ ",
" ███ ███ ███ █ ███ █ ███ ███ ███ ███ ",
" ",
" ███ ██ █████ ",
"█████████████ ███ ███ ██ ██ ",
"█████████████ ███ ████ ██ ",
"██ ██ ███████ ██ ██ ██ ██ ",
"██ ██ █████ ██ ██ ██ ██ ",
"██ ██ ███ ██ ██ ██ ██ ",
"██ ██ █ ██ ███ ██ ██ ",
"██ ██ ██ ██ ██ ██ ",
"██ ██ █ ██ ██ ██ ██ ",
"██ ██ ██ ██ ██ ██ ██ ",
"██ ██ █ ██ ██ ██ ██ ",
"██ ██ █ ██ ██ ██ ██ ",
"██ ██ █ ██ ███ ██ ██ ██ ",
"██ █████ █ ██ ███ ██ ██ ██ ██ ",
"██ █████ ███ ██ ███ █████ ████ ",
" ",
" ",
" ███ █████ ███ █ █ █ █ █ ",
"█ █ █ █ █ ██ █ █ █ █ ",
"█ ██ █ █ █ █ █ █ █ █ █ █ ",
"█ █ █ █ ███ █ █ █ █ █ ██ █ ",
"██ █ █ █ █ █████ █ █ █ █ █ ",
"█ █ ██ █ █ █ █ █ █ █ █ █ █ ",
" ███ ██ ███ ███ █ ██ █ █ █ "
))
val testFrameMainScreenWithMultiwaveBolusInfo = makeDisplayFrame(arrayOf( val testFrameMainScreenWithMultiwaveBolusInfo = makeDisplayFrame(arrayOf(
" ███ ███ ███ ███ ███ █ ███ █ █████ ███ ", " ███ ███ ███ ███ ███ █ ███ █ █████ ███ ",
" █ █ █ █ █ █ █ ██ █ █ █ █ ██ █ █ ██ ██ █ █ █", " █ █ █ █ █ █ █ ██ █ █ █ █ ██ █ █ ██ ██ █ █ █",