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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 "enum.h"
  28. #include "MarlinConfig.h"
  29. class Endstops {
  30. public:
  31. static bool enabled, enabled_globally;
  32. static volatile char endstop_hit_bits; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT value
  33. #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
  34. static uint16_t
  35. #else
  36. static byte
  37. #endif
  38. current_endstop_bits, old_endstop_bits;
  39. Endstops() {
  40. enable_globally(
  41. #if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
  42. true
  43. #else
  44. false
  45. #endif
  46. );
  47. };
  48. /**
  49. * Initialize the endstop pins
  50. */
  51. void init();
  52. /**
  53. * Update the endstops bits from the pins
  54. */
  55. static void update();
  56. /**
  57. * Print an error message reporting the position when the endstops were last hit.
  58. */
  59. 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
  60. /**
  61. * Report endstop positions in response to M119
  62. */
  63. static void M119();
  64. // Enable / disable endstop checking globally
  65. static void enable_globally(bool onoff=true) { enabled_globally = enabled = onoff; }
  66. // Enable / disable endstop checking
  67. static void enable(bool onoff=true) { enabled = onoff; }
  68. // Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
  69. static void not_homing() { enabled = enabled_globally; }
  70. // Clear endstops (i.e., they were hit intentionally) to suppress the report
  71. static void hit_on_purpose() { endstop_hit_bits = 0; }
  72. // Enable / disable endstop z-probe checking
  73. #if HAS_BED_PROBE
  74. static volatile bool z_probe_enabled;
  75. static void enable_z_probe(bool onoff=true) { z_probe_enabled = onoff; }
  76. #endif
  77. private:
  78. #if ENABLED(X_DUAL_ENDSTOPS)
  79. static void test_dual_x_endstops(const EndstopEnum es1, const EndstopEnum es2);
  80. #endif
  81. #if ENABLED(Y_DUAL_ENDSTOPS)
  82. static void test_dual_y_endstops(const EndstopEnum es1, const EndstopEnum es2);
  83. #endif
  84. #if ENABLED(Z_DUAL_ENDSTOPS)
  85. static void test_dual_z_endstops(const EndstopEnum es1, const EndstopEnum es2);
  86. #endif
  87. };
  88. extern Endstops endstops;
  89. #if HAS_BED_PROBE
  90. #define ENDSTOPS_ENABLED (endstops.enabled || endstops.z_probe_enabled)
  91. #else
  92. #define ENDSTOPS_ENABLED endstops.enabled
  93. #endif
  94. #endif // ENDSTOPS_H