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_dialog.cpp 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. /**
  23. * draw_dialog.cpp
  24. */
  25. #include "../../../../inc/MarlinConfigPre.h"
  26. #if HAS_TFT_LVGL_UI
  27. #include "lv_conf.h"
  28. #include "draw_ui.h"
  29. //#include "../lvgl/src/lv_objx/lv_imgbtn.h"
  30. //#include "../lvgl/src/lv_objx/lv_img.h"
  31. //#include "../lvgl/src/lv_core/lv_disp.h"
  32. //#include "../lvgl/src/lv_core/lv_refr.h"
  33. #include "../../../../MarlinCore.h"
  34. #include "../../../../sd/cardreader.h"
  35. #include "../../../../gcode/queue.h"
  36. #include "../../../../module/temperature.h"
  37. #include "../../../../module/planner.h"
  38. #if ENABLED(POWER_LOSS_RECOVERY)
  39. #include "../../../../feature/powerloss.h"
  40. #endif
  41. #if ENABLED(PARK_HEAD_ON_PAUSE)
  42. #include "../../../../feature/pause.h"
  43. #endif
  44. #include "../../../../gcode/gcode.h"
  45. #include "pic_manager.h"
  46. static lv_obj_t * scr;
  47. extern uint8_t sel_id;
  48. extern uint8_t once_flag;
  49. extern uint8_t gcode_preview_over;
  50. uint8_t DialogType;
  51. static void btn_ok_event_cb(lv_obj_t * btn, lv_event_t event) {
  52. if (event == LV_EVENT_CLICKED) {
  53. // nothing to do
  54. }
  55. else if (event == LV_EVENT_RELEASED) {
  56. if (DialogType == DIALOG_TYPE_PRINT_FILE) {
  57. #if HAS_GCODE_PREVIEW
  58. preview_gcode_prehandle(list_file.file_name[sel_id]);
  59. #endif
  60. reset_print_time();
  61. start_print_time();
  62. uiCfg.print_state = WORKING;
  63. lv_clear_dialog();
  64. lv_draw_printing();
  65. #if ENABLED(SDSUPPORT)
  66. if (gcode_preview_over != 1) {
  67. char *cur_name;
  68. cur_name = strrchr(list_file.file_name[sel_id], '/');
  69. SdFile file, *curDir;
  70. card.endFilePrint();
  71. const char * const fname = card.diveToFile(true, curDir, cur_name);
  72. if (!fname) return;
  73. if (file.open(curDir, fname, O_READ)) {
  74. gCfgItems.curFilesize = file.fileSize();
  75. file.close();
  76. update_spi_flash();
  77. }
  78. card.openFileRead(cur_name);
  79. if (card.isFileOpen()) {
  80. feedrate_percentage = 100;
  81. //saved_feedrate_percentage = feedrate_percentage;
  82. planner.flow_percentage[0] = 100;
  83. planner.e_factor[0] = planner.flow_percentage[0] * 0.01f;
  84. #if EXTRUDERS == 2
  85. planner.flow_percentage[1] = 100;
  86. planner.e_factor[1] = planner.flow_percentage[1] * 0.01f;
  87. #endif
  88. card.startFileprint();
  89. #if ENABLED(POWER_LOSS_RECOVERY)
  90. recovery.prepare();
  91. #endif
  92. once_flag = 0;
  93. }
  94. }
  95. #endif
  96. }
  97. else if (DialogType == DIALOG_TYPE_STOP) {
  98. stop_print_time();
  99. lv_clear_dialog();
  100. lv_draw_ready_print();
  101. #if ENABLED(SDSUPPORT)
  102. //card.endFilePrint();
  103. //wait_for_heatup = false;
  104. uiCfg.print_state = IDLE;
  105. card.flag.abort_sd_printing = true;
  106. //queue.clear();
  107. //quickstop_stepper();
  108. //print_job_timer.stop();
  109. //thermalManager.disable_all_heaters();
  110. //#if ENABLED(POWER_LOSS_RECOVERY)
  111. // recovery.purge();
  112. //#endif
  113. //queue.enqueue_now_P(PSTR("G91\nG1 Z10\nG90\nG28 X0 Y0"));
  114. //queue.inject_P(PSTR("G91\nG1 Z10\nG90\nG28 X0 Y0\nM84\nM107"));
  115. #endif
  116. }
  117. else if (DialogType == DIALOG_TYPE_FINISH_PRINT) {
  118. clear_cur_ui();
  119. lv_draw_ready_print();
  120. }
  121. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  122. else if (DialogType == DIALOG_PAUSE_MESSAGE_WAITING
  123. || DialogType == DIALOG_PAUSE_MESSAGE_INSERT
  124. || DialogType == DIALOG_PAUSE_MESSAGE_HEAT
  125. ) {
  126. wait_for_user = false;
  127. }
  128. else if (DialogType == DIALOG_PAUSE_MESSAGE_OPTION) {
  129. pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE;
  130. }
  131. else if (DialogType == DIALOG_PAUSE_MESSAGE_RESUME) {
  132. clear_cur_ui();
  133. draw_return_ui();
  134. }
  135. #endif
  136. else if (DialogType == DIALOG_STORE_EEPROM_TIPS) {
  137. gcode.process_subcommands_now_P(PSTR("M500"));
  138. clear_cur_ui();
  139. draw_return_ui();
  140. }
  141. else if (DialogType == DIALOG_READ_EEPROM_TIPS) {
  142. gcode.process_subcommands_now_P(PSTR("M501"));
  143. clear_cur_ui();
  144. draw_return_ui();
  145. }
  146. else if (DialogType == DIALOG_REVERT_EEPROM_TIPS) {
  147. gcode.process_subcommands_now_P(PSTR("M502"));
  148. clear_cur_ui();
  149. draw_return_ui();
  150. }
  151. }
  152. }
  153. static void btn_cancel_event_cb(lv_obj_t * btn, lv_event_t event) {
  154. if (event == LV_EVENT_CLICKED) {
  155. // nothing to do
  156. }
  157. else if (event == LV_EVENT_RELEASED) {
  158. if (DialogType == DIALOG_PAUSE_MESSAGE_OPTION) {
  159. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  160. pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT;
  161. #endif
  162. }
  163. else {
  164. clear_cur_ui();
  165. draw_return_ui();
  166. }
  167. }
  168. }
  169. void lv_draw_dialog(uint8_t type) {
  170. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != DIALOG_UI) {
  171. disp_state_stack._disp_index++;
  172. disp_state_stack._disp_state[disp_state_stack._disp_index] = DIALOG_UI;
  173. }
  174. disp_state = DIALOG_UI;
  175. DialogType = type;
  176. scr = lv_obj_create(NULL, NULL);
  177. lv_obj_set_style(scr, &tft_style_scr);
  178. lv_scr_load(scr);
  179. lv_obj_clean(scr);
  180. lv_obj_t * title = lv_label_create(scr, NULL);
  181. lv_obj_set_style(title, &tft_style_label_rel);
  182. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  183. lv_label_set_text(title, creat_title_text());
  184. lv_refr_now(lv_refr_get_disp_refreshing());
  185. //LV_IMG_DECLARE(bmp_pic);
  186. static lv_style_t style_btn_rel; // A variable to store the released style
  187. lv_style_copy(&style_btn_rel, &lv_style_plain); // Initialize from a built-in style
  188. style_btn_rel.body.border.color = lv_color_hex3(0x269);
  189. style_btn_rel.body.border.width = 1;
  190. style_btn_rel.body.main_color = lv_color_hex3(0xADF);
  191. style_btn_rel.body.grad_color = lv_color_hex3(0x46B);
  192. style_btn_rel.body.shadow.width = 4;
  193. style_btn_rel.body.shadow.type = LV_SHADOW_BOTTOM;
  194. style_btn_rel.body.radius = LV_RADIUS_CIRCLE;
  195. style_btn_rel.text.color = lv_color_hex3(0xDEF);
  196. style_btn_rel.text.font = &TERN(HAS_SPI_FLASH_FONT, gb2312_puhui32, lv_font_roboto_22);
  197. static lv_style_t style_btn_pr; // A variable to store the pressed style
  198. lv_style_copy(&style_btn_pr, &style_btn_rel); // Initialize from the released style
  199. style_btn_pr.body.border.color = lv_color_hex3(0x46B);
  200. style_btn_pr.body.main_color = lv_color_hex3(0x8BD);
  201. style_btn_pr.body.grad_color = lv_color_hex3(0x24A);
  202. style_btn_pr.body.shadow.width = 2;
  203. style_btn_pr.text.color = lv_color_hex3(0xBCD);
  204. style_btn_pr.text.font = &TERN(HAS_SPI_FLASH_FONT, gb2312_puhui32, lv_font_roboto_22);
  205. lv_obj_t * labelDialog = lv_label_create(scr, NULL);
  206. lv_obj_set_style(labelDialog, &tft_style_label_rel);
  207. if (DialogType == DIALOG_TYPE_FINISH_PRINT || DialogType == DIALOG_PAUSE_MESSAGE_RESUME) {
  208. lv_obj_t * btnOk = lv_btn_create(scr, NULL); // Add a button the current screen
  209. lv_obj_set_pos(btnOk, BTN_OK_X + 90, BTN_OK_Y); // Set its position
  210. lv_obj_set_size(btnOk, 100, 50); // Set its size
  211. lv_obj_set_event_cb(btnOk, btn_ok_event_cb);
  212. lv_btn_set_style(btnOk, LV_BTN_STYLE_REL, &style_btn_rel); // Set the button's released style
  213. lv_btn_set_style(btnOk, LV_BTN_STYLE_PR, &style_btn_pr); // Set the button's pressed style
  214. lv_obj_t * labelOk = lv_label_create(btnOk, NULL); // Add a label to the button
  215. lv_label_set_text(labelOk, print_file_dialog_menu.confirm); // Set the labels text
  216. }
  217. else if (DialogType == DIALOG_PAUSE_MESSAGE_WAITING
  218. || DialogType == DIALOG_PAUSE_MESSAGE_INSERT
  219. || DialogType == DIALOG_PAUSE_MESSAGE_HEAT
  220. ) {
  221. lv_obj_t * btnOk = lv_btn_create(scr, NULL); // Add a button the current screen
  222. lv_obj_set_pos(btnOk, BTN_OK_X + 90, BTN_OK_Y); // Set its position
  223. lv_obj_set_size(btnOk, 100, 50); // Set its size
  224. lv_obj_set_event_cb(btnOk, btn_ok_event_cb);
  225. lv_btn_set_style(btnOk, LV_BTN_STYLE_REL, &style_btn_rel); // Set the button's released style
  226. lv_btn_set_style(btnOk, LV_BTN_STYLE_PR, &style_btn_pr); // Set the button's pressed style
  227. lv_obj_t * labelOk = lv_label_create(btnOk, NULL); // Add a label to the button
  228. lv_label_set_text(labelOk, print_file_dialog_menu.confirm); // Set the labels text
  229. }
  230. else if (DialogType == DIALOG_PAUSE_MESSAGE_PAUSING
  231. || DialogType == DIALOG_PAUSE_MESSAGE_CHANGING
  232. || DialogType == DIALOG_PAUSE_MESSAGE_UNLOAD
  233. || DialogType == DIALOG_PAUSE_MESSAGE_LOAD
  234. || DialogType == DIALOG_PAUSE_MESSAGE_PURGE
  235. || DialogType == DIALOG_PAUSE_MESSAGE_RESUME
  236. || DialogType == DIALOG_PAUSE_MESSAGE_HEATING
  237. ) {
  238. // nothing to do
  239. }
  240. else {
  241. lv_obj_t * btnOk = lv_btn_create(scr, NULL); // Add a button the current screen
  242. lv_obj_set_pos(btnOk, BTN_OK_X, BTN_OK_Y); // Set its position
  243. lv_obj_set_size(btnOk, 100, 50); // Set its size
  244. lv_obj_set_event_cb(btnOk, btn_ok_event_cb);
  245. lv_btn_set_style(btnOk, LV_BTN_STYLE_REL, &style_btn_rel); // Set the button's released style
  246. lv_btn_set_style(btnOk, LV_BTN_STYLE_PR, &style_btn_pr); // Set the button's pressed style
  247. lv_obj_t * labelOk = lv_label_create(btnOk, NULL); // Add a label to the button
  248. lv_obj_t * btnCancel = lv_btn_create(scr, NULL); // Add a button the current screen
  249. lv_obj_set_pos(btnCancel, BTN_CANCEL_X, BTN_CANCEL_Y); // Set its position
  250. lv_obj_set_size(btnCancel, 100, 50); // Set its size
  251. lv_obj_set_event_cb(btnCancel, btn_cancel_event_cb);
  252. lv_btn_set_style(btnCancel, LV_BTN_STYLE_REL, &style_btn_rel); // Set the button's released style
  253. lv_btn_set_style(btnCancel, LV_BTN_STYLE_PR, &style_btn_pr); // Set the button's pressed style
  254. lv_obj_t * labelCancel = lv_label_create(btnCancel, NULL); // Add a label to the button
  255. if (DialogType == DIALOG_PAUSE_MESSAGE_OPTION) {
  256. lv_label_set_text(labelOk, pause_msg_menu.purgeMore); // Set the labels text
  257. lv_label_set_text(labelCancel, pause_msg_menu.continuePrint);
  258. }
  259. else {
  260. lv_label_set_text(labelOk, print_file_dialog_menu.confirm); // Set the labels text
  261. lv_label_set_text(labelCancel, print_file_dialog_menu.cancle);
  262. }
  263. }
  264. if (DialogType == DIALOG_TYPE_PRINT_FILE) {
  265. lv_label_set_text(labelDialog, print_file_dialog_menu.print_file);
  266. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  267. lv_obj_t * labelFile = lv_label_create(scr, NULL);
  268. lv_obj_set_style(labelFile, &tft_style_label_rel);
  269. lv_label_set_text(labelFile, list_file.long_name[sel_id]);
  270. lv_obj_align(labelFile, NULL, LV_ALIGN_CENTER, 0, -60);
  271. }
  272. else if (DialogType == DIALOG_TYPE_STOP) {
  273. lv_label_set_text(labelDialog, print_file_dialog_menu.cancle_print);
  274. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  275. }
  276. else if (DialogType == DIALOG_TYPE_FINISH_PRINT) {
  277. lv_label_set_text(labelDialog, print_file_dialog_menu.print_finish);
  278. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  279. }
  280. else if (DialogType == DIALOG_PAUSE_MESSAGE_PAUSING) {
  281. lv_label_set_text(labelDialog, pause_msg_menu.pausing);
  282. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  283. }
  284. else if (DialogType == DIALOG_PAUSE_MESSAGE_CHANGING) {
  285. lv_label_set_text(labelDialog, pause_msg_menu.changing);
  286. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  287. }
  288. else if (DialogType == DIALOG_PAUSE_MESSAGE_UNLOAD) {
  289. lv_label_set_text(labelDialog, pause_msg_menu.unload);
  290. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  291. }
  292. else if (DialogType == DIALOG_PAUSE_MESSAGE_WAITING) {
  293. lv_label_set_text(labelDialog, pause_msg_menu.waiting);
  294. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  295. }
  296. else if (DialogType == DIALOG_PAUSE_MESSAGE_INSERT) {
  297. lv_label_set_text(labelDialog, pause_msg_menu.insert);
  298. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  299. }
  300. else if (DialogType == DIALOG_PAUSE_MESSAGE_LOAD) {
  301. lv_label_set_text(labelDialog, pause_msg_menu.load);
  302. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  303. }
  304. else if (DialogType == DIALOG_PAUSE_MESSAGE_PURGE) {
  305. lv_label_set_text(labelDialog, pause_msg_menu.purge);
  306. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  307. }
  308. else if (DialogType == DIALOG_PAUSE_MESSAGE_RESUME) {
  309. lv_label_set_text(labelDialog, pause_msg_menu.resume);
  310. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  311. }
  312. else if (DialogType == DIALOG_PAUSE_MESSAGE_HEAT) {
  313. lv_label_set_text(labelDialog, pause_msg_menu.heat);
  314. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  315. }
  316. else if (DialogType == DIALOG_PAUSE_MESSAGE_HEATING) {
  317. lv_label_set_text(labelDialog, pause_msg_menu.heating);
  318. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  319. }
  320. else if (DialogType == DIALOG_PAUSE_MESSAGE_OPTION) {
  321. lv_label_set_text(labelDialog, pause_msg_menu.option);
  322. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  323. }
  324. else if (DialogType == DIALOG_STORE_EEPROM_TIPS) {
  325. lv_label_set_text(labelDialog, eeprom_menu.storeTips);
  326. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  327. }
  328. else if (DialogType == DIALOG_READ_EEPROM_TIPS) {
  329. lv_label_set_text(labelDialog, eeprom_menu.readTips);
  330. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  331. }
  332. else if (DialogType == DIALOG_REVERT_EEPROM_TIPS) {
  333. lv_label_set_text(labelDialog, eeprom_menu.revertTips);
  334. lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20);
  335. }
  336. }
  337. void lv_clear_dialog() { lv_obj_del(scr); }
  338. #endif // HAS_TFT_LVGL_UI