浏览代码

Extend and apply some corrections

Scott Lahteine 6 年前
父节点
当前提交
52a37913c1

+ 7
- 9
Marlin/Configuration_adv.h 查看文件

@@ -1595,6 +1595,13 @@
1595 1595
 #define FASTER_GCODE_PARSER
1596 1596
 
1597 1597
 /**
1598
+ * CNC G-code options
1599
+ * Support CNC-style G-code dialects used by laser cutters, drawing machine cams, etc.
1600
+ */
1601
+//#define PAREN_COMMENTS      // Support for parentheses-delimited comments
1602
+//#define GCODE_MOTION_MODES  // Remember the motion mode (G0 G1 G2 G3 G5 G38.X) and apply for X Y Z E F, etc.
1603
+
1604
+/**
1598 1605
  * User-defined menu items that execute custom GCode
1599 1606
  */
1600 1607
 //#define CUSTOM_USER_MENUS
@@ -1776,13 +1783,4 @@
1776 1783
 // Enable Marlin dev mode which adds some special commands
1777 1784
 //#define MARLIN_DEV_MODE
1778 1785
 
1779
-
1780
-/**
1781
- * CNC Parsing options
1782
- * 
1783
- * These options increase marlin's acceptance of non reprap dialects more in line with what laser cutter or drawing machine cams produce
1784
- */
1785
-//#define PARENTHESE_COMMENTS // Enable Marlin to interpret parenthese delimited comments as such and ignore them
1786
-//#define STICKY_MOVE_MODE    // Enable marlin to keep the current move mode (G0 G1 G2 G3 G5 G38.X) and use it even if receiving only parameters (X Y Z E F etc.)
1787
-
1788 1786
 #endif // CONFIGURATION_ADV_H

+ 7
- 0
Marlin/src/config/default/Configuration_adv.h 查看文件

@@ -1595,6 +1595,13 @@
1595 1595
 #define FASTER_GCODE_PARSER
1596 1596
 
1597 1597
 /**
1598
+ * CNC G-code options
1599
+ * Support CNC-style G-code dialects used by laser cutters, drawing machine cams, etc.
1600
+ */
1601
+//#define PAREN_COMMENTS      // Support for parentheses-delimited comments
1602
+//#define GCODE_MOTION_MODES  // Remember the motion mode (G0 G1 G2 G3 G5 G38.X) and apply for X Y Z E F, etc.
1603
+
1604
+/**
1598 1605
  * User-defined menu items that execute custom GCode
1599 1606
  */
1600 1607
 //#define CUSTOM_USER_MENUS

+ 4
- 0
Marlin/src/gcode/gcode.cpp 查看文件

@@ -263,6 +263,10 @@ void GcodeSuite::process_parsed_command(
263 263
           break;
264 264
       #endif
265 265
 
266
+      #if ENABLED(GCODE_MOTION_MODES)
267
+        case 80: G80(); break;                                    // G80: Reset the current motion mode
268
+      #endif
269
+
266 270
       case 90: relative_mode = false; break;                      // G90: Relative Mode
267 271
       case 91: relative_mode = true; break;                       // G91: Absolute Mode
268 272
 

+ 5
- 0
Marlin/src/gcode/gcode.h 查看文件

@@ -65,6 +65,7 @@
65 65
  * G33  - Delta Auto-Calibration (Requires DELTA_AUTO_CALIBRATION)
66 66
  * G38  - Probe in any direction using the Z_MIN_PROBE (Requires G38_PROBE_TARGET)
67 67
  * G42  - Coordinated move to a mesh point (Requires MESH_BED_LEVELING, AUTO_BED_LEVELING_BLINEAR, or AUTO_BED_LEVELING_UBL)
68
+ * G80  - Cancel current motion mode (Requires GCODE_MOTION_MODES)
68 69
  * G90  - Use Absolute Coordinates
69 70
  * G91  - Use Relative Coordinates
70 71
  * G92  - Set current position to coordinates given
@@ -428,6 +429,10 @@ private:
428 429
     static void G59();
429 430
   #endif
430 431
 
432
+  #if ENABLED(GCODE_MOTION_MODES)
433
+    static void G80();
434
+  #endif
435
+
431 436
   static void G92();
432 437
 
433 438
   #if HAS_RESUME_CONTINUE

+ 14
- 0
Marlin/src/gcode/host/M115.cpp 查看文件

@@ -153,5 +153,19 @@ void GcodeSuite::M115() {
153 153
       #endif
154 154
     );
155 155
 
156
+    // PAREN_COMMENTS
157
+    cap_line(PSTR("PAREN_COMMENTS")
158
+      #if ENABLED(PAREN_COMMENTS)
159
+        , true
160
+      #endif
161
+    );
162
+
163
+    // MOTION_MODES (M80-M89)
164
+    cap_line(PSTR("MOTION_MODES")
165
+      #if ENABLED(GCODE_MOTION_MODES)
166
+        , true
167
+      #endif
168
+    );
169
+
156 170
   #endif // EXTENDED_CAPABILITIES_REPORT
157 171
 }

+ 36
- 0
Marlin/src/gcode/motion/G80.cpp 查看文件

@@ -0,0 +1,36 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#include "../../inc/MarlinConfigPre.h"
24
+
25
+#if ENABLED(GCODE_MOTION_MODES)
26
+
27
+/**
28
+ * G80: Cancel current motion mode
29
+ */
30
+void GcodeSuite::G80() {
31
+
32
+  parser.cancel_motion_mode();
33
+
34
+}
35
+
36
+#endif // GCODE_MOTION_MODES

+ 50
- 48
Marlin/src/gcode/parser.cpp 查看文件

@@ -50,16 +50,17 @@ char *GCodeParser::command_ptr,
50 50
      *GCodeParser::value_ptr;
51 51
 char GCodeParser::command_letter;
52 52
 int GCodeParser::codenum;
53
+
53 54
 #if USE_GCODE_SUBCODES
54 55
   uint8_t GCodeParser::subcode;
55 56
 #endif
56
-#if ENABLED(STICKY_MOVE_MODE)
57
-  int GCodeParser::current_motion_mode_codenum;	
58
-  #if USE_GCODE_SUBCODES		  
59
-    uint8_t GCodeParser::current_motion_mode_subcode;	
57
+
58
+#if ENABLED(GCODE_MOTION_MODES)
59
+  int16_t GCodeParser::motion_mode_codenum = -1;
60
+  #if USE_GCODE_SUBCODES
61
+    uint8_t GCodeParser::motion_mode_subcode;
60 62
   #endif
61 63
 #endif
62
-  
63 64
 
64 65
 #if ENABLED(FASTER_GCODE_PARSER)
65 66
   // Optimized Parameters
@@ -124,12 +125,20 @@ void GCodeParser::parse(char *p) {
124 125
     starpos[1] = '\0';
125 126
   }
126 127
 
128
+  #if ENABLED(GCODE_MOTION_MODES)
129
+    #if ENABLED(ARC_SUPPORT)
130
+      #define GTOP 3
131
+    #else
132
+      #define GTOP 1
133
+    #endif
134
+  #endif
135
+
127 136
   // Bail if the letter is not G, M, or T
128
-  switch(letter) { 
129
-  case 'G': 
130
-  case 'M': 
131
-  case 'T': 
132
- 
137
+  // (or a valid parameter for the current motion mode)
138
+  switch (letter) {
139
+
140
+    case 'G': case 'M': case 'T':
141
+
133 142
       // Skip spaces to get the numeric part
134 143
       while (*p == ' ') p++;
135 144
 
@@ -142,9 +151,7 @@ void GCodeParser::parse(char *p) {
142 151
 
143 152
       // Get the code number - integer digits only
144 153
       codenum = 0;
145
-      do {
146
-      codenum *= 10, codenum += *p++ - '0';
147
-      } while (NUMERIC(*p));
154
+      do { codenum *= 10, codenum += *p++ - '0'; } while (NUMERIC(*p));
148 155
 
149 156
       // Allow for decimal point in command
150 157
       #if USE_GCODE_SUBCODES
@@ -158,48 +165,43 @@ void GCodeParser::parse(char *p) {
158 165
       // Skip all spaces to get to the first argument, or nul
159 166
       while (*p == ' ') p++;
160 167
 
161
-      #if ENABLED(STICKY_MOVE_MODE)
162
-        if( letter == 'G' && (codenum < 4 || codenum == 5 || codenum == 38 || (codenum>=80 &&codenum < 90  ))) {
163
-        current_motion_mode_codenum = codenum;
164
-        #if USE_GCODE_SUBCODES
165
-          current_motion_mode_subcode = subcode;
166
-        #endif
168
+      #if ENABLED(GCODE_MOTION_MODES)
169
+        if (letter == 'G' && (codenum <= GTOP || codenum == 5
170
+                                #if ENABLED(G38_PROBE_TARGET)
171
+                                  || codenum == 38
172
+                                #endif
173
+                             )
174
+        ) {
175
+          motion_mode_codenum = codenum;
176
+          #if USE_GCODE_SUBCODES
177
+            motion_mode_subcode = subcode;
178
+          #endif
167 179
         }
168 180
       #endif
181
+
169 182
       break;
170
-    
171
-  #if ENABLED(STICKY_MOVE_MODE)
172
-
173
-    case 'P':
174
-    case 'Q':
175
-      if (current_motion_mode_codenum != 5)
176
-        return;
177
-    case 'I':
178
-    case 'J':
179
-    case 'R':  
180
-      if (current_motion_mode_codenum < 2)
181
-        return;
182
-    case 'X':
183
-    case 'Y':
184
-    case 'Z':
185
-    case 'E':
186
-    case 'F':
187
-
188
-      command_letter = 'G';
189
-      codenum = current_motion_mode_codenum;
190
-      #if USE_GCODE_SUBCODES
191
-        subcode = current_motion_mode_subcode;
183
+
184
+    #if ENABLED(GCODE_MOTION_MODES)
185
+      #if ENABLED(ARC_SUPPORT)
186
+        case 'I': case 'J': case 'R':
187
+          if (motion_mode_codenum != 2 && motion_mode_codenum != 3) return;
192 188
       #endif
193
-      
194
-      // Roll back one character before to use the current arg
195
-      p--;
196
-    break;
197
-  #endif // STICKY_MOVE_MODE
189
+      case 'P': case 'Q':
190
+        if (motion_mode_codenum != 5) return;
191
+      case 'X': case 'Y': case 'Z': case 'E': case 'F':
192
+        if (motion_mode_codenum < 0) return;
193
+        command_letter = 'G';
194
+        codenum = motion_mode_codenum;
195
+        #if USE_GCODE_SUBCODES
196
+          subcode = motion_mode_subcode;
197
+        #endif
198
+        p--; // Back up one character to use the current parameter
199
+      break;
200
+    #endif // GCODE_MOTION_MODES
198 201
 
199
-  default: return; 
202
+    default: return;
200 203
   }
201 204
 
202
- 
203 205
   // The command parameters (if any) start here, for sure!
204 206
 
205 207
   #if DISABLED(FASTER_GCODE_PARSER)

+ 8
- 10
Marlin/src/gcode/parser.h 查看文件

@@ -76,23 +76,21 @@ public:
76 76
 
77 77
   // Command line state
78 78
   static char *command_ptr,               // The command, so it can be echoed
79
-              *string_arg;                // string of command line
80
-
81
-
82
-
83
-  static char command_letter;             // G, M, or T
79
+              *string_arg,                // string of command line
80
+              command_letter;             // G, M, or T
84 81
   static int codenum;                     // 123
85 82
   #if USE_GCODE_SUBCODES
86 83
     static uint8_t subcode;               // .1
87 84
   #endif
88 85
 
89
-  #if ENABLED(STICKY_MOVE_MODE)
90
-    static int current_motion_mode_codenum;	
91
-    #if USE_GCODE_SUBCODES		  
92
-      static uint8_t current_motion_mode_subcode;	
86
+  #if ENABLED(GCODE_MOTION_MODES)
87
+    static int16_t motion_mode_codenum;
88
+    #if USE_GCODE_SUBCODES
89
+      static uint8_t motion_mode_subcode;
93 90
     #endif
91
+    FORCE_INLINE static void cancel_motion_mode() { motion_mode_codenum = -1; }
94 92
   #endif
95
-  
93
+
96 94
   #if ENABLED(DEBUG_GCODE_PARSER)
97 95
     static void debug();
98 96
   #endif

+ 39
- 37
Marlin/src/gcode/queue.cpp 查看文件

@@ -282,10 +282,11 @@ static int read_serial(const int index) {
282 282
  */
283 283
 inline void get_serial_commands() {
284 284
   static char serial_line_buffer[NUM_SERIAL][MAX_CMD_SIZE];
285
-  static bool serial_comment_mode[NUM_SERIAL] = { false };
286
-  #if ENABLED(PARENTHESE_COMMENTS)
287
-    static bool serial_comment_paranthese_mode[NUM_SERIAL] = { false };
288
-  #endif
285
+  static bool serial_comment_mode[NUM_SERIAL] = { false }
286
+              #if ENABLED(PAREN_COMMENTS)
287
+                , serial_comment_paren_mode[NUM_SERIAL] = { false }
288
+              #endif
289
+            ;
289 290
 
290 291
   // If the command buffer is empty for too long,
291 292
   // send "wait" to indicate Marlin is still waiting.
@@ -313,9 +314,10 @@ inline void get_serial_commands() {
313 314
        */
314 315
       if (serial_char == '\n' || serial_char == '\r') {
315 316
 
316
-        serial_comment_mode[i] = false;                   // end of line == end of comment
317
-        #if ENABLED(PARENTHESE_COMMENTS)
318
-          serial_comment_paranthese_mode[i] = false;                   // end of line == end of comment
317
+        // Start with comment mode off
318
+        serial_comment_mode[i] = false;
319
+        #if ENABLED(PAREN_COMMENTS)
320
+          serial_comment_paren_mode[i] = false;
319 321
         #endif
320 322
 
321 323
         // Skip empty lines and comments
@@ -411,22 +413,22 @@ inline void get_serial_commands() {
411 413
       else if (serial_char == '\\') {  // Handle escapes
412 414
         // if we have one more character, copy it over
413 415
         if ((c = read_serial(i)) >= 0 && !serial_comment_mode[i]
414
-        #if ENABLED(PARENTHESE_COMMENTS)
415
-         && ! serial_comment_paranthese_mode[i]
416
-        #endif
417
-         )
416
+          #if ENABLED(PAREN_COMMENTS)
417
+            && !serial_comment_paren_mode[i]
418
+          #endif
419
+        )
418 420
           serial_line_buffer[i][serial_count[i]++] = (char)c;
419 421
       }
420 422
       else { // it's not a newline, carriage return or escape char
421
-        if (serial_char == ';') serial_comment_mode[i] = true; 
422
-        #if ENABLED(PARENTHESE_COMMENTS)
423
-          else if (serial_char == '(') serial_comment_paranthese_mode[i] = true;
424
-          else if (serial_char == ')') serial_comment_paranthese_mode[i] = false;
425
-        #endif
426
-        else if (!serial_comment_mode[i] 
427
-        #if ENABLED(PARENTHESE_COMMENTS)
428
-          && ! serial_comment_paranthese_mode[i]
423
+        if (serial_char == ';') serial_comment_mode[i] = true;
424
+        #if ENABLED(PAREN_COMMENTS)
425
+          else if (serial_char == '(') serial_comment_paren_mode[i] = true;
426
+          else if (serial_char == ')') serial_comment_paren_mode[i] = false;
429 427
         #endif
428
+        else if (!serial_comment_mode[i]
429
+          #if ENABLED(PAREN_COMMENTS)
430
+            && ! serial_comment_paren_mode[i]
431
+          #endif
430 432
         ) serial_line_buffer[i][serial_count[i]++] = serial_char;
431 433
       }
432 434
     } // for NUM_SERIAL
@@ -442,11 +444,12 @@ inline void get_serial_commands() {
442 444
    */
443 445
   inline void get_sdcard_commands() {
444 446
     static bool stop_buffering = false,
445
-                sd_comment_mode = false;
447
+                sd_comment_mode = false
448
+                #if ENABLED(PAREN_COMMENTS)
449
+                  , sd_comment_paren_mode = false
450
+                #endif
451
+              ;
446 452
 
447
-    #if ENABLED(PARENTHESE_COMMENTS)
448
-      static bool sd_comment_parenthese_mode = false;
449
-    #endif
450 453
     if (!IS_SD_PRINTING) return;
451 454
 
452 455
     /**
@@ -467,9 +470,9 @@ inline void get_serial_commands() {
467 470
       if (card_eof || n == -1
468 471
           || sd_char == '\n' || sd_char == '\r'
469 472
           || ((sd_char == '#' || sd_char == ':') && !sd_comment_mode
470
-          #if ENABLED(PARENTHESE_COMMENTS)
471
-            && ! sd_comment_parenthese_mode
472
-          #endif
473
+            #if ENABLED(PAREN_COMMENTS)
474
+              && !sd_comment_paren_mode
475
+            #endif
473 476
           )
474 477
       ) {
475 478
         if (card_eof) {
@@ -506,8 +509,8 @@ inline void get_serial_commands() {
506 509
         if (sd_char == '#') stop_buffering = true;
507 510
 
508 511
         sd_comment_mode = false; // for new command
509
-        #if ENABLED(PARENTHESE_COMMENTS)
510
-          sd_comment_parenthese_mode = false;
512
+        #if ENABLED(PAREN_COMMENTS)
513
+          sd_comment_paren_mode = false;
511 514
         #endif
512 515
 
513 516
         // Skip empty lines and comments
@@ -525,17 +528,16 @@ inline void get_serial_commands() {
525 528
          */
526 529
       }
527 530
       else {
528
-        if (sd_char == ';') sd_comment_mode = true; 
529
-        #if ENABLED(PARENTHESE_COMMENTS)
530
-          else if (sd_char == '(') sd_comment_parenthese_mode = true; 
531
-          else if (sd_char == ')') sd_comment_parenthese_mode = false; 
531
+        if (sd_char == ';') sd_comment_mode = true;
532
+        #if ENABLED(PAREN_COMMENTS)
533
+          else if (sd_char == '(') sd_comment_paren_mode = true;
534
+          else if (sd_char == ')') sd_comment_paren_mode = false;
532 535
         #endif
533 536
         else if (!sd_comment_mode
534
-        #if ENABLED(PARENTHESE_COMMENTS) 
535
-        && ! sd_comment_parenthese_mode
536
-        #endif
537
-        ) 
538
-          command_queue[cmd_queue_index_w][sd_count++] = sd_char;
537
+          #if ENABLED(PAREN_COMMENTS)
538
+            && ! sd_comment_paren_mode
539
+          #endif
540
+        ) command_queue[cmd_queue_index_w][sd_count++] = sd_char;
539 541
       }
540 542
     }
541 543
   }

+ 3
- 2
buildroot/share/tests/STM32F1_tests 查看文件

@@ -5,8 +5,9 @@ set -e
5 5
 
6 6
 restore_configs
7 7
 opt_set MOTHERBOARD BOARD_STM32F1R
8
-opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT
9
-exec_test $1 $2 "STM32F1R EEPROM_SETTINGS EEPROM_CHITCHAT REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT"
8
+opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT \
9
+           PAREN_COMMENTS GCODE_MOTION_MODES
10
+exec_test $1 $2 "STM32F1R EEPROM_SETTINGS EEPROM_CHITCHAT REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT PAREN_COMMENTS GCODE_MOTION_MODES"
10 11
 
11 12
 opt_enable SPINDLE_LASER_ENABLE
12 13
 exec_test $1 $2 "STM32F1R SPINDLE_LASER_ENABLE"

正在加载...
取消
保存