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_machine_settings.cpp 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 "../../../../MarlinCore.h"
  27. extern lv_group_t * g;
  28. static lv_obj_t * scr;
  29. #define ID_MACHINE_RETURN 1
  30. #define ID_MACHINE_ACCELERATION 2
  31. #define ID_MACHINE_ACCELERATION_ARROW 3
  32. #define ID_MACHINE_FEEDRATE 4
  33. #define ID_MACHINE_FEEDRATE_ARROW 5
  34. #define ID_MACHINE_JERK 6
  35. #define ID_MACHINE_JERK_ARROW 7
  36. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  37. switch (obj->mks_obj_id) {
  38. case ID_MACHINE_RETURN:
  39. if (event == LV_EVENT_CLICKED) {
  40. }
  41. else if (event == LV_EVENT_RELEASED) {
  42. lv_clear_machine_settings();
  43. draw_return_ui();
  44. }
  45. break;
  46. case ID_MACHINE_ACCELERATION:
  47. if (event == LV_EVENT_CLICKED) {
  48. }
  49. else if (event == LV_EVENT_RELEASED) {
  50. lv_clear_machine_settings();
  51. lv_draw_acceleration_settings();
  52. }
  53. break;
  54. case ID_MACHINE_ACCELERATION_ARROW:
  55. if (event == LV_EVENT_CLICKED) {
  56. }
  57. else if (event == LV_EVENT_RELEASED) {
  58. lv_clear_machine_settings();
  59. lv_draw_acceleration_settings();
  60. }
  61. break;
  62. case ID_MACHINE_FEEDRATE:
  63. if (event == LV_EVENT_CLICKED) {
  64. }
  65. else if (event == LV_EVENT_RELEASED) {
  66. lv_clear_machine_settings();
  67. lv_draw_max_feedrate_settings();
  68. }
  69. break;
  70. case ID_MACHINE_FEEDRATE_ARROW:
  71. if (event == LV_EVENT_CLICKED) {
  72. }
  73. else if (event == LV_EVENT_RELEASED) {
  74. lv_clear_machine_settings();
  75. lv_draw_max_feedrate_settings();
  76. }
  77. break;
  78. #if HAS_CLASSIC_JERK
  79. case ID_MACHINE_JERK:
  80. if (event == LV_EVENT_CLICKED) {
  81. }
  82. else if (event == LV_EVENT_RELEASED) {
  83. lv_clear_machine_settings();
  84. lv_draw_jerk_settings();
  85. }
  86. break;
  87. case ID_MACHINE_JERK_ARROW:
  88. if (event == LV_EVENT_CLICKED) {
  89. }
  90. else if (event == LV_EVENT_RELEASED) {
  91. lv_clear_machine_settings();
  92. lv_draw_jerk_settings();
  93. }
  94. break;
  95. #endif
  96. }
  97. }
  98. void lv_draw_machine_settings(void) {
  99. lv_obj_t *buttonBack, *label_Back;
  100. lv_obj_t *buttonAcceleration, *labelAcceleration, *buttonAccelerationNarrow;
  101. lv_obj_t *buttonMaxFeedrate, *labelMaxFeedrate, *buttonMaxFeedrateNarrow;
  102. #if HAS_CLASSIC_JERK
  103. lv_obj_t *buttonJerk, *labelJerk, *buttonJerkNarrow;
  104. #endif
  105. lv_obj_t * line1, * line2;
  106. #if HAS_CLASSIC_JERK
  107. lv_obj_t * line3;
  108. #endif
  109. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != MACHINE_SETTINGS_UI) {
  110. disp_state_stack._disp_index++;
  111. disp_state_stack._disp_state[disp_state_stack._disp_index] = MACHINE_SETTINGS_UI;
  112. }
  113. disp_state = MACHINE_SETTINGS_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.MachineConfigTitle);
  122. lv_refr_now(lv_refr_get_disp_refreshing());
  123. buttonAcceleration = lv_btn_create(scr, NULL); // Add a button the current screen
  124. lv_obj_set_pos(buttonAcceleration, PARA_UI_POS_X, PARA_UI_POS_Y); // Set its position
  125. lv_obj_set_size(buttonAcceleration, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); // Set its size
  126. //lv_obj_set_event_cb(buttonMachine, event_handler);
  127. lv_obj_set_event_cb_mks(buttonAcceleration, event_handler, ID_MACHINE_ACCELERATION, NULL, 0);
  128. lv_btn_set_style(buttonAcceleration, LV_BTN_STYLE_REL, &tft_style_label_rel); // Set the button's released style
  129. lv_btn_set_style(buttonAcceleration, LV_BTN_STYLE_PR, &tft_style_label_pre); // Set the button's pressed style
  130. lv_btn_set_layout(buttonAcceleration, LV_LAYOUT_OFF);
  131. labelAcceleration = lv_label_create(buttonAcceleration, NULL); // Add a label to the button
  132. buttonAccelerationNarrow = lv_imgbtn_create(scr, NULL);
  133. lv_obj_set_pos(buttonAccelerationNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y + PARA_UI_ARROW_V);
  134. lv_obj_set_event_cb_mks(buttonAccelerationNarrow, event_handler, ID_MACHINE_ACCELERATION_ARROW, NULL, 0);
  135. lv_imgbtn_set_src(buttonAccelerationNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin");
  136. lv_imgbtn_set_src(buttonAccelerationNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin");
  137. lv_imgbtn_set_style(buttonAccelerationNarrow, LV_BTN_STATE_PR, &tft_style_label_pre);
  138. lv_imgbtn_set_style(buttonAccelerationNarrow, LV_BTN_STATE_REL, &tft_style_label_rel);
  139. lv_btn_set_layout(buttonAccelerationNarrow, LV_LAYOUT_OFF);
  140. line1 = lv_line_create(lv_scr_act(), NULL);
  141. lv_ex_line(line1, line_points[0]);
  142. buttonMaxFeedrate = lv_btn_create(scr, NULL); // Add a button the current screen
  143. lv_obj_set_pos(buttonMaxFeedrate, PARA_UI_POS_X, PARA_UI_POS_Y * 2); // Set its position
  144. lv_obj_set_size(buttonMaxFeedrate, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); // Set its size
  145. //lv_obj_set_event_cb(buttonMachine, event_handler);
  146. lv_obj_set_event_cb_mks(buttonMaxFeedrate, event_handler, ID_MACHINE_FEEDRATE, NULL, 0);
  147. lv_btn_set_style(buttonMaxFeedrate, LV_BTN_STYLE_REL, &tft_style_label_rel); // Set the button's released style
  148. lv_btn_set_style(buttonMaxFeedrate, LV_BTN_STYLE_PR, &tft_style_label_pre); // Set the button's pressed style
  149. lv_btn_set_layout(buttonMaxFeedrate, LV_LAYOUT_OFF);
  150. labelMaxFeedrate = lv_label_create(buttonMaxFeedrate, NULL); // Add a label to the button
  151. buttonMaxFeedrateNarrow = lv_imgbtn_create(scr, NULL);
  152. lv_obj_set_pos(buttonMaxFeedrateNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 2 + PARA_UI_ARROW_V);
  153. lv_obj_set_event_cb_mks(buttonMaxFeedrateNarrow, event_handler, ID_MACHINE_FEEDRATE_ARROW, NULL, 0);
  154. lv_imgbtn_set_src(buttonMaxFeedrateNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin");
  155. lv_imgbtn_set_src(buttonMaxFeedrateNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin");
  156. lv_imgbtn_set_style(buttonMaxFeedrateNarrow, LV_BTN_STATE_PR, &tft_style_label_pre);
  157. lv_imgbtn_set_style(buttonMaxFeedrateNarrow, LV_BTN_STATE_REL, &tft_style_label_rel);
  158. lv_btn_set_layout(buttonMaxFeedrateNarrow, LV_LAYOUT_OFF);
  159. line2 = lv_line_create(lv_scr_act(), NULL);
  160. lv_ex_line(line2, line_points[1]);
  161. #if HAS_CLASSIC_JERK
  162. buttonJerk = lv_btn_create(scr, NULL); // Add a button the current screen
  163. lv_obj_set_pos(buttonJerk, PARA_UI_POS_X, PARA_UI_POS_Y * 3); // Set its position
  164. lv_obj_set_size(buttonJerk, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); // Set its size
  165. //lv_obj_set_event_cb(buttonMotor, event_handler);
  166. lv_obj_set_event_cb_mks(buttonJerk, event_handler, ID_MACHINE_JERK, NULL, 0);
  167. lv_btn_set_style(buttonJerk, LV_BTN_STYLE_REL, &tft_style_label_rel); // Set the button's released style
  168. lv_btn_set_style(buttonJerk, LV_BTN_STYLE_PR, &tft_style_label_pre); // Set the button's pressed style
  169. lv_btn_set_layout(buttonJerk, LV_LAYOUT_OFF);
  170. labelJerk = lv_label_create(buttonJerk, NULL); // Add a label to the button
  171. buttonJerkNarrow = lv_imgbtn_create(scr, NULL);
  172. lv_obj_set_pos(buttonJerkNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 3 + PARA_UI_ARROW_V);
  173. lv_obj_set_event_cb_mks(buttonJerkNarrow, event_handler, ID_MACHINE_JERK_ARROW, NULL, 0);
  174. lv_imgbtn_set_src(buttonJerkNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin");
  175. lv_imgbtn_set_src(buttonJerkNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin");
  176. lv_imgbtn_set_style(buttonJerkNarrow, LV_BTN_STATE_PR, &tft_style_label_pre);
  177. lv_imgbtn_set_style(buttonJerkNarrow, LV_BTN_STATE_REL, &tft_style_label_rel);
  178. lv_btn_set_layout(buttonJerkNarrow, LV_LAYOUT_OFF);
  179. line3 = lv_line_create(lv_scr_act(), NULL);
  180. lv_ex_line(line3, line_points[2]);
  181. #endif
  182. buttonBack = lv_imgbtn_create(scr, NULL);
  183. lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_MACHINE_RETURN, NULL, 0);
  184. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin");
  185. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin");
  186. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre);
  187. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel);
  188. lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y);
  189. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  190. label_Back = lv_label_create(buttonBack, NULL);
  191. if (gCfgItems.multiple_language != 0) {
  192. lv_label_set_text(label_Back, common_menu.text_back);
  193. lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0);
  194. lv_label_set_text(labelAcceleration, machine_menu.AccelerationConf);
  195. lv_obj_align(labelAcceleration, buttonAcceleration, LV_ALIGN_IN_LEFT_MID, 0, 0);
  196. lv_label_set_text(labelMaxFeedrate, machine_menu.MaxFeedRateConf);
  197. lv_obj_align(labelMaxFeedrate, buttonMaxFeedrate, LV_ALIGN_IN_LEFT_MID, 0, 0);
  198. #if HAS_CLASSIC_JERK
  199. lv_label_set_text(labelJerk, machine_menu.JerkConf);
  200. lv_obj_align(labelJerk, buttonJerk, LV_ALIGN_IN_LEFT_MID, 0, 0);
  201. #endif
  202. }
  203. #if HAS_ROTARY_ENCODER
  204. if (gCfgItems.encoder_enable) {
  205. lv_group_add_obj(g, buttonAcceleration);
  206. lv_group_add_obj(g, buttonMaxFeedrate);
  207. #if HAS_CLASSIC_JERK
  208. lv_group_add_obj(g, buttonJerk);
  209. #endif
  210. lv_group_add_obj(g, buttonBack);
  211. }
  212. #endif
  213. }
  214. void lv_clear_machine_settings() {
  215. #if HAS_ROTARY_ENCODER
  216. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  217. #endif
  218. lv_obj_del(scr);
  219. }
  220. #endif // HAS_TFT_LVGL_UI