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_home.cpp 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 "../../../../gcode/queue.h"
  33. #include "../../../../inc/MarlinConfig.h"
  34. extern lv_group_t * g;
  35. static lv_obj_t * scr;
  36. #define ID_H_ALL 1
  37. #define ID_H_X 2
  38. #define ID_H_Y 3
  39. #define ID_H_Z 4
  40. #define ID_H_RETURN 5
  41. #define ID_H_OFF_ALL 6
  42. #define ID_H_OFF_XY 7
  43. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  44. switch (obj->mks_obj_id) {
  45. case ID_H_ALL:
  46. if (event == LV_EVENT_CLICKED) {
  47. }
  48. else if (event == LV_EVENT_RELEASED) {
  49. queue.inject_P(PSTR("G28"));
  50. }
  51. break;
  52. case ID_H_X:
  53. if (event == LV_EVENT_CLICKED) {
  54. }
  55. else if (event == LV_EVENT_RELEASED) {
  56. queue.inject_P(PSTR("G28 X0"));
  57. }
  58. break;
  59. case ID_H_Y:
  60. if (event == LV_EVENT_CLICKED) {
  61. }
  62. else if (event == LV_EVENT_RELEASED) {
  63. queue.inject_P(PSTR("G28 Y0"));
  64. }
  65. break;
  66. case ID_H_Z:
  67. if (event == LV_EVENT_CLICKED) {
  68. }
  69. else if (event == LV_EVENT_RELEASED) {
  70. queue.inject_P(PSTR("G28 Z0"));
  71. }
  72. break;
  73. case ID_H_OFF_ALL:
  74. if (event == LV_EVENT_CLICKED) {
  75. }
  76. else if (event == LV_EVENT_RELEASED) {
  77. queue.inject_P(PSTR("M84"));
  78. }
  79. break;
  80. case ID_H_OFF_XY:
  81. if (event == LV_EVENT_CLICKED) {
  82. }
  83. else if (event == LV_EVENT_RELEASED) {
  84. queue.inject_P(PSTR("M84 X Y"));
  85. }
  86. break;
  87. case ID_H_RETURN:
  88. if (event == LV_EVENT_CLICKED) {
  89. }
  90. else if (event == LV_EVENT_RELEASED) {
  91. lv_clear_home();
  92. lv_draw_tool();
  93. }
  94. break;
  95. }
  96. }
  97. void lv_draw_home(void) {
  98. lv_obj_t *buttonHomeAll, *buttonHomeX, *buttonHomeY, *buttonHomeZ;
  99. lv_obj_t *buttonBack;
  100. lv_obj_t *buttonOffAll, *buttonOffXY;
  101. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != ZERO_UI) {
  102. disp_state_stack._disp_index++;
  103. disp_state_stack._disp_state[disp_state_stack._disp_index] = ZERO_UI;
  104. }
  105. disp_state = ZERO_UI;
  106. scr = lv_obj_create(NULL, NULL);
  107. //static lv_style_t tool_style;
  108. lv_obj_set_style(scr, &tft_style_scr);
  109. lv_scr_load(scr);
  110. lv_obj_clean(scr);
  111. lv_obj_t * title = lv_label_create(scr, NULL);
  112. lv_obj_set_style(title, &tft_style_label_rel);
  113. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  114. lv_label_set_text(title, creat_title_text());
  115. lv_refr_now(lv_refr_get_disp_refreshing());
  116. // Create image buttons
  117. //buttonWifi = lv_imgbtn_create(scr, NULL);
  118. buttonHomeAll = lv_imgbtn_create(scr, NULL);
  119. buttonHomeX = lv_imgbtn_create(scr, NULL);
  120. //buttonContinue = lv_imgbtn_create(scr, NULL);
  121. buttonHomeY = lv_imgbtn_create(scr, NULL);
  122. buttonHomeZ = lv_imgbtn_create(scr, NULL);
  123. buttonOffAll = lv_imgbtn_create(scr, NULL);
  124. buttonOffXY = lv_imgbtn_create(scr, NULL);
  125. buttonBack = lv_imgbtn_create(scr, NULL);
  126. #if 1
  127. lv_obj_set_event_cb_mks(buttonHomeAll, event_handler,ID_H_ALL, NULL,0);
  128. lv_imgbtn_set_src(buttonHomeAll, LV_BTN_STATE_REL, "F:/bmp_zeroAll.bin");
  129. lv_imgbtn_set_src(buttonHomeAll, LV_BTN_STATE_PR, "F:/bmp_zeroAll.bin");
  130. lv_imgbtn_set_style(buttonHomeAll, LV_BTN_STATE_PR, &tft_style_label_pre);
  131. lv_imgbtn_set_style(buttonHomeAll, LV_BTN_STATE_REL, &tft_style_label_rel);
  132. lv_obj_set_event_cb_mks(buttonHomeX, event_handler, ID_H_X, NULL, 0);
  133. lv_imgbtn_set_src(buttonHomeX, LV_BTN_STATE_REL, "F:/bmp_zeroX.bin");
  134. lv_imgbtn_set_src(buttonHomeX, LV_BTN_STATE_PR, "F:/bmp_zeroX.bin");
  135. lv_imgbtn_set_style(buttonHomeX, LV_BTN_STATE_PR, &tft_style_label_pre);
  136. lv_imgbtn_set_style(buttonHomeX, LV_BTN_STATE_REL, &tft_style_label_rel);
  137. lv_obj_set_event_cb_mks(buttonHomeY, event_handler, ID_H_Y, NULL, 0);
  138. lv_imgbtn_set_src(buttonHomeY, LV_BTN_STATE_REL, "F:/bmp_zeroY.bin");
  139. lv_imgbtn_set_src(buttonHomeY, LV_BTN_STATE_PR, "F:/bmp_zeroY.bin");
  140. lv_imgbtn_set_style(buttonHomeY, LV_BTN_STATE_PR, &tft_style_label_pre);
  141. lv_imgbtn_set_style(buttonHomeY, LV_BTN_STATE_REL, &tft_style_label_rel);
  142. lv_obj_set_event_cb_mks(buttonHomeZ, event_handler, ID_H_Z, NULL, 0);
  143. lv_imgbtn_set_src(buttonHomeZ, LV_BTN_STATE_REL, "F:/bmp_zeroZ.bin");
  144. lv_imgbtn_set_src(buttonHomeZ, LV_BTN_STATE_PR, "F:/bmp_zeroZ.bin");
  145. lv_imgbtn_set_style(buttonHomeZ, LV_BTN_STATE_PR, &tft_style_label_pre);
  146. lv_imgbtn_set_style(buttonHomeZ, LV_BTN_STATE_REL, &tft_style_label_rel);
  147. lv_obj_set_event_cb_mks(buttonOffAll, event_handler,ID_H_OFF_ALL, NULL,0);
  148. lv_imgbtn_set_src(buttonOffAll, LV_BTN_STATE_REL, "F:/bmp_function1.bin");
  149. lv_imgbtn_set_src(buttonOffAll, LV_BTN_STATE_PR, "F:/bmp_function1.bin");
  150. lv_imgbtn_set_style(buttonOffAll, LV_BTN_STATE_PR, &tft_style_label_pre);
  151. lv_imgbtn_set_style(buttonOffAll, LV_BTN_STATE_REL, &tft_style_label_rel);
  152. lv_obj_set_event_cb_mks(buttonOffXY, event_handler,ID_H_OFF_XY, NULL,0);
  153. lv_imgbtn_set_src(buttonOffXY, LV_BTN_STATE_REL, "F:/bmp_function1.bin");
  154. lv_imgbtn_set_src(buttonOffXY, LV_BTN_STATE_PR, "F:/bmp_function1.bin");
  155. lv_imgbtn_set_style(buttonOffXY, LV_BTN_STATE_PR, &tft_style_label_pre);
  156. lv_imgbtn_set_style(buttonOffXY, LV_BTN_STATE_REL, &tft_style_label_rel);
  157. lv_obj_set_event_cb_mks(buttonBack, event_handler,ID_H_RETURN, NULL,0);
  158. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin");
  159. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin");
  160. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre);
  161. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel);
  162. #endif
  163. lv_obj_set_pos(buttonHomeAll, INTERVAL_V, titleHeight);
  164. lv_obj_set_pos(buttonHomeX, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight);
  165. lv_obj_set_pos(buttonHomeY, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight);
  166. lv_obj_set_pos(buttonHomeZ, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight);
  167. lv_obj_set_pos(buttonOffAll, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  168. lv_obj_set_pos(buttonOffXY, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  169. lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  170. // Create labels on the image buttons
  171. lv_btn_set_layout(buttonHomeAll, LV_LAYOUT_OFF);
  172. lv_btn_set_layout(buttonHomeX, LV_LAYOUT_OFF);
  173. lv_btn_set_layout(buttonHomeY, LV_LAYOUT_OFF);
  174. lv_btn_set_layout(buttonHomeZ, LV_LAYOUT_OFF);
  175. lv_btn_set_layout(buttonOffAll, LV_LAYOUT_OFF);
  176. lv_btn_set_layout(buttonOffXY, LV_LAYOUT_OFF);
  177. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  178. lv_obj_t *labelHomeAll = lv_label_create(buttonHomeAll, NULL);
  179. lv_obj_t *labelHomeX = lv_label_create(buttonHomeX, NULL);
  180. lv_obj_t *labelHomeY = lv_label_create(buttonHomeY, NULL);
  181. lv_obj_t *labelHomeZ = lv_label_create(buttonHomeZ, NULL);
  182. lv_obj_t *labelOffAll = lv_label_create(buttonOffAll, NULL);
  183. lv_obj_t *labelOffXY = lv_label_create(buttonOffXY, NULL);
  184. lv_obj_t *label_Back = lv_label_create(buttonBack, NULL);
  185. if (gCfgItems.multiple_language) {
  186. lv_label_set_text(labelHomeAll, home_menu.home_all);
  187. lv_obj_align(labelHomeAll, buttonHomeAll, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  188. lv_label_set_text(labelHomeX, home_menu.home_x);
  189. lv_obj_align(labelHomeX, buttonHomeX, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  190. lv_label_set_text(labelHomeY, home_menu.home_y);
  191. lv_obj_align(labelHomeY, buttonHomeY, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  192. lv_label_set_text(labelHomeZ, home_menu.home_z);
  193. lv_obj_align(labelHomeZ, buttonHomeZ, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  194. lv_label_set_text(labelOffAll, set_menu.motoroff);
  195. lv_obj_align(labelOffAll, buttonOffAll, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  196. lv_label_set_text(labelOffXY, set_menu.motoroffXY);
  197. lv_obj_align(labelOffXY, buttonOffXY, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  198. lv_label_set_text(label_Back, common_menu.text_back);
  199. lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  200. }
  201. #if HAS_ROTARY_ENCODER
  202. if (gCfgItems.encoder_enable) {
  203. lv_group_add_obj(g, buttonHomeAll);
  204. lv_group_add_obj(g, buttonHomeX);
  205. lv_group_add_obj(g, buttonHomeY);
  206. lv_group_add_obj(g, buttonHomeZ);
  207. lv_group_add_obj(g, buttonOffAll);
  208. lv_group_add_obj(g, buttonOffXY);
  209. lv_group_add_obj(g, buttonBack);
  210. }
  211. #endif
  212. }
  213. void lv_clear_home() {
  214. #if HAS_ROTARY_ENCODER
  215. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  216. #endif
  217. lv_obj_del(scr);
  218. }
  219. #endif // HAS_TFT_LVGL_UI