瀏覽代碼

Add gcode_line_error to reduce code size

Scott Lahteine 10 年之前
父節點
當前提交
ce218cafdb
共有 1 個檔案被更改,包括 15 行新增22 行删除
  1. 15
    22
      Marlin/Marlin_main.cpp

+ 15
- 22
Marlin/Marlin_main.cpp 查看文件

721
   lcd_update();
721
   lcd_update();
722
 }
722
 }
723
 
723
 
724
+void gcode_line_error(const char *err, bool doFlush=true) {
725
+  SERIAL_ERROR_START;
726
+  serialprintPGM(err);
727
+  SERIAL_ERRORLN(gcode_LastN);
728
+  //Serial.println(gcode_N);
729
+  if (doFlush) FlushSerialRequestResend();
730
+  serial_count = 0;
731
+}
732
+
724
 /**
733
 /**
725
  * Add to the circular command queue the next command from:
734
  * Add to the circular command queue the next command from:
726
  *  - The command-injection queue (queued_commands_P)
735
  *  - The command-injection queue (queued_commands_P)
766
         strchr_pointer = strchr(command, 'N');
775
         strchr_pointer = strchr(command, 'N');
767
         gcode_N = (strtol(strchr_pointer + 1, NULL, 10));
776
         gcode_N = (strtol(strchr_pointer + 1, NULL, 10));
768
         if (gcode_N != gcode_LastN + 1 && strstr_P(command, PSTR("M110")) == NULL) {
777
         if (gcode_N != gcode_LastN + 1 && strstr_P(command, PSTR("M110")) == NULL) {
769
-          SERIAL_ERROR_START;
770
-          SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
771
-          SERIAL_ERRORLN(gcode_LastN);
772
-          //Serial.println(gcode_N);
773
-          FlushSerialRequestResend();
774
-          serial_count = 0;
778
+          gcode_line_error(PSTR(MSG_ERR_LINE_NO));
775
           return;
779
           return;
776
         }
780
         }
777
 
781
 
782
           strchr_pointer = strchr(command, '*');
786
           strchr_pointer = strchr(command, '*');
783
 
787
 
784
           if (strtol(strchr_pointer + 1, NULL, 10) != checksum) {
788
           if (strtol(strchr_pointer + 1, NULL, 10) != checksum) {
785
-            SERIAL_ERROR_START;
786
-            SERIAL_ERRORPGM(MSG_ERR_CHECKSUM_MISMATCH);
787
-            SERIAL_ERRORLN(gcode_LastN);
788
-            FlushSerialRequestResend();
789
-            serial_count = 0;
789
+            gcode_line_error(PSTR(MSG_ERR_CHECKSUM_MISMATCH));
790
             return;
790
             return;
791
           }
791
           }
792
-          //if no errors, continue parsing
792
+          // if no errors, continue parsing
793
         }
793
         }
794
         else {
794
         else {
795
-          SERIAL_ERROR_START;
796
-          SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM);
797
-          SERIAL_ERRORLN(gcode_LastN);
798
-          FlushSerialRequestResend();
799
-          serial_count = 0;
795
+          gcode_line_error(PSTR(MSG_ERR_NO_CHECKSUM));
800
           return;
796
           return;
801
         }
797
         }
802
 
798
 
803
         gcode_LastN = gcode_N;
799
         gcode_LastN = gcode_N;
804
-        //if no errors, continue parsing
800
+        // if no errors, continue parsing
805
       }
801
       }
806
       else {  // if we don't receive 'N' but still see '*'
802
       else {  // if we don't receive 'N' but still see '*'
807
         if ((strchr(command, '*') != NULL)) {
803
         if ((strchr(command, '*') != NULL)) {
808
-          SERIAL_ERROR_START;
809
-          SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
810
-          SERIAL_ERRORLN(gcode_LastN);
811
-          serial_count = 0;
804
+          gcode_line_error(PSTR(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM), false);
812
           return;
805
           return;
813
         }
806
         }
814
       }
807
       }

Loading…
取消
儲存