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

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