Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Marlin/src/gcode/config/M200-M205.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
*/
void GcodeSuite::M200() {

if (get_target_extruder_from_command()) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

if (parser.seen('D')) {
// setting any extruder filament size disables volumetric on the assumption that
Expand All @@ -55,11 +56,12 @@
*/
void GcodeSuite::M201() {

GET_TARGET_EXTRUDER();
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

LOOP_XYZE(i) {
if (parser.seen(axis_codes[i])) {
const uint8_t a = i + (i == E_AXIS ? TARGET_EXTRUDER : 0);
const uint8_t a = (i == E_AXIS ? E_AXIS_N(target_extruder) : i);
planner.settings.max_acceleration_mm_per_s2[a] = parser.value_axis_units((AxisEnum)a);
}
}
Expand All @@ -74,11 +76,12 @@ void GcodeSuite::M201() {
*/
void GcodeSuite::M203() {

GET_TARGET_EXTRUDER();
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

LOOP_XYZE(i)
if (parser.seen(axis_codes[i])) {
const uint8_t a = i + (i == E_AXIS ? TARGET_EXTRUDER : 0);
const uint8_t a = (i == E_AXIS ? E_AXIS_N(target_extruder) : i);
planner.settings.max_feedrate_mm_s[a] = parser.value_axis_units((AxisEnum)a);
}
}
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/gcode/config/M218.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
* Z<zoffset>
*/
void GcodeSuite::M218() {
if (get_target_extruder_from_command() || target_extruder == 0) return;

const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

if (parser.seenval('X')) hotend_offset[X_AXIS][target_extruder] = parser.value_linear_units();
if (parser.seenval('Y')) hotend_offset[Y_AXIS][target_extruder] = parser.value_linear_units();
Expand Down
5 changes: 4 additions & 1 deletion Marlin/src/gcode/config/M221.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
* M221: Set extrusion percentage (M221 T0 S95)
*/
void GcodeSuite::M221() {
if (get_target_extruder_from_command()) return;

const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

if (parser.seenval('S')) {
planner.flow_percentage[target_extruder] = parser.value_int();
planner.refresh_e_factor(target_extruder);
Expand Down
13 changes: 7 additions & 6 deletions Marlin/src/gcode/config/M92.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@
*/
void GcodeSuite::M92() {

GET_TARGET_EXTRUDER();
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

LOOP_XYZE(i) {
if (parser.seen(axis_codes[i])) {
if (i == E_AXIS) {
const float value = parser.value_per_axis_units((AxisEnum)(E_AXIS + TARGET_EXTRUDER));
const float value = parser.value_per_axis_units((AxisEnum)(E_AXIS_N(target_extruder)));
if (value < 20) {
float factor = planner.settings.axis_steps_per_mm[E_AXIS + TARGET_EXTRUDER] / value; // increase e constants if M92 E14 is given for netfab.
float factor = planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] / value; // increase e constants if M92 E14 is given for netfab.
#if HAS_CLASSIC_JERK && (DISABLED(JUNCTION_DEVIATION) || DISABLED(LIN_ADVANCE))
planner.max_jerk[E_AXIS] *= factor;
#endif
planner.settings.max_feedrate_mm_s[E_AXIS + TARGET_EXTRUDER] *= factor;
planner.max_acceleration_steps_per_s2[E_AXIS + TARGET_EXTRUDER] *= factor;
planner.settings.max_feedrate_mm_s[E_AXIS_N(target_extruder)] *= factor;
planner.max_acceleration_steps_per_s2[E_AXIS_N(target_extruder)] *= factor;
}
planner.settings.axis_steps_per_mm[E_AXIS + TARGET_EXTRUDER] = value;
planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] = value;
}
else {
planner.settings.axis_steps_per_mm[i] = parser.value_per_axis_units((AxisEnum)i);
Expand Down
14 changes: 7 additions & 7 deletions Marlin/src/gcode/control/T.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,27 @@
* F[units/min] Set the movement feedrate
* S1 Don't move the tool in XY after change
*/
void GcodeSuite::T(const uint8_t tmp_extruder) {
void GcodeSuite::T(const uint8_t tool_index) {

#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR(">>> T(", tmp_extruder);
SERIAL_ECHOPAIR(">>> T(", tool_index);
SERIAL_CHAR(')');
SERIAL_EOL();
DEBUG_POS("BEFORE", current_position);
}
#endif

#if HOTENDS == 1 || (ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1)
#if EXTRUDERS < 2

tool_change(tmp_extruder);
tool_change(tool_index);

#elif HOTENDS > 1
#else

tool_change(
tmp_extruder,
tool_index,
MMM_TO_MMS(parser.linearval('F')),
(tmp_extruder == active_extruder) || parser.boolval('S')
(tool_index == active_extruder) || parser.boolval('S')
);

#endif
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/gcode/feature/pause/M600.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
void GcodeSuite::M600() {
point_t park_point = NOZZLE_PARK_POINT;

if (get_target_extruder_from_command()) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

#if ENABLED(DUAL_X_CARRIAGE)
int8_t DXC_ext = target_extruder;
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/gcode/feature/pause/M603.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
*/
void GcodeSuite::M603() {

if (get_target_extruder_from_command()) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

// Unload length
if (parser.seen('U')) {
Expand Down
11 changes: 7 additions & 4 deletions Marlin/src/gcode/feature/pause/M701_M702.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ void GcodeSuite::M701() {
if (axis_unhomed_error()) park_point.z = 0;
#endif

if (get_target_extruder_from_command()) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;


// Z axis lift
if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
Expand Down Expand Up @@ -121,7 +123,8 @@ void GcodeSuite::M702() {
if (axis_unhomed_error()) park_point.z = 0;
#endif

if (get_target_extruder_from_command()) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

// Z axis lift
if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
Expand Down Expand Up @@ -154,8 +157,8 @@ void GcodeSuite::M702() {
#endif
{
// Unload length
const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) :
fc_settings[target_extruder].unload_length);
const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS)
: fc_settings[target_extruder].unload_length);

unload_filament(unload_length, true, ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT);
}
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/gcode/feature/trinamic/M906.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ void GcodeSuite::M906() {
#endif
break;
case E_AXIS: {
if (get_target_extruder_from_command()) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
switch (target_extruder) {
#if AXIS_IS_TMC(E0)
case 0: TMC_SET_CURRENT(E0); break;
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/gcode/feature/trinamic/M911-M915.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@
#endif
break;
case E_AXIS: {
if (get_target_extruder_from_command()) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
switch (target_extruder) {
#if AXIS_HAS_STEALTHCHOP(E0)
case 0: TMC_SET_PWMTHRS_E(0); break;
Expand Down
21 changes: 9 additions & 12 deletions Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ GcodeSuite gcode;

#include "../Marlin.h" // for idle() and suspend_auto_report

uint8_t GcodeSuite::target_extruder;
millis_t GcodeSuite::previous_move_ms;

bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES;
Expand All @@ -58,26 +57,22 @@ bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES;
#endif

/**
* Set target_extruder from the T parameter or the active_extruder
*
* Returns TRUE if the target is invalid
* Get the target extruder from the T parameter or the active_extruder
* Return -1 if the T parameter is out of range
*/
bool GcodeSuite::get_target_extruder_from_command() {
int8_t GcodeSuite::get_target_extruder_from_command() {
if (parser.seenval('T')) {
const int8_t e = parser.value_byte();
if (e >= EXTRUDERS) {
SERIAL_ECHO_START();
SERIAL_CHAR('M');
SERIAL_ECHO(parser.codenum);
SERIAL_ECHOLNPAIR(" " MSG_INVALID_EXTRUDER " ", e);
return true;
return -1;
}
target_extruder = e;
return e;
}
else
target_extruder = active_extruder;

return false;
return active_extruder;
}

/**
Expand Down Expand Up @@ -539,7 +534,9 @@ void GcodeSuite::process_parsed_command(
case 302: M302(); break; // M302: Allow cold extrudes (set the minimum extrude temperature)
#endif

case 303: M303(); break; // M303: PID autotune
#if HAS_PID_HEATING
case 303: M303(); break; // M303: PID autotune
#endif

#if ENABLED(MORGAN_SCARA)
case 360: if (M360()) return; break; // M360: SCARA Theta pos1
Expand Down
22 changes: 6 additions & 16 deletions Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,6 @@ class GcodeSuite {

GcodeSuite() {}

static uint8_t target_extruder;

static bool axis_relative_modes[];

#if ENABLED(CNC_WORKSPACE_PLANES)
Expand All @@ -290,8 +288,9 @@ class GcodeSuite {
static millis_t previous_move_ms;
FORCE_INLINE static void reset_stepper_timeout() { previous_move_ms = millis(); }

static bool get_target_extruder_from_command();
static int8_t get_target_extruder_from_command();
static void get_destination_from_command();

static void process_parsed_command(
#if USE_EXECUTE_COMMANDS_IMMEDIATE
const bool no_ok = false
Expand All @@ -306,17 +305,6 @@ class GcodeSuite {

FORCE_INLINE static void home_all_axes() { G28(true); }

/**
* Multi-stepper support for M92, M201, M203
*/
#if ENABLED(DISTINCT_E_FACTORS)
#define GET_TARGET_EXTRUDER() if (gcode.get_target_extruder_from_command()) return
#define TARGET_EXTRUDER gcode.target_extruder
#else
#define GET_TARGET_EXTRUDER() NOOP
#define TARGET_EXTRUDER 0
#endif

#if ENABLED(HOST_KEEPALIVE_FEATURE)
/**
* States for managing Marlin and host communication
Expand Down Expand Up @@ -669,7 +657,9 @@ class GcodeSuite {
static void M302();
#endif

static void M303();
#if HAS_PID_HEATING
static void M303();
#endif

#if ENABLED(PIDTEMPBED)
static void M304();
Expand Down Expand Up @@ -832,7 +822,7 @@ class GcodeSuite {

static void M999();

static void T(const uint8_t tmp_extruder);
static void T(const uint8_t tool_index);

};

Expand Down
17 changes: 14 additions & 3 deletions Marlin/src/gcode/temperature/M104_M109.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@
* M104: Set hot end temperature
*/
void GcodeSuite::M104() {
if (get_target_extruder_from_command()) return;

if (DEBUGGING(DRYRUN)) return;

const uint8_t e = target_extruder;
#if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
constexpr int8_t e = 0;
#else
const int8_t e = get_target_extruder_from_command();
if (e < 0) return;
#endif

if (parser.seenval('S')) {
const int16_t temp = parser.value_celsius();
Expand Down Expand Up @@ -82,9 +87,15 @@ void GcodeSuite::M104() {
*/
void GcodeSuite::M109() {

if (get_target_extruder_from_command()) return;
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

const bool no_wait_for_cooling = parser.seenval('S'),
set_temp = no_wait_for_cooling || parser.seenval('R');
if (set_temp) {
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/gcode/temperature/M105.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@
* M105: Read hot end and bed temperature
*/
void GcodeSuite::M105() {
if (get_target_extruder_from_command()) return;

const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

#if NUM_SERIAL > 1
const int16_t port = command_queue_port[cmd_queue_index_r];
#endif

#if HAS_TEMP_SENSOR
SERIAL_PROTOCOLPGM_P(port, MSG_OK);
thermalManager.print_heaterstates(
thermalManager.print_heater_states(target_extruder
#if NUM_SERIAL > 1
port
, port
#endif
);
#else // !HAS_TEMP_SENSOR
Expand Down
Loading