|
@@ -19,6 +19,7 @@
|
19
|
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
|
25
|
* parser.h - Parser for a GCode line, providing a parameter interface.
|
|
@@ -26,9 +27,6 @@
|
26
|
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
|
30
|
#include "../inc/MarlinConfig.h"
|
33
|
31
|
|
34
|
32
|
//#define DEBUG_GCODE_PARSER
|
|
@@ -115,7 +113,7 @@ public:
|
115
|
113
|
}
|
116
|
114
|
|
117
|
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
|
117
|
const uint8_t ind = LETTER_BIT(c);
|
120
|
118
|
if (ind >= COUNT(param)) return; // Only A-Z
|
121
|
119
|
SBI32(codebits, ind); // parameter exists
|
|
@@ -132,7 +130,7 @@ public:
|
132
|
130
|
|
133
|
131
|
// Code seen bit was set. If not found, value_ptr is unchanged.
|
134
|
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
|
134
|
const uint8_t ind = LETTER_BIT(c);
|
137
|
135
|
if (ind >= COUNT(param)) return false; // Only A-Z
|
138
|
136
|
const bool b = TEST32(codebits, ind);
|
|
@@ -143,7 +141,34 @@ public:
|
143
|
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
|
173
|
#define SEEN_TEST(L) TEST32(codebits, LETTER_BIT(L))
|
149
|
174
|
|
|
@@ -151,21 +176,28 @@ public:
|
151
|
176
|
|
152
|
177
|
// Code is found in the string. If not found, value_ptr is unchanged.
|
153
|
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
|
180
|
char *p = strchr(command_args, c);
|
156
|
181
|
const bool b = !!p;
|
157
|
182
|
if (b) value_ptr = valid_float(&p[1]) ? &p[1] : (char*)NULL;
|
158
|
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
|
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
|
197
|
#endif // !FASTER_GCODE_PARSER
|
166
|
198
|
|
167
|
199
|
// Seen any axis parameter
|
168
|
|
- static bool seen_axis() {
|
|
200
|
+ static inline bool seen_axis() {
|
169
|
201
|
return SEEN_TEST('X') || SEEN_TEST('Y') || SEEN_TEST('Z') || SEEN_TEST('E');
|
170
|
202
|
}
|
171
|
203
|
|
|
@@ -348,5 +380,3 @@ public:
|
348
|
380
|
};
|
349
|
381
|
|
350
|
382
|
extern GCodeParser parser;
|
351
|
|
-
|
352
|
|
-#endif // _PARSER_H_
|