From 894688c547c5a7f880bca628dfe235967134e230 Mon Sep 17 00:00:00 2001 From: ellensp Date: Thu, 11 Mar 2021 11:02:35 +1300 Subject: [PATCH] Fix password menu stickiness before first auth (#21295) --- Marlin/src/feature/password/password.cpp | 11 +++++++---- Marlin/src/feature/password/password.h | 4 ++-- Marlin/src/lcd/menu/menu_password.cpp | 13 +++++++++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Marlin/src/feature/password/password.cpp b/Marlin/src/feature/password/password.cpp index 90bb64711..4e841c243 100644 --- a/Marlin/src/feature/password/password.cpp +++ b/Marlin/src/feature/password/password.cpp @@ -31,7 +31,7 @@ Password password; // public: -bool Password::is_set, Password::is_locked; +bool Password::is_set, Password::is_locked, Password::did_first_run; // = false uint32_t Password::value, Password::value_entry; // @@ -47,11 +47,14 @@ void Password::lock_machine() { // Authentication check // void Password::authentication_check() { - if (value_entry == value) + if (value_entry == value) { is_locked = false; - else + did_first_run = true; + } + else { + is_locked = true; SERIAL_ECHOLNPGM(STR_WRONG_PASSWORD); - + } TERN_(HAS_LCD_MENU, authentication_done()); } diff --git a/Marlin/src/feature/password/password.h b/Marlin/src/feature/password/password.h index 1382d6df4..829d222e2 100644 --- a/Marlin/src/feature/password/password.h +++ b/Marlin/src/feature/password/password.h @@ -25,10 +25,10 @@ class Password { public: - static bool is_set, is_locked; + static bool is_set, is_locked, did_first_run; static uint32_t value, value_entry; - Password() { is_locked = false; } + Password() {} static void lock_machine(); static void authentication_check(); diff --git a/Marlin/src/lcd/menu/menu_password.cpp b/Marlin/src/lcd/menu/menu_password.cpp index 80c5c3dc6..590ce48d5 100644 --- a/Marlin/src/lcd/menu/menu_password.cpp +++ b/Marlin/src/lcd/menu/menu_password.cpp @@ -44,12 +44,18 @@ static uint8_t digit_no; // Screen for both editing and setting the password // void Password::menu_password_entry() { + ui.defer_status_screen(!did_first_run); // No timeout to status before first auth + START_MENU(); // "Login" or "New Code" STATIC_ITEM_P(authenticating ? GET_TEXT(MSG_LOGIN_REQUIRED) : GET_TEXT(MSG_EDIT_PASSWORD), SS_CENTER|SS_INVERT); - STATIC_ITEM_P(NUL_STR, SS_CENTER|SS_INVERT, string); + STATIC_ITEM_P(NUL_STR, SS_CENTER, string); + + #if HAS_MARLINUI_U8GLIB + STATIC_ITEM_P(NUL_STR, SS_CENTER, ""); + #endif // Make the digit edit item look like a sub-menu PGM_P const label = GET_TEXT(MSG_ENTER_DIGIT); @@ -57,7 +63,7 @@ void Password::menu_password_entry() { MENU_ITEM_ADDON_START(utf8_strlen_P(label) + 1); lcd_put_wchar(' '); lcd_put_wchar('1' + digit_no); - SETCURSOR_X(LCD_WIDTH - 1); + SETCURSOR_X(LCD_WIDTH - 2); lcd_put_wchar('>'); MENU_ITEM_ADDON_END(); @@ -104,7 +110,7 @@ void Password::screen_password_entry() { value_entry = 0; digit_no = 0; editable.uint8 = 0; - memset(string, '-', PASSWORD_LENGTH); + memset(string, '_', PASSWORD_LENGTH); string[PASSWORD_LENGTH] = '\0'; menu_password_entry(); } @@ -120,7 +126,6 @@ void Password::authenticate_user(const screenFunc_t in_succ_scr, const screenFun if (is_set) { authenticating = true; ui.goto_screen(screen_password_entry); - ui.defer_status_screen(); ui.update(); } else {