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.

solenoid.cpp 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../inc/MarlinConfig.h"
  23. #if EITHER(EXT_SOLENOID, MANUAL_SOLENOID_CONTROL)
  24. #include "solenoid.h"
  25. #include "../module/motion.h" // for active_extruder
  26. // PARKING_EXTRUDER options alter the default behavior of solenoids, this ensures compliance of M380-381
  27. #if ENABLED(PARKING_EXTRUDER)
  28. #include "../module/tool_change.h"
  29. #define SOLENOID_MAGNETIZED_STATE (TERN_(PARKING_EXTRUDER_SOLENOIDS_INVERT,!)PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE)
  30. #else
  31. #define SOLENOID_MAGNETIZED_STATE HIGH
  32. #endif
  33. #define HAS_SOLENOID(N) (HAS_SOLENOID_##N && TERN(MANUAL_SOLENOID_CONTROL, true, EXTRUDERS > N))
  34. // Used primarily with MANUAL_SOLENOID_CONTROL
  35. static void set_solenoid(const uint8_t num, const bool active) {
  36. const uint8_t value = active ? SOLENOID_MAGNETIZED_STATE : !SOLENOID_MAGNETIZED_STATE;
  37. switch (num) {
  38. case 0:
  39. OUT_WRITE(SOL0_PIN, value);
  40. TERN_(PARKING_EXTRUDER, if (!active && active_extruder == 0) parking_extruder_set_parked()); // If active extruder's solenoid is disabled, carriage is considered parked
  41. break;
  42. #if HAS_SOLENOID(1)
  43. case 1:
  44. OUT_WRITE(SOL1_PIN, value);
  45. TERN_(PARKING_EXTRUDER, if (!active && active_extruder == 1) parking_extruder_set_parked()); // If active extruder's solenoid is disabled, carriage is considered parked
  46. break;
  47. #endif
  48. #if HAS_SOLENOID(2)
  49. case 2:
  50. OUT_WRITE(SOL2_PIN, value);
  51. break;
  52. #endif
  53. #if HAS_SOLENOID(3)
  54. case 3:
  55. OUT_WRITE(SOL3_PIN, value);
  56. break;
  57. #endif
  58. #if HAS_SOLENOID(4)
  59. case 4:
  60. OUT_WRITE(SOL4_PIN, value);
  61. break;
  62. #endif
  63. #if HAS_SOLENOID(5)
  64. case 5:
  65. OUT_WRITE(SOL5_PIN, value);
  66. break;
  67. #endif
  68. default:
  69. SERIAL_ECHO_MSG(STR_INVALID_SOLENOID);
  70. break;
  71. }
  72. }
  73. void enable_solenoid(const uint8_t num) { set_solenoid(num, true); }
  74. void disable_solenoid(const uint8_t num) { set_solenoid(num, false); }
  75. void enable_solenoid_on_active_extruder() { enable_solenoid(active_extruder); }
  76. void disable_all_solenoids() {
  77. disable_solenoid(0);
  78. #if HAS_SOLENOID(1)
  79. disable_solenoid(1);
  80. #endif
  81. #if HAS_SOLENOID(2)
  82. disable_solenoid(2);
  83. #endif
  84. #if HAS_SOLENOID(3)
  85. disable_solenoid(3);
  86. #endif
  87. #if HAS_SOLENOID(4)
  88. disable_solenoid(4);
  89. #endif
  90. #if HAS_SOLENOID(5)
  91. disable_solenoid(5);
  92. #endif
  93. }
  94. #endif // EXT_SOLENOID || MANUAL_SOLENOID_CONTROL