My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. //
  23. // Advanced Settings Menus
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if BOTH(HAS_LCD_MENU, PASSWORD_FEATURE)
  27. #include "../../feature/password/password.h"
  28. #include "menu_item.h"
  29. #include "menu_addon.h"
  30. void menu_advanced_settings();
  31. screenFunc_t success_screen, fail_screen;
  32. bool authenticating; // = false
  33. char string[(PASSWORD_LENGTH) + 1];
  34. static uint8_t digit_no;
  35. //
  36. // Screen for both editing and setting the password
  37. //
  38. void Password::menu_password_entry() {
  39. START_MENU();
  40. // "Login" or "New Code"
  41. STATIC_ITEM_P(authenticating ? GET_TEXT(MSG_LOGIN_REQUIRED) : GET_TEXT(MSG_EDIT_PASSWORD), SS_CENTER|SS_INVERT);
  42. STATIC_ITEM_P(PSTR(""), SS_CENTER|SS_INVERT, string);
  43. // Make the digit edit item look like a sub-menu
  44. PGM_P const label = GET_TEXT(MSG_ENTER_DIGIT);
  45. EDIT_ITEM_P(uint8, label, &editable.uint8, 0, 9, digit_entered);
  46. MENU_ITEM_ADDON_START(utf8_strlen_P(label) + 1);
  47. lcd_put_wchar(' ');
  48. lcd_put_wchar('1' + digit_no);
  49. SETCURSOR_X(LCD_WIDTH - 1);
  50. lcd_put_wchar('>');
  51. MENU_ITEM_ADDON_END();
  52. ACTION_ITEM(MSG_START_OVER, start_over);
  53. if (!authenticating) BACK_ITEM(MSG_BUTTON_CANCEL);
  54. END_MENU();
  55. }
  56. //
  57. // Authentication check
  58. //
  59. void Password::authentication_done() {
  60. ui.goto_screen(is_locked ? fail_screen : success_screen);
  61. ui.completion_feedback(!is_locked);
  62. }
  63. // A single digit was completed
  64. void Password::digit_entered() {
  65. uint32_t multiplier = CAT(1e, PASSWORD_LENGTH); // 1e5 = 100000
  66. LOOP_LE_N(i, digit_no) multiplier /= 10;
  67. value_entry += editable.uint8 * multiplier;
  68. string[digit_no++] = '0' + editable.uint8;
  69. // Exit edit screen menu and go to another screen
  70. ui.goto_previous_screen();
  71. ui.use_click();
  72. ui.goto_screen(menu_password_entry);
  73. // After password has been keyed in
  74. if (digit_no == PASSWORD_LENGTH) {
  75. if (authenticating)
  76. authentication_check();
  77. else
  78. set_password_done();
  79. }
  80. }
  81. //
  82. // Set/Change Password
  83. //
  84. void Password::screen_password_entry() {
  85. value_entry = 0;
  86. digit_no = 0;
  87. editable.uint8 = 0;
  88. memset(string, '-', PASSWORD_LENGTH);
  89. string[PASSWORD_LENGTH] = '\0';
  90. menu_password_entry();
  91. }
  92. void Password::screen_set_password() {
  93. authenticating = false;
  94. screen_password_entry();
  95. }
  96. void Password::authenticate_user(const screenFunc_t in_succ_scr, const screenFunc_t in_fail_scr) {
  97. success_screen = in_succ_scr;
  98. fail_screen = in_fail_scr;
  99. if (is_set) {
  100. authenticating = true;
  101. ui.goto_screen(screen_password_entry);
  102. ui.defer_status_screen();
  103. ui.update();
  104. }
  105. else {
  106. ui.goto_screen(in_succ_scr);
  107. is_locked = false;
  108. }
  109. }
  110. void Password::access_menu_password() {
  111. authenticate_user(menu_password, menu_advanced_settings);
  112. }
  113. #if ENABLED(PASSWORD_ON_SD_PRINT_MENU)
  114. void Password::media_gatekeeper() {
  115. authenticate_user(menu_media, menu_main);
  116. }
  117. #endif
  118. void Password::start_over() {
  119. ui.goto_previous_screen(); // Goto previous screen, if any
  120. ui.goto_screen(screen_password_entry);
  121. }
  122. void Password::menu_password_report() {
  123. START_SCREEN();
  124. BACK_ITEM(MSG_PASSWORD_SETTINGS);
  125. STATIC_ITEM(MSG_PASSWORD_SET, SS_LEFT, string);
  126. STATIC_ITEM(MSG_REMINDER_SAVE_SETTINGS, SS_LEFT);
  127. END_SCREEN();
  128. }
  129. void Password::set_password_done() {
  130. is_set = true;
  131. value = value_entry;
  132. ui.completion_feedback(true);
  133. ui.goto_screen(menu_password_report);
  134. }
  135. void Password::remove_password() {
  136. is_set = false;
  137. string[0] = '0';
  138. string[1] = '\0';
  139. ui.completion_feedback(true);
  140. ui.goto_screen(menu_password_report);
  141. }
  142. //
  143. // Password Menu
  144. //
  145. void Password::menu_password() {
  146. START_MENU();
  147. BACK_ITEM(MSG_ADVANCED_SETTINGS);
  148. SUBMENU(MSG_CHANGE_PASSWORD, screen_set_password);
  149. ACTION_ITEM(MSG_REMOVE_PASSWORD, []{ ui.save_previous_screen(); remove_password(); } );
  150. #if ENABLED(EEPROM_SETTINGS)
  151. ACTION_ITEM(MSG_STORE_EEPROM, ui.store_settings);
  152. #endif
  153. END_MENU();
  154. }
  155. #endif // HAS_LCD_MENU && PASSWORD_FEATURE