Skip to content

Commit aee971b

Browse files
committed
🎨 Combine M104/M109 and M140/M190 code
1 parent 6689e5e commit aee971b

File tree

3 files changed

+27
-118
lines changed

3 files changed

+27
-118
lines changed

Marlin/src/gcode/gcode.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,9 @@ class GcodeSuite {
648648
#endif
649649

650650
#if HAS_EXTRUDERS
651-
static void M104();
652-
static void M109();
651+
static void M104_M109(const bool isM109);
652+
FORCE_INLINE static void M104() { M104_M109(false); }
653+
FORCE_INLINE static void M109() { M104_M109(true); }
653654
#endif
654655

655656
static void M105();
@@ -699,8 +700,9 @@ class GcodeSuite {
699700
#endif
700701

701702
#if HAS_HEATED_BED
702-
static void M140();
703-
static void M190();
703+
static void M140_M190(const bool isM190);
704+
FORCE_INLINE static void M140() { M140_M190(false); }
705+
FORCE_INLINE static void M190() { M140_M190(true); }
704706
#endif
705707

706708
#if HAS_HEATED_CHAMBER

Marlin/src/gcode/temp/M104_M109.cpp

+9-69
Original file line numberDiff line numberDiff line change
@@ -51,89 +51,29 @@
5151

5252
/**
5353
* M104: Set Hotend Temperature target and return immediately
54-
*
55-
* Parameters:
56-
* I<preset> : Material Preset index (if material presets are defined)
57-
* T<index> : Tool index. If omitted, applies to the active tool
58-
* S<target> : The target temperature in current units
59-
*/
60-
void GcodeSuite::M104() {
61-
62-
if (DEBUGGING(DRYRUN)) return;
63-
64-
#if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
65-
constexpr int8_t target_extruder = 0;
66-
#else
67-
const int8_t target_extruder = get_target_extruder_from_command();
68-
if (target_extruder < 0) return;
69-
#endif
70-
71-
bool got_temp = false;
72-
celsius_t temp = 0;
73-
74-
// Accept 'I' if temperature presets are defined
75-
#if PREHEAT_COUNT
76-
got_temp = parser.seenval('I');
77-
if (got_temp) {
78-
const uint8_t index = parser.value_byte();
79-
temp = ui.material_preset[_MIN(index, PREHEAT_COUNT - 1)].hotend_temp;
80-
}
81-
#endif
82-
83-
// If no 'I' get the temperature from 'S'
84-
if (!got_temp) {
85-
got_temp = parser.seenval('S');
86-
if (got_temp) temp = parser.value_celsius();
87-
}
88-
89-
if (got_temp) {
90-
#if ENABLED(SINGLENOZZLE_STANDBY_TEMP)
91-
thermalManager.singlenozzle_temp[target_extruder] = temp;
92-
if (target_extruder != active_extruder) return;
93-
#endif
94-
thermalManager.setTargetHotend(temp, target_extruder);
95-
96-
#if ENABLED(DUAL_X_CARRIAGE)
97-
if (idex_is_duplicating() && target_extruder == 0)
98-
thermalManager.setTargetHotend(temp ? temp + duplicate_extruder_temp_offset : 0, 1);
99-
#endif
100-
101-
#if ENABLED(PRINTJOB_TIMER_AUTOSTART)
102-
/**
103-
* Stop the timer at the end of print. Start is managed by 'heat and wait' M109.
104-
* Hotends use EXTRUDE_MINTEMP / 2 to allow nozzles to be put into hot standby
105-
* mode, for instance in a dual extruder setup, without affecting the running
106-
* print timer.
107-
*/
108-
thermalManager.auto_job_check_timer(false, true);
109-
#endif
110-
}
111-
112-
TERN_(AUTOTEMP, planner.autotemp_M104_M109());
113-
}
114-
115-
/**
11654
* M109: Set Hotend Temperature target and wait
11755
*
11856
* Parameters
11957
* I<preset> : Material Preset index (if material presets are defined)
12058
* T<index> : Tool index. If omitted, applies to the active tool
121-
* S<target> : The target temperature in current units. Wait for heating only.
122-
* R<target> : The target temperature in current units. Wait for heating and cooling.
59+
* S<target> : The target temperature in current units. For M109, only wait when heating up.
12360
*
12461
* With AUTOTEMP...
12562
* F<factor> : Autotemp Scaling Factor. Set non-zero to enable Auto-temp.
12663
* S<min> : Minimum temperature, in current units.
12764
* B<max> : Maximum temperature, in current units.
12865
*
66+
* M109 Parameters
67+
* R<target> : The target temperature in current units. Wait for heating and cooling.
68+
*
12969
* Examples
130-
* M109 S100 : Set target to 100°. Wait until the hotend is at or above 100°.
70+
* M104 S100 : Set target to 100° and return.
13171
* M109 R150 : Set target to 150°. Wait until the hotend gets close to 150°.
13272
*
13373
* With PRINTJOB_TIMER_AUTOSTART turning on heaters will start the print job timer
13474
* (used by printingIsActive, etc.) and turning off heaters will stop the timer.
13575
*/
136-
void GcodeSuite::M109() {
76+
void GcodeSuite::M104_M109(const bool isM109) {
13777

13878
if (DEBUGGING(DRYRUN)) return;
13979

@@ -160,7 +100,7 @@ void GcodeSuite::M109() {
160100
bool no_wait_for_cooling = false;
161101
if (!got_temp) {
162102
no_wait_for_cooling = parser.seenval('S');
163-
got_temp = no_wait_for_cooling || parser.seenval('R');
103+
got_temp = no_wait_for_cooling || (isM109 && parser.seenval('R'));
164104
if (got_temp) temp = parser.value_celsius();
165105
}
166106

@@ -182,7 +122,7 @@ void GcodeSuite::M109() {
182122
* standby mode, (e.g., in a dual extruder setup) without affecting
183123
* the running print timer.
184124
*/
185-
thermalManager.auto_job_check_timer(true, true);
125+
thermalManager.auto_job_check_timer(isM109, true);
186126
#endif
187127

188128
#if HAS_STATUS_MESSAGE
@@ -193,7 +133,7 @@ void GcodeSuite::M109() {
193133

194134
TERN_(AUTOTEMP, planner.autotemp_M104_M109());
195135

196-
if (got_temp)
136+
if (isM109 && got_temp)
197137
(void)thermalManager.wait_for_hotend(target_extruder, no_wait_for_cooling);
198138
}
199139

Marlin/src/gcode/temp/M140_M190.cpp

+12-45
Original file line numberDiff line numberDiff line change
@@ -35,62 +35,28 @@
3535
#include "../../lcd/marlinui.h"
3636

3737
/**
38-
* M140: Set bed temperature
38+
* M140 - Set Bed Temperature target and return immediately
39+
* M190 - Set Bed Temperature target and wait
3940
*
4041
* I<index> : Preset index (if material presets are defined)
4142
* S<target> : The target temperature in current units
42-
*/
43-
void GcodeSuite::M140() {
44-
if (DEBUGGING(DRYRUN)) return;
45-
46-
bool got_temp = false;
47-
celsius_t temp = 0;
48-
49-
// Accept 'I' if temperature presets are defined
50-
#if PREHEAT_COUNT
51-
got_temp = parser.seenval('I');
52-
if (got_temp) {
53-
const uint8_t index = parser.value_byte();
54-
temp = ui.material_preset[_MIN(index, PREHEAT_COUNT - 1)].bed_temp;
55-
}
56-
#endif
57-
58-
// If no 'I' get the temperature from 'S'
59-
if (!got_temp) {
60-
got_temp = parser.seenval('S');
61-
if (got_temp) temp = parser.value_celsius();
62-
}
63-
64-
if (got_temp) {
65-
thermalManager.setTargetBed(temp);
66-
67-
#if ENABLED(PRINTJOB_TIMER_AUTOSTART)
68-
/**
69-
* Stop the timer at the end of print. Hotend, bed target, and chamber
70-
* temperatures need to be set below mintemp. Order of M140, M104, and M141
71-
* at the end of the print does not matter.
72-
*/
73-
thermalManager.auto_job_check_timer(false, true);
74-
#endif
75-
}
76-
}
77-
78-
/**
79-
* M190 - Set Bed Temperature target and wait
8043
*
81-
* Parameters:
44+
* Parameters
8245
* I<index> : Preset index (if material presets are defined)
8346
* S<target> : The target temperature in current units. Wait for heating only.
47+
*
48+
* M190 Parameters
8449
* R<target> : The target temperature in current units. Wait for heating and cooling.
8550
*
86-
* Examples:
87-
* M190 S60 : Set target to 60°. Wait until the bed is at or above 60°.
51+
* Examples
52+
* M140 S60 : Set target to 60° and return right away.
8853
* M190 R40 : Set target to 40°. Wait until the bed gets close to 40°.
8954
*
9055
* With PRINTJOB_TIMER_AUTOSTART turning on heaters will start the print job timer
9156
* (used by printingIsActive, etc.) and turning off heaters will stop the timer.
9257
*/
93-
void GcodeSuite::M190() {
58+
void GcodeSuite::M140_M190(const bool isM190) {
59+
9460
if (DEBUGGING(DRYRUN)) return;
9561

9662
bool got_temp = false;
@@ -109,7 +75,7 @@ void GcodeSuite::M190() {
10975
bool no_wait_for_cooling = false;
11076
if (!got_temp) {
11177
no_wait_for_cooling = parser.seenval('S');
112-
got_temp = no_wait_for_cooling || parser.seenval('R');
78+
got_temp = no_wait_for_cooling || (isM190 && parser.seenval('R'));
11379
if (got_temp) temp = parser.value_celsius();
11480
}
11581

@@ -121,7 +87,8 @@ void GcodeSuite::M190() {
12187

12288
ui.set_status_P(thermalManager.isHeatingBed() ? GET_TEXT(MSG_BED_HEATING) : GET_TEXT(MSG_BED_COOLING));
12389

124-
thermalManager.wait_for_bed(no_wait_for_cooling);
90+
if (isM190)
91+
thermalManager.wait_for_bed(no_wait_for_cooling);
12592
}
12693

12794
#endif // HAS_HEATED_BED

0 commit comments

Comments
 (0)