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.

endstops.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * endstops.h - manages endstops
  24. */
  25. #ifndef __ENDSTOPS_H__
  26. #define __ENDSTOPS_H__
  27. #include "../inc/MarlinConfig.h"
  28. #include <stdint.h>
  29. enum EndstopEnum {
  30. X_MIN,
  31. Y_MIN,
  32. Z_MIN,
  33. Z_MIN_PROBE,
  34. X_MAX,
  35. Y_MAX,
  36. Z_MAX,
  37. X2_MIN,
  38. X2_MAX,
  39. Y2_MIN,
  40. Y2_MAX,
  41. Z2_MIN,
  42. Z2_MAX
  43. };
  44. class Endstops {
  45. public:
  46. static bool enabled, enabled_globally;
  47. static volatile char endstop_hit_bits; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT value
  48. #if ENABLED(X_DUAL_ENDSTOPS)
  49. static float x_endstop_adj;
  50. #endif
  51. #if ENABLED(Y_DUAL_ENDSTOPS)
  52. static float y_endstop_adj;
  53. #endif
  54. #if ENABLED(Z_DUAL_ENDSTOPS)
  55. static float z_endstop_adj;
  56. #endif
  57. #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
  58. typedef uint16_t esbits_t;
  59. #else
  60. typedef byte esbits_t;
  61. #endif
  62. static esbits_t current_endstop_bits, old_endstop_bits;
  63. Endstops() {
  64. enable_globally(
  65. #if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
  66. true
  67. #else
  68. false
  69. #endif
  70. );
  71. };
  72. /**
  73. * Initialize the endstop pins
  74. */
  75. static void init();
  76. /**
  77. * Update the endstops bits from the pins
  78. */
  79. static void update();
  80. /**
  81. * Print an error message reporting the position when the endstops were last hit.
  82. */
  83. static void report_state(); //call from somewhere to create an serial error message with the locations the endstops where hit, in case they were triggered
  84. /**
  85. * Report endstop positions in response to M119
  86. */
  87. static void M119();
  88. // Enable / disable endstop checking globally
  89. static void enable_globally(bool onoff=true) { enabled_globally = enabled = onoff; }
  90. // Enable / disable endstop checking
  91. static void enable(bool onoff=true) { enabled = onoff; }
  92. // Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
  93. static void not_homing() { enabled = enabled_globally; }
  94. // Clear endstops (i.e., they were hit intentionally) to suppress the report
  95. static void hit_on_purpose() { endstop_hit_bits = 0; }
  96. // Enable / disable endstop z-probe checking
  97. #if HAS_BED_PROBE
  98. static volatile bool z_probe_enabled;
  99. static void enable_z_probe(bool onoff=true) { z_probe_enabled = onoff; }
  100. #endif
  101. // Debugging of endstops
  102. #if ENABLED(PINS_DEBUGGING)
  103. static bool monitor_flag;
  104. static void monitor();
  105. FORCE_INLINE static void run_monitor() {
  106. if (!monitor_flag) return;
  107. static uint8_t monitor_count = 16; // offset this check from the others
  108. monitor_count += _BV(1); // 15 Hz
  109. monitor_count &= 0x7F;
  110. if (!monitor_count) monitor(); // report changes in endstop status
  111. }
  112. #endif
  113. private:
  114. #if ENABLED(X_DUAL_ENDSTOPS)
  115. static void test_dual_x_endstops(const EndstopEnum es1, const EndstopEnum es2);
  116. #endif
  117. #if ENABLED(Y_DUAL_ENDSTOPS)
  118. static void test_dual_y_endstops(const EndstopEnum es1, const EndstopEnum es2);
  119. #endif
  120. #if ENABLED(Z_DUAL_ENDSTOPS)
  121. static void test_dual_z_endstops(const EndstopEnum es1, const EndstopEnum es2);
  122. #endif
  123. };
  124. extern Endstops endstops;
  125. #if HAS_BED_PROBE
  126. #define ENDSTOPS_ENABLED (endstops.enabled || endstops.z_probe_enabled)
  127. #else
  128. #define ENDSTOPS_ENABLED endstops.enabled
  129. #endif
  130. #endif // __ENDSTOPS_H__