My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

touch_calibration.h 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #pragma once
  20. #include "../../inc/MarlinConfigPre.h"
  21. #include "tft_io.h"
  22. #ifndef TOUCH_SCREEN_CALIBRATION_PRECISION
  23. #define TOUCH_SCREEN_CALIBRATION_PRECISION 80
  24. #endif
  25. #ifndef TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS
  26. #define TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS 2500
  27. #endif
  28. typedef struct __attribute__((__packed__)) {
  29. int32_t x, y;
  30. int16_t offset_x, offset_y;
  31. uint8_t orientation;
  32. } touch_calibration_t;
  33. typedef struct __attribute__((__packed__)) {
  34. uint16_t x, y;
  35. int16_t raw_x, raw_y;
  36. } touch_calibration_point_t;
  37. enum calibrationState : uint8_t {
  38. CALIBRATION_TOP_LEFT = 0x00,
  39. CALIBRATION_BOTTOM_LEFT,
  40. CALIBRATION_TOP_RIGHT,
  41. CALIBRATION_BOTTOM_RIGHT,
  42. CALIBRATION_SUCCESS,
  43. CALIBRATION_FAIL,
  44. CALIBRATION_NONE,
  45. };
  46. class TouchCalibration {
  47. public:
  48. static calibrationState calibration_state;
  49. static touch_calibration_point_t calibration_points[4];
  50. static bool validate_precision(int32_t a, int32_t b) { return (a > b ? (100 * b) / a : (100 * a) / b) > TOUCH_SCREEN_CALIBRATION_PRECISION; }
  51. static bool validate_precision_x(uint8_t a, uint8_t b) { return validate_precision(calibration_points[a].raw_x, calibration_points[b].raw_x); }
  52. static bool validate_precision_y(uint8_t a, uint8_t b) { return validate_precision(calibration_points[a].raw_y, calibration_points[b].raw_y); }
  53. static void validate_calibration();
  54. static touch_calibration_t calibration;
  55. static uint8_t failed_count;
  56. static void calibration_reset() { calibration = { TOUCH_CALIBRATION_X, TOUCH_CALIBRATION_Y, TOUCH_OFFSET_X, TOUCH_OFFSET_Y, TOUCH_ORIENTATION }; }
  57. static bool need_calibration() { return !calibration.offset_x && !calibration.offset_y && !calibration.x && !calibration.y; }
  58. static calibrationState calibration_start() {
  59. calibration = { 0, 0, 0, 0, TOUCH_ORIENTATION_NONE };
  60. calibration_state = CALIBRATION_TOP_LEFT;
  61. calibration_points[CALIBRATION_TOP_LEFT].x = 30;
  62. calibration_points[CALIBRATION_TOP_LEFT].y = 30;
  63. calibration_points[CALIBRATION_BOTTOM_LEFT].x = 30;
  64. calibration_points[CALIBRATION_BOTTOM_LEFT].y = TFT_HEIGHT - 31;
  65. calibration_points[CALIBRATION_TOP_RIGHT].x = TFT_WIDTH - 31;
  66. calibration_points[CALIBRATION_TOP_RIGHT].y = 30;
  67. calibration_points[CALIBRATION_BOTTOM_RIGHT].x = TFT_WIDTH - 31;
  68. calibration_points[CALIBRATION_BOTTOM_RIGHT].y = TFT_HEIGHT - 31;
  69. failed_count = 0;
  70. return calibration_state;
  71. }
  72. static void calibration_end() { calibration_state = CALIBRATION_NONE; }
  73. static calibrationState get_calibration_state() { return calibration_state; }
  74. static bool calibration_loaded() {
  75. if (need_calibration()) calibration_reset();
  76. return !need_calibration();
  77. }
  78. static bool handleTouch(uint16_t x, uint16_t y);
  79. };
  80. extern TouchCalibration touch_calibration;