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.

controllerfan.cpp 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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(USE_CONTROLLER_FAN)
  24. #include "../module/stepper/indirection.h"
  25. #include "../module/temperature.h"
  26. uint8_t controllerfan_speed;
  27. void controllerfan_update() {
  28. static millis_t lastMotorOn = 0, // Last time a motor was turned on
  29. nextMotorCheck = 0; // Last time the state was checked
  30. const millis_t ms = millis();
  31. if (ELAPSED(ms, nextMotorCheck)) {
  32. nextMotorCheck = ms + 2500UL; // Not a time critical function, so only check every 2.5s
  33. const bool xory = X_ENABLE_READ() == X_ENABLE_ON || Y_ENABLE_READ() == Y_ENABLE_ON;
  34. // If any of the drivers or the bed are enabled...
  35. if (xory || Z_ENABLE_READ() == Z_ENABLE_ON
  36. #if HAS_HEATED_BED
  37. || thermalManager.temp_bed.soft_pwm_amount > 0
  38. #endif
  39. #if HAS_X2_ENABLE
  40. || X2_ENABLE_READ() == X_ENABLE_ON
  41. #endif
  42. #if HAS_Y2_ENABLE
  43. || Y2_ENABLE_READ() == Y_ENABLE_ON
  44. #endif
  45. #if HAS_Z2_ENABLE
  46. || Z2_ENABLE_READ() == Z_ENABLE_ON
  47. #endif
  48. #if HAS_Z3_ENABLE
  49. || Z3_ENABLE_READ() == Z_ENABLE_ON
  50. #endif
  51. #if E_STEPPERS
  52. || E0_ENABLE_READ() == E_ENABLE_ON
  53. #if E_STEPPERS > 1
  54. || E1_ENABLE_READ() == E_ENABLE_ON
  55. #if E_STEPPERS > 2
  56. || E2_ENABLE_READ() == E_ENABLE_ON
  57. #if E_STEPPERS > 3
  58. || E3_ENABLE_READ() == E_ENABLE_ON
  59. #if E_STEPPERS > 4
  60. || E4_ENABLE_READ() == E_ENABLE_ON
  61. #if E_STEPPERS > 5
  62. || E5_ENABLE_READ() == E_ENABLE_ON
  63. #endif // E_STEPPERS > 5
  64. #endif // E_STEPPERS > 4
  65. #endif // E_STEPPERS > 3
  66. #endif // E_STEPPERS > 2
  67. #endif // E_STEPPERS > 1
  68. #endif // E_STEPPERS
  69. ) {
  70. lastMotorOn = ms; //... set time to NOW so the fan will turn on
  71. }
  72. // Fan off if no steppers have been enabled for CONTROLLERFAN_SECS seconds
  73. controllerfan_speed = (!lastMotorOn || ELAPSED(ms, lastMotorOn + (CONTROLLERFAN_SECS) * 1000UL)) ? 0 : (
  74. #ifdef CONTROLLERFAN_SPEED_Z_ONLY
  75. xory ? CONTROLLERFAN_SPEED : CONTROLLERFAN_SPEED_Z_ONLY
  76. #else
  77. CONTROLLERFAN_SPEED
  78. #endif
  79. );
  80. // Allow digital or PWM fan output (see M42 handling)
  81. WRITE(CONTROLLER_FAN_PIN, controllerfan_speed);
  82. analogWrite(pin_t(CONTROLLER_FAN_PIN), controllerfan_speed);
  83. }
  84. }
  85. #endif // USE_CONTROLLER_FAN