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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 <http://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. #if ENABLED(MANUAL_SOLENOID_CONTROL)
  27. #define HAS_SOLENOID(N) HAS_SOLENOID_##N
  28. #else
  29. #define HAS_SOLENOID(N) (HAS_SOLENOID_##N && EXTRUDERS > N)
  30. #endif
  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 ? HIGH : LOW;
  34. switch (num) {
  35. case 0:
  36. OUT_WRITE(SOL0_PIN, value);
  37. break;
  38. #if HAS_SOLENOID(1)
  39. case 1:
  40. OUT_WRITE(SOL1_PIN, value);
  41. break;
  42. #endif
  43. #if HAS_SOLENOID(2)
  44. case 2:
  45. OUT_WRITE(SOL2_PIN, value);
  46. break;
  47. #endif
  48. #if HAS_SOLENOID(3)
  49. case 3:
  50. OUT_WRITE(SOL3_PIN, value);
  51. break;
  52. #endif
  53. #if HAS_SOLENOID(4)
  54. case 4:
  55. OUT_WRITE(SOL4_PIN, value);
  56. break;
  57. #endif
  58. #if HAS_SOLENOID(5)
  59. case 5:
  60. OUT_WRITE(SOL5_PIN, value);
  61. break;
  62. #endif
  63. default:
  64. SERIAL_ECHO_MSG(STR_INVALID_SOLENOID);
  65. break;
  66. }
  67. }
  68. void enable_solenoid(const uint8_t num) { set_solenoid(num, true); }
  69. void disable_solenoid(const uint8_t num) { set_solenoid(num, false); }
  70. void enable_solenoid_on_active_extruder() { enable_solenoid(active_extruder); }
  71. void disable_all_solenoids() {
  72. disable_solenoid(0);
  73. #if HAS_SOLENOID(1)
  74. disable_solenoid(1);
  75. #endif
  76. #if HAS_SOLENOID(2)
  77. disable_solenoid(2);
  78. #endif
  79. #if HAS_SOLENOID(3)
  80. disable_solenoid(3);
  81. #endif
  82. #if HAS_SOLENOID(4)
  83. disable_solenoid(4);
  84. #endif
  85. #if HAS_SOLENOID(5)
  86. disable_solenoid(5);
  87. #endif
  88. }
  89. #endif // EXT_SOLENOID || MANUAL_SOLENOID_CONTROL