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_ready_print.cpp 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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_ready_print.h"
  25. #include "draw_tool.h"
  26. #include <lv_conf.h>
  27. //#include "../lvgl/src/lv_objx/lv_imgbtn.h"
  28. //#include "../lvgl/src/lv_objx/lv_img.h"
  29. //#include "../lvgl/src/lv_core/lv_disp.h"
  30. //#include "../lvgl/src/lv_core/lv_refr.h"
  31. #include "tft_lvgl_configuration.h"
  32. #include "mks_hardware_test.h"
  33. #include "draw_ui.h"
  34. #include <lvgl.h>
  35. #include "../../../../module/temperature.h"
  36. #include "../../../../inc/MarlinConfig.h"
  37. #include <stdio.h>
  38. //static lv_obj_t *buttonPrint,*buttonTool,*buttonSet;
  39. extern lv_group_t* g;
  40. static lv_obj_t * scr;
  41. #if ENABLED(MKS_TEST)
  42. uint8_t curent_disp_ui = 0;
  43. #endif
  44. #define ID_TOOL 1
  45. #define ID_SET 2
  46. #define ID_PRINT 3
  47. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  48. switch (obj->mks_obj_id) {
  49. case ID_TOOL:
  50. if (event == LV_EVENT_CLICKED) {
  51. // nothing to do
  52. }
  53. else if (event == LV_EVENT_RELEASED) {
  54. lv_clear_ready_print();
  55. lv_draw_tool();
  56. }
  57. break;
  58. case ID_SET:
  59. if (event == LV_EVENT_CLICKED) {
  60. // nothing to do
  61. }
  62. else if (event == LV_EVENT_RELEASED) {
  63. lv_clear_ready_print();
  64. lv_draw_set();
  65. }
  66. break;
  67. case ID_PRINT:
  68. if (event == LV_EVENT_CLICKED) {
  69. // nothing to do
  70. }
  71. else if (event == LV_EVENT_RELEASED) {
  72. lv_clear_ready_print();
  73. lv_draw_print_file();
  74. }
  75. break;
  76. }
  77. }
  78. lv_obj_t *limit_info, *det_info;
  79. lv_style_t limit_style, det_style;
  80. void disp_Limit_ok() {
  81. limit_style.text.color.full = 0xFFFF;
  82. lv_obj_set_style(limit_info, &limit_style);
  83. lv_label_set_text(limit_info, "Limit:ok");
  84. }
  85. void disp_Limit_error() {
  86. limit_style.text.color.full = 0xF800;
  87. lv_obj_set_style(limit_info, &limit_style);
  88. lv_label_set_text(limit_info, "Limit:error");
  89. }
  90. void disp_det_ok() {
  91. det_style.text.color.full = 0xFFFF;
  92. lv_obj_set_style(det_info, &det_style);
  93. lv_label_set_text(det_info, "det:ok");
  94. }
  95. void disp_det_error() {
  96. det_style.text.color.full = 0xF800;
  97. lv_obj_set_style(det_info, &det_style);
  98. lv_label_set_text(det_info, "det:error");
  99. }
  100. lv_obj_t *e1, *e2, *e3, *bed;
  101. void mks_disp_test() {
  102. char buf[30] = {0};
  103. //lv_obj_t *label_tool2 = lv_label_create(scr, NULL);
  104. //lv_obj_set_pos(label_tool,20,50);
  105. ZERO(buf);
  106. sprintf_P(buf, PSTR("e1:%d"), (int)thermalManager.temp_hotend[0].celsius);
  107. lv_label_set_text(e1, buf);
  108. #if HAS_MULTI_HOTEND
  109. ZERO(buf);
  110. sprintf_P(buf, PSTR("e2:%d"), (int)thermalManager.temp_hotend[1].celsius);
  111. lv_label_set_text(e2, buf);
  112. #endif
  113. //ZERO(buf);
  114. //sprintf_P(buf, PSTR("e3:%d"), (int)thermalManager.temp_hotend[2].celsius);
  115. //lv_label_set_text(e3, buf);
  116. #if HAS_HEATED_BED
  117. ZERO(buf);
  118. sprintf_P(buf, PSTR("bed:%d"), (int)thermalManager.temp_bed.celsius);
  119. lv_label_set_text(bed, buf);
  120. #endif
  121. }
  122. void lv_draw_ready_print(void) {
  123. char buf[30] = {0};
  124. lv_obj_t *buttonPrint, *buttonTool, *buttonSet;
  125. disp_state_stack._disp_index = 0;
  126. ZERO(disp_state_stack._disp_state);
  127. disp_state_stack._disp_state[disp_state_stack._disp_index] = PRINT_READY_UI;
  128. disp_state = PRINT_READY_UI;
  129. scr = lv_obj_create(NULL, NULL);
  130. lv_obj_set_style(scr, &tft_style_scr);
  131. lv_scr_load(scr);
  132. lv_obj_clean(scr);
  133. //lv_obj_set_hidden(scr,true);
  134. lv_refr_now(lv_refr_get_disp_refreshing());
  135. if (mks_test_flag == 0x1E) {
  136. //lv_obj_t * title = lv_label_create(scr, NULL);
  137. //lv_obj_set_style(title, &tft_style_label_rel);
  138. //lv_obj_set_pos(title,TITLE_XPOS,TITLE_YPOS);
  139. //lv_label_set_text(title, creat_title_text());
  140. // Create image buttons
  141. //buttonPrint = lv_imgbtn_create(scr, NULL);
  142. buttonTool = lv_imgbtn_create(scr, NULL);
  143. //buttonSet = lv_imgbtn_create(scr, NULL);
  144. #if 1
  145. lv_obj_set_event_cb_mks(buttonTool, event_handler, ID_TOOL, NULL, 0);
  146. lv_imgbtn_set_src(buttonTool, LV_BTN_STATE_REL, "F:/bmp_tool.bin");
  147. lv_imgbtn_set_src(buttonTool, LV_BTN_STATE_PR, "F:/bmp_tool.bin");
  148. lv_imgbtn_set_style(buttonTool, LV_BTN_STATE_PR, &tft_style_label_pre);
  149. lv_imgbtn_set_style(buttonTool, LV_BTN_STATE_REL, &tft_style_label_rel);
  150. #endif
  151. lv_obj_set_pos(buttonTool, 360, 180);
  152. //lv_obj_set_pos(buttonSet,180,90);
  153. //lv_obj_set_pos(buttonPrint,340,90);
  154. //lv_obj_set_pos(buttonTool,SIMPLE_FIRST_PAGE_GRAP+1,(TFT_HEIGHT-BTN_Y_PIXEL)/2+2);
  155. //lv_obj_set_pos(buttonSet,BTN_X_PIXEL+SIMPLE_FIRST_PAGE_GRAP*2+1,(TFT_HEIGHT-BTN_Y_PIXEL)/2+2);
  156. //lv_obj_set_pos(buttonPrint,BTN_X_PIXEL*2+SIMPLE_FIRST_PAGE_GRAP*3+1,(TFT_HEIGHT-BTN_Y_PIXEL)/2+2);
  157. // Create labels on the image buttons
  158. //lv_btn_set_layout(buttonPrint, LV_LAYOUT_OFF);
  159. //lv_btn_set_layout(buttonSet, LV_LAYOUT_OFF);
  160. lv_btn_set_layout(buttonTool, LV_LAYOUT_OFF);
  161. //lv_obj_t *label_print = lv_label_create(buttonPrint, NULL);
  162. //lv_obj_t *label_set = lv_label_create(buttonSet, NULL);
  163. lv_obj_t *label_tool = lv_label_create(buttonTool, NULL);
  164. if (gCfgItems.multiple_language) {
  165. //lv_label_set_text(label_print, main_menu.print);
  166. //lv_obj_align(label_print, buttonPrint, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET);
  167. //lv_label_set_text(label_set, main_menu.set);
  168. //lv_obj_align(label_set, buttonSet, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET);
  169. //lv_label_set_style(label_tool,LV_BTN_STATE_PR,&tft_style_label_pre);
  170. //lv_label_set_style(label_tool,LV_BTN_STATE_REL,&tft_style_label_rel);
  171. lv_label_set_text(label_tool, main_menu.tool);
  172. lv_obj_align(label_tool, buttonTool, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  173. }
  174. #if 1
  175. e1 = lv_label_create(scr, NULL);
  176. lv_obj_set_pos(e1, 20, 20);
  177. sprintf_P(buf, PSTR("e1: %d"), (int)thermalManager.temp_hotend[0].celsius);
  178. lv_label_set_text(e1, buf);
  179. #if HAS_MULTI_HOTEND
  180. e2 = lv_label_create(scr, NULL);
  181. lv_obj_set_pos(e2, 20, 45);
  182. sprintf_P(buf, PSTR("e1: %d"), (int)thermalManager.temp_hotend[1].celsius);
  183. lv_label_set_text(e2, buf);
  184. #endif
  185. //e3 = lv_label_create(scr, NULL);
  186. //lv_obj_set_pos(e3,20,70);
  187. //sprintf_P(buf, PSTR("e1: %d"), (int)thermalManager.temp_hotend[2].celsius);
  188. //lv_label_set_text(e3, buf);
  189. #if HAS_HEATED_BED
  190. bed = lv_label_create(scr, NULL);
  191. lv_obj_set_pos(bed, 20, 95);
  192. sprintf_P(buf, PSTR("bed: %d"), (int)thermalManager.temp_bed.celsius);
  193. lv_label_set_text(bed, buf);
  194. #endif
  195. limit_info = lv_label_create(scr, NULL);
  196. lv_style_copy(&limit_style, &lv_style_scr);
  197. limit_style.body.main_color.full = 0X0000;
  198. limit_style.body.grad_color.full = 0X0000;
  199. limit_style.text.color.full = 0Xffff;
  200. lv_obj_set_style(limit_info, &limit_style);
  201. lv_obj_set_pos(limit_info, 20, 120);
  202. lv_label_set_text(limit_info, " ");
  203. det_info = lv_label_create(scr, NULL);
  204. lv_style_copy(&det_style, &lv_style_scr);
  205. det_style.body.main_color.full = 0X0000;
  206. det_style.body.grad_color.full = 0X0000;
  207. det_style.text.color.full = 0Xffff;
  208. lv_obj_set_style(det_info, &det_style);
  209. lv_obj_set_pos(det_info, 20, 145);
  210. lv_label_set_text(det_info, " ");
  211. #endif // if 1
  212. }
  213. else {
  214. // Create an Image button
  215. buttonTool = lv_imgbtn_create(scr, NULL);
  216. lv_obj_set_pos(buttonTool, 20, 90);
  217. lv_obj_set_event_cb_mks(buttonTool, event_handler, ID_TOOL, NULL, 0);
  218. lv_imgbtn_set_src(buttonTool, LV_BTN_STATE_REL, "F:/bmp_tool.bin");
  219. lv_imgbtn_set_src(buttonTool, LV_BTN_STATE_PR, "F:/bmp_tool.bin");
  220. lv_imgbtn_set_style(buttonTool, LV_BTN_STATE_PR, &tft_style_label_pre);
  221. lv_imgbtn_set_style(buttonTool, LV_BTN_STATE_REL, &tft_style_label_rel);
  222. lv_obj_t *label_tool = lv_label_create(buttonTool, NULL);
  223. lv_btn_set_layout(buttonTool, LV_LAYOUT_OFF);
  224. buttonSet = lv_imgbtn_create(scr, NULL);
  225. lv_obj_set_pos(buttonSet, 180, 90);
  226. lv_obj_set_event_cb_mks(buttonSet, event_handler, ID_SET, NULL, 0);
  227. lv_imgbtn_set_src(buttonSet, LV_BTN_STATE_REL, "F:/bmp_set.bin");
  228. lv_imgbtn_set_src(buttonSet, LV_BTN_STATE_PR, "F:/bmp_set.bin");
  229. lv_imgbtn_set_style(buttonSet, LV_BTN_STATE_PR, &tft_style_label_pre);
  230. lv_imgbtn_set_style(buttonSet, LV_BTN_STATE_REL, &tft_style_label_rel);
  231. lv_obj_t *label_set = lv_label_create(buttonSet, NULL);
  232. lv_btn_set_layout(buttonSet, LV_LAYOUT_OFF);
  233. buttonPrint = lv_imgbtn_create(scr, NULL);
  234. lv_obj_set_pos(buttonPrint, 340, 90);
  235. lv_obj_set_event_cb_mks(buttonPrint, event_handler, ID_PRINT, NULL, 0);
  236. lv_imgbtn_set_src(buttonPrint, LV_BTN_STATE_REL, "F:/bmp_printing.bin");
  237. lv_imgbtn_set_src(buttonPrint, LV_BTN_STATE_PR, "F:/bmp_printing.bin");
  238. lv_imgbtn_set_style(buttonPrint, LV_BTN_STATE_PR, &tft_style_label_pre);
  239. lv_imgbtn_set_style(buttonPrint, LV_BTN_STATE_REL, &tft_style_label_rel);
  240. lv_obj_t *label_print = lv_label_create(buttonPrint, NULL);
  241. lv_btn_set_layout(buttonPrint, LV_LAYOUT_OFF);
  242. if (gCfgItems.multiple_language) {
  243. lv_label_set_text(label_print, main_menu.print);
  244. lv_obj_align(label_print, buttonPrint, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  245. lv_label_set_text(label_set, main_menu.set);
  246. lv_obj_align(label_set, buttonSet, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  247. lv_label_set_text(label_tool, main_menu.tool);
  248. lv_obj_align(label_tool, buttonTool, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  249. }
  250. #if HAS_ROTARY_ENCODER
  251. if (gCfgItems.encoder_enable == true) {
  252. lv_group_add_obj(g, buttonTool);
  253. lv_group_add_obj(g, buttonSet);
  254. lv_group_add_obj(g, buttonPrint);
  255. }
  256. #endif
  257. }
  258. }
  259. void lv_clear_ready_print() {
  260. #if HAS_ROTARY_ENCODER
  261. if (gCfgItems.encoder_enable == true) lv_group_remove_all_objs(g);
  262. #endif
  263. lv_obj_del(scr);
  264. }
  265. #endif // HAS_TFT_LVGL_UI