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_touch_calibration.cpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 BOTH(HAS_TFT_LVGL_UI, TOUCH_SCREEN_CALIBRATION)
  24. #include "draw_ui.h"
  25. #include "draw_touch_calibration.h"
  26. #include <lv_conf.h>
  27. #include "../../../inc/MarlinConfig.h"
  28. #include "../../tft_io/touch_calibration.h"
  29. #include "SPI_TFT.h"
  30. static lv_obj_t *scr;
  31. static lv_obj_t *status_label;
  32. #if ENABLED(MKS_TEST)
  33. extern uint8_t current_disp_ui;
  34. #endif
  35. static void event_handler(lv_obj_t *obj, lv_event_t event);
  36. enum {
  37. ID_TC_RETURN = 1
  38. };
  39. static void drawCross(uint16_t x, uint16_t y, uint16_t color) {
  40. SPI_TFT.tftio.set_window(x - 15, y, x + 15, y);
  41. SPI_TFT.tftio.WriteMultiple(color, 31);
  42. SPI_TFT.tftio.set_window(x, y - 15, x, y + 15);
  43. SPI_TFT.tftio.WriteMultiple(color, 31);
  44. }
  45. void lv_update_touch_calibration_screen() {
  46. uint16_t x, y;
  47. calibrationState calibration_stage = touch_calibration.get_calibration_state();
  48. if (calibration_stage == CALIBRATION_NONE) {
  49. // start and clear screen
  50. calibration_stage = touch_calibration.calibration_start();
  51. }
  52. else {
  53. // clear last cross
  54. x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x;
  55. y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y;
  56. drawCross(x, y, LV_COLOR_BACKGROUND.full);
  57. }
  58. const char *str = nullptr;
  59. if (calibration_stage < CALIBRATION_SUCCESS) {
  60. // handle current state
  61. switch (calibration_stage) {
  62. case CALIBRATION_TOP_LEFT: str = GET_TEXT(MSG_TOP_LEFT); break;
  63. case CALIBRATION_BOTTOM_LEFT: str = GET_TEXT(MSG_BOTTOM_LEFT); break;
  64. case CALIBRATION_TOP_RIGHT: str = GET_TEXT(MSG_TOP_RIGHT); break;
  65. case CALIBRATION_BOTTOM_RIGHT: str = GET_TEXT(MSG_BOTTOM_RIGHT); break;
  66. default: break;
  67. }
  68. x = touch_calibration.calibration_points[calibration_stage].x;
  69. y = touch_calibration.calibration_points[calibration_stage].y;
  70. drawCross(x, y, LV_COLOR_WHITE.full);
  71. }
  72. else {
  73. // end calibration
  74. str = calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED);
  75. touch_calibration.calibration_end();
  76. lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_TC_RETURN);
  77. }
  78. // draw current message
  79. lv_label_set_text(status_label, str);
  80. lv_obj_align(status_label, nullptr, LV_ALIGN_CENTER, 0, 0);
  81. }
  82. static void event_handler(lv_obj_t *obj, lv_event_t event) {
  83. if (event != LV_EVENT_RELEASED) return;
  84. switch (obj->mks_obj_id) {
  85. case ID_TC_RETURN:
  86. TERN_(MKS_TEST, current_disp_ui = 1);
  87. goto_previous_ui();
  88. break;
  89. }
  90. }
  91. void lv_draw_touch_calibration_screen() {
  92. scr = lv_screen_create(TOUCH_CALIBRATION_UI, "");
  93. status_label = lv_label_create(scr, "");
  94. lv_obj_align(status_label, nullptr, LV_ALIGN_CENTER, 0, 0);
  95. lv_refr_now(lv_refr_get_disp_refreshing());
  96. lv_update_touch_calibration_screen();
  97. }
  98. void lv_clear_touch_calibration_screen() {
  99. lv_obj_del(scr);
  100. }
  101. #endif // HAS_TFT_LVGL_UI && TOUCH_SCREEN_CALIBRATION