瀏覽代碼

Add CNC-like G-code options

thesfreader 6 年之前
父節點
當前提交
e09c144674
共有 4 個文件被更改,包括 139 次插入32 次删除
  1. 9
    0
      Marlin/Configuration_adv.h
  2. 78
    26
      Marlin/src/gcode/parser.cpp
  3. 9
    0
      Marlin/src/gcode/parser.h
  4. 43
    6
      Marlin/src/gcode/queue.cpp

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

@@ -1776,4 +1776,13 @@
1776 1776
 // Enable Marlin dev mode which adds some special commands
1777 1777
 //#define MARLIN_DEV_MODE
1778 1778
 
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
+
1779 1788
 #endif // CONFIGURATION_ADV_H

+ 78
- 26
Marlin/src/gcode/parser.cpp 查看文件

@@ -53,6 +53,13 @@ int GCodeParser::codenum;
53 53
 #if USE_GCODE_SUBCODES
54 54
   uint8_t GCodeParser::subcode;
55 55
 #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;	
60
+  #endif
61
+#endif
62
+  
56 63
 
57 64
 #if ENABLED(FASTER_GCODE_PARSER)
58 65
   // Optimized Parameters
@@ -118,36 +125,81 @@ void GCodeParser::parse(char *p) {
118 125
   }
119 126
 
120 127
   // Bail if the letter is not G, M, or T
121
-  switch (letter) { case 'G': case 'M': case 'T': break; default: return; }
122
-
123
-  // Skip spaces to get the numeric part
124
-  while (*p == ' ') p++;
125
-
126
-  // Bail if there's no command code number
127
-  if (!NUMERIC(*p)) return;
128
-
129
-  // Save the command letter at this point
130
-  // A '?' signifies an unknown command
131
-  command_letter = letter;
128
+  switch(letter) { 
129
+  case 'G': 
130
+  case 'M': 
131
+  case 'T': 
132
+ 
133
+      // Skip spaces to get the numeric part
134
+      while (*p == ' ') p++;
135
+
136
+      // Bail if there's no command code number
137
+      if (!NUMERIC(*p)) return;
138
+
139
+      // Save the command letter at this point
140
+      // A '?' signifies an unknown command
141
+      command_letter = letter;
142
+
143
+      // Get the code number - integer digits only
144
+      codenum = 0;
145
+      do {
146
+      codenum *= 10, codenum += *p++ - '0';
147
+      } while (NUMERIC(*p));
148
+
149
+      // Allow for decimal point in command
150
+      #if USE_GCODE_SUBCODES
151
+      if (*p == '.') {
152
+        p++;
153
+        while (NUMERIC(*p))
154
+        subcode *= 10, subcode += *p++ - '0';
155
+      }
156
+      #endif
132 157
 
133
-  // Get the code number - integer digits only
134
-  codenum = 0;
135
-  do {
136
-    codenum *= 10, codenum += *p++ - '0';
137
-  } while (NUMERIC(*p));
158
+      // Skip all spaces to get to the first argument, or nul
159
+      while (*p == ' ') p++;
138 160
 
139
-  // Allow for decimal point in command
140
-  #if USE_GCODE_SUBCODES
141
-    if (*p == '.') {
142
-      p++;
143
-      while (NUMERIC(*p))
144
-        subcode *= 10, subcode += *p++ - '0';
145
-    }
146
-  #endif
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
167
+        }
168
+      #endif
169
+      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;
192
+      #endif
193
+      
194
+      // Roll back one character before to use the current arg
195
+      p--;
196
+    break;
197
+  #endif // STICKY_MOVE_MODE
147 198
 
148
-  // Skip all spaces to get to the first argument, or nul
149
-  while (*p == ' ') p++;
199
+  default: return; 
200
+  }
150 201
 
202
+ 
151 203
   // The command parameters (if any) start here, for sure!
152 204
 
153 205
   #if DISABLED(FASTER_GCODE_PARSER)

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

@@ -78,12 +78,21 @@ public:
78 78
   static char *command_ptr,               // The command, so it can be echoed
79 79
               *string_arg;                // string of command line
80 80
 
81
+
82
+
81 83
   static char command_letter;             // G, M, or T
82 84
   static int codenum;                     // 123
83 85
   #if USE_GCODE_SUBCODES
84 86
     static uint8_t subcode;               // .1
85 87
   #endif
86 88
 
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;	
93
+    #endif
94
+  #endif
95
+  
87 96
   #if ENABLED(DEBUG_GCODE_PARSER)
88 97
     static void debug();
89 98
   #endif

+ 43
- 6
Marlin/src/gcode/queue.cpp 查看文件

@@ -283,6 +283,9 @@ static int read_serial(const int index) {
283 283
 inline void get_serial_commands() {
284 284
   static char serial_line_buffer[NUM_SERIAL][MAX_CMD_SIZE];
285 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
286 289
 
287 290
   // If the command buffer is empty for too long,
288 291
   // send "wait" to indicate Marlin is still waiting.
@@ -311,6 +314,9 @@ inline void get_serial_commands() {
311 314
       if (serial_char == '\n' || serial_char == '\r') {
312 315
 
313 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
319
+        #endif
314 320
 
315 321
         // Skip empty lines and comments
316 322
         if (!serial_count[i]) { thermalManager.manage_heater(); continue; }
@@ -404,12 +410,24 @@ inline void get_serial_commands() {
404 410
       }
405 411
       else if (serial_char == '\\') {  // Handle escapes
406 412
         // if we have one more character, copy it over
407
-        if ((c = read_serial(i)) >= 0 && !serial_comment_mode[i])
413
+        if ((c = read_serial(i)) >= 0 && !serial_comment_mode[i]
414
+        #if ENABLED(PARENTHESE_COMMENTS)
415
+         && ! serial_comment_paranthese_mode[i]
416
+        #endif
417
+         )
408 418
           serial_line_buffer[i][serial_count[i]++] = (char)c;
409 419
       }
410 420
       else { // it's not a newline, carriage return or escape char
411
-        if (serial_char == ';') serial_comment_mode[i] = true;
412
-        if (!serial_comment_mode[i]) serial_line_buffer[i][serial_count[i]++] = serial_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]
429
+        #endif
430
+        ) serial_line_buffer[i][serial_count[i]++] = serial_char;
413 431
       }
414 432
     } // for NUM_SERIAL
415 433
   } // queue has space, serial has data
@@ -426,6 +444,9 @@ inline void get_serial_commands() {
426 444
     static bool stop_buffering = false,
427 445
                 sd_comment_mode = false;
428 446
 
447
+    #if ENABLED(PARENTHESE_COMMENTS)
448
+      static bool sd_comment_parenthese_mode = false;
449
+    #endif
429 450
     if (!IS_SD_PRINTING) return;
430 451
 
431 452
     /**
@@ -445,7 +466,11 @@ inline void get_serial_commands() {
445 466
       card_eof = card.eof();
446 467
       if (card_eof || n == -1
447 468
           || sd_char == '\n' || sd_char == '\r'
448
-          || ((sd_char == '#' || sd_char == ':') && !sd_comment_mode)
469
+          || ((sd_char == '#' || sd_char == ':') && !sd_comment_mode
470
+          #if ENABLED(PARENTHESE_COMMENTS)
471
+            && ! sd_comment_parenthese_mode
472
+          #endif
473
+          )
449 474
       ) {
450 475
         if (card_eof) {
451 476
 
@@ -481,6 +506,9 @@ inline void get_serial_commands() {
481 506
         if (sd_char == '#') stop_buffering = true;
482 507
 
483 508
         sd_comment_mode = false; // for new command
509
+        #if ENABLED(PARENTHESE_COMMENTS)
510
+          sd_comment_parenthese_mode = false;
511
+        #endif
484 512
 
485 513
         // Skip empty lines and comments
486 514
         if (!sd_count) { thermalManager.manage_heater(); continue; }
@@ -497,8 +525,17 @@ inline void get_serial_commands() {
497 525
          */
498 526
       }
499 527
       else {
500
-        if (sd_char == ';') sd_comment_mode = true;
501
-        if (!sd_comment_mode) command_queue[cmd_queue_index_w][sd_count++] = sd_char;
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; 
532
+        #endif
533
+        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;
502 539
       }
503 540
     }
504 541
   }

Loading…
取消
儲存