Optimize target_extruder, ignore T with mixing (#12432)

* Optimize target_extruder, ignore T with mixing
* Give G-code Tn parity with tool_change
This commit is contained in:
Scott Lahteine 2018-11-14 17:33:04 -06:00 committed by GitHub
parent 5e586a6b39
commit d2bb53702a
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 150 additions and 138 deletions

View file

@ -34,7 +34,8 @@
*/ */
void GcodeSuite::M200() { 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')) { if (parser.seen('D')) {
// setting any extruder filament size disables volumetric on the assumption that // setting any extruder filament size disables volumetric on the assumption that
@ -55,11 +56,12 @@
*/ */
void GcodeSuite::M201() { void GcodeSuite::M201() {
GET_TARGET_EXTRUDER(); const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
LOOP_XYZE(i) { LOOP_XYZE(i) {
if (parser.seen(axis_codes[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); planner.settings.max_acceleration_mm_per_s2[a] = parser.value_axis_units((AxisEnum)a);
} }
} }
@ -74,11 +76,12 @@ void GcodeSuite::M201() {
*/ */
void GcodeSuite::M203() { void GcodeSuite::M203() {
GET_TARGET_EXTRUDER(); const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
LOOP_XYZE(i) LOOP_XYZE(i)
if (parser.seen(axis_codes[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); planner.settings.max_feedrate_mm_s[a] = parser.value_axis_units((AxisEnum)a);
} }
} }

View file

@ -40,7 +40,9 @@
* Z<zoffset> * Z<zoffset>
*/ */
void GcodeSuite::M218() { 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('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(); if (parser.seenval('Y')) hotend_offset[Y_AXIS][target_extruder] = parser.value_linear_units();

View file

@ -27,7 +27,10 @@
* M221: Set extrusion percentage (M221 T0 S95) * M221: Set extrusion percentage (M221 T0 S95)
*/ */
void GcodeSuite::M221() { 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')) { if (parser.seenval('S')) {
planner.flow_percentage[target_extruder] = parser.value_int(); planner.flow_percentage[target_extruder] = parser.value_int();
planner.refresh_e_factor(target_extruder); planner.refresh_e_factor(target_extruder);

View file

@ -31,21 +31,22 @@
*/ */
void GcodeSuite::M92() { void GcodeSuite::M92() {
GET_TARGET_EXTRUDER(); const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
LOOP_XYZE(i) { LOOP_XYZE(i) {
if (parser.seen(axis_codes[i])) { if (parser.seen(axis_codes[i])) {
if (i == E_AXIS) { 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) { 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)) #if HAS_CLASSIC_JERK && (DISABLED(JUNCTION_DEVIATION) || DISABLED(LIN_ADVANCE))
planner.max_jerk[E_AXIS] *= factor; planner.max_jerk[E_AXIS] *= factor;
#endif #endif
planner.settings.max_feedrate_mm_s[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 + 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 { else {
planner.settings.axis_steps_per_mm[i] = parser.value_per_axis_units((AxisEnum)i); planner.settings.axis_steps_per_mm[i] = parser.value_per_axis_units((AxisEnum)i);

View file

@ -33,27 +33,27 @@
* F[units/min] Set the movement feedrate * F[units/min] Set the movement feedrate
* S1 Don't move the tool in XY after change * 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 ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR(">>> T(", tmp_extruder); SERIAL_ECHOPAIR(">>> T(", tool_index);
SERIAL_CHAR(')'); SERIAL_CHAR(')');
SERIAL_EOL(); SERIAL_EOL();
DEBUG_POS("BEFORE", current_position); DEBUG_POS("BEFORE", current_position);
} }
#endif #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( tool_change(
tmp_extruder, tool_index,
MMM_TO_MMS(parser.linearval('F')), MMM_TO_MMS(parser.linearval('F')),
(tmp_extruder == active_extruder) || parser.boolval('S') (tool_index == active_extruder) || parser.boolval('S')
); );
#endif #endif

View file

@ -54,7 +54,8 @@
void GcodeSuite::M600() { void GcodeSuite::M600() {
point_t park_point = NOZZLE_PARK_POINT; 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) #if ENABLED(DUAL_X_CARRIAGE)
int8_t DXC_ext = target_extruder; int8_t DXC_ext = target_extruder;

View file

@ -43,7 +43,8 @@
*/ */
void GcodeSuite::M603() { 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 // Unload length
if (parser.seen('U')) { if (parser.seen('U')) {

View file

@ -55,7 +55,9 @@ void GcodeSuite::M701() {
if (axis_unhomed_error()) park_point.z = 0; if (axis_unhomed_error()) park_point.z = 0;
#endif #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 // Z axis lift
if (parser.seenval('Z')) park_point.z = parser.linearval('Z'); if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
@ -121,7 +123,8 @@ void GcodeSuite::M702() {
if (axis_unhomed_error()) park_point.z = 0; if (axis_unhomed_error()) park_point.z = 0;
#endif #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 // Z axis lift
if (parser.seenval('Z')) park_point.z = parser.linearval('Z'); if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
@ -154,8 +157,8 @@ void GcodeSuite::M702() {
#endif #endif
{ {
// Unload length // Unload length
const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) : const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS)
fc_settings[target_extruder].unload_length); : fc_settings[target_extruder].unload_length);
unload_filament(unload_length, true, ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT); unload_filament(unload_length, true, ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT);
} }

View file

@ -73,7 +73,8 @@ void GcodeSuite::M906() {
#endif #endif
break; break;
case E_AXIS: { 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) { switch (target_extruder) {
#if AXIS_IS_TMC(E0) #if AXIS_IS_TMC(E0)
case 0: TMC_SET_CURRENT(E0); break; case 0: TMC_SET_CURRENT(E0); break;

View file

@ -232,7 +232,8 @@
#endif #endif
break; break;
case E_AXIS: { 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) { switch (target_extruder) {
#if AXIS_HAS_STEALTHCHOP(E0) #if AXIS_HAS_STEALTHCHOP(E0)
case 0: TMC_SET_PWMTHRS_E(0); break; case 0: TMC_SET_PWMTHRS_E(0); break;

View file

@ -38,7 +38,6 @@ GcodeSuite gcode;
#include "../Marlin.h" // for idle() and suspend_auto_report #include "../Marlin.h" // for idle() and suspend_auto_report
uint8_t GcodeSuite::target_extruder;
millis_t GcodeSuite::previous_move_ms; millis_t GcodeSuite::previous_move_ms;
bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES; bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES;
@ -58,11 +57,10 @@ bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES;
#endif #endif
/** /**
* Set target_extruder from the T parameter or the active_extruder * Get the target extruder from the T parameter or the active_extruder
* * Return -1 if the T parameter is out of range
* Returns TRUE if the target is invalid
*/ */
bool GcodeSuite::get_target_extruder_from_command() { int8_t GcodeSuite::get_target_extruder_from_command() {
if (parser.seenval('T')) { if (parser.seenval('T')) {
const int8_t e = parser.value_byte(); const int8_t e = parser.value_byte();
if (e >= EXTRUDERS) { if (e >= EXTRUDERS) {
@ -70,14 +68,11 @@ bool GcodeSuite::get_target_extruder_from_command() {
SERIAL_CHAR('M'); SERIAL_CHAR('M');
SERIAL_ECHO(parser.codenum); SERIAL_ECHO(parser.codenum);
SERIAL_ECHOLNPAIR(" " MSG_INVALID_EXTRUDER " ", e); SERIAL_ECHOLNPAIR(" " MSG_INVALID_EXTRUDER " ", e);
return true; return -1;
} }
target_extruder = e; return e;
} }
else return active_extruder;
target_extruder = active_extruder;
return false;
} }
/** /**
@ -539,7 +534,9 @@ void GcodeSuite::process_parsed_command(
case 302: M302(); break; // M302: Allow cold extrudes (set the minimum extrude temperature) case 302: M302(); break; // M302: Allow cold extrudes (set the minimum extrude temperature)
#endif #endif
case 303: M303(); break; // M303: PID autotune #if HAS_PID_HEATING
case 303: M303(); break; // M303: PID autotune
#endif
#if ENABLED(MORGAN_SCARA) #if ENABLED(MORGAN_SCARA)
case 360: if (M360()) return; break; // M360: SCARA Theta pos1 case 360: if (M360()) return; break; // M360: SCARA Theta pos1

View file

@ -267,8 +267,6 @@ public:
GcodeSuite() {} GcodeSuite() {}
static uint8_t target_extruder;
static bool axis_relative_modes[]; static bool axis_relative_modes[];
#if ENABLED(CNC_WORKSPACE_PLANES) #if ENABLED(CNC_WORKSPACE_PLANES)
@ -290,8 +288,9 @@ public:
static millis_t previous_move_ms; static millis_t previous_move_ms;
FORCE_INLINE static void reset_stepper_timeout() { previous_move_ms = millis(); } 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 get_destination_from_command();
static void process_parsed_command( static void process_parsed_command(
#if USE_EXECUTE_COMMANDS_IMMEDIATE #if USE_EXECUTE_COMMANDS_IMMEDIATE
const bool no_ok = false const bool no_ok = false
@ -306,17 +305,6 @@ public:
FORCE_INLINE static void home_all_axes() { G28(true); } 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) #if ENABLED(HOST_KEEPALIVE_FEATURE)
/** /**
* States for managing Marlin and host communication * States for managing Marlin and host communication
@ -669,7 +657,9 @@ private:
static void M302(); static void M302();
#endif #endif
static void M303(); #if HAS_PID_HEATING
static void M303();
#endif
#if ENABLED(PIDTEMPBED) #if ENABLED(PIDTEMPBED)
static void M304(); static void M304();
@ -832,7 +822,7 @@ private:
static void M999(); static void M999();
static void T(const uint8_t tmp_extruder); static void T(const uint8_t tool_index);
}; };

View file

@ -39,10 +39,15 @@
* M104: Set hot end temperature * M104: Set hot end temperature
*/ */
void GcodeSuite::M104() { void GcodeSuite::M104() {
if (get_target_extruder_from_command()) return;
if (DEBUGGING(DRYRUN)) 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')) { if (parser.seenval('S')) {
const int16_t temp = parser.value_celsius(); const int16_t temp = parser.value_celsius();
@ -82,9 +87,15 @@ void GcodeSuite::M104() {
*/ */
void GcodeSuite::M109() { void GcodeSuite::M109() {
if (get_target_extruder_from_command()) return;
if (DEBUGGING(DRYRUN)) 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'), const bool no_wait_for_cooling = parser.seenval('S'),
set_temp = no_wait_for_cooling || parser.seenval('R'); set_temp = no_wait_for_cooling || parser.seenval('R');
if (set_temp) { if (set_temp) {

View file

@ -31,7 +31,9 @@
* M105: Read hot end and bed temperature * M105: Read hot end and bed temperature
*/ */
void GcodeSuite::M105() { 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 #if NUM_SERIAL > 1
const int16_t port = command_queue_port[cmd_queue_index_r]; const int16_t port = command_queue_port[cmd_queue_index_r];
@ -39,9 +41,9 @@ void GcodeSuite::M105() {
#if HAS_TEMP_SENSOR #if HAS_TEMP_SENSOR
SERIAL_PROTOCOLPGM_P(port, MSG_OK); SERIAL_PROTOCOLPGM_P(port, MSG_OK);
thermalManager.print_heaterstates( thermalManager.print_heater_states(target_extruder
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
port , port
#endif #endif
); );
#else // !HAS_TEMP_SENSOR #else // !HAS_TEMP_SENSOR

View file

@ -20,6 +20,10 @@
* *
*/ */
#include "../../inc/MarlinConfig.h"
#if HAS_PID_HEATING
#include "../gcode.h" #include "../gcode.h"
#include "../../module/temperature.h" #include "../../module/temperature.h"
@ -32,26 +36,36 @@
* U<bool> with a non-zero value will apply the result to current settings * U<bool> with a non-zero value will apply the result to current settings
*/ */
void GcodeSuite::M303() { void GcodeSuite::M303() {
#if HAS_PID_HEATING
const int e = parser.intval('E'), c = parser.intval('C', 5);
const bool u = parser.boolval('U');
int16_t temp = parser.celsiusval('S', e < 0 ? 70 : 150); const int8_t e = parser.byteval('E');
if (WITHIN(e, 0, HOTENDS - 1)) if (!WITHIN(e, 0
target_extruder = e; #if ENABLED(PIDTEMPBED)
-1
#if DISABLED(BUSY_WHILE_HEATING)
KEEPALIVE_STATE(NOT_BUSY);
#endif #endif
,
thermalManager.PID_autotune(temp, e, c, u); #if ENABLED(PIDTEMP)
HOTENDS
#if DISABLED(BUSY_WHILE_HEATING)
KEEPALIVE_STATE(IN_HANDLER);
#endif #endif
#else -1
SERIAL_ERROR_START(); )) {
SERIAL_ERRORLNPGM(MSG_ERR_M303_DISABLED); SERIAL_ECHOLNPGM(MSG_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 ? 70 : 150);
#if DISABLED(BUSY_WHILE_HEATING)
KEEPALIVE_STATE(NOT_BUSY);
#endif
thermalManager.PID_autotune(temp, e, c, u);
#if DISABLED(BUSY_WHILE_HEATING)
KEEPALIVE_STATE(IN_HANDLER);
#endif #endif
} }
#endif // HAS_PID_HEATING

View file

@ -236,7 +236,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
* Alternately heat and cool the nozzle, observing its behavior to * Alternately heat and cool the nozzle, observing its behavior to
* determine the best PID values to achieve a stable temperature. * determine the best PID values to achieve a stable temperature.
*/ */
void Temperature::PID_autotune(const float &target, const int8_t hotend, const int8_t ncycles, const bool set_result/*=false*/) { void Temperature::PID_autotune(const float &target, const int8_t heater, const int8_t ncycles, const bool set_result/*=false*/) {
float current = 0.0; float current = 0.0;
int cycles = 0; int cycles = 0;
bool heating = true; bool heating = true;
@ -249,10 +249,10 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
float max = 0, min = 10000; float max = 0, min = 10000;
#if HAS_PID_FOR_BOTH #if HAS_PID_FOR_BOTH
#define GHV(B,H) (hotend < 0 ? (B) : (H)) #define GHV(B,H) (heater < 0 ? (B) : (H))
#define SHV(S,B,H) do{ if (hotend < 0) S##_bed = B; else S [hotend] = H; }while(0) #define SHV(S,B,H) do{ if (heater < 0) S##_bed = B; else S [heater] = H; }while(0)
#define ONHEATINGSTART() (hotend < 0 ? printerEventLEDs.onBedHeatingStart() : printerEventLEDs.onHotendHeatingStart()) #define ONHEATINGSTART() (heater < 0 ? printerEventLEDs.onBedHeatingStart() : printerEventLEDs.onHotendHeatingStart())
#define ONHEATING(S,C,T) do{ if (hotend < 0) printerEventLEDs.onBedHeating(S,C,T); else printerEventLEDs.onHotendHeating(S,C,T); }while(0) #define ONHEATING(S,C,T) do{ if (heater < 0) printerEventLEDs.onBedHeating(S,C,T); else printerEventLEDs.onHotendHeating(S,C,T); }while(0)
#elif ENABLED(PIDTEMPBED) #elif ENABLED(PIDTEMPBED)
#define GHV(B,H) B #define GHV(B,H) B
#define SHV(S,B,H) (S##_bed = B) #define SHV(S,B,H) (S##_bed = B)
@ -260,7 +260,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
#define ONHEATING(S,C,T) printerEventLEDs.onBedHeating(S,C,T) #define ONHEATING(S,C,T) printerEventLEDs.onBedHeating(S,C,T)
#else #else
#define GHV(B,H) H #define GHV(B,H) H
#define SHV(S,B,H) (S [hotend] = H) #define SHV(S,B,H) (S [heater] = H)
#define ONHEATINGSTART() printerEventLEDs.onHotendHeatingStart() #define ONHEATINGSTART() printerEventLEDs.onHotendHeatingStart()
#define ONHEATING(S,C,T) printerEventLEDs.onHotendHeating(S,C,T) #define ONHEATING(S,C,T) printerEventLEDs.onHotendHeating(S,C,T)
#endif #endif
@ -268,7 +268,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
#if WATCH_THE_BED || WATCH_HOTENDS #if WATCH_THE_BED || WATCH_HOTENDS
#define HAS_TP_BED (ENABLED(THERMAL_PROTECTION_BED) && ENABLED(PIDTEMPBED)) #define HAS_TP_BED (ENABLED(THERMAL_PROTECTION_BED) && ENABLED(PIDTEMPBED))
#if HAS_TP_BED && ENABLED(THERMAL_PROTECTION_HOTENDS) && ENABLED(PIDTEMP) #if HAS_TP_BED && ENABLED(THERMAL_PROTECTION_HOTENDS) && ENABLED(PIDTEMP)
#define GTV(B,H) (hotend < 0 ? (B) : (H)) #define GTV(B,H) (heater < 0 ? (B) : (H))
#elif HAS_TP_BED #elif HAS_TP_BED
#define GTV(B,H) (B) #define GTV(B,H) (B)
#else #else
@ -286,22 +286,6 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
next_auto_fan_check_ms = next_temp_ms + 2500UL; next_auto_fan_check_ms = next_temp_ms + 2500UL;
#endif #endif
#if ENABLED(PIDTEMP)
#define _TOP_HOTEND HOTENDS - 1
#else
#define _TOP_HOTEND -1
#endif
#if ENABLED(PIDTEMPBED)
#define _BOT_HOTEND -1
#else
#define _BOT_HOTEND 0
#endif
if (!WITHIN(hotend, _BOT_HOTEND, _TOP_HOTEND)) {
SERIAL_ECHOLNPGM(MSG_PID_BAD_EXTRUDER_NUM);
return;
}
SERIAL_ECHOLNPGM(MSG_PID_AUTOTUNE_START); SERIAL_ECHOLNPGM(MSG_PID_AUTOTUNE_START);
disable_all_heaters(); disable_all_heaters();
@ -310,7 +294,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
wait_for_heatup = true; // Can be interrupted with M108 wait_for_heatup = true; // Can be interrupted with M108
#if ENABLED(PRINTER_EVENT_LEDS) #if ENABLED(PRINTER_EVENT_LEDS)
const float start_temp = GHV(current_temperature_bed, current_temperature[hotend]); const float start_temp = GHV(current_temperature_bed, current_temperature[heater]);
LEDColor color = ONHEATINGSTART(); LEDColor color = ONHEATINGSTART();
#endif #endif
@ -323,7 +307,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
updateTemperaturesFromRawValues(); updateTemperaturesFromRawValues();
// Get the current temperature and constrain it // Get the current temperature and constrain it
current = GHV(current_temperature_bed, current_temperature[hotend]); current = GHV(current_temperature_bed, current_temperature[heater]);
NOLESS(max, current); NOLESS(max, current);
NOMORE(min, current); NOMORE(min, current);
@ -412,7 +396,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
// Report heater states every 2 seconds // Report heater states every 2 seconds
if (ELAPSED(ms, next_temp_ms)) { if (ELAPSED(ms, next_temp_ms)) {
#if HAS_TEMP_SENSOR #if HAS_TEMP_SENSOR
print_heaterstates(); print_heater_states(heater >= 0 ? heater : active_extruder);
SERIAL_EOL(); SERIAL_EOL();
#endif #endif
next_temp_ms = ms + 2000UL; next_temp_ms = ms + 2000UL;
@ -423,9 +407,9 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
#if WATCH_THE_BED && WATCH_HOTENDS #if WATCH_THE_BED && WATCH_HOTENDS
true true
#elif WATCH_HOTENDS #elif WATCH_HOTENDS
hotend >= 0 heater >= 0
#else #else
hotend < 0 heater < 0
#endif #endif
) { ) {
if (!heated) { // If not yet reached target... if (!heated) { // If not yet reached target...
@ -435,10 +419,10 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
if (current > watch_temp_target) heated = true; // - Flag if target temperature reached if (current > watch_temp_target) heated = true; // - Flag if target temperature reached
} }
else if (ELAPSED(ms, temp_change_ms)) // Watch timer expired else if (ELAPSED(ms, temp_change_ms)) // Watch timer expired
_temp_error(hotend, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, hotend)); _temp_error(heater, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, heater));
} }
else if (current < target - (MAX_OVERSHOOT_PID_AUTOTUNE)) // Heated, then temperature fell too far? else if (current < target - (MAX_OVERSHOOT_PID_AUTOTUNE)) // Heated, then temperature fell too far?
_temp_error(hotend, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, hotend)); _temp_error(heater, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, heater));
} }
#endif #endif
} // every 2 seconds } // every 2 seconds
@ -477,15 +461,15 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
}while(0) }while(0)
#define _SET_EXTRUDER_PID() do { \ #define _SET_EXTRUDER_PID() do { \
PID_PARAM(Kp, hotend) = tune_pid.Kp; \ PID_PARAM(Kp, heater) = tune_pid.Kp; \
PID_PARAM(Ki, hotend) = scalePID_i(tune_pid.Ki); \ PID_PARAM(Ki, heater) = scalePID_i(tune_pid.Ki); \
PID_PARAM(Kd, hotend) = scalePID_d(tune_pid.Kd); \ PID_PARAM(Kd, heater) = scalePID_d(tune_pid.Kd); \
updatePID(); }while(0) updatePID(); }while(0)
// Use the result? (As with "M303 U1") // Use the result? (As with "M303 U1")
if (set_result) { if (set_result) {
#if HAS_PID_FOR_BOTH #if HAS_PID_FOR_BOTH
if (hotend < 0) _SET_BED_PID(); else _SET_EXTRUDER_PID(); if (heater < 0) _SET_BED_PID(); else _SET_EXTRUDER_PID();
#elif ENABLED(PIDTEMP) #elif ENABLED(PIDTEMP)
_SET_EXTRUDER_PID(); _SET_EXTRUDER_PID();
#else #else
@ -575,13 +559,13 @@ int Temperature::getHeaterPower(const int heater) {
// //
// Temperature Error Handlers // Temperature Error Handlers
// //
void Temperature::_temp_error(const int8_t e, PGM_P const serial_msg, PGM_P const lcd_msg) { void Temperature::_temp_error(const int8_t heater, PGM_P const serial_msg, PGM_P const lcd_msg) {
static bool killed = false; static bool killed = false;
if (IsRunning()) { if (IsRunning()) {
SERIAL_ERROR_START(); SERIAL_ERROR_START();
serialprintPGM(serial_msg); serialprintPGM(serial_msg);
SERIAL_ERRORPGM(MSG_STOPPED_HEATER); SERIAL_ERRORPGM(MSG_STOPPED_HEATER);
if (e >= 0) SERIAL_ERRORLN((int)e); else SERIAL_ERRORLNPGM(MSG_HEATER_BED); if (heater >= 0) SERIAL_ERRORLN((int)heater); else SERIAL_ERRORLNPGM(MSG_HEATER_BED);
} }
#if DISABLED(BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE) #if DISABLED(BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE)
if (!killed) { if (!killed) {
@ -594,12 +578,12 @@ void Temperature::_temp_error(const int8_t e, PGM_P const serial_msg, PGM_P cons
#endif #endif
} }
void Temperature::max_temp_error(const int8_t e) { void Temperature::max_temp_error(const int8_t heater) {
_temp_error(e, PSTR(MSG_T_MAXTEMP), TEMP_ERR_PSTR(MSG_ERR_MAXTEMP, e)); _temp_error(heater, PSTR(MSG_T_MAXTEMP), TEMP_ERR_PSTR(MSG_ERR_MAXTEMP, heater));
} }
void Temperature::min_temp_error(const int8_t e) { void Temperature::min_temp_error(const int8_t heater) {
_temp_error(e, PSTR(MSG_T_MINTEMP), TEMP_ERR_PSTR(MSG_ERR_MINTEMP, e)); _temp_error(heater, PSTR(MSG_T_MINTEMP), TEMP_ERR_PSTR(MSG_ERR_MINTEMP, heater));
} }
float Temperature::get_pid_output(const int8_t e) { float Temperature::get_pid_output(const int8_t e) {
@ -2346,15 +2330,15 @@ void Temperature::isr() {
delay(2); delay(2);
} }
void Temperature::print_heaterstates( void Temperature::print_heater_states(const uint8_t target_extruder
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
const int8_t port , const int8_t port
#endif #endif
) { ) {
#if HAS_TEMP_HOTEND #if HAS_TEMP_HOTEND
print_heater_state(degHotend(gcode.target_extruder), degTargetHotend(gcode.target_extruder) print_heater_state(degHotend(target_extruder), degTargetHotend(target_extruder)
#if ENABLED(SHOW_TEMP_ADC_VALUES) #if ENABLED(SHOW_TEMP_ADC_VALUES)
, rawHotendTemp(gcode.target_extruder) , rawHotendTemp(target_extruder)
#endif #endif
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
, port , port
@ -2392,7 +2376,7 @@ void Temperature::isr() {
); );
#endif #endif
SERIAL_PROTOCOLPGM_P(port, " @:"); SERIAL_PROTOCOLPGM_P(port, " @:");
SERIAL_PROTOCOL_P(port, getHeaterPower(gcode.target_extruder)); SERIAL_PROTOCOL_P(port, getHeaterPower(target_extruder));
#if HAS_HEATED_BED #if HAS_HEATED_BED
SERIAL_PROTOCOLPGM_P(port, " B@:"); SERIAL_PROTOCOLPGM_P(port, " B@:");
SERIAL_PROTOCOL_P(port, getHeaterPower(-1)); SERIAL_PROTOCOL_P(port, getHeaterPower(-1));
@ -2414,7 +2398,7 @@ void Temperature::isr() {
void Temperature::auto_report_temperatures() { void Temperature::auto_report_temperatures() {
if (auto_report_temp_interval && ELAPSED(millis(), next_temp_report_ms)) { if (auto_report_temp_interval && ELAPSED(millis(), next_temp_report_ms)) {
next_temp_report_ms = millis() + 1000UL * auto_report_temp_interval; next_temp_report_ms = millis() + 1000UL * auto_report_temp_interval;
print_heaterstates(); print_heater_states(active_extruder);
SERIAL_EOL(); SERIAL_EOL();
} }
} }
@ -2480,9 +2464,9 @@ void Temperature::isr() {
} }
now = millis(); now = millis();
if (ELAPSED(now, next_temp_ms)) { //Print temp & remaining time every 1s while waiting if (ELAPSED(now, next_temp_ms)) { // Print temp & remaining time every 1s while waiting
next_temp_ms = now + 1000UL; next_temp_ms = now + 1000UL;
print_heaterstates(); print_heater_states(target_extruder);
#if TEMP_RESIDENCY_TIME > 0 #if TEMP_RESIDENCY_TIME > 0
SERIAL_PROTOCOLPGM(" W:"); SERIAL_PROTOCOLPGM(" W:");
if (residency_start_ms) if (residency_start_ms)
@ -2587,8 +2571,6 @@ void Temperature::isr() {
KEEPALIVE_STATE(NOT_BUSY); KEEPALIVE_STATE(NOT_BUSY);
#endif #endif
gcode.target_extruder = active_extruder; // for print_heaterstates
#if ENABLED(PRINTER_EVENT_LEDS) #if ENABLED(PRINTER_EVENT_LEDS)
const float start_temp = degBed(); const float start_temp = degBed();
printerEventLEDs.onBedHeatingStart(); printerEventLEDs.onBedHeatingStart();
@ -2607,7 +2589,7 @@ void Temperature::isr() {
now = millis(); now = millis();
if (ELAPSED(now, next_temp_ms)) { //Print Temp Reading every 1 second while heating up. if (ELAPSED(now, next_temp_ms)) { //Print Temp Reading every 1 second while heating up.
next_temp_ms = now + 1000UL; next_temp_ms = now + 1000UL;
print_heaterstates(); print_heater_states(active_extruder);
#if TEMP_BED_RESIDENCY_TIME > 0 #if TEMP_BED_RESIDENCY_TIME > 0
SERIAL_PROTOCOLPGM(" W:"); SERIAL_PROTOCOLPGM(" W:");
if (residency_start_ms) if (residency_start_ms)

View file

@ -601,9 +601,9 @@ class Temperature {
#endif // HEATER_IDLE_HANDLER #endif // HEATER_IDLE_HANDLER
#if HAS_TEMP_SENSOR #if HAS_TEMP_SENSOR
static void print_heaterstates( static void print_heater_states(const uint8_t target_extruder
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
const int8_t port = -1 , const int8_t port = -1
#endif #endif
); );
#if ENABLED(AUTO_REPORT_TEMPERATURES) #if ENABLED(AUTO_REPORT_TEMPERATURES)

View file

@ -500,8 +500,8 @@ inline void invalid_extruder_error(const uint8_t e) {
void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool no_move/*=false*/) { void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool no_move/*=false*/) {
#if ENABLED(MIXING_EXTRUDER) #if ENABLED(MIXING_EXTRUDER)
UNUSED(fr_mm_s); UNUSED(fr_mm_s); UNUSED(no_move);
UNUSED(no_move);
if (tmp_extruder >= MIXING_VIRTUAL_TOOLS) if (tmp_extruder >= MIXING_VIRTUAL_TOOLS)
return invalid_extruder_error(tmp_extruder); return invalid_extruder_error(tmp_extruder);
@ -512,12 +512,12 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
#elif EXTRUDERS < 2 #elif EXTRUDERS < 2
UNUSED(fr_mm_s); UNUSED(fr_mm_s); UNUSED(no_move);
UNUSED(no_move);
if (tmp_extruder) invalid_extruder_error(tmp_extruder); if (tmp_extruder) invalid_extruder_error(tmp_extruder);
return; return;
#else #else // EXTRUDERS > 1
planner.synchronize(); planner.synchronize();
@ -751,5 +751,5 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
SERIAL_ECHO_START(); SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, int(active_extruder)); SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, int(active_extruder));
#endif // EXTRUDERS <= 1 && (!MIXING_EXTRUDER || MIXING_VIRTUAL_TOOLS <= 1) #endif // EXTRUDERS > 1
} }