Browse Source

Merge pull request #2095 from thinkyhead/cherry_picking2

Add gcode_line_error to reduce code size
Scott Lahteine 10 years ago
parent
commit
64825a3d1e
1 changed files with 15 additions and 22 deletions
  1. 15
    22
      Marlin/Marlin_main.cpp

+ 15
- 22
Marlin/Marlin_main.cpp View File

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

Loading…
Cancel
Save