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_set.cpp 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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_ready_print.h"
  25. #include "draw_set.h"
  26. #include "draw_ui.h"
  27. #include <lv_conf.h>
  28. //#include "../lvgl/src/lv_objx/lv_imgbtn.h"
  29. //#include "../lvgl/src/lv_objx/lv_img.h"
  30. //#include "../lvgl/src/lv_core/lv_disp.h"
  31. //#include "../lvgl/src/lv_core/lv_refr.h"
  32. #include "pic_manager.h"
  33. #include "../../../../gcode/queue.h"
  34. #include "../../../../inc/MarlinConfig.h"
  35. static lv_obj_t * scr;
  36. extern lv_group_t* g;
  37. #define ID_S_WIFI 1
  38. #define ID_S_FAN 2
  39. #define ID_S_ABOUT 3
  40. #define ID_S_CONTINUE 4
  41. #define ID_S_MOTOR_OFF 5
  42. #define ID_S_LANGUAGE 6
  43. #define ID_S_MACHINE_PARA 7
  44. #define ID_S_EEPROM_SET 8
  45. #define ID_S_RETURN 9
  46. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  47. #if ENABLED(USE_WIFI_FUNCTION)
  48. char buf[6] = { 0 };
  49. #endif
  50. switch (obj->mks_obj_id) {
  51. case ID_S_FAN:
  52. if (event == LV_EVENT_CLICKED) {
  53. // nothing to do
  54. }
  55. else if (event == LV_EVENT_RELEASED) {
  56. lv_clear_set();
  57. lv_draw_fan();
  58. }
  59. break;
  60. case ID_S_ABOUT:
  61. if (event == LV_EVENT_CLICKED) {
  62. // nothing to do
  63. }
  64. else if (event == LV_EVENT_RELEASED) {
  65. lv_clear_set();
  66. lv_draw_about();
  67. }
  68. break;
  69. case ID_S_CONTINUE:
  70. break;
  71. case ID_S_MOTOR_OFF:
  72. if (event == LV_EVENT_CLICKED) {
  73. // nothing to do
  74. }
  75. else if (event == LV_EVENT_RELEASED) {
  76. #if HAS_SUICIDE
  77. suicide();
  78. #else
  79. queue.enqueue_now_P(PSTR("M84"));
  80. #endif
  81. }
  82. break;
  83. case ID_S_LANGUAGE:
  84. if (event == LV_EVENT_CLICKED) {
  85. // nothing to do
  86. }
  87. else if (event == LV_EVENT_RELEASED) {
  88. lv_clear_set();
  89. lv_draw_language();
  90. }
  91. break;
  92. case ID_S_MACHINE_PARA:
  93. if (event == LV_EVENT_CLICKED) {
  94. }
  95. else if (event == LV_EVENT_RELEASED) {
  96. lv_clear_set();
  97. lv_draw_machine_para();
  98. }
  99. break;
  100. case ID_S_EEPROM_SET:
  101. if (event == LV_EVENT_CLICKED) {
  102. }
  103. else if (event == LV_EVENT_RELEASED) {
  104. lv_clear_set();
  105. lv_draw_eeprom_settings();
  106. }
  107. break;
  108. case ID_S_RETURN:
  109. if (event == LV_EVENT_CLICKED) {
  110. // nothing to do
  111. }
  112. else if (event == LV_EVENT_RELEASED) {
  113. lv_clear_set();
  114. lv_draw_ready_print();
  115. }
  116. break;
  117. #if ENABLED(USE_WIFI_FUNCTION)
  118. case ID_S_WIFI:
  119. if (event == LV_EVENT_CLICKED) {
  120. }
  121. else if (event == LV_EVENT_RELEASED) {
  122. if (gCfgItems.wifi_mode_sel == STA_MODEL) {
  123. if (wifi_link_state == WIFI_CONNECTED) {
  124. last_disp_state = SET_UI;
  125. lv_clear_set();
  126. lv_draw_wifi();
  127. }
  128. else {
  129. if (uiCfg.command_send == 1) {
  130. buf[0] = 0xA5;
  131. buf[1] = 0x07;
  132. buf[2] = 0x00;
  133. buf[3] = 0x00;
  134. buf[4] = 0xFC;
  135. raw_send_to_wifi(buf, 5);
  136. last_disp_state = SET_UI;
  137. lv_clear_set();
  138. lv_draw_wifi_list();
  139. }
  140. else {
  141. last_disp_state = SET_UI;
  142. lv_clear_set();
  143. lv_draw_dialog(WIFI_ENABLE_TIPS);
  144. }
  145. }
  146. }
  147. else {
  148. last_disp_state = SET_UI;
  149. lv_clear_set();
  150. lv_draw_wifi();
  151. }
  152. }
  153. break;
  154. #endif
  155. }
  156. }
  157. void lv_draw_set(void) {
  158. lv_obj_t *buttonFan, *buttonAbout;
  159. lv_obj_t *buMotorOff, *buttonBack;
  160. #if HAS_LANG_SELECT_SCREEN
  161. lv_obj_t *buttonLanguage;
  162. #endif
  163. lv_obj_t *buttonMachinePara;
  164. lv_obj_t *buttonEepromSet;
  165. #if ENABLED(USE_WIFI_FUNCTION)
  166. lv_obj_t *buttonWifi;
  167. #endif
  168. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != SET_UI) {
  169. disp_state_stack._disp_index++;
  170. disp_state_stack._disp_state[disp_state_stack._disp_index] = SET_UI;
  171. }
  172. disp_state = SET_UI;
  173. scr = lv_obj_create(NULL, NULL);
  174. //static lv_style_t tool_style;
  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. buttonEepromSet = lv_imgbtn_create(scr, NULL);
  185. //buttonWifi = lv_imgbtn_create(scr, NULL);
  186. buttonFan = lv_imgbtn_create(scr, NULL);
  187. buttonAbout = lv_imgbtn_create(scr, NULL);
  188. //buttonContinue = lv_imgbtn_create(scr, NULL);
  189. buMotorOff = lv_imgbtn_create(scr, NULL);
  190. buttonMachinePara = lv_imgbtn_create(scr, NULL);
  191. #if HAS_LANG_SELECT_SCREEN
  192. buttonLanguage = lv_imgbtn_create(scr, NULL);
  193. #endif
  194. #if ENABLED(USE_WIFI_FUNCTION)
  195. buttonWifi = lv_imgbtn_create(scr, NULL);
  196. #endif
  197. buttonBack = lv_imgbtn_create(scr, NULL);
  198. lv_obj_set_event_cb_mks(buttonEepromSet, event_handler, ID_S_EEPROM_SET, NULL, 0);
  199. lv_imgbtn_set_src(buttonEepromSet, LV_BTN_STATE_REL, "F:/bmp_eeprom_settings.bin");
  200. lv_imgbtn_set_src(buttonEepromSet, LV_BTN_STATE_PR, "F:/bmp_eeprom_settings.bin");
  201. lv_imgbtn_set_style(buttonEepromSet, LV_BTN_STATE_PR, &tft_style_label_pre);
  202. lv_imgbtn_set_style(buttonEepromSet, LV_BTN_STATE_REL, &tft_style_label_rel);
  203. #if 1
  204. lv_obj_set_event_cb_mks(buttonFan, event_handler, ID_S_FAN, NULL, 0);
  205. lv_imgbtn_set_src(buttonFan, LV_BTN_STATE_REL, "F:/bmp_fan.bin");
  206. lv_imgbtn_set_src(buttonFan, LV_BTN_STATE_PR, "F:/bmp_fan.bin");
  207. lv_imgbtn_set_style(buttonFan, LV_BTN_STATE_PR, &tft_style_label_pre);
  208. lv_imgbtn_set_style(buttonFan, LV_BTN_STATE_REL, &tft_style_label_rel);
  209. lv_obj_set_event_cb_mks(buttonAbout, event_handler, ID_S_ABOUT, NULL, 0);
  210. lv_imgbtn_set_src(buttonAbout, LV_BTN_STATE_REL, "F:/bmp_about.bin");
  211. lv_imgbtn_set_src(buttonAbout, LV_BTN_STATE_PR, "F:/bmp_about.bin");
  212. lv_imgbtn_set_style(buttonAbout, LV_BTN_STATE_PR, &tft_style_label_pre);
  213. lv_imgbtn_set_style(buttonAbout, LV_BTN_STATE_REL, &tft_style_label_rel);
  214. lv_obj_set_event_cb_mks(buMotorOff, event_handler, ID_S_MOTOR_OFF, NULL, 0);
  215. #if HAS_SUICIDE
  216. lv_imgbtn_set_src(buMotorOff, LV_BTN_STATE_REL, "F:/bmp_manual_off.bin");
  217. lv_imgbtn_set_src(buMotorOff, LV_BTN_STATE_PR, "F:/bmp_manual_off.bin");
  218. #else
  219. lv_imgbtn_set_src(buMotorOff, LV_BTN_STATE_REL, "F:/bmp_function1.bin");
  220. lv_imgbtn_set_src(buMotorOff, LV_BTN_STATE_PR, "F:/bmp_function1.bin");
  221. #endif
  222. lv_imgbtn_set_style(buMotorOff, LV_BTN_STATE_PR, &tft_style_label_pre);
  223. lv_imgbtn_set_style(buMotorOff, LV_BTN_STATE_REL, &tft_style_label_rel);
  224. lv_obj_set_event_cb_mks(buttonMachinePara, event_handler, ID_S_MACHINE_PARA, NULL, 0);
  225. lv_imgbtn_set_src(buttonMachinePara, LV_BTN_STATE_REL, "F:/bmp_machine_para.bin");
  226. lv_imgbtn_set_src(buttonMachinePara, LV_BTN_STATE_PR, "F:/bmp_machine_para.bin");
  227. lv_imgbtn_set_style(buttonMachinePara, LV_BTN_STATE_PR, &tft_style_label_pre);
  228. lv_imgbtn_set_style(buttonMachinePara, LV_BTN_STATE_REL, &tft_style_label_rel);
  229. #if HAS_LANG_SELECT_SCREEN
  230. lv_obj_set_event_cb_mks(buttonLanguage, event_handler, ID_S_LANGUAGE, NULL, 0);
  231. lv_imgbtn_set_src(buttonLanguage, LV_BTN_STATE_REL, "F:/bmp_language.bin");
  232. lv_imgbtn_set_src(buttonLanguage, LV_BTN_STATE_PR, "F:/bmp_language.bin");
  233. lv_imgbtn_set_style(buttonLanguage, LV_BTN_STATE_PR, &tft_style_label_pre);
  234. lv_imgbtn_set_style(buttonLanguage, LV_BTN_STATE_REL, &tft_style_label_rel);
  235. #endif
  236. #if ENABLED(USE_WIFI_FUNCTION)
  237. lv_obj_set_event_cb_mks(buttonWifi, event_handler,ID_S_WIFI,NULL,0);
  238. lv_imgbtn_set_src(buttonWifi, LV_BTN_STATE_REL, "F:/bmp_wifi.bin");
  239. lv_imgbtn_set_src(buttonWifi, LV_BTN_STATE_PR, "F:/bmp_wifi.bin");
  240. lv_imgbtn_set_style(buttonWifi, LV_BTN_STATE_PR, &tft_style_label_pre);
  241. lv_imgbtn_set_style(buttonWifi, LV_BTN_STATE_REL, &tft_style_label_rel);
  242. #endif
  243. lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_S_RETURN,NULL , 0);
  244. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin");
  245. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin");
  246. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre);
  247. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel);
  248. #endif // if 1
  249. /*lv_obj_set_pos(buttonWifi,INTERVAL_V,titleHeight);
  250. lv_obj_set_pos(buttonFan,BTN_X_PIXEL+INTERVAL_V*2,titleHeight);
  251. lv_obj_set_pos(buttonAbout,BTN_X_PIXEL*2+INTERVAL_V*3,titleHeight);
  252. lv_obj_set_pos(buttonContinue,BTN_X_PIXEL*3+INTERVAL_V*4,titleHeight);
  253. lv_obj_set_pos(buMotorOff,INTERVAL_V, BTN_Y_PIXEL+INTERVAL_H+titleHeight);
  254. lv_obj_set_pos(buttonLanguage,BTN_X_PIXEL+INTERVAL_V*2,BTN_Y_PIXEL+INTERVAL_H+titleHeight);
  255. lv_obj_set_pos(buttonBack,BTN_X_PIXEL*3+INTERVAL_V*4, BTN_Y_PIXEL+INTERVAL_H+titleHeight);*/
  256. //lv_obj_set_pos(buttonWifi,INTERVAL_V,titleHeight);
  257. lv_obj_set_pos(buttonEepromSet, INTERVAL_V, titleHeight);
  258. lv_obj_set_pos(buttonFan, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight);
  259. lv_obj_set_pos(buttonAbout, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight);
  260. //lv_obj_set_pos(buttonContinue,BTN_X_PIXEL*3+INTERVAL_V*4,titleHeight);
  261. lv_obj_set_pos(buMotorOff, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight);
  262. lv_obj_set_pos(buttonMachinePara, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  263. #if HAS_LANG_SELECT_SCREEN
  264. lv_obj_set_pos(buttonLanguage, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  265. #endif
  266. #if ENABLED(USE_WIFI_FUNCTION)
  267. lv_obj_set_pos(buttonWifi,BTN_X_PIXEL*2+INTERVAL_V*3,BTN_Y_PIXEL+INTERVAL_H+titleHeight);
  268. #endif
  269. lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  270. /// Create labels on the buttons
  271. //lv_btn_set_layout(buttonWifi, LV_LAYOUT_OFF);
  272. lv_btn_set_layout(buttonEepromSet, LV_LAYOUT_OFF);
  273. lv_btn_set_layout(buttonFan, LV_LAYOUT_OFF);
  274. lv_btn_set_layout(buttonAbout, LV_LAYOUT_OFF);
  275. //lv_btn_set_layout(buttonContinue, LV_LAYOUT_OFF);
  276. lv_btn_set_layout(buMotorOff, LV_LAYOUT_OFF);
  277. lv_btn_set_layout(buttonMachinePara, LV_LAYOUT_OFF);
  278. #if HAS_LANG_SELECT_SCREEN
  279. lv_btn_set_layout(buttonLanguage, LV_LAYOUT_OFF);
  280. #endif
  281. #if ENABLED(USE_WIFI_FUNCTION)
  282. lv_btn_set_layout(buttonWifi, LV_LAYOUT_OFF);
  283. #endif
  284. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  285. //lv_obj_t *labelWifi= lv_label_create(buttonWifi, NULL);
  286. lv_obj_t *label_EepromSet = lv_label_create(buttonEepromSet, NULL);
  287. lv_obj_t *labelFan = lv_label_create(buttonFan, NULL);
  288. lv_obj_t *label_About = lv_label_create(buttonAbout, NULL);
  289. //lv_obj_t *label_Continue = lv_label_create(buttonContinue, NULL);
  290. lv_obj_t *label_MotorOff = lv_label_create(buMotorOff, NULL);
  291. lv_obj_t *label_MachinePara = lv_label_create(buttonMachinePara, NULL);
  292. #if HAS_LANG_SELECT_SCREEN
  293. lv_obj_t *label_Language = lv_label_create(buttonLanguage, NULL);
  294. #endif
  295. #if ENABLED(USE_WIFI_FUNCTION)
  296. lv_obj_t *label_Wifi = lv_label_create(buttonWifi, NULL);
  297. #endif
  298. lv_obj_t *label_Back = lv_label_create(buttonBack, NULL);
  299. if (gCfgItems.multiple_language) {
  300. lv_label_set_text(label_EepromSet, set_menu.eepromSet);
  301. lv_obj_align(label_EepromSet, buttonEepromSet, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  302. lv_label_set_text(labelFan, set_menu.fan);
  303. lv_obj_align(labelFan, buttonFan, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  304. lv_label_set_text(label_About, set_menu.about);
  305. lv_obj_align(label_About, buttonAbout, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  306. //lv_label_set_text(label_Continue, set_menu.breakpoint);
  307. //lv_obj_align(label_Continue, buttonContinue, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET);
  308. lv_label_set_text(label_MotorOff, set_menu.TERN(HAS_SUICIDE, shutdown, motoroff));
  309. lv_obj_align(label_MotorOff, buMotorOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  310. lv_label_set_text(label_MachinePara, set_menu.machine_para);
  311. lv_obj_align(label_MachinePara, buttonMachinePara, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  312. #if HAS_LANG_SELECT_SCREEN
  313. lv_label_set_text(label_Language, set_menu.language);
  314. lv_obj_align(label_Language, buttonLanguage, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  315. #endif
  316. #if ENABLED(USE_WIFI_FUNCTION)
  317. lv_label_set_text(label_Wifi, set_menu.wifi);
  318. lv_obj_align(label_Wifi, buttonWifi, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET);
  319. #endif
  320. lv_label_set_text(label_Back, common_menu.text_back);
  321. lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  322. }
  323. #if HAS_ROTARY_ENCODER
  324. if (gCfgItems.encoder_enable) {
  325. lv_group_add_obj(g, buttonEepromSet);
  326. lv_group_add_obj(g, buttonFan);
  327. lv_group_add_obj(g, buttonAbout);
  328. lv_group_add_obj(g, buMotorOff);
  329. lv_group_add_obj(g, buttonMachinePara);
  330. lv_group_add_obj(g, buttonLanguage);
  331. #if ENABLED(USE_WIFI_FUNCTION)
  332. lv_group_add_obj(g, buttonWifi);
  333. #endif
  334. lv_group_add_obj(g, buttonBack);
  335. }
  336. #endif
  337. }
  338. void lv_clear_set() {
  339. #if HAS_ROTARY_ENCODER
  340. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  341. #endif
  342. lv_obj_del(scr);
  343. }
  344. #endif // HAS_TFT_LVGL_UI