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_extrusion.cpp 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../../inc/MarlinConfigPre.h"
  23. #if ENABLED(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 "../../../../module/temperature.h"
  32. #include "../../../../gcode/queue.h"
  33. static lv_obj_t * scr;
  34. static lv_obj_t * buttoType, *buttonStep, *buttonSpeed;
  35. static lv_obj_t * labelType;
  36. static lv_obj_t * labelStep;
  37. static lv_obj_t * labelSpeed;
  38. static lv_obj_t * tempText;
  39. static lv_obj_t * ExtruText;
  40. #define ID_E_ADD 1
  41. #define ID_E_DEC 2
  42. #define ID_E_TYPE 3
  43. #define ID_E_STEP 4
  44. #define ID_E_SPEED 5
  45. #define ID_E_RETURN 6
  46. static int32_t extructAmount;
  47. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  48. switch (obj->mks_obj_id) {
  49. case ID_E_ADD:
  50. if (event == LV_EVENT_CLICKED) {
  51. // nothing to do
  52. }
  53. else if (event == LV_EVENT_RELEASED) {
  54. if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius >= EXTRUDE_MINTEMP) {
  55. queue.enqueue_one_now(PSTR("G91"));
  56. memset(public_buf_l, 0, sizeof(public_buf_l));
  57. sprintf((char *)public_buf_l, "G1 E%d F%d", uiCfg.extruStep, 60 * uiCfg.extruSpeed);
  58. queue.enqueue_one_now(PSTR(public_buf_l));
  59. queue.enqueue_one_now(PSTR("G90"));
  60. extructAmount += uiCfg.extruStep;
  61. disp_extru_amount();
  62. }
  63. }
  64. break;
  65. case ID_E_DEC:
  66. if (event == LV_EVENT_CLICKED) {
  67. // nothing to do
  68. }
  69. else if (event == LV_EVENT_RELEASED) {
  70. if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius >= EXTRUDE_MINTEMP) {
  71. queue.enqueue_one_now(PSTR("G91"));
  72. memset(public_buf_l, 0, sizeof(public_buf_l));
  73. sprintf((char *)public_buf_l, "G1 E%d F%d", 0 - uiCfg.extruStep, 60 * uiCfg.extruSpeed);
  74. queue.enqueue_one_now(PSTR(public_buf_l));
  75. queue.enqueue_one_now(PSTR("G90"));
  76. extructAmount -= uiCfg.extruStep;
  77. disp_extru_amount();
  78. }
  79. }
  80. break;
  81. case ID_E_TYPE:
  82. if (event == LV_EVENT_CLICKED) {
  83. // nothing to do
  84. }
  85. else if (event == LV_EVENT_RELEASED) {
  86. if (EXTRUDERS == 2) {
  87. if (uiCfg.curSprayerChoose == 0) {
  88. uiCfg.curSprayerChoose = 1;
  89. queue.inject_P(PSTR("T1"));
  90. }
  91. else {
  92. uiCfg.curSprayerChoose = 0;
  93. queue.inject_P(PSTR("T0"));
  94. }
  95. }
  96. else {
  97. uiCfg.curSprayerChoose = 0;
  98. }
  99. extructAmount = 0;
  100. disp_hotend_temp();
  101. disp_ext_type();
  102. disp_extru_amount();
  103. }
  104. break;
  105. case ID_E_STEP:
  106. if (event == LV_EVENT_CLICKED) {
  107. // nothing to do
  108. }
  109. else if (event == LV_EVENT_RELEASED) {
  110. switch (abs(uiCfg.extruStep)) {
  111. case 1: uiCfg.extruStep = 5; break;
  112. case 5: uiCfg.extruStep = 10; break;
  113. case 10: uiCfg.extruStep = 1; break;
  114. default: break;
  115. }
  116. disp_ext_step();
  117. }
  118. break;
  119. case ID_E_SPEED:
  120. if (event == LV_EVENT_CLICKED) {
  121. // nothing to do
  122. }
  123. else if (event == LV_EVENT_RELEASED) {
  124. switch (uiCfg.extruSpeed) {
  125. case 1: uiCfg.extruSpeed = 10; break;
  126. case 10: uiCfg.extruSpeed = 20; break;
  127. case 20: uiCfg.extruSpeed = 1; break;
  128. default: break;
  129. }
  130. disp_ext_speed();
  131. }
  132. break;
  133. case ID_E_RETURN:
  134. if (event == LV_EVENT_CLICKED) {
  135. // nothing to do
  136. }
  137. else if (event == LV_EVENT_RELEASED) {
  138. clear_cur_ui();
  139. draw_return_ui();
  140. }
  141. break;
  142. }
  143. }
  144. void lv_draw_extrusion(void) {
  145. lv_obj_t *buttonAdd, *buttonDec, *buttonBack;
  146. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != EXTRUSION_UI) {
  147. disp_state_stack._disp_index++;
  148. disp_state_stack._disp_state[disp_state_stack._disp_index] = EXTRUSION_UI;
  149. }
  150. disp_state = EXTRUSION_UI;
  151. scr = lv_obj_create(NULL, NULL);
  152. lv_obj_set_style(scr, &tft_style_scr);
  153. lv_scr_load(scr);
  154. lv_obj_clean(scr);
  155. lv_obj_t * title = lv_label_create(scr, NULL);
  156. lv_obj_set_style(title, &tft_style_lable_rel);
  157. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  158. lv_label_set_text(title, creat_title_text());
  159. lv_refr_now(lv_refr_get_disp_refreshing());
  160. LV_IMG_DECLARE(bmp_pic);
  161. /*Create an Image button*/
  162. buttonAdd = lv_imgbtn_create(scr, NULL);
  163. buttonDec = lv_imgbtn_create(scr, NULL);
  164. buttoType = lv_imgbtn_create(scr, NULL);
  165. buttonStep = lv_imgbtn_create(scr, NULL);
  166. buttonSpeed = lv_imgbtn_create(scr, NULL);
  167. buttonBack = lv_imgbtn_create(scr, NULL);
  168. lv_obj_set_event_cb_mks(buttonAdd, event_handler, ID_E_ADD, "bmp_In.bin", 0);
  169. lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_REL, &bmp_pic);
  170. lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_PR, &bmp_pic);
  171. lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_PR, &tft_style_lable_pre);
  172. lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_REL, &tft_style_lable_rel);
  173. lv_obj_clear_protect(buttonAdd, LV_PROTECT_FOLLOW);
  174. #if 1
  175. lv_obj_set_event_cb_mks(buttonDec, event_handler, ID_E_DEC, "bmp_Out.bin", 0);
  176. lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_REL, &bmp_pic);
  177. lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_PR, &bmp_pic);
  178. lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_PR, &tft_style_lable_pre);
  179. lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_REL, &tft_style_lable_rel);
  180. lv_imgbtn_set_src(buttoType, LV_BTN_STATE_REL, &bmp_pic);
  181. lv_imgbtn_set_src(buttoType, LV_BTN_STATE_PR, &bmp_pic);
  182. lv_imgbtn_set_style(buttoType, LV_BTN_STATE_PR, &tft_style_lable_pre);
  183. lv_imgbtn_set_style(buttoType, LV_BTN_STATE_REL, &tft_style_lable_rel);
  184. lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_REL, &bmp_pic);
  185. lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_PR, &bmp_pic);
  186. lv_imgbtn_set_style(buttonStep, LV_BTN_STATE_PR, &tft_style_lable_pre);
  187. lv_imgbtn_set_style(buttonStep, LV_BTN_STATE_REL, &tft_style_lable_rel);
  188. lv_imgbtn_set_src(buttonSpeed, LV_BTN_STATE_REL, &bmp_pic);
  189. lv_imgbtn_set_src(buttonSpeed, LV_BTN_STATE_PR, &bmp_pic);
  190. lv_imgbtn_set_style(buttonSpeed, LV_BTN_STATE_PR, &tft_style_lable_pre);
  191. lv_imgbtn_set_style(buttonSpeed, LV_BTN_STATE_REL, &tft_style_lable_rel);
  192. lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_E_RETURN, "bmp_Return.bin", 0);
  193. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, &bmp_pic);
  194. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, &bmp_pic);
  195. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_lable_pre);
  196. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_lable_rel);
  197. #endif
  198. lv_obj_set_pos(buttonAdd, INTERVAL_V, titleHeight);
  199. lv_obj_set_pos(buttonDec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight);
  200. lv_obj_set_pos(buttoType, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  201. lv_obj_set_pos(buttonStep, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  202. lv_obj_set_pos(buttonSpeed, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  203. lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  204. /*Create a label on the Image button*/
  205. lv_btn_set_layout(buttonAdd, LV_LAYOUT_OFF);
  206. lv_btn_set_layout(buttonDec, LV_LAYOUT_OFF);
  207. lv_btn_set_layout(buttoType, LV_LAYOUT_OFF);
  208. lv_btn_set_layout(buttonStep, LV_LAYOUT_OFF);
  209. lv_btn_set_layout(buttonSpeed, LV_LAYOUT_OFF);
  210. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  211. lv_obj_t * labelAdd = lv_label_create(buttonAdd, NULL);
  212. lv_obj_t * labelDec = lv_label_create(buttonDec, NULL);
  213. labelType = lv_label_create(buttoType, NULL);
  214. labelStep = lv_label_create(buttonStep, NULL);
  215. labelSpeed = lv_label_create(buttonSpeed, NULL);
  216. lv_obj_t * label_Back = lv_label_create(buttonBack, NULL);
  217. if (gCfgItems.multiple_language != 0) {
  218. lv_label_set_text(labelAdd, extrude_menu.in);
  219. lv_obj_align(labelAdd, buttonAdd, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  220. lv_label_set_text(labelDec, extrude_menu.out);
  221. lv_obj_align(labelDec, buttonDec, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  222. lv_label_set_text(label_Back, common_menu.text_back);
  223. lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  224. }
  225. disp_ext_type();
  226. disp_ext_step();
  227. disp_ext_speed();
  228. tempText = lv_label_create(scr, NULL);
  229. lv_obj_set_style(tempText, &tft_style_lable_rel);
  230. disp_hotend_temp();
  231. ExtruText = lv_label_create(scr, NULL);
  232. lv_obj_set_style(ExtruText, &tft_style_lable_rel);
  233. disp_extru_amount();
  234. }
  235. void disp_ext_type() {
  236. if (uiCfg.curSprayerChoose == 1) {
  237. lv_obj_set_event_cb_mks(buttoType, event_handler, ID_E_TYPE, "bmp_Extru2.bin", 0);
  238. if (gCfgItems.multiple_language != 0) {
  239. lv_label_set_text(labelType, extrude_menu.ext2);
  240. lv_obj_align(labelType, buttoType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  241. }
  242. }
  243. else {
  244. lv_obj_set_event_cb_mks(buttoType, event_handler, ID_E_TYPE, "bmp_Extru1.bin", 0);
  245. if (gCfgItems.multiple_language != 0) {
  246. lv_label_set_text(labelType, extrude_menu.ext1);
  247. lv_obj_align(labelType, buttoType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  248. }
  249. }
  250. }
  251. void disp_ext_speed() {
  252. if (uiCfg.extruSpeed == 20)
  253. lv_obj_set_event_cb_mks(buttonSpeed, event_handler, ID_E_SPEED, "bmp_Speed_high.bin", 0);
  254. else if (uiCfg.extruSpeed == 1)
  255. lv_obj_set_event_cb_mks(buttonSpeed, event_handler, ID_E_SPEED, "bmp_Speed_slow.bin", 0);
  256. else
  257. lv_obj_set_event_cb_mks(buttonSpeed, event_handler, ID_E_SPEED, "bmp_Speed_normal.bin", 0);
  258. if (gCfgItems.multiple_language != 0) {
  259. if (uiCfg.extruSpeed == 20) {
  260. lv_label_set_text(labelSpeed, extrude_menu.high);
  261. lv_obj_align(labelSpeed, buttonSpeed, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  262. }
  263. else if (uiCfg.extruSpeed == 1) {
  264. lv_label_set_text(labelSpeed, extrude_menu.low);
  265. lv_obj_align(labelSpeed, buttonSpeed, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  266. }
  267. else {
  268. lv_label_set_text(labelSpeed, extrude_menu.normal);
  269. lv_obj_align(labelSpeed, buttonSpeed, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  270. }
  271. }
  272. }
  273. void disp_hotend_temp() {
  274. char buf[20] = {0};
  275. public_buf_l[0] = '\0';
  276. strcat(public_buf_l, extrude_menu.temper_text);
  277. sprintf(buf, extrude_menu.temp_value, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target);
  278. strcat(public_buf_l, buf);
  279. lv_label_set_text(tempText, public_buf_l);
  280. lv_obj_align(tempText, NULL, LV_ALIGN_CENTER, 0, -50);
  281. }
  282. void disp_extru_amount() {
  283. char buf1[10] = {0};
  284. public_buf_l[0] = '\0';
  285. if (extructAmount < 999 && extructAmount > -99) {
  286. sprintf(buf1, extrude_menu.count_value_mm, extructAmount);
  287. if (uiCfg.curSprayerChoose < 1)
  288. strcat(public_buf_l, extrude_menu.ext1);
  289. else
  290. strcat(public_buf_l, extrude_menu.ext2);
  291. strcat(public_buf_l, buf1);
  292. }
  293. else if (extructAmount < 9999 && extructAmount > -999) {
  294. sprintf(buf1, extrude_menu.count_value_cm, extructAmount / 10);
  295. if (uiCfg.curSprayerChoose < 1)
  296. strcat(public_buf_l, extrude_menu.ext1);
  297. else
  298. strcat(public_buf_l, extrude_menu.ext2);
  299. strcat(public_buf_l, buf1);
  300. }
  301. else {
  302. sprintf(buf1, extrude_menu.count_value_m, extructAmount / 1000);
  303. if (uiCfg.curSprayerChoose < 1)
  304. strcat(public_buf_l, extrude_menu.ext1);
  305. else
  306. strcat(public_buf_l, extrude_menu.ext2);
  307. strcat(public_buf_l, buf1);
  308. }
  309. lv_label_set_text(ExtruText, public_buf_l);
  310. lv_obj_align(ExtruText, NULL, LV_ALIGN_CENTER, 0, -75);
  311. }
  312. void disp_ext_step() {
  313. if (uiCfg.extruStep == 1)
  314. lv_obj_set_event_cb_mks(buttonStep, event_handler, ID_E_STEP, "bmp_Step1_mm.bin", 0);
  315. else if (uiCfg.extruStep == 5)
  316. lv_obj_set_event_cb_mks(buttonStep, event_handler, ID_E_STEP, "bmp_Step5_mm.bin", 0);
  317. else if (uiCfg.extruStep == 10)
  318. lv_obj_set_event_cb_mks(buttonStep, event_handler, ID_E_STEP, "bmp_Step10_mm.bin", 0);
  319. if (gCfgItems.multiple_language != 0) {
  320. if (uiCfg.extruStep == 1) {
  321. lv_label_set_text(labelStep, extrude_menu.step_1mm);
  322. lv_obj_align(labelStep, buttonStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  323. }
  324. else if (uiCfg.extruStep == 5) {
  325. lv_label_set_text(labelStep, extrude_menu.step_5mm);
  326. lv_obj_align(labelStep, buttonStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  327. }
  328. else if (uiCfg.extruStep == 10) {
  329. lv_label_set_text(labelStep, extrude_menu.step_10mm);
  330. lv_obj_align(labelStep, buttonStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  331. }
  332. }
  333. }
  334. void lv_clear_extrusion() { lv_obj_del(scr); }
  335. #endif // TFT_LVGL_UI