Browse Source

Synchronize on M204, M205 (#12302)

* Add parser.seen for multiple parameters
* Fix M666, use !seen for report
* Synchronize on M204, M205
Scott Lahteine 6 years ago
parent
commit
e4cf175163
No account linked to committer's email address

+ 7
- 18
Marlin/src/gcode/calibrate/M666.cpp View File

22
 
22
 
23
 #include "../../inc/MarlinConfig.h"
23
 #include "../../inc/MarlinConfig.h"
24
 
24
 
25
-#if ENABLED(DELTA) || ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
25
+#if ENABLED(DELTA) || ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || Z_MULTI_ENDSTOPS
26
 
26
 
27
 #include "../gcode.h"
27
 #include "../gcode.h"
28
 
28
 
73
    *      Set Both: M666 Z<offset>
73
    *      Set Both: M666 Z<offset>
74
    */
74
    */
75
   void GcodeSuite::M666() {
75
   void GcodeSuite::M666() {
76
-    bool report = true;
77
     #if ENABLED(X_DUAL_ENDSTOPS)
76
     #if ENABLED(X_DUAL_ENDSTOPS)
78
-      if (parser.seen('X')) {
79
-        endstops.x2_endstop_adj = parser.value_linear_units();
80
-        report = false;
81
-      }
77
+      if (parser.seenval('X')) endstops.x2_endstop_adj = parser.value_linear_units();
82
     #endif
78
     #endif
83
     #if ENABLED(Y_DUAL_ENDSTOPS)
79
     #if ENABLED(Y_DUAL_ENDSTOPS)
84
-      if (parser.seen('Y')) {
85
-        endstops.y2_endstop_adj = parser.value_linear_units();
86
-        report = false;
87
-      }
80
+      if (parser.seenval('Y')) endstops.y2_endstop_adj = parser.value_linear_units();
88
     #endif
81
     #endif
89
     #if ENABLED(Z_TRIPLE_ENDSTOPS)
82
     #if ENABLED(Z_TRIPLE_ENDSTOPS)
90
-      if (parser.seen('Z')) {
91
-        const int ind = parser.intval('S');
83
+      if (parser.seenval('Z')) {
92
         const float z_adj = parser.value_linear_units();
84
         const float z_adj = parser.value_linear_units();
85
+        const int ind = parser.intval('S');
93
         if (!ind || ind == 2) endstops.z2_endstop_adj = z_adj;
86
         if (!ind || ind == 2) endstops.z2_endstop_adj = z_adj;
94
         if (!ind || ind == 3) endstops.z3_endstop_adj = z_adj;
87
         if (!ind || ind == 3) endstops.z3_endstop_adj = z_adj;
95
-        report = false;
96
       }
88
       }
97
     #elif Z_MULTI_ENDSTOPS
89
     #elif Z_MULTI_ENDSTOPS
98
-      if (parser.seen('Z')) {
99
-        endstops.z2_endstop_adj = parser.value_linear_units();
100
-        report = false;
101
-      }
90
+      if (parser.seen('Z')) endstops.z2_endstop_adj = parser.value_linear_units();
102
     #endif
91
     #endif
103
-    if (report) {
92
+    if (!parser.seen("XYZ")) {
104
       SERIAL_ECHOPGM("Dual Endstop Adjustment (mm): ");
93
       SERIAL_ECHOPGM("Dual Endstop Adjustment (mm): ");
105
       #if ENABLED(X_DUAL_ENDSTOPS)
94
       #if ENABLED(X_DUAL_ENDSTOPS)
106
         SERIAL_ECHOPAIR(" X2:", endstops.x2_endstop_adj);
95
         SERIAL_ECHOPAIR(" X2:", endstops.x2_endstop_adj);

+ 22
- 18
Marlin/src/gcode/config/M200-M205.cpp View File

91
  *    T = Travel (non printing) moves
91
  *    T = Travel (non printing) moves
92
  */
92
  */
93
 void GcodeSuite::M204() {
93
 void GcodeSuite::M204() {
94
-  bool report = true;
95
-  if (parser.seenval('S')) { // Kept for legacy compatibility. Should NOT BE USED for new developments.
96
-    planner.settings.travel_acceleration = planner.settings.acceleration = parser.value_linear_units();
97
-    report = false;
98
-  }
99
-  if (parser.seenval('P')) {
100
-    planner.settings.acceleration = parser.value_linear_units();
101
-    report = false;
102
-  }
103
-  if (parser.seenval('R')) {
104
-    planner.settings.retract_acceleration = parser.value_linear_units();
105
-    report = false;
106
-  }
107
-  if (parser.seenval('T')) {
108
-    planner.settings.travel_acceleration = parser.value_linear_units();
109
-    report = false;
110
-  }
111
-  if (report) {
94
+  if (!parser.seen("PRST")) {
112
     SERIAL_ECHOPAIR("Acceleration: P", planner.settings.acceleration);
95
     SERIAL_ECHOPAIR("Acceleration: P", planner.settings.acceleration);
113
     SERIAL_ECHOPAIR(" R", planner.settings.retract_acceleration);
96
     SERIAL_ECHOPAIR(" R", planner.settings.retract_acceleration);
114
     SERIAL_ECHOLNPAIR(" T", planner.settings.travel_acceleration);
97
     SERIAL_ECHOLNPAIR(" T", planner.settings.travel_acceleration);
115
   }
98
   }
99
+  else {
100
+    planner.synchronize();
101
+    // 'S' for legacy compatibility. Should NOT BE USED for new development
102
+    if (parser.seenval('S')) planner.settings.travel_acceleration = planner.settings.acceleration = parser.value_linear_units();
103
+    if (parser.seenval('P')) planner.settings.acceleration = parser.value_linear_units();
104
+    if (parser.seenval('R')) planner.settings.retract_acceleration = parser.value_linear_units();
105
+    if (parser.seenval('T')) planner.settings.travel_acceleration = parser.value_linear_units();
106
+  }
116
 }
107
 }
117
 
108
 
118
 /**
109
 /**
128
  *    J = Junction Deviation (mm) (Requires JUNCTION_DEVIATION)
119
  *    J = Junction Deviation (mm) (Requires JUNCTION_DEVIATION)
129
  */
120
  */
130
 void GcodeSuite::M205() {
121
 void GcodeSuite::M205() {
122
+  #if ENABLED(JUNCTION_DEVIATION)
123
+    #define J_PARAM  "J"
124
+  #else
125
+    #define J_PARAM 
126
+  #endif
127
+  #if HAS_CLASSIC_JERK
128
+    #define XYZE_PARAM "XYZE"
129
+  #else
130
+    #define XYZE_PARAM 
131
+  #endif
132
+  if (!parser.seen("BST" J_PARAM XYZE_PARAM)) return;
133
+
134
+  planner.synchronize();
131
   if (parser.seen('B')) planner.settings.min_segment_time_us = parser.value_ulong();
135
   if (parser.seen('B')) planner.settings.min_segment_time_us = parser.value_ulong();
132
   if (parser.seen('S')) planner.settings.min_feedrate_mm_s = parser.value_linear_units();
136
   if (parser.seen('S')) planner.settings.min_feedrate_mm_s = parser.value_linear_units();
133
   if (parser.seen('T')) planner.settings.min_travel_feedrate_mm_s = parser.value_linear_units();
137
   if (parser.seen('T')) planner.settings.min_travel_feedrate_mm_s = parser.value_linear_units();

+ 14
- 8
Marlin/src/gcode/config/M217.cpp View File

66
  */
66
  */
67
 void GcodeSuite::M217() {
67
 void GcodeSuite::M217() {
68
 
68
 
69
-  bool report = true;
69
+  #define SPR_PARAM
70
+  #define XY_PARAM
70
 
71
 
71
   #if ENABLED(SINGLENOZZLE)
72
   #if ENABLED(SINGLENOZZLE)
72
 
73
 
73
-    if (parser.seenval('S')) { report = false; const float v = parser.value_linear_units(); toolchange_settings.swap_length = constrain(v, 0, 500); }
74
-    if (parser.seenval('P')) { report = false; const int16_t v = parser.value_linear_units(); toolchange_settings.prime_speed = constrain(v, 10, 5400); }
75
-    if (parser.seenval('R')) { report = false; const int16_t v = parser.value_linear_units(); toolchange_settings.retract_speed = constrain(v, 10, 5400); }
74
+    #undef SPR_PARAM
75
+    #define SPR_PARAM "SPR"
76
+
77
+    if (parser.seenval('S')) { const float v = parser.value_linear_units(); toolchange_settings.swap_length = constrain(v, 0, 500); }
78
+    if (parser.seenval('P')) { const int16_t v = parser.value_linear_units(); toolchange_settings.prime_speed = constrain(v, 10, 5400); }
79
+    if (parser.seenval('R')) { const int16_t v = parser.value_linear_units(); toolchange_settings.retract_speed = constrain(v, 10, 5400); }
76
 
80
 
77
     #if ENABLED(SINGLENOZZLE_SWAP_PARK)
81
     #if ENABLED(SINGLENOZZLE_SWAP_PARK)
78
-      if (parser.seenval('X')) { report = false; toolchange_settings.change_point.x = parser.value_linear_units(); }
79
-      if (parser.seenval('Y')) { report = false; toolchange_settings.change_point.y = parser.value_linear_units(); }
82
+      #undef XY_PARAM
83
+      #define XY_PARAM "XY"
84
+      if (parser.seenval('X')) { toolchange_settings.change_point.x = parser.value_linear_units(); }
85
+      if (parser.seenval('Y')) { toolchange_settings.change_point.y = parser.value_linear_units(); }
80
     #endif
86
     #endif
81
 
87
 
82
   #endif
88
   #endif
83
 
89
 
84
-  if (parser.seenval('Z')) { report = false; toolchange_settings.z_raise = parser.value_linear_units(); }
90
+  if (parser.seenval('Z')) { toolchange_settings.z_raise = parser.value_linear_units(); }
85
 
91
 
86
-  if (report) M217_report();
92
+  if (!parser.seen(SPR_PARAM XY_PARAM "Z")) M217_report();
87
 
93
 
88
 }
94
 }
89
 
95
 

+ 4
- 14
Marlin/src/gcode/config/M218.cpp View File

42
 void GcodeSuite::M218() {
42
 void GcodeSuite::M218() {
43
   if (get_target_extruder_from_command() || target_extruder == 0) return;
43
   if (get_target_extruder_from_command() || target_extruder == 0) return;
44
 
44
 
45
-  bool report = true;
46
-  if (parser.seenval('X')) {
47
-    hotend_offset[X_AXIS][target_extruder] = parser.value_linear_units();
48
-    report = false;
49
-  }
50
-  if (parser.seenval('Y')) {
51
-    hotend_offset[Y_AXIS][target_extruder] = parser.value_linear_units();
52
-    report = false;
53
-  }
54
-  if (parser.seenval('Z')) {
55
-    hotend_offset[Z_AXIS][target_extruder] = parser.value_linear_units();
56
-    report = false;
57
-  }
45
+  if (parser.seenval('X')) hotend_offset[X_AXIS][target_extruder] = parser.value_linear_units();
46
+  if (parser.seenval('Y')) hotend_offset[Y_AXIS][target_extruder] = parser.value_linear_units();
47
+  if (parser.seenval('Z')) hotend_offset[Z_AXIS][target_extruder] = parser.value_linear_units();
58
 
48
 
59
-  if (report) {
49
+  if (!parser.seen("XYZ")) {
60
     SERIAL_ECHO_START();
50
     SERIAL_ECHO_START();
61
     SERIAL_ECHOPGM(MSG_HOTEND_OFFSET);
51
     SERIAL_ECHOPGM(MSG_HOTEND_OFFSET);
62
     HOTEND_LOOP() {
52
     HOTEND_LOOP() {

+ 1
- 1
Marlin/src/gcode/gcode.h View File

749
     static void M665();
749
     static void M665();
750
   #endif
750
   #endif
751
 
751
 
752
-  #if ENABLED(DELTA) || ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
752
+  #if ENABLED(DELTA) || ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || Z_MULTI_ENDSTOPS
753
     static void M666();
753
     static void M666();
754
   #endif
754
   #endif
755
 
755
 

+ 41
- 11
Marlin/src/gcode/parser.h View File

19
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
  *
20
  *
21
  */
21
  */
22
+#pragma once
22
 
23
 
23
 /**
24
 /**
24
  * parser.h - Parser for a GCode line, providing a parameter interface.
25
  * parser.h - Parser for a GCode line, providing a parameter interface.
26
  *           so settings for these codes are located in this class.
27
  *           so settings for these codes are located in this class.
27
  */
28
  */
28
 
29
 
29
-#ifndef _PARSER_H_
30
-#define _PARSER_H_
31
-
32
 #include "../inc/MarlinConfig.h"
30
 #include "../inc/MarlinConfig.h"
33
 
31
 
34
 //#define DEBUG_GCODE_PARSER
32
 //#define DEBUG_GCODE_PARSER
115
     }
113
     }
116
 
114
 
117
     // Set the flag and pointer for a parameter
115
     // Set the flag and pointer for a parameter
118
-    static void set(const char c, char * const ptr) {
116
+    static inline void set(const char c, char * const ptr) {
119
       const uint8_t ind = LETTER_BIT(c);
117
       const uint8_t ind = LETTER_BIT(c);
120
       if (ind >= COUNT(param)) return;           // Only A-Z
118
       if (ind >= COUNT(param)) return;           // Only A-Z
121
       SBI32(codebits, ind);                      // parameter exists
119
       SBI32(codebits, ind);                      // parameter exists
132
 
130
 
133
     // Code seen bit was set. If not found, value_ptr is unchanged.
131
     // Code seen bit was set. If not found, value_ptr is unchanged.
134
     // This allows "if (seen('A')||seen('B'))" to use the last-found value.
132
     // This allows "if (seen('A')||seen('B'))" to use the last-found value.
135
-    static bool seen(const char c) {
133
+    static inline bool seen(const char c) {
136
       const uint8_t ind = LETTER_BIT(c);
134
       const uint8_t ind = LETTER_BIT(c);
137
       if (ind >= COUNT(param)) return false; // Only A-Z
135
       if (ind >= COUNT(param)) return false; // Only A-Z
138
       const bool b = TEST32(codebits, ind);
136
       const bool b = TEST32(codebits, ind);
143
       return b;
141
       return b;
144
     }
142
     }
145
 
143
 
146
-    static bool seen_any() { return !!codebits; }
144
+    FORCE_INLINE static constexpr uint32_t letter_bits(const char * const str) {
145
+      return  (str[0] ? _BV32(LETTER_BIT(str[0])) |
146
+              (str[1] ? _BV32(LETTER_BIT(str[1])) |
147
+              (str[2] ? _BV32(LETTER_BIT(str[2])) |
148
+              (str[3] ? _BV32(LETTER_BIT(str[3])) |
149
+              (str[4] ? _BV32(LETTER_BIT(str[4])) |
150
+              (str[5] ? _BV32(LETTER_BIT(str[5])) |
151
+              (str[6] ? _BV32(LETTER_BIT(str[6])) |
152
+              (str[7] ? _BV32(LETTER_BIT(str[7])) |
153
+              (str[8] ? _BV32(LETTER_BIT(str[8])) |
154
+              (str[9] ? _BV32(LETTER_BIT(str[9]))
155
+            : 0) : 0) : 0) : 0) : 0) : 0) : 0) : 0) : 0) : 0);
156
+    }
157
+
158
+    // At least one of a list of code letters was seen
159
+    #ifdef CPU_32_BIT
160
+      FORCE_INLINE static bool seen(const char * const str) { return !!(codebits & letter_bits(str)); }
161
+    #else
162
+      // At least one of a list of code letters was seen
163
+      FORCE_INLINE static bool seen(const char * const str) {
164
+        const uint32_t letrbits = letter_bits(str);
165
+        const uint8_t * const cb = (uint8_t*)&codebits;
166
+        const uint8_t * const lb = (uint8_t*)&letrbits;
167
+        return (cb[0] & lb[0]) || (cb[1] & lb[1]) || (cb[2] & lb[2]) || (cb[3] & lb[3]);
168
+      }
169
+    #endif
170
+
171
+    static inline bool seen_any() { return !!codebits; }
147
 
172
 
148
     #define SEEN_TEST(L) TEST32(codebits, LETTER_BIT(L))
173
     #define SEEN_TEST(L) TEST32(codebits, LETTER_BIT(L))
149
 
174
 
151
 
176
 
152
     // Code is found in the string. If not found, value_ptr is unchanged.
177
     // Code is found in the string. If not found, value_ptr is unchanged.
153
     // This allows "if (seen('A')||seen('B'))" to use the last-found value.
178
     // This allows "if (seen('A')||seen('B'))" to use the last-found value.
154
-    static bool seen(const char c) {
179
+    static inline bool seen(const char c) {
155
       char *p = strchr(command_args, c);
180
       char *p = strchr(command_args, c);
156
       const bool b = !!p;
181
       const bool b = !!p;
157
       if (b) value_ptr = valid_float(&p[1]) ? &p[1] : (char*)NULL;
182
       if (b) value_ptr = valid_float(&p[1]) ? &p[1] : (char*)NULL;
158
       return b;
183
       return b;
159
     }
184
     }
160
 
185
 
161
-    static bool seen_any() { return *command_args == '\0'; }
186
+    static inline bool seen_any() { return *command_args == '\0'; }
162
 
187
 
163
     #define SEEN_TEST(L) !!strchr(command_args, L)
188
     #define SEEN_TEST(L) !!strchr(command_args, L)
164
 
189
 
190
+    // At least one of a list of code letters was seen
191
+    static inline bool seen(const char * const str) {
192
+      for (uint8_t i = 0; const char c = str[i]; i++)
193
+        if (SEEN_TEST(c)) return true;
194
+      return false;
195
+    }
196
+
165
   #endif // !FASTER_GCODE_PARSER
197
   #endif // !FASTER_GCODE_PARSER
166
 
198
 
167
   // Seen any axis parameter
199
   // Seen any axis parameter
168
-  static bool seen_axis() {
200
+  static inline bool seen_axis() {
169
     return SEEN_TEST('X') || SEEN_TEST('Y') || SEEN_TEST('Z') || SEEN_TEST('E');
201
     return SEEN_TEST('X') || SEEN_TEST('Y') || SEEN_TEST('Z') || SEEN_TEST('E');
170
   }
202
   }
171
 
203
 
348
 };
380
 };
349
 
381
 
350
 extern GCodeParser parser;
382
 extern GCodeParser parser;
351
-
352
-#endif // _PARSER_H_

Loading…
Cancel
Save