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.

bltouch.cpp 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2019 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. #include "../inc/MarlinConfig.h"
  23. #if ENABLED(BLTOUCH)
  24. #include "bltouch.h"
  25. BLTouch bltouch;
  26. #include "../module/servo.h"
  27. void stop();
  28. #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
  29. #include "../core/debug_out.h"
  30. void BLTouch::command(const BLTCommand cmd) {
  31. MOVE_SERVO(Z_PROBE_SERVO_NR, cmd);
  32. safe_delay(BLTOUCH_DELAY);
  33. }
  34. void BLTouch::init() {
  35. reset(); // Clear all BLTouch error conditions
  36. stow();
  37. }
  38. bool BLTouch::triggered() {
  39. return (
  40. #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
  41. READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING
  42. #else
  43. READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING
  44. #endif
  45. );
  46. }
  47. bool BLTouch::set_deployed(const bool in_deploy) {
  48. if (in_deploy && triggered()) { // If BLTouch says it's triggered
  49. reset(); // try to reset it.
  50. _deploy(); _stow(); // Deploy and stow to clear the "triggered" condition.
  51. safe_delay(1500); // Wait for internal self-test to complete.
  52. // (Measured completion time was 0.65 seconds
  53. // after reset, deploy, and stow sequence)
  54. if (triggered()) { // If it still claims to be triggered...
  55. SERIAL_ERROR_MSG(MSG_STOP_BLTOUCH);
  56. stop(); // punt!
  57. return true;
  58. }
  59. }
  60. #if ENABLED(BLTOUCH_V3)
  61. #if ENABLED(BLTOUCH_FORCE_5V_MODE)
  62. set_5V_mode(); // Assume 5V DC logic level if endstop pullup resistors are enabled
  63. #else
  64. set_OD_mode();
  65. #endif
  66. #endif
  67. if (in_deploy) {
  68. _deploy();
  69. #if ENABLED(BLTOUCH_V3)
  70. set_SW_mode(); // Ensure Switch mode is activated for BLTouch V3. Ignored on V2.
  71. #endif
  72. }
  73. else _stow();
  74. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("bltouch.set_deployed(", in_deploy, ")");
  75. return false;
  76. }
  77. #endif // BLTOUCH