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

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