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.

M106_M107.cpp 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 HAS_FAN
  24. #include "../gcode.h"
  25. #include "../../module/motion.h"
  26. #include "../../module/temperature.h"
  27. #if ENABLED(LASER_SYNCHRONOUS_M106_M107)
  28. #include "../../module/planner.h"
  29. #endif
  30. #if PREHEAT_COUNT
  31. #include "../../lcd/marlinui.h"
  32. #endif
  33. #if ENABLED(SINGLENOZZLE)
  34. #define _ALT_P active_extruder
  35. #define _CNT_P EXTRUDERS
  36. #else
  37. #define _ALT_P _MIN(active_extruder, FAN_COUNT - 1)
  38. #define _CNT_P FAN_COUNT
  39. #endif
  40. /**
  41. * M106: Set Fan Speed
  42. *
  43. * I<index> Material Preset index (if material presets are defined)
  44. * S<int> Speed between 0-255
  45. * P<index> Fan index, if more than one fan
  46. *
  47. * With EXTRA_FAN_SPEED enabled:
  48. *
  49. * T<int> Restore/Use/Set Temporary Speed:
  50. * 1 = Restore previous speed after T2
  51. * 2 = Use temporary speed set with T3-255
  52. * 3-255 = Set the speed for use with T2
  53. */
  54. void GcodeSuite::M106() {
  55. const uint8_t pfan = parser.byteval('P', _ALT_P);
  56. if (pfan < _CNT_P) {
  57. #if ENABLED(EXTRA_FAN_SPEED)
  58. const uint16_t t = parser.intval('T');
  59. if (t > 0) return thermalManager.set_temp_fan_speed(pfan, t);
  60. #endif
  61. const uint16_t dspeed = parser.seen('A') ? thermalManager.fan_speed[active_extruder] : 255;
  62. uint16_t speed = dspeed;
  63. // Accept 'I' if temperature presets are defined
  64. #if PREHEAT_COUNT
  65. const bool got_preset = parser.seenval('I');
  66. if (got_preset) speed = ui.material_preset[_MIN(parser.value_byte(), PREHEAT_COUNT - 1)].fan_speed;
  67. #else
  68. constexpr bool got_preset = false;
  69. #endif
  70. if (!got_preset && parser.seenval('S'))
  71. speed = parser.value_ushort();
  72. // Set speed, with constraint
  73. thermalManager.set_fan_speed(pfan, speed);
  74. TERN_(LASER_SYNCHRONOUS_M106_M107, planner.buffer_sync_block(BLOCK_FLAG_SYNC_FANS));
  75. if (TERN0(DUAL_X_CARRIAGE, idex_is_duplicating())) // pfan == 0 when duplicating
  76. thermalManager.set_fan_speed(1 - pfan, speed);
  77. }
  78. }
  79. /**
  80. * M107: Fan Off
  81. */
  82. void GcodeSuite::M107() {
  83. const uint8_t pfan = parser.byteval('P', _ALT_P);
  84. if (pfan >= _CNT_P) return;
  85. thermalManager.set_fan_speed(pfan, 0);
  86. if (TERN0(DUAL_X_CARRIAGE, idex_is_duplicating())) // pfan == 0 when duplicating
  87. thermalManager.set_fan_speed(1 - pfan, 0);
  88. TERN_(LASER_SYNCHRONOUS_M106_M107, planner.buffer_sync_block(BLOCK_FLAG_SYNC_FANS));
  89. }
  90. #endif // HAS_FAN