From 6ccbfeb80c675ad6f819a6e96b621def7d442c7d Mon Sep 17 00:00:00 2001 From: "G. W. C." Date: Fri, 14 Sep 2012 16:38:54 +0300 Subject: [PATCH] Update Marlin/Marlin.pde MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added function 'setTargetedHotend' that turns into a function an operation repeated 3 times through the M-codes processing. This modification saves a few bytes that can be used to add support for new commands. --- Marlin/Marlin.pde | 60 +++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index 5c46e7355f..9412404c50 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -202,6 +202,7 @@ bool Stopped=false; //=========================================================================== void get_arc_coordinates(); +bool setTargetedHotend(int code); void serial_echopair_P(const char *s_P, float v) { serialprintPGM(s_P); SERIAL_ECHO(v); } @@ -957,15 +958,8 @@ void process_commands() } break; case 104: // M104 - tmp_extruder = active_extruder; - if(code_seen('T')) { - tmp_extruder = code_value(); - if(tmp_extruder >= EXTRUDERS) { - SERIAL_ECHO_START; - SERIAL_ECHO(MSG_M104_INVALID_EXTRUDER); - SERIAL_ECHOLN(tmp_extruder); - break; - } + if(setTargetedHotend(104)){ + break; } if (code_seen('S')) setTargetHotend(code_value(), tmp_extruder); setWatch(); @@ -974,15 +968,8 @@ void process_commands() if (code_seen('S')) setTargetBed(code_value()); break; case 105 : // M105 - tmp_extruder = active_extruder; - if(code_seen('T')) { - tmp_extruder = code_value(); - if(tmp_extruder >= EXTRUDERS) { - SERIAL_ECHO_START; - SERIAL_ECHO(MSG_M105_INVALID_EXTRUDER); - SERIAL_ECHOLN(tmp_extruder); - break; - } + if(setTargetedHotend(105)){ + break; } #if (TEMP_0_PIN > -1) SERIAL_PROTOCOLPGM("ok T:"); @@ -1008,15 +995,8 @@ void process_commands() break; case 109: {// M109 - Wait for extruder heater to reach target. - tmp_extruder = active_extruder; - if(code_seen('T')) { - tmp_extruder = code_value(); - if(tmp_extruder >= EXTRUDERS) { - SERIAL_ECHO_START; - SERIAL_ECHO(MSG_M109_INVALID_EXTRUDER); - SERIAL_ECHOLN(tmp_extruder); - break; - } + if(setTargetedHotend(109)){ + break; } LCD_MESSAGEPGM(MSG_HEATING); #ifdef AUTOTEMP @@ -1829,4 +1809,28 @@ void setPwmFrequency(uint8_t pin, int val) } } -#endif +#endif //FAST_PWM_FAN + +bool setTargetedHotend(int code){ + tmp_extruder = active_extruder; + if(code_seen('T')) { + tmp_extruder = code_value(); + if(tmp_extruder >= EXTRUDERS) { + SERIAL_ECHO_START; + 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; + } + SERIAL_ECHOLN(tmp_extruder); + return true; + } + } + return false; +} \ No newline at end of file