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 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 "tft_lvgl_configuration.h"
  28. #include "draw_ui.h"
  29. #include <lvgl.h>
  30. #include "../../../module/temperature.h"
  31. #include "../../../inc/MarlinConfig.h"
  32. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  33. #include "../../tft_io/touch_calibration.h"
  34. #include "draw_touch_calibration.h"
  35. #endif
  36. #include "mks_hardware.h"
  37. #include <stdio.h>
  38. #define ICON_POS_Y 260
  39. #define TARGET_LABEL_MOD_Y -36
  40. #define LABEL_MOD_Y 30
  41. extern lv_group_t* g;
  42. static lv_obj_t *scr;
  43. static lv_obj_t *buttonExt1, *labelExt1, *buttonFanstate, *labelFan;
  44. #if HAS_MULTI_HOTEND
  45. static lv_obj_t *labelExt2;
  46. static lv_obj_t *buttonExt2;
  47. #endif
  48. #if HAS_HEATED_BED
  49. static lv_obj_t* labelBed;
  50. static lv_obj_t* buttonBedstate;
  51. #endif
  52. #if ENABLED(MKS_TEST)
  53. uint8_t current_disp_ui = 0;
  54. #endif
  55. enum { ID_TOOL = 1, ID_SET, ID_PRINT, ID_INFO_EXT, ID_INFO_BED, ID_INFO_FAN };
  56. static void event_handler(lv_obj_t *obj, lv_event_t event) {
  57. if (event != LV_EVENT_RELEASED) return;
  58. lv_clear_ready_print();
  59. switch (obj->mks_obj_id) {
  60. case ID_TOOL: lv_draw_tool(); break;
  61. case ID_SET: lv_draw_set(); break;
  62. case ID_INFO_EXT: uiCfg.curTempType = 0; lv_draw_preHeat(); break;
  63. case ID_INFO_BED: uiCfg.curTempType = 1; lv_draw_preHeat(); break;
  64. case ID_INFO_FAN: lv_draw_fan(); break;
  65. case ID_PRINT: TERN(MULTI_VOLUME, lv_draw_media_select(), lv_draw_print_file()); break;
  66. }
  67. }
  68. lv_obj_t *limit_info, *det_info;
  69. lv_style_t limit_style, det_style;
  70. void disp_Limit_ok() {
  71. limit_style.text.color.full = 0xFFFF;
  72. lv_obj_set_style(limit_info, &limit_style);
  73. lv_label_set_text(limit_info, "Limit:ok");
  74. }
  75. void disp_Limit_error() {
  76. limit_style.text.color.full = 0xF800;
  77. lv_obj_set_style(limit_info, &limit_style);
  78. lv_label_set_text(limit_info, "Limit:error");
  79. }
  80. void disp_det_ok() {
  81. det_style.text.color.full = 0xFFFF;
  82. lv_obj_set_style(det_info, &det_style);
  83. lv_label_set_text(det_info, "det:ok");
  84. }
  85. void disp_det_error() {
  86. det_style.text.color.full = 0xF800;
  87. lv_obj_set_style(det_info, &det_style);
  88. lv_label_set_text(det_info, "det:error");
  89. }
  90. lv_obj_t *e1, *e2, *e3, *bed;
  91. void mks_disp_test() {
  92. char buf[30] = {0};
  93. #if HAS_HOTEND
  94. sprintf_P(buf, PSTR("e1:%d"), thermalManager.wholeDegHotend(0));
  95. lv_label_set_text(e1, buf);
  96. #endif
  97. #if HAS_MULTI_HOTEND
  98. sprintf_P(buf, PSTR("e2:%d"), thermalManager.wholeDegHotend(1));
  99. lv_label_set_text(e2, buf);
  100. #endif
  101. #if HAS_HEATED_BED
  102. sprintf_P(buf, PSTR("bed:%d"), thermalManager.wholeDegBed());
  103. lv_label_set_text(bed, buf);
  104. #endif
  105. }
  106. void lv_draw_ready_print() {
  107. char buf[30] = {0};
  108. lv_obj_t *buttonTool;
  109. disp_state_stack._disp_index = 0;
  110. ZERO(disp_state_stack._disp_state);
  111. scr = lv_screen_create(PRINT_READY_UI, "");
  112. if (mks_test_flag == 0x1E) {
  113. // Create image buttons
  114. buttonTool = lv_imgbtn_create(scr, "F:/bmp_tool.bin", event_handler, ID_TOOL);
  115. lv_obj_set_pos(buttonTool, 360, 180);
  116. lv_obj_t *label_tool = lv_label_create_empty(buttonTool);
  117. if (gCfgItems.multiple_language) {
  118. lv_label_set_text(label_tool, main_menu.tool);
  119. lv_obj_align(label_tool, buttonTool, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  120. }
  121. #if HAS_HOTEND
  122. e1 = lv_label_create_empty(scr);
  123. lv_obj_set_pos(e1, 20, 20);
  124. sprintf_P(buf, PSTR("e1: %d"), thermalManager.wholeDegHotend(0));
  125. lv_label_set_text(e1, buf);
  126. #endif
  127. #if HAS_MULTI_HOTEND
  128. e2 = lv_label_create_empty(scr);
  129. lv_obj_set_pos(e2, 20, 45);
  130. sprintf_P(buf, PSTR("e2: %d"), thermalManager.wholeDegHotend(1));
  131. lv_label_set_text(e2, buf);
  132. #endif
  133. #if HAS_HEATED_BED
  134. bed = lv_label_create_empty(scr);
  135. lv_obj_set_pos(bed, 20, 95);
  136. sprintf_P(buf, PSTR("bed: %d"), thermalManager.wholeDegBed());
  137. lv_label_set_text(bed, buf);
  138. #endif
  139. limit_info = lv_label_create_empty(scr);
  140. lv_style_copy(&limit_style, &lv_style_scr);
  141. limit_style.body.main_color.full = 0x0000;
  142. limit_style.body.grad_color.full = 0x0000;
  143. limit_style.text.color.full = 0xFFFF;
  144. lv_obj_set_style(limit_info, &limit_style);
  145. lv_obj_set_pos(limit_info, 20, 120);
  146. lv_label_set_text(limit_info, " ");
  147. det_info = lv_label_create_empty(scr);
  148. lv_style_copy(&det_style, &lv_style_scr);
  149. det_style.body.main_color.full = 0x0000;
  150. det_style.body.grad_color.full = 0x0000;
  151. det_style.text.color.full = 0xFFFF;
  152. lv_obj_set_style(det_info, &det_style);
  153. lv_obj_set_pos(det_info, 20, 145);
  154. lv_label_set_text(det_info, " ");
  155. }
  156. else {
  157. lv_big_button_create(scr, "F:/bmp_tool.bin", main_menu.tool, 20, 90, event_handler, ID_TOOL);
  158. lv_big_button_create(scr, "F:/bmp_set.bin", main_menu.set, 180, 90, event_handler, ID_SET);
  159. lv_big_button_create(scr, "F:/bmp_printing.bin", main_menu.print, 340, 90, event_handler, ID_PRINT);
  160. // Monitoring
  161. #if HAS_HOTEND
  162. buttonExt1 = lv_big_button_create(scr, "F:/bmp_ext1_state.bin", " ", 20, ICON_POS_Y, event_handler, ID_INFO_EXT);
  163. #endif
  164. #if HAS_MULTI_HOTEND
  165. buttonExt2 = lv_big_button_create(scr, "F:/bmp_ext2_state.bin", " ", 180, ICON_POS_Y, event_handler, ID_INFO_EXT);
  166. #endif
  167. #if HAS_HEATED_BED
  168. buttonBedstate = lv_big_button_create(scr, "F:/bmp_bed_state.bin", " ", TERN(HAS_MULTI_HOTEND, 340, 210), ICON_POS_Y, event_handler, ID_INFO_BED);
  169. #endif
  170. TERN_(HAS_HOTEND, labelExt1 = lv_label_create_empty(scr));
  171. TERN_(HAS_MULTI_HOTEND, labelExt2 = lv_label_create_empty(scr));
  172. TERN_(HAS_HEATED_BED, labelBed = lv_label_create_empty(scr));
  173. TERN_(HAS_FAN, labelFan = lv_label_create_empty(scr));
  174. lv_temp_refr();
  175. }
  176. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  177. // If calibration is required, let's trigger it now, handles the case when there is default value in configuration files
  178. if (!touch_calibration.calibration_loaded()) {
  179. lv_clear_ready_print();
  180. lv_draw_touch_calibration_screen();
  181. }
  182. #endif
  183. }
  184. void lv_temp_refr() {
  185. #if HAS_HOTEND
  186. sprintf(public_buf_l, printing_menu.temp1, thermalManager.wholeDegHotend(0), thermalManager.degTargetHotend(0));
  187. lv_label_set_text(labelExt1, public_buf_l);
  188. lv_obj_align(labelExt1, buttonExt1, LV_ALIGN_OUT_RIGHT_MID, 0, 0);
  189. #endif
  190. #if HAS_MULTI_HOTEND
  191. sprintf(public_buf_l, printing_menu.temp1, thermalManager.wholeDegHotend(1), thermalManager.degTargetHotend(1));
  192. lv_label_set_text(labelExt2, public_buf_l);
  193. lv_obj_align(labelExt2, buttonExt2, LV_ALIGN_OUT_RIGHT_MID, 0, 0);
  194. #endif
  195. #if HAS_HEATED_BED
  196. sprintf(public_buf_l, printing_menu.bed_temp, thermalManager.wholeDegBed(), thermalManager.degTargetBed());
  197. lv_label_set_text(labelBed, public_buf_l);
  198. lv_obj_align(labelBed, buttonBedstate, LV_ALIGN_OUT_RIGHT_MID, 0, 0);
  199. #endif
  200. #if HAS_FAN
  201. sprintf_P(public_buf_l, PSTR("%d%%"), (int)thermalManager.fanSpeedPercent(0));
  202. lv_label_set_text(labelFan, public_buf_l);
  203. lv_obj_align(labelFan, buttonFanstate, LV_ALIGN_OUT_RIGHT_MID, 0, 0);
  204. #endif
  205. }
  206. void lv_clear_ready_print() {
  207. #if HAS_ROTARY_ENCODER
  208. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  209. #endif
  210. lv_obj_del(scr);
  211. }
  212. #endif // HAS_TFT_LVGL_UI