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_level_settings.cpp 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 "../../../../inc/MarlinConfig.h"
  27. extern lv_group_t * g;
  28. static lv_obj_t * scr;
  29. #define ID_LEVEL_RETURN 1
  30. #define ID_LEVEL_POSITION 2
  31. #define ID_LEVEL_POSITION_ARROW 3
  32. #define ID_LEVEL_COMMAND 4
  33. #define ID_LEVEL_COMMAND_ARROW 5
  34. #define ID_LEVEL_ZOFFSET 6
  35. #define ID_LEVEL_ZOFFSET_ARROW 7
  36. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  37. switch (obj->mks_obj_id) {
  38. case ID_LEVEL_RETURN:
  39. if (event == LV_EVENT_CLICKED) {
  40. }
  41. else if (event == LV_EVENT_RELEASED) {
  42. lv_clear_level_settings();
  43. draw_return_ui();
  44. }
  45. break;
  46. case ID_LEVEL_POSITION:
  47. if (event == LV_EVENT_CLICKED) {
  48. }
  49. else if (event == LV_EVENT_RELEASED) {
  50. lv_clear_level_settings();
  51. lv_draw_manual_level_pos_settings();
  52. }
  53. break;
  54. case ID_LEVEL_POSITION_ARROW:
  55. if (event == LV_EVENT_CLICKED) {
  56. }
  57. else if (event == LV_EVENT_RELEASED) {
  58. lv_clear_level_settings();
  59. lv_draw_manual_level_pos_settings();
  60. }
  61. break;
  62. case ID_LEVEL_COMMAND:
  63. if (event == LV_EVENT_CLICKED) {
  64. }
  65. else if (event == LV_EVENT_RELEASED) {
  66. keyboard_value = gcodeCommand;
  67. lv_clear_level_settings();
  68. lv_draw_keyboard();
  69. }
  70. break;
  71. case ID_LEVEL_COMMAND_ARROW:
  72. if (event == LV_EVENT_CLICKED) {
  73. }
  74. else if (event == LV_EVENT_RELEASED) {
  75. keyboard_value = gcodeCommand;
  76. lv_clear_level_settings();
  77. lv_draw_keyboard();
  78. }
  79. break;
  80. #if HAS_BED_PROBE
  81. case ID_LEVEL_ZOFFSET:
  82. if (event == LV_EVENT_CLICKED) {
  83. }
  84. else if (event == LV_EVENT_RELEASED) {
  85. lv_clear_level_settings();
  86. lv_draw_auto_level_offset_settings();
  87. }
  88. break;
  89. case ID_LEVEL_ZOFFSET_ARROW:
  90. if (event == LV_EVENT_CLICKED) {
  91. }
  92. else if (event == LV_EVENT_RELEASED) {
  93. lv_clear_level_settings();
  94. lv_draw_auto_level_offset_settings();
  95. }
  96. break;
  97. #endif
  98. }
  99. }
  100. void lv_draw_level_settings(void) {
  101. lv_obj_t *buttonBack, *label_Back;
  102. lv_obj_t *buttonPosition, *labelPosition, *buttonPositionNarrow;
  103. lv_obj_t *buttonCommand, *labelCommand, *buttonCommandNarrow;
  104. #if HAS_BED_PROBE
  105. lv_obj_t *buttonZoffset, *labelZoffset, *buttonZoffsetNarrow;
  106. lv_obj_t * line3;
  107. #endif
  108. lv_obj_t * line1, * line2;
  109. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != LEVELING_PARA_UI) {
  110. disp_state_stack._disp_index++;
  111. disp_state_stack._disp_state[disp_state_stack._disp_index] = LEVELING_PARA_UI;
  112. }
  113. disp_state = LEVELING_PARA_UI;
  114. scr = lv_obj_create(NULL, NULL);
  115. lv_obj_set_style(scr, &tft_style_scr);
  116. lv_scr_load(scr);
  117. lv_obj_clean(scr);
  118. lv_obj_t * title = lv_label_create(scr, NULL);
  119. lv_obj_set_style(title, &tft_style_label_rel);
  120. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  121. lv_label_set_text(title, machine_menu.LevelingParaConfTitle);
  122. lv_refr_now(lv_refr_get_disp_refreshing());
  123. buttonPosition = lv_btn_create(scr, NULL); /*Add a button the current screen*/
  124. lv_obj_set_pos(buttonPosition, PARA_UI_POS_X, PARA_UI_POS_Y); /*Set its position*/
  125. lv_obj_set_size(buttonPosition, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/
  126. lv_obj_set_event_cb_mks(buttonPosition, event_handler, ID_LEVEL_POSITION, NULL, 0);
  127. lv_btn_set_style(buttonPosition, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/
  128. lv_btn_set_style(buttonPosition, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/
  129. lv_btn_set_layout(buttonPosition, LV_LAYOUT_OFF);
  130. labelPosition = lv_label_create(buttonPosition, NULL); /*Add a label to the button*/
  131. #if HAS_ROTARY_ENCODER
  132. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonPosition);
  133. #endif
  134. buttonPositionNarrow = lv_imgbtn_create(scr, NULL);
  135. lv_obj_set_pos(buttonPositionNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y + PARA_UI_ARROW_V);
  136. lv_obj_set_event_cb_mks(buttonPositionNarrow, event_handler, ID_LEVEL_POSITION_ARROW, NULL, 0);
  137. lv_imgbtn_set_src(buttonPositionNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin");
  138. lv_imgbtn_set_src(buttonPositionNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin");
  139. lv_imgbtn_set_style(buttonPositionNarrow, LV_BTN_STATE_PR, &tft_style_label_pre);
  140. lv_imgbtn_set_style(buttonPositionNarrow, LV_BTN_STATE_REL, &tft_style_label_rel);
  141. lv_btn_set_layout(buttonPositionNarrow, LV_LAYOUT_OFF);
  142. line1 = lv_line_create(scr, NULL);
  143. lv_ex_line(line1, line_points[0]);
  144. buttonCommand = lv_btn_create(scr, NULL);
  145. lv_obj_set_pos(buttonCommand, PARA_UI_POS_X, PARA_UI_POS_Y * 2);
  146. lv_obj_set_size(buttonCommand, PARA_UI_SIZE_X, PARA_UI_SIZE_Y);
  147. lv_obj_set_event_cb_mks(buttonCommand, event_handler, ID_LEVEL_COMMAND, NULL, 0);
  148. lv_btn_set_style(buttonCommand, LV_BTN_STYLE_REL, &tft_style_label_rel);
  149. lv_btn_set_style(buttonCommand, LV_BTN_STYLE_PR, &tft_style_label_pre);
  150. lv_btn_set_layout(buttonCommand, LV_LAYOUT_OFF);
  151. labelCommand = lv_label_create(buttonCommand, NULL);
  152. #if HAS_ROTARY_ENCODER
  153. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonCommand);
  154. #endif
  155. buttonCommandNarrow = lv_imgbtn_create(scr, NULL);
  156. lv_obj_set_pos(buttonCommandNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 2 + PARA_UI_ARROW_V);
  157. lv_obj_set_event_cb_mks(buttonCommandNarrow, event_handler, ID_LEVEL_COMMAND_ARROW, NULL, 0);
  158. lv_imgbtn_set_src(buttonCommandNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin");
  159. lv_imgbtn_set_src(buttonCommandNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin");
  160. lv_imgbtn_set_style(buttonCommandNarrow, LV_BTN_STATE_PR, &tft_style_label_pre);
  161. lv_imgbtn_set_style(buttonCommandNarrow, LV_BTN_STATE_REL, &tft_style_label_rel);
  162. lv_btn_set_layout(buttonCommandNarrow, LV_LAYOUT_OFF);
  163. line2 = lv_line_create(scr, NULL);
  164. lv_ex_line(line2, line_points[1]);
  165. #if HAS_BED_PROBE
  166. buttonZoffset = lv_btn_create(scr, NULL); /*Add a button the current screen*/
  167. lv_obj_set_pos(buttonZoffset, PARA_UI_POS_X, PARA_UI_POS_Y * 3); /*Set its position*/
  168. lv_obj_set_size(buttonZoffset, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/
  169. lv_obj_set_event_cb_mks(buttonZoffset, event_handler, ID_LEVEL_ZOFFSET, NULL, 0);
  170. lv_btn_set_style(buttonZoffset, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/
  171. lv_btn_set_style(buttonZoffset, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/
  172. lv_btn_set_layout(buttonZoffset, LV_LAYOUT_OFF);
  173. labelZoffset = lv_label_create(buttonZoffset, NULL); /*Add a label to the button*/
  174. #if HAS_ROTARY_ENCODER
  175. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonZoffset);
  176. #endif
  177. buttonZoffsetNarrow = lv_imgbtn_create(scr, NULL);
  178. lv_obj_set_pos(buttonZoffsetNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 3 + PARA_UI_ARROW_V);
  179. lv_obj_set_event_cb_mks(buttonZoffsetNarrow, event_handler, ID_LEVEL_ZOFFSET_ARROW, NULL, 0);
  180. lv_imgbtn_set_src(buttonZoffsetNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin");
  181. lv_imgbtn_set_src(buttonZoffsetNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin");
  182. lv_imgbtn_set_style(buttonZoffsetNarrow, LV_BTN_STATE_PR, &tft_style_label_pre);
  183. lv_imgbtn_set_style(buttonZoffsetNarrow, LV_BTN_STATE_REL, &tft_style_label_rel);
  184. lv_btn_set_layout(buttonZoffsetNarrow, LV_LAYOUT_OFF);
  185. line3 = lv_line_create(scr, NULL);
  186. lv_ex_line(line3, line_points[2]);
  187. #endif // HAS_BED_PROBE
  188. buttonBack = lv_imgbtn_create(scr, NULL);
  189. lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_LEVEL_RETURN, NULL, 0);
  190. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin");
  191. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin");
  192. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre);
  193. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel);
  194. #if HAS_ROTARY_ENCODER
  195. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack);
  196. #endif
  197. lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y);
  198. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  199. label_Back = lv_label_create(buttonBack, NULL);
  200. if (gCfgItems.multiple_language) {
  201. lv_label_set_text(label_Back, common_menu.text_back);
  202. lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0);
  203. lv_label_set_text(labelPosition, machine_menu.LevelingManuPosConf);
  204. lv_obj_align(labelPosition, buttonPosition, LV_ALIGN_IN_LEFT_MID, 0, 0);
  205. lv_label_set_text(labelCommand, machine_menu.LevelingAutoCommandConf);
  206. lv_obj_align(labelCommand, buttonCommand, LV_ALIGN_IN_LEFT_MID, 0, 0);
  207. #if HAS_BED_PROBE
  208. lv_label_set_text(labelZoffset, machine_menu.LevelingAutoZoffsetConf);
  209. lv_obj_align(labelZoffset, buttonZoffset, LV_ALIGN_IN_LEFT_MID, 0, 0);
  210. #endif
  211. }
  212. }
  213. void lv_clear_level_settings() {
  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