My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

draw_keyboard.cpp 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. #include "../../../../inc/MarlinConfigPre.h"
  23. #if HAS_TFT_LVGL_UI
  24. #include "lv_conf.h"
  25. #include "draw_ui.h"
  26. #include "../../../../../Configuration.h"
  27. #include "../../../../MarlinCore.h"
  28. extern lv_group_t * g;
  29. static lv_obj_t * scr;
  30. #define LV_KB_CTRL_BTN_FLAGS (LV_BTNM_CTRL_NO_REPEAT | LV_BTNM_CTRL_CLICK_TRIG)
  31. static const char * kb_map_lc[] = {"1#", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", LV_SYMBOL_BACKSPACE, "\n",
  32. "ABC", "a", "s", "d", "f", "g", "h", "j", "k", "l", LV_SYMBOL_NEW_LINE, "\n",
  33. "_", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ":", "\n",
  34. LV_SYMBOL_CLOSE, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, ""};
  35. static const lv_btnm_ctrl_t kb_ctrl_lc_map[] = {
  36. LV_KB_CTRL_BTN_FLAGS | 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7,
  37. LV_KB_CTRL_BTN_FLAGS | 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7,
  38. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  39. LV_KB_CTRL_BTN_FLAGS | 2, 2, 6, 2, LV_KB_CTRL_BTN_FLAGS | 2};
  40. static const char * kb_map_uc[] = {"1#", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", LV_SYMBOL_BACKSPACE, "\n",
  41. "abc", "A", "S", "D", "F", "G", "H", "J", "K", "L", LV_SYMBOL_NEW_LINE, "\n",
  42. "_", "-", "Z", "X", "C", "V", "B", "N", "M", ".", ",", ":", "\n",
  43. LV_SYMBOL_CLOSE, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, ""};
  44. static const lv_btnm_ctrl_t kb_ctrl_uc_map[] = {
  45. LV_KB_CTRL_BTN_FLAGS | 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7,
  46. LV_KB_CTRL_BTN_FLAGS | 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7,
  47. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  48. LV_KB_CTRL_BTN_FLAGS | 2, 2, 6, 2, LV_KB_CTRL_BTN_FLAGS | 2};
  49. static const char * kb_map_spec[] = {"0", "1", "2", "3", "4" ,"5", "6", "7", "8", "9", LV_SYMBOL_BACKSPACE, "\n",
  50. "abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n",
  51. "\\", "@", "$", "(", ")", "{", "}", "[", "]", ";", "\"", "'", "\n",
  52. LV_SYMBOL_CLOSE, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, ""};
  53. static const lv_btnm_ctrl_t kb_ctrl_spec_map[] = {
  54. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, LV_KB_CTRL_BTN_FLAGS | 2,
  55. LV_KB_CTRL_BTN_FLAGS | 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  56. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  57. LV_KB_CTRL_BTN_FLAGS | 2, 2, 6, 2, LV_KB_CTRL_BTN_FLAGS | 2};
  58. static const lv_btnm_ctrl_t kb_ctrl_num_map[] = {
  59. 1, 1, 1, LV_KB_CTRL_BTN_FLAGS | 2,
  60. 1, 1, 1, LV_KB_CTRL_BTN_FLAGS | 2,
  61. 1, 1, 1, 2,
  62. 1, 1, 1, 1, 1};
  63. static void lv_kb_event_cb(lv_obj_t * kb, lv_event_t event) {
  64. //LV_ASSERT_OBJ(kb, LV_OBJX_NAME);
  65. if (event != LV_EVENT_VALUE_CHANGED) return;
  66. lv_kb_ext_t * ext = (lv_kb_ext_t * )lv_obj_get_ext_attr(kb);
  67. const uint16_t btn_id = lv_btnm_get_active_btn(kb);
  68. if (btn_id == LV_BTNM_BTN_NONE) return;
  69. if (lv_btnm_get_btn_ctrl(kb, btn_id, LV_BTNM_CTRL_HIDDEN | LV_BTNM_CTRL_INACTIVE)) return;
  70. if (lv_btnm_get_btn_ctrl(kb, btn_id, LV_BTNM_CTRL_NO_REPEAT) && event == LV_EVENT_LONG_PRESSED_REPEAT) return;
  71. const char * txt = lv_btnm_get_active_btn_text(kb);
  72. if (txt == NULL) return;
  73. // Do the corresponding action according to the text of the button
  74. if (strcmp(txt, "abc") == 0) {
  75. lv_btnm_set_map(kb, kb_map_lc);
  76. lv_btnm_set_ctrl_map(kb, kb_ctrl_lc_map);
  77. return;
  78. }
  79. else if (strcmp(txt, "ABC") == 0) {
  80. lv_btnm_set_map(kb, kb_map_uc);
  81. lv_btnm_set_ctrl_map(kb, kb_ctrl_uc_map);
  82. return;
  83. }
  84. else if (strcmp(txt, "1#") == 0) {
  85. lv_btnm_set_map(kb, kb_map_spec);
  86. lv_btnm_set_ctrl_map(kb, kb_ctrl_spec_map);
  87. return;
  88. }
  89. else if (strcmp(txt, LV_SYMBOL_CLOSE) == 0) {
  90. if (kb->event_cb != lv_kb_def_event_cb) {
  91. //lv_res_t res = lv_event_send(kb, LV_EVENT_CANCEL, NULL);
  92. //if (res != LV_RES_OK) return;
  93. lv_clear_keyboard();
  94. draw_return_ui();
  95. }
  96. else {
  97. lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/
  98. lv_obj_del(kb);
  99. return;
  100. }
  101. return;
  102. }
  103. else if (strcmp(txt, LV_SYMBOL_OK) == 0) {
  104. if (kb->event_cb != lv_kb_def_event_cb) {
  105. //lv_res_t res = lv_event_send(kb, LV_EVENT_APPLY, NULL);
  106. //if (res != LV_RES_OK) return;
  107. const char * ret_ta_txt = lv_ta_get_text(ext->ta);
  108. switch (keyboard_value) {
  109. #if ENABLED(USE_WIFI_FUNCTION)
  110. case wifiName:
  111. memcpy(uiCfg.wifi_name,ret_ta_txt,sizeof(uiCfg.wifi_name));
  112. lv_clear_keyboard();
  113. draw_return_ui();
  114. break;
  115. case wifiPassWord:
  116. memcpy(uiCfg.wifi_key,ret_ta_txt,sizeof(uiCfg.wifi_name));
  117. lv_clear_keyboard();
  118. draw_return_ui();
  119. break;
  120. case wifiConfig:
  121. memset((void *)uiCfg.wifi_name, 0, sizeof(uiCfg.wifi_name));
  122. memcpy((void *)uiCfg.wifi_name, wifi_list.wifiName[wifi_list.nameIndex], 32);
  123. memset((void *)uiCfg.wifi_key, 0, sizeof(uiCfg.wifi_key));
  124. memcpy((void *)uiCfg.wifi_key, ret_ta_txt, sizeof(uiCfg.wifi_key));
  125. gCfgItems.wifi_mode_sel = STA_MODEL;
  126. package_to_wifi(WIFI_PARA_SET, (char *)0, 0);
  127. memset(public_buf_l,0,sizeof(public_buf_l));
  128. public_buf_l[0] = 0xA5;
  129. public_buf_l[1] = 0x09;
  130. public_buf_l[2] = 0x01;
  131. public_buf_l[3] = 0x00;
  132. public_buf_l[4] = 0x01;
  133. public_buf_l[5] = 0xFC;
  134. public_buf_l[6] = 0x00;
  135. raw_send_to_wifi(public_buf_l, 6);
  136. last_disp_state = KEY_BOARD_UI;
  137. lv_clear_keyboard();
  138. wifi_tips_type = TIPS_TYPE_JOINING;
  139. lv_draw_wifi_tips();
  140. break;
  141. #endif // USE_WIFI_FUNCTION
  142. case gcodeCommand:
  143. uint8_t buf[100];
  144. strncpy((char *)buf,ret_ta_txt,sizeof(buf));
  145. update_gcode_command(AUTO_LEVELING_COMMAND_ADDR,buf);
  146. lv_clear_keyboard();
  147. draw_return_ui();
  148. break;
  149. default: break;
  150. }
  151. }
  152. else {
  153. lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/
  154. }
  155. return;
  156. }
  157. /*Add the characters to the text area if set*/
  158. if (ext->ta == NULL) return;
  159. if (strcmp(txt, "Enter") == 0 || strcmp(txt, LV_SYMBOL_NEW_LINE) == 0)
  160. lv_ta_add_char(ext->ta, '\n');
  161. else if (strcmp(txt, LV_SYMBOL_LEFT) == 0)
  162. lv_ta_cursor_left(ext->ta);
  163. else if (strcmp(txt, LV_SYMBOL_RIGHT) == 0)
  164. lv_ta_cursor_right(ext->ta);
  165. else if (strcmp(txt, LV_SYMBOL_BACKSPACE) == 0)
  166. lv_ta_del_char(ext->ta);
  167. else if (strcmp(txt, "+/-") == 0) {
  168. uint16_t cur = lv_ta_get_cursor_pos(ext->ta);
  169. const char * ta_txt = lv_ta_get_text(ext->ta);
  170. if (ta_txt[0] == '-') {
  171. lv_ta_set_cursor_pos(ext->ta, 1);
  172. lv_ta_del_char(ext->ta);
  173. lv_ta_add_char(ext->ta, '+');
  174. lv_ta_set_cursor_pos(ext->ta, cur);
  175. }
  176. else if (ta_txt[0] == '+') {
  177. lv_ta_set_cursor_pos(ext->ta, 1);
  178. lv_ta_del_char(ext->ta);
  179. lv_ta_add_char(ext->ta, '-');
  180. lv_ta_set_cursor_pos(ext->ta, cur);
  181. }
  182. else {
  183. lv_ta_set_cursor_pos(ext->ta, 0);
  184. lv_ta_add_char(ext->ta, '-');
  185. lv_ta_set_cursor_pos(ext->ta, cur + 1);
  186. }
  187. }
  188. else {
  189. lv_ta_add_text(ext->ta, txt);
  190. }
  191. }
  192. void lv_draw_keyboard() {
  193. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != KEY_BOARD_UI) {
  194. disp_state_stack._disp_index++;
  195. disp_state_stack._disp_state[disp_state_stack._disp_index] = KEY_BOARD_UI;
  196. }
  197. disp_state = KEY_BOARD_UI;
  198. scr = lv_obj_create(NULL, NULL);
  199. lv_obj_set_style(scr, &tft_style_scr);
  200. lv_scr_load(scr);
  201. lv_obj_clean(scr);
  202. lv_refr_now(lv_refr_get_disp_refreshing());
  203. /*Create styles for the keyboard*/
  204. static lv_style_t rel_style, pr_style;
  205. lv_style_copy(&rel_style, &lv_style_btn_rel);
  206. rel_style.body.radius = 0;
  207. rel_style.body.border.width = 1;
  208. rel_style.body.main_color = lv_color_make(0xA9, 0x62, 0x1D);
  209. rel_style.body.grad_color = lv_color_make(0xA7, 0x59, 0x0E);
  210. lv_style_copy(&pr_style, &lv_style_btn_pr);
  211. pr_style.body.radius = 0;
  212. pr_style.body.border.width = 1;
  213. pr_style.body.main_color = lv_color_make(0x72, 0x42, 0x15);
  214. pr_style.body.grad_color = lv_color_make(0x6A, 0x3A, 0x0C);
  215. /*Create a keyboard and apply the styles*/
  216. lv_obj_t *kb = lv_kb_create(scr, NULL);
  217. lv_obj_set_event_cb(kb, lv_kb_event_cb);
  218. lv_kb_set_cursor_manage(kb, true);
  219. lv_kb_set_style(kb, LV_KB_STYLE_BG, &lv_style_transp_tight);
  220. lv_kb_set_style(kb, LV_KB_STYLE_BTN_REL, &rel_style);
  221. lv_kb_set_style(kb, LV_KB_STYLE_BTN_PR, &pr_style);
  222. #if HAS_ROTARY_ENCODER
  223. if (gCfgItems.encoder_enable) {
  224. //lv_group_add_obj(g, kb);
  225. //lv_group_set_editing(g, true);
  226. }
  227. #endif
  228. /*Create a text area. The keyboard will write here*/
  229. lv_obj_t *ta = lv_ta_create(scr, NULL);
  230. lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_MID, 0, 10);
  231. if (keyboard_value == gcodeCommand) {
  232. get_gcode_command(AUTO_LEVELING_COMMAND_ADDR,(uint8_t *)public_buf_m);
  233. public_buf_m[sizeof(public_buf_m)-1] = 0;
  234. lv_ta_set_text(ta, public_buf_m);
  235. }
  236. else {
  237. lv_ta_set_text(ta, "");
  238. }
  239. /*Assign the text area to the keyboard*/
  240. lv_kb_set_ta(kb, ta);
  241. }
  242. void lv_clear_keyboard() {
  243. #if HAS_ROTARY_ENCODER
  244. if (gCfgItems.encoder_enable) { /* lv_group_remove_all_objs(g); */ }
  245. #endif
  246. lv_obj_del(scr);
  247. }
  248. #endif // HAS_TFT_LVGL_UI