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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 "../../../../module/temperature.h"
  27. #include "../../../../inc/MarlinConfig.h"
  28. static lv_obj_t *scr;
  29. extern lv_group_t* g;
  30. static lv_obj_t *buttonType, *buttonStep;
  31. static lv_obj_t *labelType;
  32. static lv_obj_t *labelStep;
  33. static lv_obj_t *tempText1;
  34. enum {
  35. ID_P_ADD = 1,
  36. ID_P_DEC,
  37. ID_P_TYPE,
  38. ID_P_STEP,
  39. ID_P_OFF,
  40. ID_P_RETURN
  41. };
  42. static void event_handler(lv_obj_t *obj, lv_event_t event) {
  43. if (event != LV_EVENT_RELEASED) return;
  44. switch (obj->mks_obj_id) {
  45. case ID_P_ADD: {
  46. if (uiCfg.curTempType == 0) {
  47. int16_t max_target;
  48. thermalManager.temp_hotend[uiCfg.extruderIndex].target += uiCfg.stepHeat;
  49. if (uiCfg.extruderIndex == 0)
  50. max_target = HEATER_0_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1);
  51. #if HAS_MULTI_HOTEND
  52. else
  53. max_target = HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1);
  54. #endif
  55. if (thermalManager.degTargetHotend(uiCfg.extruderIndex) > max_target)
  56. thermalManager.setTargetHotend(max_target, uiCfg.extruderIndex);
  57. thermalManager.start_watching_hotend(uiCfg.extruderIndex);
  58. }
  59. else {
  60. #if HAS_HEATED_BED
  61. constexpr int16_t max_target = BED_MAXTEMP - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1);
  62. thermalManager.temp_bed.target += uiCfg.stepHeat;
  63. if (thermalManager.degTargetBed() > max_target)
  64. thermalManager.setTargetBed(max_target);
  65. thermalManager.start_watching_bed();
  66. #endif
  67. }
  68. disp_desire_temp();
  69. } break;
  70. case ID_P_DEC:
  71. if (uiCfg.curTempType == 0) {
  72. if (thermalManager.degTargetHotend(uiCfg.extruderIndex) > uiCfg.stepHeat)
  73. thermalManager.temp_hotend[uiCfg.extruderIndex].target -= uiCfg.stepHeat;
  74. else
  75. thermalManager.setTargetHotend(0, uiCfg.extruderIndex);
  76. thermalManager.start_watching_hotend(uiCfg.extruderIndex);
  77. }
  78. #if HAS_HEATED_BED
  79. else {
  80. if (thermalManager.degTargetBed() > uiCfg.stepHeat)
  81. thermalManager.temp_bed.target -= uiCfg.stepHeat;
  82. else
  83. thermalManager.setTargetBed(0);
  84. thermalManager.start_watching_bed();
  85. }
  86. #endif
  87. disp_desire_temp();
  88. break;
  89. case ID_P_TYPE:
  90. if (uiCfg.curTempType == 0) {
  91. if (ENABLED(HAS_MULTI_EXTRUDER)) {
  92. if (uiCfg.extruderIndex == 0) {
  93. uiCfg.extruderIndex = 1;
  94. }
  95. else if (uiCfg.extruderIndex == 1) {
  96. if (TEMP_SENSOR_BED != 0) {
  97. uiCfg.curTempType = 1;
  98. }
  99. else {
  100. uiCfg.curTempType = 0;
  101. uiCfg.extruderIndex = 0;
  102. }
  103. }
  104. }
  105. else if (uiCfg.extruderIndex == 0) {
  106. if (TEMP_SENSOR_BED != 0)
  107. uiCfg.curTempType = 1;
  108. else
  109. uiCfg.curTempType = 0;
  110. }
  111. }
  112. else if (uiCfg.curTempType == 1) {
  113. uiCfg.extruderIndex = 0;
  114. uiCfg.curTempType = 0;
  115. }
  116. disp_temp_type();
  117. break;
  118. case ID_P_STEP:
  119. switch (uiCfg.stepHeat) {
  120. case 1: uiCfg.stepHeat = 5; break;
  121. case 5: uiCfg.stepHeat = 10; break;
  122. case 10: uiCfg.stepHeat = 1; break;
  123. default: break;
  124. }
  125. disp_step_heat();
  126. break;
  127. case ID_P_OFF:
  128. if (uiCfg.curTempType == 0) {
  129. thermalManager.setTargetHotend(0, uiCfg.extruderIndex);
  130. thermalManager.start_watching_hotend(uiCfg.extruderIndex);
  131. }
  132. #if HAS_HEATED_BED
  133. else {
  134. thermalManager.temp_bed.target = 0;
  135. thermalManager.start_watching_bed();
  136. }
  137. #endif
  138. disp_desire_temp();
  139. break;
  140. case ID_P_RETURN:
  141. clear_cur_ui();
  142. draw_return_ui();
  143. break;
  144. }
  145. }
  146. void lv_draw_preHeat() {
  147. scr = lv_screen_create(PRE_HEAT_UI);
  148. // Create image buttons
  149. lv_big_button_create(scr, "F:/bmp_Add.bin", preheat_menu.add, INTERVAL_V, titleHeight, event_handler, ID_P_ADD);
  150. lv_big_button_create(scr, "F:/bmp_Dec.bin", preheat_menu.dec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_P_DEC);
  151. buttonType = lv_imgbtn_create(scr, nullptr, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_TYPE);
  152. buttonStep = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_STEP);
  153. #if HAS_ROTARY_ENCODER
  154. if (gCfgItems.encoder_enable) {
  155. lv_group_add_obj(g, buttonType);
  156. lv_group_add_obj(g, buttonStep);
  157. }
  158. #endif
  159. lv_big_button_create(scr, "F:/bmp_speed0.bin", preheat_menu.off, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_OFF);
  160. lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_RETURN);
  161. // Create labels on the image buttons
  162. labelType = lv_label_create_empty(buttonType);
  163. labelStep = lv_label_create_empty(buttonStep);
  164. disp_temp_type();
  165. disp_step_heat();
  166. tempText1 = lv_label_create_empty(scr);
  167. lv_obj_set_style(tempText1, &tft_style_label_rel);
  168. disp_desire_temp();
  169. }
  170. void disp_temp_type() {
  171. if (uiCfg.curTempType == 0) {
  172. if (uiCfg.extruderIndex == 1) {
  173. lv_imgbtn_set_src_both(buttonType, "F:/bmp_extru2.bin");
  174. if (gCfgItems.multiple_language) {
  175. lv_label_set_text(labelType, preheat_menu.ext2);
  176. lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  177. }
  178. }
  179. else {
  180. lv_imgbtn_set_src_both(buttonType, "F:/bmp_extru1.bin");
  181. if (gCfgItems.multiple_language) {
  182. lv_label_set_text(labelType, preheat_menu.ext1);
  183. lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  184. }
  185. }
  186. }
  187. else {
  188. lv_imgbtn_set_src_both(buttonType, "F:/bmp_bed.bin");
  189. if (gCfgItems.multiple_language) {
  190. lv_label_set_text(labelType, preheat_menu.hotbed);
  191. lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  192. }
  193. }
  194. }
  195. void disp_desire_temp() {
  196. char buf[20] = { 0 };
  197. public_buf_l[0] = '\0';
  198. if (uiCfg.curTempType == 0) {
  199. strcat(public_buf_l, uiCfg.extruderIndex < 1 ? preheat_menu.ext1 : preheat_menu.ext2);
  200. sprintf(buf, preheat_menu.value_state, thermalManager.wholeDegHotend(uiCfg.extruderIndex), thermalManager.degTargetHotend(uiCfg.extruderIndex));
  201. }
  202. else {
  203. #if HAS_HEATED_BED
  204. strcat(public_buf_l, preheat_menu.hotbed);
  205. sprintf(buf, preheat_menu.value_state, thermalManager.wholeDegBed(), thermalManager.degTargetBed());
  206. #endif
  207. }
  208. strcat_P(public_buf_l, PSTR(": "));
  209. strcat(public_buf_l, buf);
  210. lv_label_set_text(tempText1, public_buf_l);
  211. lv_obj_align(tempText1, nullptr, LV_ALIGN_CENTER, 0, -50);
  212. }
  213. void disp_step_heat() {
  214. if (uiCfg.stepHeat == 1) {
  215. lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step1_degree.bin");
  216. }
  217. else if (uiCfg.stepHeat == 5) {
  218. lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step5_degree.bin");
  219. }
  220. else if (uiCfg.stepHeat == 10) {
  221. lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step10_degree.bin");
  222. }
  223. if (gCfgItems.multiple_language) {
  224. if (uiCfg.stepHeat == 1) {
  225. lv_label_set_text(labelStep, preheat_menu.step_1c);
  226. lv_obj_align(labelStep, buttonStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  227. }
  228. else if (uiCfg.stepHeat == 5) {
  229. lv_label_set_text(labelStep, preheat_menu.step_5c);
  230. lv_obj_align(labelStep, buttonStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  231. }
  232. else if (uiCfg.stepHeat == 10) {
  233. lv_label_set_text(labelStep, preheat_menu.step_10c);
  234. lv_obj_align(labelStep, buttonStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  235. }
  236. }
  237. }
  238. void lv_clear_preHeat() {
  239. #if HAS_ROTARY_ENCODER
  240. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  241. #endif
  242. lv_obj_del(scr);
  243. }
  244. #endif // HAS_TFT_LVGL_UI