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:
parent
e9294c59a0
commit
8d6171db49
|
@ -70,6 +70,7 @@ sealed class MainScreenContent {
|
|||
val remainingBolusDurationInMinutes: Int,
|
||||
val isExtendedBolus: Boolean,
|
||||
val remainingBolusAmount: Int,
|
||||
val tbrIsActive: Boolean,
|
||||
val activeBasalProfileNumber: Int,
|
||||
val currentBasalRateFactor: Int,
|
||||
val batteryState: BatteryState
|
||||
|
@ -1381,6 +1382,7 @@ class ExtendedAndMultiwaveBolusMainScreenParser : Parser() {
|
|||
SingleGlyphParser(Glyph.SmallSymbol(SmallSymbol.ARROW)),
|
||||
TimeParser(), // Remaining extended/multiwave bolus duration
|
||||
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
|
||||
SingleGlyphParser(Glyph.LargeCharacter('u')),
|
||||
SingleGlyphTypeParser(Glyph.SmallDigit::class), // Active basal rate number
|
||||
|
@ -1395,7 +1397,7 @@ class ExtendedAndMultiwaveBolusMainScreenParser : Parser() {
|
|||
return ParseResult.Failed
|
||||
|
||||
parseResult as ParseResult.Sequence
|
||||
if (parseResult.size < 5)
|
||||
if (parseResult.size < 6)
|
||||
return ParseResult.Failed
|
||||
|
||||
// At that location, only the extended and multiwave bolus symbols
|
||||
|
@ -1406,8 +1408,15 @@ class ExtendedAndMultiwaveBolusMainScreenParser : Parser() {
|
|||
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(
|
||||
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)
|
||||
|
@ -1418,9 +1427,10 @@ class ExtendedAndMultiwaveBolusMainScreenParser : Parser() {
|
|||
currentTime = parseContext.topLeftTime!!,
|
||||
remainingBolusDurationInMinutes = remainingBolusDuration.hour * 60 + remainingBolusDuration.minute,
|
||||
isExtendedBolus = isExtendedBolus,
|
||||
remainingBolusAmount = parseResult.valueAt<Int>(2),
|
||||
activeBasalProfileNumber = parseResult.valueAt<Glyph.SmallDigit>(3).digit,
|
||||
currentBasalRateFactor = parseResult.valueAt<Int>(4),
|
||||
remainingBolusAmount = parseResult.valueAt<Int>(3),
|
||||
tbrIsActive = tbrIsActive,
|
||||
activeBasalProfileNumber = parseResult.valueAt<Glyph.SmallDigit>(4).digit,
|
||||
currentBasalRateFactor = parseResult.valueAt<Int>(5),
|
||||
batteryState = batteryState
|
||||
)
|
||||
)
|
||||
|
|
|
@ -480,6 +480,7 @@ class ParserTest {
|
|||
remainingBolusDurationInMinutes = 3 * 60 + 0,
|
||||
isExtendedBolus = true,
|
||||
remainingBolusAmount = 2300,
|
||||
tbrIsActive = false,
|
||||
activeBasalProfileNumber = 1,
|
||||
currentBasalRateFactor = 790,
|
||||
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
|
||||
fun checkMultiwaveBolusMainScreenParsing() {
|
||||
val testContext = TestContext(testFrameMainScreenWithMultiwaveBolusInfo, 1, parseTopLeftTime = true)
|
||||
|
@ -501,6 +523,7 @@ class ParserTest {
|
|||
remainingBolusDurationInMinutes = 1 * 60 + 30,
|
||||
isExtendedBolus = false,
|
||||
remainingBolusAmount = 1700,
|
||||
tbrIsActive = false,
|
||||
activeBasalProfileNumber = 1,
|
||||
currentBasalRateFactor = 790,
|
||||
batteryState = BatteryState.FULL_BATTERY
|
||||
|
|
|
@ -195,6 +195,41 @@ val testFrameMainScreenWithExtendedBolusInfo = makeDisplayFrame(arrayOf(
|
|||
" ███ ██ █ ██ ███ ██ █ █ █ "
|
||||
))
|
||||
|
||||
val testFrameMainScreenWithExtendedBolusInfoAndTbr = makeDisplayFrame(arrayOf(
|
||||
" ███ █ █████ █ █ █ ███ █ █████ █ ",
|
||||
" █ █ █ ██ █ ██ ██ ██ █ █ ██ ██ █ ██ ",
|
||||
"█ █ █ █ ████ █ █ █ ███████ █ ██ █ ██ █ █ ",
|
||||
"█ ██ █ █ █ █ █ █ ████████ █ █ █ █ █ █ ",
|
||||
"█ █ █ █ █████ █ ███████ ██ █ █ ██ █ █ ",
|
||||
" █ █ █ █ █ █ █ ██ █ █ █ ██ █ █ █ ",
|
||||
" ███ ███ ███ █ ███ █ ███ ███ ███ ███ ",
|
||||
" ",
|
||||
" ███ ██ █████ ",
|
||||
"█████████████ ███ ███ ██ ██ ",
|
||||
"█████████████ ███ ████ ██ ",
|
||||
"██ ██ ███████ ██ ██ ██ ██ ",
|
||||
"██ ██ █████ ██ ██ ██ ██ ",
|
||||
"██ ██ ███ ██ ██ ██ ██ ",
|
||||
"██ ██ █ ██ ███ ██ ██ ",
|
||||
"██ ██ ██ ██ ██ ██ ",
|
||||
"██ ██ █ ██ ██ ██ ██ ",
|
||||
"██ ██ ██ ██ ██ ██ ██ ",
|
||||
"██ ██ █ ██ ██ ██ ██ ",
|
||||
"██ ██ █ ██ ██ ██ ██ ",
|
||||
"██ ██ █ ██ ███ ██ ██ ██ ",
|
||||
"██ █████ █ ██ ███ ██ ██ ██ ██ ",
|
||||
"██ █████ ███ ██ ███ █████ ████ ",
|
||||
" ",
|
||||
" ",
|
||||
" ███ █████ ███ █ █ █ █ █ ",
|
||||
"█ █ █ █ █ ██ █ █ █ █ ",
|
||||
"█ ██ █ █ █ █ █ █ █ █ █ █ ",
|
||||
"█ █ █ █ ███ █ █ █ █ █ ██ █ ",
|
||||
"██ █ █ █ █ █████ █ █ █ █ █ ",
|
||||
"█ █ ██ █ █ █ █ █ █ █ █ █ █ ",
|
||||
" ███ ██ ███ ███ █ ██ █ █ █ "
|
||||
))
|
||||
|
||||
val testFrameMainScreenWithMultiwaveBolusInfo = makeDisplayFrame(arrayOf(
|
||||
" ███ ███ ███ ███ ███ █ ███ █ █████ ███ ",
|
||||
" █ █ █ █ █ █ █ ██ █ █ █ █ ██ █ █ ██ ██ █ █ █",
|
||||
|
|
Loading…
Reference in a new issue