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

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