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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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 "../../../../module/motion.h"
  32. #include "../../../../sd/cardreader.h"
  33. #include "../../../../inc/MarlinConfig.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) {
  131. gCfgItems.finish_power_off = false;
  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. }
  136. else {
  137. gCfgItems.finish_power_off = true;
  138. lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_REL, "F:/bmp_auto_off.bin");
  139. lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_PR, "F:/bmp_auto_off.bin");
  140. lv_label_set_text(label_PowerOff, printing_more_menu.auto_close);
  141. }
  142. lv_obj_align(label_PowerOff, buttonPowerOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  143. lv_obj_refresh_ext_draw_pad(label_PowerOff);
  144. update_spi_flash();
  145. }
  146. break;
  147. case ID_O_BABY_STEP:
  148. if (event == LV_EVENT_CLICKED) {
  149. // nothing to do
  150. }
  151. else if (event == LV_EVENT_RELEASED) {
  152. lv_clear_operation();
  153. lv_draw_baby_stepping();
  154. }
  155. break;
  156. }
  157. }
  158. void lv_draw_operation(void) {
  159. lv_obj_t *buttonPreHeat = NULL, *buttonExtrusion = NULL, *buttonSpeed = NULL;
  160. lv_obj_t *buttonBack = NULL, *buttonFan = NULL;
  161. lv_obj_t *labelPreHeat = NULL, *labelExtrusion = NULL;
  162. lv_obj_t *label_Back = NULL, *label_Speed = NULL, *label_Fan = NULL;
  163. lv_obj_t *buttonMove = NULL, *label_Move = NULL;
  164. lv_obj_t *buttonBabyStep = NULL, *label_BabyStep = NULL;
  165. lv_obj_t *buttonFilament = NULL, *label_Filament = NULL;
  166. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != OPERATE_UI) {
  167. disp_state_stack._disp_index++;
  168. disp_state_stack._disp_state[disp_state_stack._disp_index] = OPERATE_UI;
  169. }
  170. disp_state = OPERATE_UI;
  171. scr = lv_obj_create(NULL, NULL);
  172. lv_obj_set_style(scr, &tft_style_scr);
  173. lv_scr_load(scr);
  174. lv_obj_clean(scr);
  175. lv_obj_t * title = lv_label_create(scr, NULL);
  176. lv_obj_set_style(title, &tft_style_label_rel);
  177. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  178. lv_label_set_text(title, creat_title_text());
  179. lv_refr_now(lv_refr_get_disp_refreshing());
  180. // Create image buttons
  181. buttonPreHeat = lv_imgbtn_create(scr, NULL);
  182. buttonFilament = lv_imgbtn_create(scr, NULL);
  183. buttonFan = lv_imgbtn_create(scr, NULL);
  184. buttonPowerOff = lv_imgbtn_create(scr, NULL);
  185. if (uiCfg.print_state != WORKING) {
  186. buttonExtrusion = lv_imgbtn_create(scr, NULL);
  187. buttonMove = lv_imgbtn_create(scr, NULL);
  188. }
  189. else {
  190. buttonSpeed = lv_imgbtn_create(scr, NULL);
  191. buttonBabyStep = lv_imgbtn_create(scr, NULL);
  192. }
  193. buttonBack = lv_imgbtn_create(scr, NULL);
  194. lv_obj_set_event_cb_mks(buttonPreHeat, event_handler, ID_O_PRE_HEAT, NULL, 0);
  195. lv_imgbtn_set_src(buttonPreHeat, LV_BTN_STATE_REL, "F:/bmp_temp.bin");
  196. lv_imgbtn_set_src(buttonPreHeat, LV_BTN_STATE_PR, "F:/bmp_temp.bin");
  197. lv_imgbtn_set_style(buttonPreHeat, LV_BTN_STATE_PR, &tft_style_label_pre);
  198. lv_imgbtn_set_style(buttonPreHeat, LV_BTN_STATE_REL, &tft_style_label_rel);
  199. lv_obj_set_event_cb_mks(buttonFilament, event_handler, ID_O_FILAMENT, NULL, 0);
  200. lv_imgbtn_set_src(buttonFilament, LV_BTN_STATE_REL, "F:/bmp_filamentchange.bin");
  201. lv_imgbtn_set_src(buttonFilament, LV_BTN_STATE_PR, "F:/bmp_filamentchange.bin");
  202. lv_imgbtn_set_style(buttonFilament, LV_BTN_STATE_PR, &tft_style_label_pre);
  203. lv_imgbtn_set_style(buttonFilament, LV_BTN_STATE_REL, &tft_style_label_rel);
  204. #if 1
  205. lv_obj_set_event_cb_mks(buttonFan, event_handler, ID_O_FAN, NULL, 0);
  206. lv_imgbtn_set_src(buttonFan, LV_BTN_STATE_REL, "F:/bmp_fan.bin");
  207. lv_imgbtn_set_src(buttonFan, LV_BTN_STATE_PR, "F:/bmp_fan.bin");
  208. lv_imgbtn_set_style(buttonFan, LV_BTN_STATE_PR, &tft_style_label_pre);
  209. lv_imgbtn_set_style(buttonFan, LV_BTN_STATE_REL, &tft_style_label_rel);
  210. if (gCfgItems.finish_power_off) {
  211. lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_REL, "F:/bmp_auto_off.bin");
  212. lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_PR, "F:/bmp_auto_off.bin");
  213. }
  214. else {
  215. lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_REL, "F:/bmp_manual_off.bin");
  216. lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_PR, "F:/bmp_manual_off.bin");
  217. }
  218. lv_obj_set_event_cb_mks(buttonPowerOff, event_handler, ID_O_POWER_OFF, NULL, 0);
  219. lv_imgbtn_set_style(buttonPowerOff, LV_BTN_STATE_PR, &tft_style_label_pre);
  220. lv_imgbtn_set_style(buttonPowerOff, LV_BTN_STATE_REL, &tft_style_label_rel);
  221. #if HAS_ROTARY_ENCODER
  222. if (gCfgItems.encoder_enable) {
  223. lv_group_add_obj(g, buttonPreHeat);
  224. lv_group_add_obj(g, buttonFilament);
  225. lv_group_add_obj(g, buttonFan);
  226. lv_group_add_obj(g, buttonPowerOff);
  227. }
  228. #endif
  229. if (uiCfg.print_state != WORKING) {
  230. lv_obj_set_event_cb_mks(buttonExtrusion, event_handler, ID_O_EXTRUCT, NULL, 0);
  231. lv_imgbtn_set_src(buttonExtrusion, LV_BTN_STATE_REL, "F:/bmp_extrude_opr.bin");
  232. lv_imgbtn_set_src(buttonExtrusion, LV_BTN_STATE_PR, "F:/bmp_extrude_opr.bin");
  233. lv_imgbtn_set_style(buttonExtrusion, LV_BTN_STATE_PR, &tft_style_label_pre);
  234. lv_imgbtn_set_style(buttonExtrusion, LV_BTN_STATE_REL, &tft_style_label_rel);
  235. lv_obj_set_event_cb_mks(buttonMove, event_handler, ID_O_MOV, NULL, 0);
  236. lv_imgbtn_set_src(buttonMove, LV_BTN_STATE_REL, "F:/bmp_move_opr.bin");
  237. lv_imgbtn_set_src(buttonMove, LV_BTN_STATE_PR, "F:/bmp_move_opr.bin");
  238. lv_imgbtn_set_style(buttonMove, LV_BTN_STATE_PR, &tft_style_label_pre);
  239. lv_imgbtn_set_style(buttonMove, LV_BTN_STATE_REL, &tft_style_label_rel);
  240. #if HAS_ROTARY_ENCODER
  241. if (gCfgItems.encoder_enable) {
  242. lv_group_add_obj(g, buttonExtrusion);
  243. lv_group_add_obj(g, buttonMove);
  244. }
  245. #endif
  246. }
  247. else {
  248. lv_obj_set_event_cb_mks(buttonSpeed, event_handler, ID_O_SPEED, NULL, 0);
  249. lv_imgbtn_set_src(buttonSpeed, LV_BTN_STATE_REL, "F:/bmp_speed.bin");
  250. lv_imgbtn_set_src(buttonSpeed, LV_BTN_STATE_PR, "F:/bmp_speed.bin");
  251. lv_imgbtn_set_style(buttonSpeed, LV_BTN_STATE_PR, &tft_style_label_pre);
  252. lv_imgbtn_set_style(buttonSpeed, LV_BTN_STATE_REL, &tft_style_label_rel);
  253. lv_obj_set_event_cb_mks(buttonBabyStep, event_handler, ID_O_BABY_STEP, NULL, 0);
  254. lv_imgbtn_set_src(buttonBabyStep, LV_BTN_STATE_REL, "F:/bmp_mov.bin");
  255. lv_imgbtn_set_src(buttonBabyStep, LV_BTN_STATE_PR, "F:/bmp_mov.bin");
  256. lv_imgbtn_set_style(buttonBabyStep, LV_BTN_STATE_PR, &tft_style_label_pre);
  257. lv_imgbtn_set_style(buttonBabyStep, LV_BTN_STATE_REL, &tft_style_label_rel);
  258. #if HAS_ROTARY_ENCODER
  259. if (gCfgItems.encoder_enable) {
  260. lv_group_add_obj(g, buttonSpeed);
  261. lv_group_add_obj(g, buttonBabyStep);
  262. }
  263. #endif
  264. }
  265. lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_O_RETURN, NULL, 0);
  266. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin");
  267. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin");
  268. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre);
  269. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel);
  270. #endif // if 1
  271. #if HAS_ROTARY_ENCODER
  272. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack);
  273. #endif
  274. lv_obj_set_pos(buttonPreHeat, INTERVAL_V, titleHeight);
  275. lv_obj_set_pos(buttonFilament, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight);
  276. lv_obj_set_pos(buttonFan, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight);
  277. lv_obj_set_pos(buttonPowerOff, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight);
  278. if (uiCfg.print_state != WORKING) {
  279. /*
  280. lv_obj_set_pos(buttonFilament,INTERVAL_V,BTN_Y_PIXEL+INTERVAL_H+titleHeight);
  281. } else {
  282. */
  283. lv_obj_set_pos(buttonExtrusion, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  284. lv_obj_set_pos(buttonMove, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  285. }
  286. else {
  287. lv_obj_set_pos(buttonSpeed, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  288. lv_obj_set_pos(buttonBabyStep, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  289. }
  290. lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  291. // Create labels on the image buttons
  292. lv_btn_set_layout(buttonPreHeat, LV_LAYOUT_OFF);
  293. lv_btn_set_layout(buttonFilament, LV_LAYOUT_OFF);
  294. lv_btn_set_layout(buttonFan, LV_LAYOUT_OFF);
  295. lv_btn_set_layout(buttonPowerOff, LV_LAYOUT_OFF);
  296. if (uiCfg.print_state != WORKING) {
  297. /*
  298. lv_btn_set_layout(buttonFilament, LV_LAYOUT_OFF);
  299. } else {
  300. */
  301. lv_btn_set_layout(buttonExtrusion, LV_LAYOUT_OFF);
  302. lv_btn_set_layout(buttonMove, LV_LAYOUT_OFF);
  303. }
  304. else {
  305. lv_btn_set_layout(buttonSpeed, LV_LAYOUT_OFF);
  306. lv_btn_set_layout(buttonBabyStep, LV_LAYOUT_OFF);
  307. }
  308. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  309. labelPreHeat = lv_label_create(buttonPreHeat, NULL);
  310. label_Filament = lv_label_create(buttonFilament, NULL);
  311. label_Fan = lv_label_create(buttonFan, NULL);
  312. label_PowerOff = lv_label_create(buttonPowerOff, NULL);
  313. if (uiCfg.print_state != WORKING) {
  314. /*
  315. label_Filament = lv_label_create(buttonFilament, NULL);
  316. } else {
  317. */
  318. labelExtrusion = lv_label_create(buttonExtrusion, NULL);
  319. label_Move = lv_label_create(buttonMove, NULL);
  320. }
  321. else {
  322. label_Speed = lv_label_create(buttonSpeed, NULL);
  323. label_BabyStep = lv_label_create(buttonBabyStep, NULL);
  324. }
  325. label_Back = lv_label_create(buttonBack, NULL);
  326. if (gCfgItems.multiple_language) {
  327. lv_label_set_text(labelPreHeat, operation_menu.temp);
  328. lv_obj_align(labelPreHeat, buttonPreHeat, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  329. lv_label_set_text(label_Filament, operation_menu.filament);
  330. lv_obj_align(label_Filament, buttonFilament, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  331. lv_label_set_text(label_Fan, operation_menu.fan);
  332. lv_obj_align(label_Fan, buttonFan, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  333. if (gCfgItems.finish_power_off)
  334. lv_label_set_text(label_PowerOff, printing_more_menu.auto_close);
  335. else
  336. lv_label_set_text(label_PowerOff, printing_more_menu.manual);
  337. lv_obj_align(label_PowerOff, buttonPowerOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  338. if (uiCfg.print_state != WORKING) {
  339. /*
  340. lv_label_set_text(label_Filament, operation_menu.filament);
  341. lv_obj_align(label_Filament, buttonFilament, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET);
  342. } else {
  343. */
  344. lv_label_set_text(labelExtrusion, operation_menu.extr);
  345. lv_obj_align(labelExtrusion, buttonExtrusion, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  346. lv_label_set_text(label_Move, operation_menu.move);
  347. lv_obj_align(label_Move, buttonMove, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  348. }
  349. else {
  350. lv_label_set_text(label_Speed, operation_menu.speed);
  351. lv_obj_align(label_Speed, buttonSpeed, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  352. lv_label_set_text(label_BabyStep, operation_menu.babystep);
  353. lv_obj_align(label_BabyStep, buttonBabyStep, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  354. }
  355. lv_label_set_text(label_Back, common_menu.text_back);
  356. lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  357. }
  358. }
  359. void lv_clear_operation() {
  360. #if HAS_ROTARY_ENCODER
  361. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  362. #endif
  363. lv_obj_del(scr);
  364. }
  365. #endif // HAS_TFT_LVGL_UI