comboctl-main: During corrective short button presses check screens

After a long button press, short button presses may be necessary to
fix "overshoots". An alert screen may appear during those short button
presses, so look at the screens to make sure alerts are not missed.

Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
This commit is contained in:
Carlos Rafael Giani 2022-11-20 18:36:18 +01:00
parent 8b2666ff74
commit 96c8145dc3

View file

@ -845,12 +845,33 @@ suspend fun adjustQuantityOnScreen(
incrementButton = incrementButton,
decrementButton = decrementButton
)
logger(LogLevel.DEBUG) {
"Need to short-press the $shortRTButtonToPress " +
"RT button $numNeededShortRTButtonPresses time(s)"
}
repeat(numNeededShortRTButtonPresses) {
rtNavigationContext.shortPressButton(shortRTButtonToPress)
if (numNeededShortRTButtonPresses != 0) {
logger(LogLevel.DEBUG) {
"Need to short-press the $shortRTButtonToPress " +
"RT button $numNeededShortRTButtonPresses time(s)"
}
repeat(numNeededShortRTButtonPresses) {
// Get display frames. We don't actually do anything with the frame
// (other than check for a blinked-out screen); this here is done
// just to avoid missing alert screens while we short-press the button.
// If an alert screen appears, getParsedDisplayFrame() throws an
// AlertScreenException, the caller handles the exception, and if the
// operation that was being performed before the alert screen appeared
// can be retried, the caller can attempt to do so.
while (true) {
val displayFrame = rtNavigationContext.getParsedDisplayFrame(processAlertScreens = true, filterDuplicates = true)
if ((displayFrame != null) && displayFrame.parsedScreen.isBlinkedOut) {
logger(LogLevel.DEBUG) { "Screen is blinked out (contents: ${displayFrame.parsedScreen}); skipping" }
continue
}
break
}
rtNavigationContext.shortPressButton(shortRTButtonToPress)
}
} else {
logger(LogLevel.DEBUG) {
"Quantity on screen is already equal to target quantity; no need to press any button"
}
}
}