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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. #include "../../../../module/motion.h"
  33. #include "../../../../sd/cardreader.h"
  34. extern lv_group_t * g;
  35. static lv_obj_t * scr;
  36. #define ID_O_PRE_HEAT 1
  37. #define ID_O_EXTRUCT 2
  38. #define ID_O_MOV 3
  39. #define ID_O_FILAMENT 4
  40. #define ID_O_SPEED 5
  41. #define ID_O_RETURN 6
  42. #define ID_O_FAN 7
  43. #define ID_O_POWER_OFF 8
  44. #define ID_O_BABY_STEP 9
  45. static lv_obj_t *label_PowerOff;
  46. static lv_obj_t *buttonPowerOff;
  47. extern feedRate_t feedrate_mm_s;
  48. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  49. switch (obj->mks_obj_id) {
  50. case ID_O_PRE_HEAT:
  51. if (event == LV_EVENT_CLICKED) {
  52. // nothing to do
  53. }
  54. else if (event == LV_EVENT_RELEASED) {
  55. lv_clear_operation();
  56. lv_draw_preHeat();
  57. }
  58. break;
  59. case ID_O_EXTRUCT:
  60. if (event == LV_EVENT_CLICKED) {
  61. // nothing to do
  62. }
  63. else if (event == LV_EVENT_RELEASED) {
  64. lv_clear_operation();
  65. lv_draw_extrusion();
  66. }
  67. break;
  68. case ID_O_MOV:
  69. if (event == LV_EVENT_CLICKED) {
  70. // nothing to do
  71. }
  72. else if (event == LV_EVENT_RELEASED) {
  73. lv_clear_operation();
  74. lv_draw_move_motor();
  75. }
  76. break;
  77. case ID_O_FILAMENT:
  78. if (event == LV_EVENT_CLICKED) {
  79. // nothing to do
  80. }
  81. else if (event == LV_EVENT_RELEASED) {
  82. #if HAS_MULTI_EXTRUDER
  83. uiCfg.curSprayerChoose_bak = active_extruder;
  84. #endif
  85. if (uiCfg.print_state == WORKING) {
  86. #if ENABLED(SDSUPPORT)
  87. card.pauseSDPrint();
  88. stop_print_time();
  89. uiCfg.print_state = PAUSING;
  90. #endif
  91. }
  92. uiCfg.moveSpeed_bak = (uint16_t)feedrate_mm_s;
  93. uiCfg.desireSprayerTempBak = thermalManager.temp_hotend[active_extruder].target;
  94. lv_clear_operation();
  95. lv_draw_filament_change();
  96. }
  97. break;
  98. case ID_O_FAN:
  99. if (event == LV_EVENT_CLICKED) {
  100. // nothing to do
  101. }
  102. else if (event == LV_EVENT_RELEASED) {
  103. lv_clear_operation();
  104. lv_draw_fan();
  105. }
  106. break;
  107. case ID_O_SPEED:
  108. if (event == LV_EVENT_CLICKED) {
  109. // nothing to do
  110. }
  111. else if (event == LV_EVENT_RELEASED) {
  112. lv_clear_operation();
  113. lv_draw_change_speed();
  114. }
  115. break;
  116. case ID_O_RETURN:
  117. if (event == LV_EVENT_CLICKED) {
  118. // nothing to do
  119. }
  120. else if (event == LV_EVENT_RELEASED) {
  121. clear_cur_ui();
  122. draw_return_ui();
  123. }
  124. break;
  125. case ID_O_POWER_OFF:
  126. if (event == LV_EVENT_CLICKED) {
  127. // nothing to do
  128. }
  129. else if (event == LV_EVENT_RELEASED) {
  130. if (gCfgItems.finish_power_off == 1) {
  131. gCfgItems.finish_power_off = 0;
  132. lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_REL, "F:/bmp_manual_off.bin");
  133. lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_PR, "F:/bmp_manual_off.bin");
  134. lv_label_set_text(label_PowerOff, printing_more_menu.manual);
  135. lv_obj_align(label_PowerOff, buttonPowerOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  136. lv_obj_refresh_ext_draw_pad(label_PowerOff);
  137. update_spi_flash();
  138. }
  139. else {
  140. gCfgItems.finish_power_off = 1;
  141. lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_REL, "F:/bmp_auto_off.bin");
  142. lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_PR, "F:/bmp_auto_off.bin");
  143. lv_label_set_text(label_PowerOff, printing_more_menu.auto_close);
  144. lv_obj_align(label_PowerOff, buttonPowerOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  145. lv_obj_refresh_ext_draw_pad(label_PowerOff);
  146. update_spi_flash();
  147. }
  148. }
  149. break;
  150. case ID_O_BABY_STEP:
  151. if (event == LV_EVENT_CLICKED) {
  152. // nothing to do
  153. }
  154. else if (event == LV_EVENT_RELEASED) {
  155. lv_clear_operation();
  156. lv_draw_baby_stepping();
  157. }
  158. break;
  159. }
  160. }
  161. void lv_draw_operation(void) {
  162. lv_obj_t *buttonPreHeat = NULL, *buttonExtrusion = NULL, *buttonSpeed = NULL;
  163. lv_obj_t *buttonBack = NULL, *buttonFan = NULL;
  164. lv_obj_t *labelPreHeat = NULL, *labelExtrusion = NULL;
  165. lv_obj_t *label_Back = NULL, *label_Speed = NULL, *label_Fan = NULL;
  166. lv_obj_t *buttonMove = NULL, *label_Move = NULL;
  167. lv_obj_t *buttonBabyStep = NULL, *label_BabyStep = NULL;
  168. lv_obj_t *buttonFilament = NULL, *label_Filament = NULL;
  169. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != OPERATE_UI) {
  170. disp_state_stack._disp_index++;
  171. disp_state_stack._disp_state[disp_state_stack._disp_index] = OPERATE_UI;
  172. }
  173. disp_state = OPERATE_UI;
  174. scr = lv_obj_create(NULL, NULL);
  175. lv_obj_set_style(scr, &tft_style_scr);
  176. lv_scr_load(scr);
  177. lv_obj_clean(scr);
  178. lv_obj_t * title = lv_label_create(scr, NULL);
  179. lv_obj_set_style(title, &tft_style_label_rel);
  180. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  181. lv_label_set_text(title, creat_title_text());
  182. lv_refr_now(lv_refr_get_disp_refreshing());
  183. // Create image buttons
  184. buttonPreHeat = lv_imgbtn_create(scr, NULL);
  185. buttonFilament = lv_imgbtn_create(scr, NULL);
  186. buttonFan = lv_imgbtn_create(scr, NULL);
  187. buttonPowerOff = lv_imgbtn_create(scr, NULL);
  188. if (uiCfg.print_state != WORKING) {
  189. buttonExtrusion = lv_imgbtn_create(scr, NULL);
  190. buttonMove = lv_imgbtn_create(scr, NULL);
  191. }
  192. else {
  193. buttonSpeed = lv_imgbtn_create(scr, NULL);
  194. buttonBabyStep = lv_imgbtn_create(scr, NULL);
  195. }
  196. buttonBack = lv_imgbtn_create(scr, NULL);
  197. lv_obj_set_event_cb_mks(buttonPreHeat, event_handler, ID_O_PRE_HEAT, NULL, 0);
  198. lv_imgbtn_set_src(buttonPreHeat, LV_BTN_STATE_REL, "F:/bmp_temp.bin");
  199. lv_imgbtn_set_src(buttonPreHeat, LV_BTN_STATE_PR, "F:/bmp_temp.bin");
  200. lv_imgbtn_set_style(buttonPreHeat, LV_BTN_STATE_PR, &tft_style_label_pre);
  201. lv_imgbtn_set_style(buttonPreHeat, LV_BTN_STATE_REL, &tft_style_label_rel);
  202. lv_obj_set_event_cb_mks(buttonFilament, event_handler, ID_O_FILAMENT, NULL, 0);
  203. lv_imgbtn_set_src(buttonFilament, LV_BTN_STATE_REL, "F:/bmp_filamentchange.bin");
  204. lv_imgbtn_set_src(buttonFilament, LV_BTN_STATE_PR, "F:/bmp_filamentchange.bin");
  205. lv_imgbtn_set_style(buttonFilament, LV_BTN_STATE_PR, &tft_style_label_pre);
  206. lv_imgbtn_set_style(buttonFilament, LV_BTN_STATE_REL, &tft_style_label_rel);
  207. #if 1
  208. lv_obj_set_event_cb_mks(buttonFan, event_handler, ID_O_FAN, NULL, 0);
  209. lv_imgbtn_set_src(buttonFan, LV_BTN_STATE_REL, "F:/bmp_fan.bin");
  210. lv_imgbtn_set_src(buttonFan, LV_BTN_STATE_PR, "F:/bmp_fan.bin");
  211. lv_imgbtn_set_style(buttonFan, LV_BTN_STATE_PR, &tft_style_label_pre);
  212. lv_imgbtn_set_style(buttonFan, LV_BTN_STATE_REL, &tft_style_label_rel);
  213. if (gCfgItems.finish_power_off == 1) {
  214. lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_REL, "F:/bmp_auto_off.bin");
  215. lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_PR, "F:/bmp_auto_off.bin");
  216. }
  217. else {
  218. lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_REL, "F:/bmp_manual_off.bin");
  219. lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_PR, "F:/bmp_manual_off.bin");
  220. }
  221. lv_obj_set_event_cb_mks(buttonPowerOff, event_handler, ID_O_POWER_OFF, NULL, 0);
  222. lv_imgbtn_set_style(buttonPowerOff, LV_BTN_STATE_PR, &tft_style_label_pre);
  223. lv_imgbtn_set_style(buttonPowerOff, LV_BTN_STATE_REL, &tft_style_label_rel);
  224. #if HAS_ROTARY_ENCODER
  225. if (gCfgItems.encoder_enable) {
  226. lv_group_add_obj(g, buttonPreHeat);
  227. lv_group_add_obj(g, buttonFilament);
  228. lv_group_add_obj(g, buttonFan);
  229. lv_group_add_obj(g, buttonPowerOff);
  230. }
  231. #endif
  232. if (uiCfg.print_state != WORKING) {
  233. lv_obj_set_event_cb_mks(buttonExtrusion, event_handler, ID_O_EXTRUCT, NULL, 0);
  234. lv_imgbtn_set_src(buttonExtrusion, LV_BTN_STATE_REL, "F:/bmp_extrude_opr.bin");
  235. lv_imgbtn_set_src(buttonExtrusion, LV_BTN_STATE_PR, "F:/bmp_extrude_opr.bin");
  236. lv_imgbtn_set_style(buttonExtrusion, LV_BTN_STATE_PR, &tft_style_label_pre);
  237. lv_imgbtn_set_style(buttonExtrusion, LV_BTN_STATE_REL, &tft_style_label_rel);
  238. lv_obj_set_event_cb_mks(buttonMove, event_handler, ID_O_MOV, NULL, 0);
  239. lv_imgbtn_set_src(buttonMove, LV_BTN_STATE_REL, "F:/bmp_move_opr.bin");
  240. lv_imgbtn_set_src(buttonMove, LV_BTN_STATE_PR, "F:/bmp_move_opr.bin");
  241. lv_imgbtn_set_style(buttonMove, LV_BTN_STATE_PR, &tft_style_label_pre);
  242. lv_imgbtn_set_style(buttonMove, LV_BTN_STATE_REL, &tft_style_label_rel);
  243. #if HAS_ROTARY_ENCODER
  244. if (gCfgItems.encoder_enable) {
  245. lv_group_add_obj(g, buttonExtrusion);
  246. lv_group_add_obj(g, buttonMove);
  247. }
  248. #endif
  249. }
  250. else {
  251. lv_obj_set_event_cb_mks(buttonSpeed, event_handler, ID_O_SPEED, NULL, 0);
  252. lv_imgbtn_set_src(buttonSpeed, LV_BTN_STATE_REL, "F:/bmp_speed.bin");
  253. lv_imgbtn_set_src(buttonSpeed, LV_BTN_STATE_PR, "F:/bmp_speed.bin");
  254. lv_imgbtn_set_style(buttonSpeed, LV_BTN_STATE_PR, &tft_style_label_pre);
  255. lv_imgbtn_set_style(buttonSpeed, LV_BTN_STATE_REL, &tft_style_label_rel);
  256. lv_obj_set_event_cb_mks(buttonBabyStep, event_handler, ID_O_BABY_STEP, NULL, 0);
  257. lv_imgbtn_set_src(buttonBabyStep, LV_BTN_STATE_REL, "F:/bmp_mov.bin");
  258. lv_imgbtn_set_src(buttonBabyStep, LV_BTN_STATE_PR, "F:/bmp_mov.bin");
  259. lv_imgbtn_set_style(buttonBabyStep, LV_BTN_STATE_PR, &tft_style_label_pre);
  260. lv_imgbtn_set_style(buttonBabyStep, LV_BTN_STATE_REL, &tft_style_label_rel);
  261. #if HAS_ROTARY_ENCODER
  262. if (gCfgItems.encoder_enable) {
  263. lv_group_add_obj(g, buttonSpeed);
  264. lv_group_add_obj(g, buttonBabyStep);
  265. }
  266. #endif
  267. }
  268. lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_O_RETURN, NULL, 0);
  269. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin");
  270. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin");
  271. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre);
  272. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel);
  273. #endif // if 1
  274. #if HAS_ROTARY_ENCODER
  275. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack);
  276. #endif
  277. lv_obj_set_pos(buttonPreHeat, INTERVAL_V, titleHeight);
  278. lv_obj_set_pos(buttonFilament, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight);
  279. lv_obj_set_pos(buttonFan, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight);
  280. lv_obj_set_pos(buttonPowerOff, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight);
  281. if (uiCfg.print_state != WORKING) {
  282. /*
  283. lv_obj_set_pos(buttonFilament,INTERVAL_V,BTN_Y_PIXEL+INTERVAL_H+titleHeight);
  284. } else {
  285. */
  286. lv_obj_set_pos(buttonExtrusion, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  287. lv_obj_set_pos(buttonMove, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  288. }
  289. else {
  290. lv_obj_set_pos(buttonSpeed, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  291. lv_obj_set_pos(buttonBabyStep, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  292. }
  293. lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  294. // Create labels on the image buttons
  295. lv_btn_set_layout(buttonPreHeat, LV_LAYOUT_OFF);
  296. lv_btn_set_layout(buttonFilament, LV_LAYOUT_OFF);
  297. lv_btn_set_layout(buttonFan, LV_LAYOUT_OFF);
  298. lv_btn_set_layout(buttonPowerOff, LV_LAYOUT_OFF);
  299. if (uiCfg.print_state != WORKING) {
  300. /*
  301. lv_btn_set_layout(buttonFilament, LV_LAYOUT_OFF);
  302. } else {
  303. */
  304. lv_btn_set_layout(buttonExtrusion, LV_LAYOUT_OFF);
  305. lv_btn_set_layout(buttonMove, LV_LAYOUT_OFF);
  306. }
  307. else {
  308. lv_btn_set_layout(buttonSpeed, LV_LAYOUT_OFF);
  309. lv_btn_set_layout(buttonBabyStep, LV_LAYOUT_OFF);
  310. }
  311. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  312. labelPreHeat = lv_label_create(buttonPreHeat, NULL);
  313. label_Filament = lv_label_create(buttonFilament, NULL);
  314. label_Fan = lv_label_create(buttonFan, NULL);
  315. label_PowerOff = lv_label_create(buttonPowerOff, NULL);
  316. if (uiCfg.print_state != WORKING) {
  317. /*
  318. label_Filament = lv_label_create(buttonFilament, NULL);
  319. } else {
  320. */
  321. labelExtrusion = lv_label_create(buttonExtrusion, NULL);
  322. label_Move = lv_label_create(buttonMove, NULL);
  323. }
  324. else {
  325. label_Speed = lv_label_create(buttonSpeed, NULL);
  326. label_BabyStep = lv_label_create(buttonBabyStep, NULL);
  327. }
  328. label_Back = lv_label_create(buttonBack, NULL);
  329. if (gCfgItems.multiple_language != 0) {
  330. lv_label_set_text(labelPreHeat, operation_menu.temp);
  331. lv_obj_align(labelPreHeat, buttonPreHeat, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  332. lv_label_set_text(label_Filament, operation_menu.filament);
  333. lv_obj_align(label_Filament, buttonFilament, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  334. lv_label_set_text(label_Fan, operation_menu.fan);
  335. lv_obj_align(label_Fan, buttonFan, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  336. if (gCfgItems.finish_power_off == 1)
  337. lv_label_set_text(label_PowerOff, printing_more_menu.auto_close);
  338. else
  339. lv_label_set_text(label_PowerOff, printing_more_menu.manual);
  340. lv_obj_align(label_PowerOff, buttonPowerOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  341. if (uiCfg.print_state != WORKING) {
  342. /*
  343. lv_label_set_text(label_Filament, operation_menu.filament);
  344. lv_obj_align(label_Filament, buttonFilament, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET);
  345. } else {
  346. */
  347. lv_label_set_text(labelExtrusion, operation_menu.extr);
  348. lv_obj_align(labelExtrusion, buttonExtrusion, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  349. lv_label_set_text(label_Move, operation_menu.move);
  350. lv_obj_align(label_Move, buttonMove, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  351. }
  352. else {
  353. lv_label_set_text(label_Speed, operation_menu.speed);
  354. lv_obj_align(label_Speed, buttonSpeed, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  355. lv_label_set_text(label_BabyStep, operation_menu.babystep);
  356. lv_obj_align(label_BabyStep, buttonBabyStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  357. }
  358. lv_label_set_text(label_Back, common_menu.text_back);
  359. lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  360. }
  361. }
  362. void lv_clear_operation() {
  363. #if HAS_ROTARY_ENCODER
  364. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  365. #endif
  366. lv_obj_del(scr);
  367. }
  368. #endif // HAS_TFT_LVGL_UI