From 06f401e7e5c74acf40967bb5eeca797f6cbd3793 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 28 May 2015 22:25:28 -0700 Subject: [PATCH 1/2] Redo "invalid extruder" to save 264 bytes - Use `setTargetedHotend` in `M200`, as with other commands that use `T` for the extruder - Synthesize the "invalid extruder" message, obviating several long strings --- Marlin/Marlin_main.cpp | 41 ++++++++++----------------- Marlin/configurator/config/language.h | 6 ---- Marlin/language.h | 6 ---- 3 files changed, 15 insertions(+), 38 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 4fa3e6584..509ec3066 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -3938,20 +3938,14 @@ inline void gcode_M121() { enable_endstops(false); } #endif // BLINKM /** - * M200: Set filament diameter and set E axis units to cubic millimeters (use S0 to set back to millimeters). - * T - * D + * M200: Set filament diameter and set E axis units to cubic millimeters + * + * T - Optional extruder number. Current extruder if omitted. + * D - Diameter of the filament. Use "D0" to set units back to millimeters. */ inline void gcode_M200() { - int tmp_extruder = active_extruder; - if (code_seen('T')) { - tmp_extruder = code_value_short(); - if (tmp_extruder >= EXTRUDERS) { - SERIAL_ECHO_START; - SERIAL_ECHO(MSG_M200_INVALID_EXTRUDER); - return; - } - } + + if (setTargetedHotend(200)) return; if (code_seen('D')) { float diameter = code_value(); @@ -3960,7 +3954,7 @@ inline void gcode_M200() { // for all extruders volumetric_enabled = (diameter != 0.0); if (volumetric_enabled) { - filament_size[tmp_extruder] = diameter; + filament_size[target_extruder] = diameter; // make sure all extruders have some sane value for the filament size for (int i=0; i= EXTRUDERS) { - SERIAL_ECHO_START; - switch(code){ + switch(code) { case 104: - SERIAL_ECHO(MSG_M104_INVALID_EXTRUDER); - break; case 105: - SERIAL_ECHO(MSG_M105_INVALID_EXTRUDER); - break; case 109: - SERIAL_ECHO(MSG_M109_INVALID_EXTRUDER); - break; case 218: - SERIAL_ECHO(MSG_M218_INVALID_EXTRUDER); - break; case 221: - SERIAL_ECHO(MSG_M221_INVALID_EXTRUDER); + case 200: + SERIAL_ECHO_START; + SERIAL_CHAR('M'); + SERIAL_ECHO(code); + SERIAL_ECHOPGM(" " MSG_INVALID_EXTRUDER " "); + SERIAL_ECHOLN(target_extruder); break; } - SERIAL_ECHOLN(target_extruder); return true; } } diff --git a/Marlin/configurator/config/language.h b/Marlin/configurator/config/language.h index 856bd58db..c709ce4d4 100644 --- a/Marlin/configurator/config/language.h +++ b/Marlin/configurator/config/language.h @@ -121,12 +121,6 @@ #define MSG_END_FILE_LIST "End file list" #define MSG_INVALID_EXTRUDER "Invalid extruder" #define MSG_INVALID_SOLENOID "Invalid solenoid" -#define MSG_M104_INVALID_EXTRUDER "M104 " MSG_INVALID_EXTRUDER " " -#define MSG_M105_INVALID_EXTRUDER "M105 " MSG_INVALID_EXTRUDER " " -#define MSG_M109_INVALID_EXTRUDER "M109 " MSG_INVALID_EXTRUDER " " -#define MSG_M200_INVALID_EXTRUDER "M200 " MSG_INVALID_EXTRUDER " " -#define MSG_M218_INVALID_EXTRUDER "M218 " MSG_INVALID_EXTRUDER " " -#define MSG_M221_INVALID_EXTRUDER "M221 " MSG_INVALID_EXTRUDER " " #define MSG_ERR_NO_THERMISTORS "No thermistors - no temperature" #define MSG_HEATING "Heating..." #define MSG_HEATING_COMPLETE "Heating done." diff --git a/Marlin/language.h b/Marlin/language.h index 22e113117..66f4144d4 100644 --- a/Marlin/language.h +++ b/Marlin/language.h @@ -122,12 +122,6 @@ #define MSG_END_FILE_LIST "End file list" #define MSG_INVALID_EXTRUDER "Invalid extruder" #define MSG_INVALID_SOLENOID "Invalid solenoid" -#define MSG_M104_INVALID_EXTRUDER "M104 " MSG_INVALID_EXTRUDER " " -#define MSG_M105_INVALID_EXTRUDER "M105 " MSG_INVALID_EXTRUDER " " -#define MSG_M109_INVALID_EXTRUDER "M109 " MSG_INVALID_EXTRUDER " " -#define MSG_M200_INVALID_EXTRUDER "M200 " MSG_INVALID_EXTRUDER " " -#define MSG_M218_INVALID_EXTRUDER "M218 " MSG_INVALID_EXTRUDER " " -#define MSG_M221_INVALID_EXTRUDER "M221 " MSG_INVALID_EXTRUDER " " #define MSG_ERR_NO_THERMISTORS "No thermistors - no temperature" #define MSG_HEATING "Heating..." #define MSG_HEATING_COMPLETE "Heating done." From be5236e839f8ae262129020a39693f20ce38450b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 29 May 2015 18:03:58 -0700 Subject: [PATCH 2/2] Reduce setTargetedHotend by removing the switch --- Marlin/Marlin_main.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 509ec3066..4c445191b 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -6518,25 +6518,21 @@ void Stop() { } } +/** + * Set target_extruder from the T parameter or the active_extruder + * + * Returns TRUE if the target is invalid + */ bool setTargetedHotend(int code) { target_extruder = active_extruder; if (code_seen('T')) { target_extruder = code_value_short(); if (target_extruder >= EXTRUDERS) { - switch(code) { - case 104: - case 105: - case 109: - case 218: - case 221: - case 200: - SERIAL_ECHO_START; - SERIAL_CHAR('M'); - SERIAL_ECHO(code); - SERIAL_ECHOPGM(" " MSG_INVALID_EXTRUDER " "); - SERIAL_ECHOLN(target_extruder); - break; - } + SERIAL_ECHO_START; + SERIAL_CHAR('M'); + SERIAL_ECHO(code); + SERIAL_ECHOPGM(" " MSG_INVALID_EXTRUDER " "); + SERIAL_ECHOLN(target_extruder); return true; } }