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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #endif
  30. #define HAS_SOLENOID(N) (HAS_SOLENOID_##N && (ENABLED(MANUAL_SOLENOID_CONTROL) || N < EXTRUDERS))
  31. // Used primarily with MANUAL_SOLENOID_CONTROL
  32. static void set_solenoid(const uint8_t num, const bool active) {
  33. const uint8_t value = active ? PE_MAGNET_ON_STATE : !PE_MAGNET_ON_STATE;
  34. switch (num) {
  35. case 0: OUT_WRITE(SOL0_PIN, value); break;
  36. #if HAS_SOLENOID(1)
  37. case 1: OUT_WRITE(SOL1_PIN, value); break;
  38. #endif
  39. #if HAS_SOLENOID(2)
  40. case 2: OUT_WRITE(SOL2_PIN, value); break;
  41. #endif
  42. #if HAS_SOLENOID(3)
  43. case 3: OUT_WRITE(SOL3_PIN, value); break;
  44. #endif
  45. #if HAS_SOLENOID(4)
  46. case 4: OUT_WRITE(SOL4_PIN, value); break;
  47. #endif
  48. #if HAS_SOLENOID(5)
  49. case 5: OUT_WRITE(SOL5_PIN, value); break;
  50. #endif
  51. default: SERIAL_ECHO_MSG(STR_INVALID_SOLENOID); break;
  52. }
  53. #if ENABLED(PARKING_EXTRUDER)
  54. if (!active && active_extruder == num) // If active extruder's solenoid is disabled, carriage is considered parked
  55. parking_extruder_set_parked(true);
  56. #endif
  57. }
  58. void enable_solenoid(const uint8_t num) { set_solenoid(num, true); }
  59. void disable_solenoid(const uint8_t num) { set_solenoid(num, false); }
  60. void enable_solenoid_on_active_extruder() { enable_solenoid(active_extruder); }
  61. void disable_all_solenoids() {
  62. disable_solenoid(0);
  63. #if HAS_SOLENOID(1)
  64. disable_solenoid(1);
  65. #endif
  66. #if HAS_SOLENOID(2)
  67. disable_solenoid(2);
  68. #endif
  69. #if HAS_SOLENOID(3)
  70. disable_solenoid(3);
  71. #endif
  72. #if HAS_SOLENOID(4)
  73. disable_solenoid(4);
  74. #endif
  75. #if HAS_SOLENOID(5)
  76. disable_solenoid(5);
  77. #endif
  78. }
  79. #endif // EXT_SOLENOID || MANUAL_SOLENOID_CONTROL