diff options
author | Georgiy Bondarenko <69736697+nehilo@users.noreply.github.com> | 2021-03-04 20:54:23 +0300 |
---|---|---|
committer | Georgiy Bondarenko <69736697+nehilo@users.noreply.github.com> | 2021-03-04 20:54:23 +0300 |
commit | e8701195e66f2d27ffe17fb514eae8173795aaf7 (patch) | |
tree | 9f519c4abf6556b9ae7190a6210d87ead1dfadde /Marlin/src/gcode/temp | |
download | kp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.tar.xz kp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.zip |
Initial commit
Diffstat (limited to 'Marlin/src/gcode/temp')
-rw-r--r-- | Marlin/src/gcode/temp/M104_M109.cpp | 200 | ||||
-rw-r--r-- | Marlin/src/gcode/temp/M105.cpp | 51 | ||||
-rw-r--r-- | Marlin/src/gcode/temp/M106_M107.cpp | 95 | ||||
-rw-r--r-- | Marlin/src/gcode/temp/M140_M190.cpp | 138 | ||||
-rw-r--r-- | Marlin/src/gcode/temp/M141_M191.cpp | 89 | ||||
-rw-r--r-- | Marlin/src/gcode/temp/M155.cpp | 40 | ||||
-rw-r--r-- | Marlin/src/gcode/temp/M303.cpp | 85 |
7 files changed, 698 insertions, 0 deletions
diff --git a/Marlin/src/gcode/temp/M104_M109.cpp b/Marlin/src/gcode/temp/M104_M109.cpp new file mode 100644 index 0000000..07e46e1 --- /dev/null +++ b/Marlin/src/gcode/temp/M104_M109.cpp @@ -0,0 +1,200 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + */ + +/** + * gcode/temp/M104_M109.cpp + * + * Hotend target temperature control + */ + +#include "../../inc/MarlinConfigPre.h" + +#if EXTRUDERS + +#include "../gcode.h" +#include "../../module/temperature.h" +#include "../../module/motion.h" +#include "../../module/planner.h" +#include "../../lcd/marlinui.h" + +#include "../../MarlinCore.h" // for startOrResumeJob, etc. + +#if ENABLED(PRINTJOB_TIMER_AUTOSTART) + #include "../../module/printcounter.h" + #if ENABLED(CANCEL_OBJECTS) + #include "../../feature/cancel_object.h" + #endif +#endif + +#if ENABLED(SINGLENOZZLE_STANDBY_TEMP) + #include "../../module/tool_change.h" +#endif + +/** + * M104: Set Hotend Temperature target and return immediately + * + * Parameters: + * I<preset> : Material Preset index (if material presets are defined) + * T<index> : Tool index. If omitted, applies to the active tool + * S<target> : The target temperature in current units + */ +void GcodeSuite::M104() { + + if (DEBUGGING(DRYRUN)) return; + + #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1 + constexpr int8_t target_extruder = 0; + #else + const int8_t target_extruder = get_target_extruder_from_command(); + if (target_extruder < 0) return; + #endif + + bool got_temp = false; + int16_t temp = 0; + + // Accept 'I' if temperature presets are defined + #if PREHEAT_COUNT + got_temp = parser.seenval('I'); + if (got_temp) { + const uint8_t index = parser.value_byte(); + temp = ui.material_preset[_MIN(index, PREHEAT_COUNT - 1)].hotend_temp; + } + #endif + + // If no 'I' get the temperature from 'S' + if (!got_temp) { + got_temp = parser.seenval('S'); + if (got_temp) temp = parser.value_celsius(); + } + + if (got_temp) { + #if ENABLED(SINGLENOZZLE_STANDBY_TEMP) + thermalManager.singlenozzle_temp[target_extruder] = temp; + if (target_extruder != active_extruder) return; + #endif + thermalManager.setTargetHotend(temp, target_extruder); + + #if ENABLED(DUAL_X_CARRIAGE) + if (idex_is_duplicating() && target_extruder == 0) + thermalManager.setTargetHotend(temp ? temp + duplicate_extruder_temp_offset : 0, 1); + #endif + + #if ENABLED(PRINTJOB_TIMER_AUTOSTART) + /** + * Stop the timer at the end of print. Start is managed by 'heat and wait' M109. + * Hotends use EXTRUDE_MINTEMP / 2 to allow nozzles to be put into hot standby + * mode, for instance in a dual extruder setup, without affecting the running + * print timer. + */ + thermalManager.auto_job_check_timer(false, true); + #endif + } + + TERN_(AUTOTEMP, planner.autotemp_M104_M109()); +} + +/** + * M109: Set Hotend Temperature target and wait + * + * Parameters + * I<preset> : Material Preset index (if material presets are defined) + * T<index> : Tool index. If omitted, applies to the active tool + * S<target> : The target temperature in current units. Wait for heating only. + * R<target> : The target temperature in current units. Wait for heating and cooling. + * + * With AUTOTEMP... + * F<factor> : Autotemp Scaling Factor. Set non-zero to enable Auto-temp. + * S<min> : Minimum temperature, in current units. + * B<max> : Maximum temperature, in current units. + * + * Examples + * M109 S100 : Set target to 100°. Wait until the hotend is at or above 100°. + * M109 R150 : Set target to 150°. Wait until the hotend gets close to 150°. + * + * With PRINTJOB_TIMER_AUTOSTART turning on heaters will start the print job timer + * (used by printingIsActive, etc.) and turning off heaters will stop the timer. + */ +void GcodeSuite::M109() { + + if (DEBUGGING(DRYRUN)) return; + + #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1 + constexpr int8_t target_extruder = 0; + #else + const int8_t target_extruder = get_target_extruder_from_command(); + if (target_extruder < 0) return; + #endif + + bool got_temp = false; + int16_t temp = 0; + + // Accept 'I' if temperature presets are defined + #if PREHEAT_COUNT + got_temp = parser.seenval('I'); + if (got_temp) { + const uint8_t index = parser.value_byte(); + temp = ui.material_preset[_MIN(index, PREHEAT_COUNT - 1)].hotend_temp; + } + #endif + + // Get the temperature from 'S' or 'R' + bool no_wait_for_cooling = false; + if (!got_temp) { + no_wait_for_cooling = parser.seenval('S'); + got_temp = no_wait_for_cooling || parser.seenval('R'); + if (got_temp) temp = int16_t(parser.value_celsius()); + } + + if (got_temp) { + #if ENABLED(SINGLENOZZLE_STANDBY_TEMP) + thermalManager.singlenozzle_temp[target_extruder] = temp; + if (target_extruder != active_extruder) return; + #endif + thermalManager.setTargetHotend(temp, target_extruder); + + #if ENABLED(DUAL_X_CARRIAGE) + if (idex_is_duplicating() && target_extruder == 0) + thermalManager.setTargetHotend(temp ? temp + duplicate_extruder_temp_offset : 0, 1); + #endif + + #if ENABLED(PRINTJOB_TIMER_AUTOSTART) + /** + * Use half EXTRUDE_MINTEMP to allow nozzles to be put into hot + * standby mode, (e.g., in a dual extruder setup) without affecting + * the running print timer. + */ + thermalManager.auto_job_check_timer(true, true); + #endif + + #if HAS_DISPLAY + if (thermalManager.isHeatingHotend(target_extruder) || !no_wait_for_cooling) + thermalManager.set_heating_message(target_extruder); + #endif + } + + TERN_(AUTOTEMP, planner.autotemp_M104_M109()); + + if (got_temp) + (void)thermalManager.wait_for_hotend(target_extruder, no_wait_for_cooling); +} + +#endif // EXTRUDERS diff --git a/Marlin/src/gcode/temp/M105.cpp b/Marlin/src/gcode/temp/M105.cpp new file mode 100644 index 0000000..eefc3ae --- /dev/null +++ b/Marlin/src/gcode/temp/M105.cpp @@ -0,0 +1,51 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + */ + +#include "../gcode.h" +#include "../../module/temperature.h" + +/** + * M105: Read hot end and bed temperature + */ +void GcodeSuite::M105() { + + const int8_t target_extruder = get_target_extruder_from_command(); + if (target_extruder < 0) return; + + SERIAL_ECHOPGM(STR_OK); + + #if HAS_TEMP_SENSOR + + thermalManager.print_heater_states(target_extruder + #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT) + , parser.boolval('R') + #endif + ); + + SERIAL_EOL(); + + #else + + SERIAL_ECHOLNPGM(" T:0"); // Some hosts send M105 to test the serial connection + + #endif +} diff --git a/Marlin/src/gcode/temp/M106_M107.cpp b/Marlin/src/gcode/temp/M106_M107.cpp new file mode 100644 index 0000000..9c70f1e --- /dev/null +++ b/Marlin/src/gcode/temp/M106_M107.cpp @@ -0,0 +1,95 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + */ + +#include "../../inc/MarlinConfig.h" + +#if HAS_FAN + +#include "../gcode.h" +#include "../../module/motion.h" +#include "../../module/temperature.h" + +#if PREHEAT_COUNT + #include "../../lcd/marlinui.h" +#endif + +#if ENABLED(SINGLENOZZLE) + #define _ALT_P active_extruder + #define _CNT_P EXTRUDERS +#else + #define _ALT_P _MIN(active_extruder, FAN_COUNT - 1) + #define _CNT_P FAN_COUNT +#endif + +/** + * M106: Set Fan Speed + * + * I<index> Material Preset index (if material presets are defined) + * S<int> Speed between 0-255 + * P<index> Fan index, if more than one fan + * + * With EXTRA_FAN_SPEED enabled: + * + * T<int> Restore/Use/Set Temporary Speed: + * 1 = Restore previous speed after T2 + * 2 = Use temporary speed set with T3-255 + * 3-255 = Set the speed for use with T2 + */ +void GcodeSuite::M106() { + const uint8_t pfan = parser.byteval('P', _ALT_P); + + if (pfan < _CNT_P) { + + #if ENABLED(EXTRA_FAN_SPEED) + const uint16_t t = parser.intval('T'); + if (t > 0) return thermalManager.set_temp_fan_speed(pfan, t); + #endif + + const uint16_t dspeed = parser.seen('A') ? thermalManager.fan_speed[active_extruder] : 255; + + uint16_t speed = dspeed; + + // Accept 'I' if temperature presets are defined + #if PREHEAT_COUNT + const bool got_preset = parser.seenval('I'); + if (got_preset) speed = ui.material_preset[_MIN(parser.value_byte(), PREHEAT_COUNT - 1)].fan_speed; + #else + constexpr bool got_preset = false; + #endif + + if (!got_preset && parser.seenval('S')) + speed = parser.value_ushort(); + + // Set speed, with constraint + thermalManager.set_fan_speed(pfan, speed); + } +} + +/** + * M107: Fan Off + */ +void GcodeSuite::M107() { + const uint8_t p = parser.byteval('P', _ALT_P); + thermalManager.set_fan_speed(p, 0); +} + +#endif // HAS_FAN diff --git a/Marlin/src/gcode/temp/M140_M190.cpp b/Marlin/src/gcode/temp/M140_M190.cpp new file mode 100644 index 0000000..d684127 --- /dev/null +++ b/Marlin/src/gcode/temp/M140_M190.cpp @@ -0,0 +1,138 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + */ + +/** + * gcode/temp/M140_M190.cpp + * + * Bed target temperature control + */ + +#include "../../inc/MarlinConfig.h" + +#if HAS_HEATED_BED + +#include "../gcode.h" +#include "../../module/temperature.h" +#include "../../module/motion.h" +#include "../../lcd/marlinui.h" + +#if ENABLED(PRINTJOB_TIMER_AUTOSTART) + #include "../../module/printcounter.h" +#endif + +#if ENABLED(PRINTER_EVENT_LEDS) + #include "../../feature/leds/leds.h" +#endif + +#include "../../MarlinCore.h" // for wait_for_heatup, idle, startOrResumeJob + +/** + * M140: Set bed temperature + * + * I<index> : Preset index (if material presets are defined) + * S<target> : The target temperature in current units + */ +void GcodeSuite::M140() { + if (DEBUGGING(DRYRUN)) return; + + bool got_temp = false; + int16_t temp = 0; + + // Accept 'I' if temperature presets are defined + #if PREHEAT_COUNT + got_temp = parser.seenval('I'); + if (got_temp) { + const uint8_t index = parser.value_byte(); + temp = ui.material_preset[_MIN(index, PREHEAT_COUNT - 1)].bed_temp; + } + #endif + + // If no 'I' get the temperature from 'S' + if (!got_temp) { + got_temp = parser.seenval('S'); + if (got_temp) temp = parser.value_celsius(); + } + + if (got_temp) { + thermalManager.setTargetBed(temp); + + #if ENABLED(PRINTJOB_TIMER_AUTOSTART) + /** + * Stop the timer at the end of print. Hotend, bed target, and chamber + * temperatures need to be set below mintemp. Order of M140, M104, and M141 + * at the end of the print does not matter. + */ + thermalManager.auto_job_check_timer(false, true); + #endif + } +} + +/** + * M190 - Set Bed Temperature target and wait + * + * Parameters: + * I<index> : Preset index (if material presets are defined) + * S<target> : The target temperature in current units. Wait for heating only. + * R<target> : The target temperature in current units. Wait for heating and cooling. + * + * Examples: + * M190 S60 : Set target to 60°. Wait until the bed is at or above 60°. + * M190 R40 : Set target to 40°. Wait until the bed gets close to 40°. + * + * With PRINTJOB_TIMER_AUTOSTART turning on heaters will start the print job timer + * (used by printingIsActive, etc.) and turning off heaters will stop the timer. + */ +void GcodeSuite::M190() { + if (DEBUGGING(DRYRUN)) return; + + bool got_temp = false; + int16_t temp = 0; + + // Accept 'I' if temperature presets are defined + #if PREHEAT_COUNT + got_temp = parser.seenval('I'); + if (got_temp) { + const uint8_t index = parser.value_byte(); + temp = ui.material_preset[_MIN(index, PREHEAT_COUNT - 1)].bed_temp; + } + #endif + + // Get the temperature from 'S' or 'R' + bool no_wait_for_cooling = false; + if (!got_temp) { + no_wait_for_cooling = parser.seenval('S'); + got_temp = no_wait_for_cooling || parser.seenval('R'); + if (got_temp) temp = int16_t(parser.value_celsius()); + } + + if (!got_temp) return; + + thermalManager.setTargetBed(temp); + + TERN_(PRINTJOB_TIMER_AUTOSTART, thermalManager.auto_job_check_timer(true, false)); + + ui.set_status_P(thermalManager.isHeatingBed() ? GET_TEXT(MSG_BED_HEATING) : GET_TEXT(MSG_BED_COOLING)); + + thermalManager.wait_for_bed(no_wait_for_cooling); +} + +#endif // HAS_HEATED_BED diff --git a/Marlin/src/gcode/temp/M141_M191.cpp b/Marlin/src/gcode/temp/M141_M191.cpp new file mode 100644 index 0000000..17eb71e --- /dev/null +++ b/Marlin/src/gcode/temp/M141_M191.cpp @@ -0,0 +1,89 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + */ + +/** + * gcode/temp/M141_M191.cpp + * + * Chamber target temperature control + */ + +#include "../../inc/MarlinConfig.h" + +#if HAS_HEATED_CHAMBER + +#include "../gcode.h" +#include "../../module/temperature.h" + +#include "../../module/motion.h" +#include "../../lcd/marlinui.h" + +#if ENABLED(PRINTJOB_TIMER_AUTOSTART) + #include "../../module/printcounter.h" +#endif + +#if ENABLED(PRINTER_EVENT_LEDS) + #include "../../feature/leds/leds.h" +#endif + +#include "../../MarlinCore.h" // for wait_for_heatup, idle, startOrResumeJob + +/** + * M141: Set chamber temperature + */ +void GcodeSuite::M141() { + if (DEBUGGING(DRYRUN)) return; + if (parser.seenval('S')) { + thermalManager.setTargetChamber(parser.value_celsius()); + + #if ENABLED(PRINTJOB_TIMER_AUTOSTART) + /** + * Stop the timer at the end of print. Hotend, bed target, and chamber + * temperatures need to be set below mintemp. Order of M140, M104, and M141 + * at the end of the print does not matter. + */ + thermalManager.auto_job_check_timer(false, true); + #endif + } +} + +/** + * M191: Sxxx Wait for chamber current temp to reach target temp. Waits only when heating + * Rxxx Wait for chamber current temp to reach target temp. Waits when heating and cooling + */ +void GcodeSuite::M191() { + if (DEBUGGING(DRYRUN)) return; + + const bool no_wait_for_cooling = parser.seenval('S'); + if (no_wait_for_cooling || parser.seenval('R')) { + thermalManager.setTargetChamber(parser.value_celsius()); + TERN_(PRINTJOB_TIMER_AUTOSTART, thermalManager.auto_job_check_timer(true, false)); + } + else return; + + const bool is_heating = thermalManager.isHeatingChamber(); + if (is_heating || !no_wait_for_cooling) { + ui.set_status_P(is_heating ? GET_TEXT(MSG_CHAMBER_HEATING) : GET_TEXT(MSG_CHAMBER_COOLING)); + thermalManager.wait_for_chamber(false); + } +} + +#endif // HAS_HEATED_CHAMBER diff --git a/Marlin/src/gcode/temp/M155.cpp b/Marlin/src/gcode/temp/M155.cpp new file mode 100644 index 0000000..48c2398 --- /dev/null +++ b/Marlin/src/gcode/temp/M155.cpp @@ -0,0 +1,40 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + */ + +#include "../../inc/MarlinConfig.h" + +#if BOTH(AUTO_REPORT_TEMPERATURES, HAS_TEMP_SENSOR) + +#include "../gcode.h" +#include "../../module/temperature.h" + +/** + * M155: Set temperature auto-report interval. M155 S<seconds> + */ +void GcodeSuite::M155() { + + if (parser.seenval('S')) + thermalManager.auto_reporter.set_interval(parser.value_byte()); + +} + +#endif // AUTO_REPORT_TEMPERATURES && HAS_TEMP_SENSOR diff --git a/Marlin/src/gcode/temp/M303.cpp b/Marlin/src/gcode/temp/M303.cpp new file mode 100644 index 0000000..a066ddc --- /dev/null +++ b/Marlin/src/gcode/temp/M303.cpp @@ -0,0 +1,85 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + */ + +#include "../../inc/MarlinConfig.h" + +#if HAS_PID_HEATING + +#include "../gcode.h" +#include "../../lcd/marlinui.h" +#include "../../module/temperature.h" + +#if ENABLED(EXTENSIBLE_UI) + #include "../../lcd/extui/ui_api.h" +#endif + +/** + * M303: PID relay autotune + * + * S<temperature> Set the target temperature. (Default: 150C / 70C) + * E<extruder> Extruder number to tune, or -1 for the bed. (Default: E0) + * C<cycles> Number of times to repeat the procedure. (Minimum: 3, Default: 5) + * U<bool> Flag to apply the result to the current PID values + * + * With PID_DEBUG: + * D Toggle PID debugging and EXIT without further action. + */ + +#if ENABLED(PID_DEBUG) + bool pid_debug_flag = 0; +#endif + +void GcodeSuite::M303() { + + #if ENABLED(PID_DEBUG) + if (parser.seen('D')) { + pid_debug_flag = !pid_debug_flag; + SERIAL_ECHO_START(); + SERIAL_ECHOPGM("PID Debug "); + serialprintln_onoff(pid_debug_flag); + return; + } + #endif + + #define SI TERN(PIDTEMPBED, H_BED, H_E0) + #define EI TERN(PIDTEMP, HOTENDS - 1, H_BED) + const heater_id_t e = (heater_id_t)parser.intval('E'); + if (!WITHIN(e, SI, EI)) { + SERIAL_ECHOLNPGM(STR_PID_BAD_EXTRUDER_NUM); + TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_BAD_EXTRUDER_NUM)); + return; + } + + const int c = parser.intval('C', 5); + const bool u = parser.boolval('U'); + const int16_t temp = parser.celsiusval('S', e < 0 ? PREHEAT_1_TEMP_BED : PREHEAT_1_TEMP_HOTEND); + + #if DISABLED(BUSY_WHILE_HEATING) + KEEPALIVE_STATE(NOT_BUSY); + #endif + + LCD_MESSAGEPGM(MSG_PID_AUTOTUNE); + thermalManager.PID_autotune(temp, e, c, u); + ui.reset_status(); +} + +#endif // HAS_PID_HEATING |