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_encoder_settings.cpp 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. #include "../../../../module/planner.h"
  28. #include "../../../../module/stepper/indirection.h"
  29. #include "../../../../feature/tmc_util.h"
  30. #include "../../../../gcode/gcode.h"
  31. #include "../../../../module/planner.h"
  32. #if BUTTONS_EXIST(EN1, EN2)
  33. extern lv_group_t * g;
  34. static lv_obj_t * scr;
  35. static lv_obj_t * buttonEncoderState = NULL;
  36. static lv_obj_t *labelEncoderState = NULL;
  37. #define ID_ENCODER_RETURN 1
  38. #define ID_ENCODER_STATE 2
  39. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  40. switch (obj->mks_obj_id) {
  41. case ID_ENCODER_RETURN:
  42. if (event == LV_EVENT_CLICKED) {
  43. }
  44. else if (event == LV_EVENT_RELEASED) {
  45. lv_clear_encoder_settings();
  46. draw_return_ui();
  47. }
  48. break;
  49. case ID_ENCODER_STATE:
  50. if (event == LV_EVENT_CLICKED) {
  51. }
  52. else if (event == LV_EVENT_RELEASED) {
  53. if (gCfgItems.encoder_enable) {
  54. gCfgItems.encoder_enable = false;
  55. lv_imgbtn_set_src(buttonEncoderState, LV_BTN_STATE_REL, "F:/bmp_disable.bin");
  56. lv_imgbtn_set_src(buttonEncoderState, LV_BTN_STATE_PR, "F:/bmp_disable.bin");
  57. lv_label_set_text(labelEncoderState, machine_menu.disable);
  58. update_spi_flash();
  59. }
  60. else {
  61. gCfgItems.encoder_enable = true;
  62. lv_imgbtn_set_src(buttonEncoderState, LV_BTN_STATE_REL, "F:/bmp_enable.bin");
  63. lv_imgbtn_set_src(buttonEncoderState, LV_BTN_STATE_PR, "F:/bmp_enable.bin");
  64. lv_label_set_text(labelEncoderState, machine_menu.enable);
  65. update_spi_flash();
  66. }
  67. }
  68. break;
  69. }
  70. }
  71. void lv_draw_encoder_settings(void) {
  72. lv_obj_t *buttonBack = NULL, *label_Back = NULL;
  73. lv_obj_t *labelEncoderTips = NULL;
  74. lv_obj_t * line1 = NULL;
  75. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != ENCODER_SETTINGS_UI) {
  76. disp_state_stack._disp_index++;
  77. disp_state_stack._disp_state[disp_state_stack._disp_index] = ENCODER_SETTINGS_UI;
  78. }
  79. disp_state = ENCODER_SETTINGS_UI;
  80. scr = lv_obj_create(NULL, NULL);
  81. lv_obj_set_style(scr, &tft_style_scr);
  82. lv_scr_load(scr);
  83. lv_obj_clean(scr);
  84. lv_obj_t * title = lv_label_create(scr, NULL);
  85. lv_obj_set_style(title, &tft_style_label_rel);
  86. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  87. lv_label_set_text(title, machine_menu.EncoderConfTitle);
  88. lv_refr_now(lv_refr_get_disp_refreshing());
  89. labelEncoderTips = lv_label_create(scr, NULL);
  90. lv_obj_set_style(labelEncoderTips, &tft_style_label_rel);
  91. lv_obj_set_pos(labelEncoderTips, PARA_UI_POS_X, PARA_UI_POS_Y + 10);
  92. lv_label_set_text(labelEncoderTips, machine_menu.EncoderConfText);
  93. buttonEncoderState = lv_imgbtn_create(scr, NULL);
  94. lv_obj_set_pos(buttonEncoderState, PARA_UI_STATE_POS_X, PARA_UI_POS_Y + PARA_UI_STATE_V);
  95. if (gCfgItems.encoder_enable) {
  96. lv_imgbtn_set_src(buttonEncoderState, LV_BTN_STATE_REL, "F:/bmp_enable.bin");
  97. lv_imgbtn_set_src(buttonEncoderState, LV_BTN_STATE_PR, "F:/bmp_enable.bin");
  98. }
  99. else {
  100. lv_imgbtn_set_src(buttonEncoderState, LV_BTN_STATE_REL, "F:/bmp_disable.bin");
  101. lv_imgbtn_set_src(buttonEncoderState, LV_BTN_STATE_PR, "F:/bmp_disable.bin");
  102. }
  103. lv_obj_set_event_cb_mks(buttonEncoderState, event_handler, ID_ENCODER_STATE, NULL, 0);
  104. lv_imgbtn_set_style(buttonEncoderState, LV_BTN_STATE_PR, &tft_style_label_pre);
  105. lv_imgbtn_set_style(buttonEncoderState, LV_BTN_STATE_REL, &tft_style_label_rel);
  106. lv_btn_set_layout(buttonEncoderState, LV_LAYOUT_OFF);
  107. labelEncoderState = lv_label_create(buttonEncoderState, NULL);
  108. line1 = lv_line_create(scr, NULL);
  109. lv_ex_line(line1, line_points[0]);
  110. buttonBack = lv_imgbtn_create(scr, NULL);
  111. lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_ENCODER_RETURN, NULL, 0);
  112. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin");
  113. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin");
  114. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre);
  115. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel);
  116. lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y);
  117. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  118. label_Back = lv_label_create(buttonBack, NULL);
  119. if (gCfgItems.encoder_enable) {
  120. lv_label_set_text(labelEncoderState, machine_menu.enable);
  121. lv_obj_align(labelEncoderState, buttonEncoderState, LV_ALIGN_CENTER, 0, 0);
  122. }
  123. else {
  124. lv_label_set_text(labelEncoderState, machine_menu.disable);
  125. lv_obj_align(labelEncoderState, buttonEncoderState, LV_ALIGN_CENTER, 0, 0);
  126. }
  127. lv_label_set_text(label_Back, common_menu.text_back);
  128. lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0);
  129. #if HAS_ROTARY_ENCODER
  130. if (gCfgItems.encoder_enable) {
  131. lv_group_add_obj(g, buttonEncoderState);
  132. lv_group_add_obj(g, buttonBack);
  133. }
  134. #endif
  135. }
  136. void lv_clear_encoder_settings() {
  137. #if HAS_ROTARY_ENCODER
  138. lv_group_remove_all_objs(g);
  139. #endif
  140. lv_obj_del(scr);
  141. }
  142. #endif // BUTTONS_EXIST(EN1, EN2)
  143. #endif // HAS_TFT_LVGL_UI