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.

M104_M109.cpp 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. /**
  23. * gcode/temp/M104_M109.cpp
  24. *
  25. * Hotend target temperature control
  26. */
  27. #include "../../inc/MarlinConfigPre.h"
  28. #if EXTRUDERS
  29. #include "../gcode.h"
  30. #include "../../module/temperature.h"
  31. #include "../../module/motion.h"
  32. #include "../../module/planner.h"
  33. #include "../../lcd/marlinui.h"
  34. #include "../../MarlinCore.h" // for startOrResumeJob, etc.
  35. #if ENABLED(PRINTJOB_TIMER_AUTOSTART)
  36. #include "../../module/printcounter.h"
  37. #if ENABLED(CANCEL_OBJECTS)
  38. #include "../../feature/cancel_object.h"
  39. #endif
  40. #endif
  41. #if ENABLED(SINGLENOZZLE)
  42. #include "../../module/tool_change.h"
  43. #endif
  44. /**
  45. * M104: Set Hotend Temperature target and return immediately
  46. *
  47. * Parameters:
  48. * I<preset> : Material Preset index (if material presets are defined)
  49. * T<index> : Tool index. If omitted, applies to the active tool
  50. * S<target> : The target temperature in current units
  51. */
  52. void GcodeSuite::M104() {
  53. if (DEBUGGING(DRYRUN)) return;
  54. #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
  55. constexpr int8_t target_extruder = 0;
  56. #else
  57. const int8_t target_extruder = get_target_extruder_from_command();
  58. if (target_extruder < 0) return;
  59. #endif
  60. bool got_temp = false;
  61. int16_t temp = 0;
  62. // Accept 'I' if temperature presets are defined
  63. #if PREHEAT_COUNT
  64. got_temp = parser.seenval('I');
  65. if (got_temp) {
  66. const uint8_t index = parser.value_byte();
  67. temp = ui.material_preset[_MIN(index, PREHEAT_COUNT - 1)].hotend_temp;
  68. }
  69. #endif
  70. // If no 'I' get the temperature from 'S'
  71. if (!got_temp) {
  72. got_temp = parser.seenval('S');
  73. if (got_temp) temp = parser.value_celsius();
  74. }
  75. if (got_temp) {
  76. #if ENABLED(SINGLENOZZLE_STANDBY_TEMP)
  77. singlenozzle_temp[target_extruder] = temp;
  78. if (target_extruder != active_extruder) return;
  79. #endif
  80. thermalManager.setTargetHotend(temp, target_extruder);
  81. #if ENABLED(DUAL_X_CARRIAGE)
  82. if (idex_is_duplicating() && target_extruder == 0)
  83. thermalManager.setTargetHotend(temp ? temp + duplicate_extruder_temp_offset : 0, 1);
  84. #endif
  85. #if ENABLED(PRINTJOB_TIMER_AUTOSTART)
  86. /**
  87. * Stop the timer at the end of print. Start is managed by 'heat and wait' M109.
  88. * Hotends use EXTRUDE_MINTEMP / 2 to allow nozzles to be put into hot standby
  89. * mode, for instance in a dual extruder setup, without affecting the running
  90. * print timer.
  91. */
  92. thermalManager.check_timer_autostart(false, true);
  93. #endif
  94. }
  95. TERN_(AUTOTEMP, planner.autotemp_M104_M109());
  96. }
  97. /**
  98. * M109: Set Hotend Temperature target and wait
  99. *
  100. * Parameters
  101. * I<preset> : Material Preset index (if material presets are defined)
  102. * T<index> : Tool index. If omitted, applies to the active tool
  103. * S<target> : The target temperature in current units. Wait for heating only.
  104. * R<target> : The target temperature in current units. Wait for heating and cooling.
  105. *
  106. * With AUTOTEMP...
  107. * F<factor> : Autotemp Scaling Factor. Set non-zero to enable Auto-temp.
  108. * S<min> : Minimum temperature, in current units.
  109. * B<max> : Maximum temperature, in current units.
  110. *
  111. * Examples
  112. * M109 S100 : Set target to 100°. Wait until the hotend is at or above 100°.
  113. * M109 R150 : Set target to 150°. Wait until the hotend gets close to 150°.
  114. *
  115. * With PRINTJOB_TIMER_AUTOSTART turning on heaters will start the print job timer
  116. * (used by printingIsActive, etc.) and turning off heaters will stop the timer.
  117. */
  118. void GcodeSuite::M109() {
  119. if (DEBUGGING(DRYRUN)) return;
  120. #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
  121. constexpr int8_t target_extruder = 0;
  122. #else
  123. const int8_t target_extruder = get_target_extruder_from_command();
  124. if (target_extruder < 0) return;
  125. #endif
  126. bool got_temp = false;
  127. int16_t temp = 0;
  128. // Accept 'I' if temperature presets are defined
  129. #if PREHEAT_COUNT
  130. got_temp = parser.seenval('I');
  131. if (got_temp) {
  132. const uint8_t index = parser.value_byte();
  133. temp = ui.material_preset[_MIN(index, PREHEAT_COUNT - 1)].hotend_temp;
  134. }
  135. #endif
  136. // Get the temperature from 'S' or 'R'
  137. bool no_wait_for_cooling = false;
  138. if (!got_temp) {
  139. no_wait_for_cooling = parser.seenval('S');
  140. got_temp = no_wait_for_cooling || parser.seenval('R');
  141. if (got_temp) temp = int16_t(parser.value_celsius());
  142. }
  143. if (got_temp) {
  144. #if ENABLED(SINGLENOZZLE_STANDBY_TEMP)
  145. singlenozzle_temp[target_extruder] = temp;
  146. if (target_extruder != active_extruder) return;
  147. #endif
  148. thermalManager.setTargetHotend(temp, target_extruder);
  149. #if ENABLED(DUAL_X_CARRIAGE)
  150. if (idex_is_duplicating() && target_extruder == 0)
  151. thermalManager.setTargetHotend(temp ? temp + duplicate_extruder_temp_offset : 0, 1);
  152. #endif
  153. #if ENABLED(PRINTJOB_TIMER_AUTOSTART)
  154. /**
  155. * Use half EXTRUDE_MINTEMP to allow nozzles to be put into hot
  156. * standby mode, (e.g., in a dual extruder setup) without affecting
  157. * the running print timer.
  158. */
  159. thermalManager.check_timer_autostart(true, true);
  160. #endif
  161. #if HAS_DISPLAY
  162. if (thermalManager.isHeatingHotend(target_extruder) || !no_wait_for_cooling)
  163. thermalManager.set_heating_message(target_extruder);
  164. #endif
  165. }
  166. TERN_(AUTOTEMP, planner.autotemp_M104_M109());
  167. if (got_temp)
  168. (void)thermalManager.wait_for_hotend(target_extruder, no_wait_for_cooling);
  169. }
  170. #endif // EXTRUDERS