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.

touch.h 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. #pragma once
  23. #include "../../inc/MarlinConfigPre.h"
  24. #include "tft_color.h"
  25. #include "tft_image.h"
  26. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  27. #include "../tft_io/touch_calibration.h"
  28. #endif
  29. #if ENABLED(TFT_TOUCH_DEVICE_GT911)
  30. #include HAL_PATH(../../HAL, tft/gt911.h)
  31. #define TOUCH_DRIVER_CLASS GT911
  32. #elif ENABLED(TFT_TOUCH_DEVICE_XPT2046)
  33. #include HAL_PATH(../../HAL, tft/xpt2046.h)
  34. #define TOUCH_DRIVER_CLASS XPT2046
  35. #else
  36. #error "Unknown Touch Screen Type."
  37. #endif
  38. // Menu Navigation
  39. extern int8_t encoderTopLine, encoderLine, screen_items;
  40. enum TouchControlType : uint16_t {
  41. NONE = 0x0000,
  42. CALIBRATE,
  43. MENU_SCREEN,
  44. MENU_ITEM,
  45. BACK,
  46. PAGE_UP,
  47. PAGE_DOWN,
  48. CLICK,
  49. MENU_CLICK,
  50. RESUME_CONTINUE,
  51. SLIDER,
  52. INCREASE,
  53. DECREASE,
  54. CANCEL,
  55. CONFIRM,
  56. HEATER,
  57. FAN,
  58. FEEDRATE,
  59. FLOWRATE,
  60. UBL,
  61. MOVE_AXIS,
  62. BUTTON,
  63. };
  64. typedef void (*screenFunc_t)();
  65. void add_control(uint16_t x, uint16_t y, TouchControlType control_type, intptr_t data, MarlinImage image, bool is_enabled = true, uint16_t color_enabled = COLOR_CONTROL_ENABLED, uint16_t color_disabled = COLOR_CONTROL_DISABLED);
  66. inline void add_control(uint16_t x, uint16_t y, TouchControlType control_type, MarlinImage image, bool is_enabled = true, uint16_t color_enabled = COLOR_CONTROL_ENABLED, uint16_t color_disabled = COLOR_CONTROL_DISABLED) { add_control(x, y, control_type, 0, image, is_enabled, color_enabled, color_disabled); }
  67. inline void add_control(uint16_t x, uint16_t y, screenFunc_t screen, MarlinImage image, bool is_enabled = true, uint16_t color_enabled = COLOR_CONTROL_ENABLED, uint16_t color_disabled = COLOR_CONTROL_DISABLED) { add_control(x, y, MENU_SCREEN, (intptr_t)screen, image, is_enabled, color_enabled, color_disabled); }
  68. typedef struct __attribute__((__packed__)) {
  69. TouchControlType type;
  70. uint16_t x;
  71. uint16_t y;
  72. uint16_t width;
  73. uint16_t height;
  74. intptr_t data;
  75. } touch_control_t;
  76. #define MAX_CONTROLS 16
  77. #define MINIMUM_HOLD_TIME 15
  78. #define TOUCH_REPEAT_DELAY 75
  79. #define MIN_REPEAT_DELAY 25
  80. #define UBL_REPEAT_DELAY 125
  81. #define FREE_MOVE_RANGE 32
  82. #define TSLP_PREINIT 0
  83. #define TSLP_SLEEPING 1
  84. class Touch {
  85. private:
  86. static TOUCH_DRIVER_CLASS io;
  87. static int16_t x, y;
  88. static bool enabled;
  89. static touch_control_t controls[MAX_CONTROLS];
  90. static touch_control_t *current_control;
  91. static uint16_t controls_count;
  92. static millis_t last_touch_ms, time_to_hold, repeat_delay, touch_time;
  93. static TouchControlType touch_control_type;
  94. static bool get_point(int16_t *x, int16_t *y);
  95. static void touch(touch_control_t *control);
  96. static void hold(touch_control_t *control, millis_t delay = 0);
  97. public:
  98. static void init();
  99. static void reset() { controls_count = 0; touch_time = 0; current_control = nullptr; }
  100. static void clear() { controls_count = 0; }
  101. static void idle();
  102. static bool is_clicked() {
  103. if (touch_control_type == CLICK) {
  104. touch_control_type = NONE;
  105. return true;
  106. }
  107. return false;
  108. }
  109. static void disable() { enabled = false; }
  110. static void enable() { enabled = true; }
  111. #if HAS_TOUCH_SLEEP
  112. static millis_t next_sleep_ms;
  113. static bool isSleeping() { return next_sleep_ms == TSLP_SLEEPING; }
  114. static void sleepTimeout();
  115. static void wakeUp();
  116. #endif
  117. static void add_control(TouchControlType type, uint16_t x, uint16_t y, uint16_t width, uint16_t height, intptr_t data = 0);
  118. };
  119. extern Touch touch;