Fix bug with button choice on MMU error screen isn't reset

PFW-1381
This commit is contained in:
Guðni Már Gilbert 2023-01-15 13:17:11 +00:00 committed by DRracer
parent d2f3835b2c
commit a35e7d543f
1 changed files with 11 additions and 3 deletions

View File

@ -101,6 +101,7 @@ static uint8_t ReportErrorHookMonitor(uint8_t ei) {
uint8_t ret = 0;
bool two_choices = false;
static int8_t enc_dif = lcd_encoder_diff;
static uint8_t reset_button_selection = 1;
if (lcd_encoder_diff == 0)
{
@ -123,6 +124,14 @@ static uint8_t ReportErrorHookMonitor(uint8_t ei) {
static int8_t current_selection = two_choices ? LCD_LEFT_BUTTON_CHOICE : LCD_MIDDLE_BUTTON_CHOICE;
static int8_t choice_selected = -1;
if (reset_button_selection) {
// If a new error screen is shown, we must reset the button selection
// Default selection is different depending on how many buttons are present
current_selection = two_choices ? LCD_LEFT_BUTTON_CHOICE : LCD_MIDDLE_BUTTON_CHOICE;
choice_selected = -1;
reset_button_selection = 0;
}
// Check if knob was rotated
if (abs(enc_dif - lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
if (two_choices == false) { // third_choice is not nullptr, safe to dereference
@ -203,9 +212,8 @@ static uint8_t ReportErrorHookMonitor(uint8_t ei) {
ret = 2;
}
// Reset static variables to their default value
current_selection = two_choices ? LCD_LEFT_BUTTON_CHOICE : LCD_MIDDLE_BUTTON_CHOICE;
choice_selected = -1;
// Next MMU error screen should reset the choice selection
reset_button_selection = 1;
return ret;
}