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_preHeat.cpp 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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 "../../../../module/temperature.h"
  31. #include "../../../../inc/MarlinConfig.h"
  32. static lv_obj_t * scr;
  33. extern lv_group_t* g;
  34. static lv_obj_t *buttoType, *buttonStep;
  35. static lv_obj_t *labelType;
  36. static lv_obj_t *labelStep;
  37. static lv_obj_t * tempText1;
  38. #define ID_P_ADD 1
  39. #define ID_P_DEC 2
  40. #define ID_P_TYPE 3
  41. #define ID_P_STEP 4
  42. #define ID_P_OFF 5
  43. #define ID_P_RETURN 6
  44. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  45. switch (obj->mks_obj_id) {
  46. case ID_P_ADD:
  47. if (event == LV_EVENT_CLICKED) {
  48. // nothing to do
  49. }
  50. else if (event == LV_EVENT_RELEASED) {
  51. if (uiCfg.curTempType == 0) {
  52. thermalManager.temp_hotend[uiCfg.curSprayerChoose].target += uiCfg.stepHeat;
  53. if (uiCfg.curSprayerChoose == 0) {
  54. if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > (HEATER_0_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1))) {
  55. thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_0_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1);
  56. }
  57. }
  58. #if !defined(SINGLENOZZLE) && HAS_MULTI_EXTRUDER
  59. else if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > (HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1))) {
  60. thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1);
  61. }
  62. #endif
  63. thermalManager.start_watching_hotend(uiCfg.curSprayerChoose);
  64. }
  65. #if HAS_HEATED_BED
  66. else {
  67. thermalManager.temp_bed.target += uiCfg.stepHeat;
  68. if ((int)thermalManager.temp_bed.target > BED_MAXTEMP - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1)) {
  69. thermalManager.temp_bed.target = (float)BED_MAXTEMP - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1);
  70. }
  71. thermalManager.start_watching_bed();
  72. }
  73. #endif
  74. disp_desire_temp();
  75. }
  76. break;
  77. case ID_P_DEC:
  78. if (event == LV_EVENT_CLICKED) {
  79. // nothing to do
  80. }
  81. else if (event == LV_EVENT_RELEASED) {
  82. if (uiCfg.curTempType == 0) {
  83. if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > uiCfg.stepHeat) {
  84. thermalManager.temp_hotend[uiCfg.curSprayerChoose].target -= uiCfg.stepHeat;
  85. }
  86. else {
  87. thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)0;
  88. }
  89. thermalManager.start_watching_hotend(uiCfg.curSprayerChoose);
  90. }
  91. #if HAS_HEATED_BED
  92. else {
  93. if ((int)thermalManager.temp_bed.target > uiCfg.stepHeat) {
  94. thermalManager.temp_bed.target -= uiCfg.stepHeat;
  95. }
  96. else {
  97. thermalManager.temp_bed.target = (float)0;
  98. }
  99. thermalManager.start_watching_bed();
  100. }
  101. #endif
  102. disp_desire_temp();
  103. }
  104. break;
  105. case ID_P_TYPE:
  106. if (event == LV_EVENT_CLICKED) {
  107. // nothing to do
  108. }
  109. else if (event == LV_EVENT_RELEASED) {
  110. if (uiCfg.curTempType == 0) {
  111. if (ENABLED(HAS_MULTI_EXTRUDER)) {
  112. if (uiCfg.curSprayerChoose == 0) {
  113. uiCfg.curSprayerChoose = 1;
  114. }
  115. else if (uiCfg.curSprayerChoose == 1) {
  116. if (TEMP_SENSOR_BED != 0) {
  117. uiCfg.curTempType = 1;
  118. }
  119. else {
  120. uiCfg.curTempType = 0;
  121. uiCfg.curSprayerChoose = 0;
  122. }
  123. }
  124. }
  125. else if (uiCfg.curSprayerChoose == 0) {
  126. if (TEMP_SENSOR_BED != 0)
  127. uiCfg.curTempType = 1;
  128. else
  129. uiCfg.curTempType = 0;
  130. }
  131. }
  132. else if (uiCfg.curTempType == 1) {
  133. uiCfg.curSprayerChoose = 0;
  134. uiCfg.curTempType = 0;
  135. }
  136. disp_temp_type();
  137. }
  138. break;
  139. case ID_P_STEP:
  140. if (event == LV_EVENT_CLICKED) {
  141. // nothing to do
  142. }
  143. else if (event == LV_EVENT_RELEASED) {
  144. switch (uiCfg.stepHeat) {
  145. case 1: uiCfg.stepHeat = 5; break;
  146. case 5: uiCfg.stepHeat = 10; break;
  147. case 10: uiCfg.stepHeat = 1; break;
  148. default: break;
  149. }
  150. disp_step_heat();
  151. }
  152. break;
  153. case ID_P_OFF:
  154. if (event == LV_EVENT_CLICKED) {
  155. // nothing to do
  156. }
  157. else if (event == LV_EVENT_RELEASED) {
  158. if (uiCfg.curTempType == 0) {
  159. thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)0;
  160. thermalManager.start_watching_hotend(uiCfg.curSprayerChoose);
  161. }
  162. #if HAS_HEATED_BED
  163. else {
  164. thermalManager.temp_bed.target = (float)0;
  165. thermalManager.start_watching_bed();
  166. }
  167. #endif
  168. disp_desire_temp();
  169. }
  170. break;
  171. case ID_P_RETURN:
  172. if (event == LV_EVENT_CLICKED) {
  173. // nothing to do
  174. }
  175. else if (event == LV_EVENT_RELEASED) {
  176. clear_cur_ui();
  177. draw_return_ui();
  178. }
  179. break;
  180. }
  181. }
  182. void lv_draw_preHeat(void) {
  183. lv_obj_t *buttonAdd, *buttonDec;
  184. lv_obj_t *buttonOff, *buttonBack;
  185. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != PRE_HEAT_UI) {
  186. disp_state_stack._disp_index++;
  187. disp_state_stack._disp_state[disp_state_stack._disp_index] = PRE_HEAT_UI;
  188. }
  189. disp_state = PRE_HEAT_UI;
  190. scr = lv_obj_create(NULL, NULL);
  191. lv_obj_set_style(scr, &tft_style_scr);
  192. lv_scr_load(scr);
  193. lv_obj_clean(scr);
  194. lv_obj_t * title = lv_label_create(scr, NULL);
  195. lv_obj_set_style(title, &tft_style_label_rel);
  196. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  197. lv_label_set_text(title, creat_title_text());
  198. lv_refr_now(lv_refr_get_disp_refreshing());
  199. // Create image buttons
  200. buttonAdd = lv_imgbtn_create(scr, NULL);
  201. buttonDec = lv_imgbtn_create(scr, NULL);
  202. buttoType = lv_imgbtn_create(scr, NULL);
  203. buttonStep = lv_imgbtn_create(scr, NULL);
  204. buttonOff = lv_imgbtn_create(scr, NULL);
  205. buttonBack = lv_imgbtn_create(scr, NULL);
  206. lv_obj_set_event_cb_mks(buttonAdd, event_handler, ID_P_ADD, NULL, 0);
  207. lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_REL, "F:/bmp_Add.bin");
  208. lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_PR, "F:/bmp_Add.bin");
  209. lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_PR, &tft_style_label_pre);
  210. lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_REL, &tft_style_label_rel);
  211. lv_obj_clear_protect(buttonAdd, LV_PROTECT_FOLLOW);
  212. #if 1
  213. lv_obj_set_event_cb_mks(buttonDec, event_handler, ID_P_DEC, NULL, 0);
  214. lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_REL, "F:/bmp_Dec.bin");
  215. lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_PR, "F:/bmp_Dec.bin");
  216. lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_PR, &tft_style_label_pre);
  217. lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_REL, &tft_style_label_rel);
  218. lv_obj_set_event_cb_mks(buttoType, event_handler, ID_P_TYPE, NULL, 0);
  219. lv_imgbtn_set_style(buttoType, LV_BTN_STATE_PR, &tft_style_label_pre);
  220. lv_imgbtn_set_style(buttoType, LV_BTN_STATE_REL, &tft_style_label_rel);
  221. lv_obj_set_event_cb_mks(buttonStep, event_handler, ID_P_STEP, NULL, 0);
  222. lv_imgbtn_set_style(buttonStep, LV_BTN_STATE_PR, &tft_style_label_pre);
  223. lv_imgbtn_set_style(buttonStep, LV_BTN_STATE_REL, &tft_style_label_rel);
  224. lv_obj_set_event_cb_mks(buttonOff, event_handler, ID_P_OFF, NULL, 0);
  225. lv_imgbtn_set_src(buttonOff, LV_BTN_STATE_REL, "F:/bmp_speed0.bin");
  226. lv_imgbtn_set_src(buttonOff, LV_BTN_STATE_PR, "F:/bmp_speed0.bin");
  227. lv_imgbtn_set_style(buttonOff, LV_BTN_STATE_PR, &tft_style_label_pre);
  228. lv_imgbtn_set_style(buttonOff, LV_BTN_STATE_REL, &tft_style_label_rel);
  229. lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_P_RETURN, NULL, 0);
  230. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin");
  231. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin");
  232. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre);
  233. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel);
  234. #endif
  235. lv_obj_set_pos(buttonAdd, INTERVAL_V, titleHeight);
  236. lv_obj_set_pos(buttonDec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight);
  237. lv_obj_set_pos(buttoType, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  238. lv_obj_set_pos(buttonStep, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  239. lv_obj_set_pos(buttonOff, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  240. lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  241. // Create labels on the image buttons
  242. lv_btn_set_layout(buttonAdd, LV_LAYOUT_OFF);
  243. lv_btn_set_layout(buttonDec, LV_LAYOUT_OFF);
  244. lv_btn_set_layout(buttoType, LV_LAYOUT_OFF);
  245. lv_btn_set_layout(buttonStep, LV_LAYOUT_OFF);
  246. lv_btn_set_layout(buttonOff, LV_LAYOUT_OFF);
  247. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  248. lv_obj_t *labelAdd = lv_label_create(buttonAdd, NULL);
  249. lv_obj_t *labelDec = lv_label_create(buttonDec, NULL);
  250. labelType = lv_label_create(buttoType, NULL);
  251. labelStep = lv_label_create(buttonStep, NULL);
  252. lv_obj_t *labelOff = lv_label_create(buttonOff, NULL);
  253. lv_obj_t *label_Back = lv_label_create(buttonBack, NULL);
  254. if (gCfgItems.multiple_language) {
  255. lv_label_set_text(labelAdd, preheat_menu.add);
  256. lv_obj_align(labelAdd, buttonAdd, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  257. lv_label_set_text(labelDec, preheat_menu.dec);
  258. lv_obj_align(labelDec, buttonDec, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  259. lv_label_set_text(labelOff, preheat_menu.off);
  260. lv_obj_align(labelOff, buttonOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  261. lv_label_set_text(label_Back, common_menu.text_back);
  262. lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  263. }
  264. #if HAS_ROTARY_ENCODER
  265. if (gCfgItems.encoder_enable) {
  266. lv_group_add_obj(g, buttonAdd);
  267. lv_group_add_obj(g, buttonDec);
  268. lv_group_add_obj(g, buttoType);
  269. lv_group_add_obj(g, buttonStep);
  270. lv_group_add_obj(g, buttonOff);
  271. lv_group_add_obj(g, buttonBack);
  272. }
  273. #endif
  274. disp_temp_type();
  275. disp_step_heat();
  276. tempText1 = lv_label_create(scr, NULL);
  277. lv_obj_set_style(tempText1, &tft_style_label_rel);
  278. disp_desire_temp();
  279. }
  280. void disp_temp_type() {
  281. if (uiCfg.curTempType == 0) {
  282. if (uiCfg.curSprayerChoose == 1) {
  283. lv_imgbtn_set_src(buttoType, LV_BTN_STATE_REL, "F:/bmp_extru2.bin");
  284. lv_imgbtn_set_src(buttoType, LV_BTN_STATE_PR, "F:/bmp_extru2.bin");
  285. if (gCfgItems.multiple_language) {
  286. lv_label_set_text(labelType, preheat_menu.ext2);
  287. lv_obj_align(labelType, buttoType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  288. }
  289. }
  290. else {
  291. lv_imgbtn_set_src(buttoType, LV_BTN_STATE_REL, "F:/bmp_extru1.bin");
  292. lv_imgbtn_set_src(buttoType, LV_BTN_STATE_PR, "F:/bmp_extru1.bin");
  293. if (gCfgItems.multiple_language) {
  294. lv_label_set_text(labelType, preheat_menu.ext1);
  295. lv_obj_align(labelType, buttoType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  296. }
  297. }
  298. }
  299. else {
  300. lv_imgbtn_set_src(buttoType, LV_BTN_STATE_REL, "F:/bmp_bed.bin");
  301. lv_imgbtn_set_src(buttoType, LV_BTN_STATE_PR, "F:/bmp_bed.bin");
  302. if (gCfgItems.multiple_language) {
  303. lv_label_set_text(labelType, preheat_menu.hotbed);
  304. lv_obj_align(labelType, buttoType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  305. }
  306. }
  307. }
  308. void disp_desire_temp() {
  309. char buf[20] = {0};
  310. public_buf_l[0] = '\0';
  311. if (uiCfg.curTempType == 0) {
  312. if (uiCfg.curSprayerChoose < 1)
  313. strcat(public_buf_l, preheat_menu.ext1);
  314. else
  315. strcat(public_buf_l, preheat_menu.ext2);
  316. sprintf(buf, preheat_menu.value_state, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target);
  317. }
  318. #if HAS_HEATED_BED
  319. else {
  320. strcat(public_buf_l, preheat_menu.hotbed);
  321. sprintf(buf, preheat_menu.value_state, (int)thermalManager.temp_bed.celsius, (int)thermalManager.temp_bed.target);
  322. }
  323. #endif
  324. strcat_P(public_buf_l, PSTR(": "));
  325. strcat(public_buf_l, buf);
  326. lv_label_set_text(tempText1, public_buf_l);
  327. lv_obj_align(tempText1, NULL, LV_ALIGN_CENTER, 0, -50);
  328. }
  329. void disp_step_heat() {
  330. if (uiCfg.stepHeat == 1) {
  331. lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_REL, "F:/bmp_step1_degree.bin");
  332. lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_PR, "F:/bmp_step1_degree.bin");
  333. }
  334. else if (uiCfg.stepHeat == 5) {
  335. lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_REL, "F:/bmp_step5_degree.bin");
  336. lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_PR, "F:/bmp_step5_degree.bin");
  337. }
  338. else if (uiCfg.stepHeat == 10) {
  339. lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_REL, "F:/bmp_step10_degree.bin");
  340. lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_PR, "F:/bmp_step10_degree.bin");
  341. }
  342. if (gCfgItems.multiple_language) {
  343. if (uiCfg.stepHeat == 1) {
  344. lv_label_set_text(labelStep, preheat_menu.step_1c);
  345. lv_obj_align(labelStep, buttonStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  346. }
  347. else if (uiCfg.stepHeat == 5) {
  348. lv_label_set_text(labelStep, preheat_menu.step_5c);
  349. lv_obj_align(labelStep, buttonStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  350. }
  351. else if (uiCfg.stepHeat == 10) {
  352. lv_label_set_text(labelStep, preheat_menu.step_10c);
  353. lv_obj_align(labelStep, buttonStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  354. }
  355. }
  356. }
  357. void lv_clear_preHeat() {
  358. #if HAS_ROTARY_ENCODER
  359. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  360. #endif
  361. lv_obj_del(scr);
  362. }
  363. #endif // HAS_TFT_LVGL_UI