My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

draw_tool.cpp 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../../inc/MarlinConfigPre.h"
  23. #if ENABLED(TFT_LVGL_UI)
  24. #include "lv_conf.h"
  25. #include "draw_ui.h"
  26. //#include "../lvgl/src/lv_objx/lv_imgbtn.h"
  27. //#include "../lvgl/src/lv_objx/lv_img.h"
  28. //#include "../lvgl/src/lv_core/lv_disp.h"
  29. //#include "../lvgl/src/lv_core/lv_refr.h"
  30. #include "../../../../MarlinCore.h"
  31. #include "../../../../gcode/queue.h"
  32. //static lv_obj_t *buttonMoveZ,*buttonTest,*buttonZ0,*buttonStop,*buttonReturn;
  33. static lv_obj_t * scr;
  34. #if ENABLED(MKS_TEST)
  35. extern uint8_t curent_disp_ui;
  36. #endif
  37. #define ID_T_PRE_HEAT 1
  38. #define ID_T_EXTRUCT 2
  39. #define ID_T_MOV 3
  40. #define ID_T_HOME 4
  41. #define ID_T_LEVELING 5
  42. #define ID_T_FILAMENT 6
  43. #define ID_T_MORE 7
  44. #define ID_T_RETURN 8
  45. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  46. switch (obj->mks_obj_id) {
  47. case ID_T_PRE_HEAT:
  48. if (event == LV_EVENT_CLICKED) {
  49. // nothing to do
  50. }
  51. else if (event == LV_EVENT_RELEASED) {
  52. lv_clear_tool();
  53. lv_draw_preHeat();
  54. }
  55. break;
  56. case ID_T_EXTRUCT:
  57. if (event == LV_EVENT_CLICKED) {
  58. // nothing to do
  59. }
  60. else if (event == LV_EVENT_RELEASED) {
  61. lv_clear_tool();
  62. lv_draw_extrusion();
  63. }
  64. break;
  65. case ID_T_MOV:
  66. if (event == LV_EVENT_CLICKED) {
  67. // nothing to do
  68. }
  69. else if (event == LV_EVENT_RELEASED) {
  70. lv_clear_tool();
  71. lv_draw_move_motor();
  72. }
  73. break;
  74. case ID_T_HOME:
  75. if (event == LV_EVENT_CLICKED) {
  76. // nothing to do
  77. }
  78. else if (event == LV_EVENT_RELEASED) {
  79. lv_clear_tool();
  80. lv_draw_home();
  81. }
  82. break;
  83. case ID_T_LEVELING:
  84. if (event == LV_EVENT_CLICKED) {
  85. // nothing to do
  86. }
  87. else if (event == LV_EVENT_RELEASED) {
  88. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  89. queue.enqueue_one_P(PSTR("G28"));
  90. queue.enqueue_one_P(PSTR("G29"));
  91. #else
  92. uiCfg.leveling_first_time = 1;
  93. lv_clear_tool();
  94. lv_draw_manualLevel();
  95. #endif
  96. }
  97. break;
  98. case ID_T_FILAMENT: break;
  99. case ID_T_MORE: break;
  100. case ID_T_RETURN:
  101. if (event == LV_EVENT_CLICKED) {
  102. // nothing to do
  103. }
  104. else if (event == LV_EVENT_RELEASED) {
  105. TERN_(MKS_TEST, curent_disp_ui = 1);
  106. lv_obj_del(scr);
  107. lv_draw_ready_print();
  108. }
  109. break;
  110. }
  111. }
  112. void lv_draw_tool(void) {
  113. lv_obj_t *buttonPreHeat, *buttonExtrusion, *buttonMove, *buttonHome, *buttonLevel;
  114. lv_obj_t *buttonBack;
  115. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != TOOL_UI) {
  116. disp_state_stack._disp_index++;
  117. disp_state_stack._disp_state[disp_state_stack._disp_index] = TOOL_UI;
  118. }
  119. disp_state = TOOL_UI;
  120. scr = lv_obj_create(NULL, NULL);
  121. //static lv_style_t tool_style;
  122. lv_obj_set_style(scr, &tft_style_scr);
  123. lv_scr_load(scr);
  124. lv_obj_clean(scr);
  125. lv_obj_t * title = lv_label_create(scr, NULL);
  126. lv_obj_set_style(title, &tft_style_lable_rel);
  127. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  128. lv_label_set_text(title, creat_title_text());
  129. lv_refr_now(lv_refr_get_disp_refreshing());
  130. LV_IMG_DECLARE(bmp_pic);
  131. /*Create an Image button*/
  132. buttonPreHeat = lv_imgbtn_create(scr, NULL);
  133. buttonExtrusion = lv_imgbtn_create(scr, NULL);
  134. buttonMove = lv_imgbtn_create(scr, NULL);
  135. buttonHome = lv_imgbtn_create(scr, NULL);
  136. buttonLevel = lv_imgbtn_create(scr, NULL);
  137. //buttonFilament = lv_imgbtn_create(scr, NULL);
  138. //buttonMore = lv_imgbtn_create(scr, NULL);
  139. buttonBack = lv_imgbtn_create(scr, NULL);
  140. lv_obj_set_event_cb_mks(buttonPreHeat, event_handler, ID_T_PRE_HEAT, "bmp_PreHeat.bin", 0);
  141. lv_imgbtn_set_src(buttonPreHeat, LV_BTN_STATE_REL, &bmp_pic);
  142. lv_imgbtn_set_src(buttonPreHeat, LV_BTN_STATE_PR, &bmp_pic);
  143. lv_imgbtn_set_style(buttonPreHeat, LV_BTN_STATE_PR, &tft_style_lable_pre);
  144. lv_imgbtn_set_style(buttonPreHeat, LV_BTN_STATE_REL, &tft_style_lable_rel);
  145. lv_obj_clear_protect(buttonPreHeat, LV_PROTECT_FOLLOW);
  146. #if 1
  147. lv_obj_set_event_cb_mks(buttonExtrusion, event_handler, ID_T_EXTRUCT, "bmp_Extruct.bin", 0);
  148. lv_imgbtn_set_src(buttonExtrusion, LV_BTN_STATE_REL, &bmp_pic);
  149. lv_imgbtn_set_src(buttonExtrusion, LV_BTN_STATE_PR, &bmp_pic);
  150. lv_imgbtn_set_style(buttonExtrusion, LV_BTN_STATE_PR, &tft_style_lable_pre);
  151. lv_imgbtn_set_style(buttonExtrusion, LV_BTN_STATE_REL, &tft_style_lable_rel);
  152. lv_obj_set_event_cb_mks(buttonMove, event_handler, ID_T_MOV, "bmp_Mov.bin", 0);
  153. lv_imgbtn_set_src(buttonMove, LV_BTN_STATE_REL, &bmp_pic);
  154. lv_imgbtn_set_src(buttonMove, LV_BTN_STATE_PR, &bmp_pic);
  155. lv_imgbtn_set_style(buttonMove, LV_BTN_STATE_PR, &tft_style_lable_pre);
  156. lv_imgbtn_set_style(buttonMove, LV_BTN_STATE_REL, &tft_style_lable_rel);
  157. lv_obj_set_event_cb_mks(buttonHome, event_handler, ID_T_HOME, "bmp_Zero.bin", 0);
  158. lv_imgbtn_set_src(buttonHome, LV_BTN_STATE_REL, &bmp_pic);
  159. lv_imgbtn_set_src(buttonHome, LV_BTN_STATE_PR, &bmp_pic);
  160. lv_imgbtn_set_style(buttonHome, LV_BTN_STATE_PR, &tft_style_lable_pre);
  161. lv_imgbtn_set_style(buttonHome, LV_BTN_STATE_REL, &tft_style_lable_rel);
  162. lv_obj_set_event_cb_mks(buttonLevel, event_handler, ID_T_LEVELING, "bmp_Leveling.bin", 0);
  163. lv_imgbtn_set_src(buttonLevel, LV_BTN_STATE_REL, &bmp_pic);
  164. lv_imgbtn_set_src(buttonLevel, LV_BTN_STATE_PR, &bmp_pic);
  165. lv_imgbtn_set_style(buttonLevel, LV_BTN_STATE_PR, &tft_style_lable_pre);
  166. lv_imgbtn_set_style(buttonLevel, LV_BTN_STATE_REL, &tft_style_lable_rel);
  167. //lv_obj_set_event_cb_mks(buttonFilament, event_handler,ID_T_FILAMENT,"bmp_Filamentchange.bin",0);
  168. //lv_imgbtn_set_src(buttonFilament, LV_BTN_STATE_REL, &bmp_pic);
  169. //lv_imgbtn_set_src(buttonFilament, LV_BTN_STATE_PR, &bmp_pic);
  170. //lv_imgbtn_set_style(buttonFilament, LV_BTN_STATE_PR, &tft_style_lable_pre);
  171. //lv_imgbtn_set_style(buttonFilament, LV_BTN_STATE_REL, &tft_style_lable_rel);
  172. //lv_obj_set_event_cb_mks(buttonMore, event_handler,ID_T_MORE,"bmp_More.bin",0);
  173. //lv_imgbtn_set_src(buttonMore, LV_BTN_STATE_REL, &bmp_pic);
  174. //lv_imgbtn_set_src(buttonMore, LV_BTN_STATE_PR, &bmp_pic);
  175. //lv_imgbtn_set_style(buttonMore, LV_BTN_STATE_PR, &tft_style_lable_pre);
  176. //lv_imgbtn_set_style(buttonMore, LV_BTN_STATE_REL, &tft_style_lable_rel);
  177. lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_T_RETURN, "bmp_Return.bin", 0);
  178. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, &bmp_pic);
  179. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, &bmp_pic);
  180. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_lable_pre);
  181. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_lable_rel);
  182. #endif
  183. lv_obj_set_pos(buttonPreHeat, INTERVAL_V, titleHeight);
  184. lv_obj_set_pos(buttonExtrusion, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight);
  185. lv_obj_set_pos(buttonMove, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight);
  186. lv_obj_set_pos(buttonHome, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight);
  187. lv_obj_set_pos(buttonLevel, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  188. //lv_obj_set_pos(buttonFilament,BTN_X_PIXEL+INTERVAL_V*2,BTN_Y_PIXEL+INTERVAL_H+titleHeight);
  189. //lv_obj_set_pos(buttonMore,BTN_X_PIXEL*2+INTERVAL_V*3, BTN_Y_PIXEL+INTERVAL_H+titleHeight);
  190. lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  191. /*Create a label on the Image button*/
  192. lv_btn_set_layout(buttonPreHeat, LV_LAYOUT_OFF);
  193. lv_btn_set_layout(buttonExtrusion, LV_LAYOUT_OFF);
  194. lv_btn_set_layout(buttonMove, LV_LAYOUT_OFF);
  195. lv_btn_set_layout(buttonHome, LV_LAYOUT_OFF);
  196. lv_btn_set_layout(buttonLevel, LV_LAYOUT_OFF);
  197. //lv_btn_set_layout(buttonFilament, LV_LAYOUT_OFF);
  198. //lv_btn_set_layout(buttonMore, LV_LAYOUT_OFF);
  199. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  200. lv_obj_t * labelPreHeat = lv_label_create(buttonPreHeat, NULL);
  201. lv_obj_t * labelExtrusion = lv_label_create(buttonExtrusion, NULL);
  202. lv_obj_t * label_Move = lv_label_create(buttonMove, NULL);
  203. lv_obj_t * label_Home = lv_label_create(buttonHome, NULL);
  204. lv_obj_t * label_Level = lv_label_create(buttonLevel, NULL);
  205. //lv_obj_t * label_Filament = lv_label_create(buttonFilament, NULL);
  206. //lv_obj_t * label_More = lv_label_create(buttonMore, NULL);
  207. lv_obj_t * label_Back = lv_label_create(buttonBack, NULL);
  208. if (gCfgItems.multiple_language != 0) {
  209. lv_label_set_text(labelPreHeat, tool_menu.preheat);
  210. lv_obj_align(labelPreHeat, buttonPreHeat, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  211. lv_label_set_text(labelExtrusion, tool_menu.extrude);
  212. lv_obj_align(labelExtrusion, buttonExtrusion, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  213. lv_label_set_text(label_Move, tool_menu.move);
  214. lv_obj_align(label_Move, buttonMove, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  215. lv_label_set_text(label_Home, tool_menu.home);
  216. lv_obj_align(label_Home, buttonHome, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  217. /*
  218. if (gCfgItems.leveling_mode != 2) {
  219. lv_label_set_text(label_Level, gCfgItems.leveling_mode == 1 ? tool_menu.autoleveling : tool_menu.leveling);
  220. lv_obj_align(label_Level, buttonLevel, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  221. }
  222. */
  223. lv_label_set_text(label_Level, tool_menu.TERN(AUTO_BED_LEVELING_BILINEAR, autoleveling, leveling));
  224. lv_obj_align(label_Level, buttonLevel, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  225. //lv_label_set_text(label_Filament, tool_menu.filament);
  226. //lv_obj_align(label_Filament, buttonFilament, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  227. //lv_label_set_text(label_More, tool_menu.more);
  228. //lv_obj_align(label_More, buttonMore, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  229. lv_label_set_text(label_Back, common_menu.text_back);
  230. lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  231. }
  232. }
  233. void lv_clear_tool() { lv_obj_del(scr); }
  234. #endif // TFT_LVGL_UI