Browse Source

Update Marlin/Marlin.pde

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.
G. W. C. 11 years ago
parent
commit
6ccbfeb80c
1 changed files with 32 additions and 28 deletions
  1. 32
    28
      Marlin/Marlin.pde

+ 32
- 28
Marlin/Marlin.pde View File

202
 //===========================================================================
202
 //===========================================================================
203
 
203
 
204
 void get_arc_coordinates();
204
 void get_arc_coordinates();
205
+bool setTargetedHotend(int code);
205
 
206
 
206
 void serial_echopair_P(const char *s_P, float v)
207
 void serial_echopair_P(const char *s_P, float v)
207
     { serialprintPGM(s_P); SERIAL_ECHO(v); }
208
     { serialprintPGM(s_P); SERIAL_ECHO(v); }
957
       }
958
       }
958
      break;
959
      break;
959
     case 104: // M104
960
     case 104: // M104
960
-      tmp_extruder = active_extruder;
961
-      if(code_seen('T')) {
962
-        tmp_extruder = code_value();
963
-        if(tmp_extruder >= EXTRUDERS) {
964
-          SERIAL_ECHO_START;
965
-          SERIAL_ECHO(MSG_M104_INVALID_EXTRUDER);
966
-          SERIAL_ECHOLN(tmp_extruder);
967
-          break;
968
-        }
961
+      if(setTargetedHotend(104)){
962
+        break;
969
       }
963
       }
970
       if (code_seen('S')) setTargetHotend(code_value(), tmp_extruder);
964
       if (code_seen('S')) setTargetHotend(code_value(), tmp_extruder);
971
       setWatch();
965
       setWatch();
974
       if (code_seen('S')) setTargetBed(code_value());
968
       if (code_seen('S')) setTargetBed(code_value());
975
       break;
969
       break;
976
     case 105 : // M105
970
     case 105 : // M105
977
-      tmp_extruder = active_extruder;
978
-      if(code_seen('T')) {
979
-        tmp_extruder = code_value();
980
-        if(tmp_extruder >= EXTRUDERS) {
981
-          SERIAL_ECHO_START;
982
-          SERIAL_ECHO(MSG_M105_INVALID_EXTRUDER);
983
-          SERIAL_ECHOLN(tmp_extruder);
984
-          break;
985
-        }
971
+      if(setTargetedHotend(105)){
972
+        break;
986
       }
973
       }
987
       #if (TEMP_0_PIN > -1)
974
       #if (TEMP_0_PIN > -1)
988
         SERIAL_PROTOCOLPGM("ok T:");
975
         SERIAL_PROTOCOLPGM("ok T:");
1008
       break;
995
       break;
1009
     case 109: 
996
     case 109: 
1010
     {// M109 - Wait for extruder heater to reach target.
997
     {// M109 - Wait for extruder heater to reach target.
1011
-      tmp_extruder = active_extruder;
1012
-      if(code_seen('T')) {
1013
-        tmp_extruder = code_value();
1014
-        if(tmp_extruder >= EXTRUDERS) {
1015
-          SERIAL_ECHO_START;
1016
-          SERIAL_ECHO(MSG_M109_INVALID_EXTRUDER);
1017
-          SERIAL_ECHOLN(tmp_extruder);
1018
-          break;
1019
-        }
998
+      if(setTargetedHotend(109)){
999
+        break;
1020
       }
1000
       }
1021
       LCD_MESSAGEPGM(MSG_HEATING);   
1001
       LCD_MESSAGEPGM(MSG_HEATING);   
1022
       #ifdef AUTOTEMP
1002
       #ifdef AUTOTEMP
1829
 
1809
 
1830
   }
1810
   }
1831
 }
1811
 }
1832
-#endif
1812
+#endif //FAST_PWM_FAN
1813
+
1814
+bool setTargetedHotend(int code){
1815
+  tmp_extruder = active_extruder;
1816
+  if(code_seen('T')) {
1817
+    tmp_extruder = code_value();
1818
+    if(tmp_extruder >= EXTRUDERS) {
1819
+      SERIAL_ECHO_START;
1820
+      switch(code){
1821
+        case 104:
1822
+          SERIAL_ECHO(MSG_M104_INVALID_EXTRUDER);
1823
+          break;
1824
+        case 105:
1825
+          SERIAL_ECHO(MSG_M105_INVALID_EXTRUDER);
1826
+          break;
1827
+        case 109:
1828
+          SERIAL_ECHO(MSG_M109_INVALID_EXTRUDER);
1829
+          break;
1830
+      }
1831
+      SERIAL_ECHOLN(tmp_extruder);
1832
+      return true;
1833
+    }
1834
+  }
1835
+  return false;
1836
+}

Loading…
Cancel
Save