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

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