My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

lock_screen.cpp 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*******************
  2. * lock_screen.cpp *
  3. *******************/
  4. /****************************************************************************
  5. * Written By Mark Pelletier 2017 - Aleph Objects, Inc. *
  6. * Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
  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. * To view a copy of the GNU General Public License, go to the following *
  19. * location: <http://www.gnu.org/licenses/>. *
  20. ****************************************************************************/
  21. #include "../config.h"
  22. #if ENABLED(LULZBOT_TOUCH_UI)
  23. #include "screens.h"
  24. #include "screen_data.h"
  25. using namespace FTDI;
  26. using namespace Theme;
  27. uint16_t LockScreen::passcode = 0;
  28. void LockScreen::onEntry() {
  29. const uint8_t siz = sizeof(screen_data.LockScreen.passcode);
  30. memset(screen_data.LockScreen.passcode, '_', siz-1);
  31. screen_data.LockScreen.passcode[siz-1] = '\0';
  32. BaseScreen::onEntry();
  33. }
  34. void LockScreen::onRedraw(draw_mode_t what) {
  35. CommandProcessor cmd;
  36. if (what & BACKGROUND) {
  37. cmd.cmd(CLEAR_COLOR_RGB(bg_color))
  38. .cmd(CLEAR(true,true,true))
  39. .tag(0);
  40. }
  41. if (what & FOREGROUND) {
  42. #ifdef TOUCH_UI_PORTRAIT
  43. #define GRID_COLS 1
  44. #define GRID_ROWS 10
  45. #else
  46. #define GRID_COLS 1
  47. #define GRID_ROWS 7
  48. #endif
  49. #undef MARGIN_T
  50. #undef MARGIN_B
  51. #define MARGIN_T 3
  52. #define MARGIN_B 3
  53. progmem_str message;
  54. switch (message_style()) {
  55. case 'w':
  56. message = GET_TEXTF(PASSCODE_REJECTED);
  57. break;
  58. case 'g':
  59. message = GET_TEXTF(PASSCODE_ACCEPTED);
  60. break;
  61. default:
  62. if (passcode == 0) {
  63. message = GET_TEXTF(PASSCODE_SELECT);
  64. } else {
  65. message = GET_TEXTF(PASSCODE_REQUEST);
  66. }
  67. }
  68. message_style() = '\0'; // Terminate the string.
  69. #ifdef TOUCH_UI_PORTRAIT
  70. constexpr uint8_t l = 6;
  71. #else
  72. constexpr uint8_t l = 3;
  73. #endif
  74. const uint8_t pressed = EventLoop::get_pressed_tag();
  75. cmd.font(font_large)
  76. .cmd(COLOR_RGB(bg_text_enabled))
  77. #ifdef TOUCH_UI_PORTRAIT
  78. .text(BTN_POS(1,2), BTN_SIZE(1,1), message)
  79. .font(font_xlarge)
  80. .text(BTN_POS(1,4), BTN_SIZE(1,1), screen_data.LockScreen.passcode)
  81. #else
  82. .text(BTN_POS(1,1), BTN_SIZE(1,1), message)
  83. .font(font_xlarge)
  84. .text(BTN_POS(1,2), BTN_SIZE(1,1), screen_data.LockScreen.passcode)
  85. #endif
  86. .font(font_large)
  87. .colors(normal_btn)
  88. #ifdef TOUCH_UI_PASSCODE
  89. .keys(BTN_POS(1,l+1), BTN_SIZE(1,1), F("123"), pressed)
  90. .keys(BTN_POS(1,l+2), BTN_SIZE(1,1), F("456"), pressed)
  91. .keys(BTN_POS(1,l+3), BTN_SIZE(1,1), F("789"), pressed)
  92. .keys(BTN_POS(1,l+4), BTN_SIZE(1,1), F("0.<"), pressed);
  93. #else
  94. .keys(BTN_POS(1,l+1), BTN_SIZE(1,1), F("1234567890"), pressed)
  95. .keys(BTN_POS(1,l+2), BTN_SIZE(1,1), F("qwertyuiop"), pressed)
  96. .keys(BTN_POS(1,l+3), BTN_SIZE(1,1), F("asdfghjkl "), pressed)
  97. .keys(BTN_POS(1,l+4), BTN_SIZE(1,1), F("zxcvbnm!?<"), pressed);
  98. #endif
  99. #undef MARGIN_T
  100. #undef MARGIN_B
  101. #define MARGIN_T MARGIN_DEFAULT
  102. #define MARGIN_B MARGIN_DEFAULT
  103. #undef GRID_COLS
  104. #undef GRID_ROWS
  105. }
  106. }
  107. char &LockScreen::message_style() {
  108. // We use the last byte of the passcode string as a flag to indicate,
  109. // which message to show.
  110. constexpr uint8_t last_char = sizeof(screen_data.LockScreen.passcode)-1;
  111. return screen_data.LockScreen.passcode[last_char];
  112. }
  113. void LockScreen::onPasscodeEntered() {
  114. if (passcode == 0) {
  115. // We are defining a passcode
  116. message_style() = 0;
  117. onRefresh();
  118. sound.play(twinkle, PLAY_SYNCHRONOUS);
  119. passcode = compute_checksum();
  120. GOTO_PREVIOUS();
  121. } else {
  122. // We are verifying a passcode
  123. if (passcode == compute_checksum()) {
  124. message_style() = 'g';
  125. onRefresh();
  126. sound.play(twinkle, PLAY_SYNCHRONOUS);
  127. GOTO_PREVIOUS();
  128. } else {
  129. message_style() = 'w';
  130. onRefresh();
  131. sound.play(sad_trombone, PLAY_SYNCHRONOUS);
  132. current_screen.forget(); // Discard the screen the user was trying to go to.
  133. GOTO_PREVIOUS();
  134. }
  135. }
  136. }
  137. bool LockScreen::onTouchEnd(uint8_t tag) {
  138. char *c = strchr(screen_data.LockScreen.passcode,'_');
  139. if (c) {
  140. if (tag == '<') {
  141. if (c != screen_data.LockScreen.passcode) {
  142. // Backspace deletes previous entered characters.
  143. *--c = '_';
  144. }
  145. } else {
  146. // Append character to passcode
  147. *c++ = tag;
  148. if (*c == '\0') {
  149. // If at last character, then process the code.
  150. onPasscodeEntered();
  151. }
  152. }
  153. }
  154. return true;
  155. }
  156. uint16_t LockScreen::compute_checksum() {
  157. uint16_t checksum = 0;
  158. const char* c = screen_data.LockScreen.passcode;
  159. while (*c) {
  160. checksum = (checksum << 2) ^ *c++;
  161. }
  162. if (checksum == 0) checksum = 0xFFFF; // Prevent a zero checksum
  163. return checksum;
  164. }
  165. // This function should be called *after* calling GOTO_SCREEN
  166. // to move to new screen. If a passcode is enabled, it will
  167. // immediately jump to the keypad screen, pushing the previous
  168. // screen onto the stack. If the code is entered correctly,
  169. // the stack will be popped, allowing the user to proceed to
  170. // the new screen. Otherwise it will be popped twice, taking
  171. // the user back to where they were before.
  172. void LockScreen::check_passcode() {
  173. if (passcode == 0) return;
  174. message_style() = 0;
  175. GOTO_SCREEN(LockScreen);
  176. }
  177. bool LockScreen::is_enabled() {
  178. return passcode != 0;
  179. }
  180. void LockScreen::disable() {
  181. passcode = 0;
  182. }
  183. void LockScreen::enable() {
  184. message_style() = 0;
  185. passcode = 0;
  186. GOTO_SCREEN(LockScreen);
  187. }
  188. #endif // LULZBOT_TOUCH_UI