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 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. Z2_MIN,
  38. Z2_MAX
  39. };
  40. class Endstops {
  41. public:
  42. static bool enabled, enabled_globally;
  43. static volatile char endstop_hit_bits; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT value
  44. #if ENABLED(Z_DUAL_ENDSTOPS)
  45. static float z_endstop_adj;
  46. typedef uint16_t esbits_t;
  47. #else
  48. typedef byte esbits_t;
  49. #endif
  50. static esbits_t current_endstop_bits, old_endstop_bits;
  51. Endstops() {};
  52. /**
  53. * Initialize the endstop pins
  54. */
  55. static void init();
  56. /**
  57. * Update the endstops bits from the pins
  58. */
  59. static void update();
  60. /**
  61. * Print an error message reporting the position when the endstops were last hit.
  62. */
  63. 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
  64. /**
  65. * Report endstop positions in response to M119
  66. */
  67. static void M119();
  68. // Enable / disable endstop checking globally
  69. static void enable_globally(bool onoff=true) { enabled_globally = enabled = onoff; }
  70. // Enable / disable endstop checking
  71. static void enable(bool onoff=true) { enabled = onoff; }
  72. // Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
  73. static void not_homing() { enabled = enabled_globally; }
  74. // Clear endstops (i.e., they were hit intentionally) to suppress the report
  75. static void hit_on_purpose() { endstop_hit_bits = 0; }
  76. // Enable / disable endstop z-probe checking
  77. #if HAS_BED_PROBE
  78. static volatile bool z_probe_enabled;
  79. static void enable_z_probe(bool onoff=true) { z_probe_enabled = onoff; }
  80. #endif
  81. // Debugging of endstops
  82. #if ENABLED(PINS_DEBUGGING)
  83. static bool monitor_flag;
  84. static void monitor();
  85. FORCE_INLINE static void run_monitor() {
  86. if (!monitor_flag) return;
  87. static uint8_t monitor_count = 16; // offset this check from the others
  88. monitor_count += _BV(1); // 15 Hz
  89. monitor_count &= 0x7F;
  90. if (!monitor_count) monitor(); // report changes in endstop status
  91. }
  92. #endif
  93. private:
  94. #if ENABLED(Z_DUAL_ENDSTOPS)
  95. static void test_dual_z_endstops(const EndstopEnum es1, const EndstopEnum es2);
  96. #endif
  97. };
  98. extern Endstops endstops;
  99. #if HAS_BED_PROBE
  100. #define ENDSTOPS_ENABLED (endstops.enabled || endstops.z_probe_enabled)
  101. #else
  102. #define ENDSTOPS_ENABLED endstops.enabled
  103. #endif
  104. #endif // __ENDSTOPS_H__