瀏覽代碼

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 年之前
父節點
當前提交
6ccbfeb80c
共有 1 個文件被更改,包括 32 次插入28 次删除
  1. 32
    28
      Marlin/Marlin.pde

+ 32
- 28
Marlin/Marlin.pde 查看文件

@@ -202,6 +202,7 @@ bool Stopped=false;
202 202
 //===========================================================================
203 203
 
204 204
 void get_arc_coordinates();
205
+bool setTargetedHotend(int code);
205 206
 
206 207
 void serial_echopair_P(const char *s_P, float v)
207 208
     { serialprintPGM(s_P); SERIAL_ECHO(v); }
@@ -957,15 +958,8 @@ void process_commands()
957 958
       }
958 959
      break;
959 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 964
       if (code_seen('S')) setTargetHotend(code_value(), tmp_extruder);
971 965
       setWatch();
@@ -974,15 +968,8 @@ void process_commands()
974 968
       if (code_seen('S')) setTargetBed(code_value());
975 969
       break;
976 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 974
       #if (TEMP_0_PIN > -1)
988 975
         SERIAL_PROTOCOLPGM("ok T:");
@@ -1008,15 +995,8 @@ void process_commands()
1008 995
       break;
1009 996
     case 109: 
1010 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 1001
       LCD_MESSAGEPGM(MSG_HEATING);   
1022 1002
       #ifdef AUTOTEMP
@@ -1829,4 +1809,28 @@ void setPwmFrequency(uint8_t pin, int val)
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…
取消
儲存