|
@@ -97,6 +97,13 @@ public:
|
97
|
97
|
// Reset is done before parsing
|
98
|
98
|
static void reset();
|
99
|
99
|
|
|
100
|
+ // Index so that 'X' falls on index 24
|
|
101
|
+ #define PARAM_IND(N) ((N) >> 3)
|
|
102
|
+ #define PARAM_BIT(N) ((N) & 0x7)
|
|
103
|
+ #define LETTER_OFF(N) ((N) - 'A' + 1)
|
|
104
|
+ #define LETTER_IND(N) PARAM_IND(LETTER_OFF(N))
|
|
105
|
+ #define LETTER_BIT(N) PARAM_BIT(LETTER_OFF(N))
|
|
106
|
+
|
100
|
107
|
#if ENABLED(FASTER_GCODE_PARSER)
|
101
|
108
|
|
102
|
109
|
// Set the flag and pointer for a parameter
|
|
@@ -105,14 +112,14 @@ public:
|
105
|
112
|
, const bool debug=false
|
106
|
113
|
#endif
|
107
|
114
|
) {
|
108
|
|
- const uint8_t ind = c - 'A';
|
|
115
|
+ const uint8_t ind = LETTER_OFF(c);
|
109
|
116
|
if (ind >= COUNT(param)) return; // Only A-Z
|
110
|
|
- SBI(codebits[ind >> 3], ind & 0x7); // parameter exists
|
|
117
|
+ SBI(codebits[PARAM_IND(ind)], PARAM_BIT(ind)); // parameter exists
|
111
|
118
|
param[ind] = ptr ? ptr - command_ptr : 0; // parameter offset or 0
|
112
|
119
|
#if ENABLED(DEBUG_GCODE_PARSER)
|
113
|
120
|
if (debug) {
|
114
|
|
- SERIAL_ECHOPAIR("Set bit ", (int)(ind & 0x7));
|
115
|
|
- SERIAL_ECHOPAIR(" of index ", (int)(ind >> 3));
|
|
121
|
+ SERIAL_ECHOPAIR("Set bit ", (int)PARAM_BIT(ind));
|
|
122
|
+ SERIAL_ECHOPAIR(" of index ", (int)PARAM_IND(ind));
|
116
|
123
|
SERIAL_ECHOLNPAIR(" | param = ", hex_address((void*)param[ind]));
|
117
|
124
|
}
|
118
|
125
|
#endif
|
|
@@ -120,22 +127,28 @@ public:
|
120
|
127
|
|
121
|
128
|
// Code seen bit was set. If not found, value_ptr is unchanged.
|
122
|
129
|
// This allows "if (seen('A')||seen('B'))" to use the last-found value.
|
|
130
|
+ // This is volatile because its side-effects are important
|
123
|
131
|
static volatile bool seen(const char c) {
|
124
|
|
- const uint8_t ind = c - 'A';
|
|
132
|
+ const uint8_t ind = LETTER_OFF(c);
|
125
|
133
|
if (ind >= COUNT(param)) return false; // Only A-Z
|
126
|
|
- const bool b = TEST(codebits[ind >> 3], ind & 0x7);
|
|
134
|
+ const bool b = TEST(codebits[PARAM_IND(ind)], PARAM_BIT(ind));
|
127
|
135
|
if (b) value_ptr = command_ptr + param[ind];
|
128
|
136
|
return b;
|
129
|
137
|
}
|
130
|
138
|
|
131
|
|
- static volatile bool seen_any() { return codebits[3] || codebits[2] || codebits[1] || codebits[0]; }
|
|
139
|
+ static bool seen_any() { return codebits[3] || codebits[2] || codebits[1] || codebits[0]; }
|
132
|
140
|
|
133
|
|
- #define SEEN_TEST(L) TEST(codebits[(L - 'A') >> 3], (L - 'A') & 0x7)
|
|
141
|
+ #define SEEN_TEST(L) TEST(codebits[LETTER_IND(L)], LETTER_BIT(L))
|
134
|
142
|
|
135
|
|
- #else
|
|
143
|
+ // Seen any axis parameter
|
|
144
|
+ // Optimized by moving 'X' up to index 24
|
|
145
|
+ FORCE_INLINE bool seen_axis() { return codebits[3] || SEEN_TEST('E'); }
|
|
146
|
+
|
|
147
|
+ #else // !FASTER_GCODE_PARSER
|
136
|
148
|
|
137
|
149
|
// Code is found in the string. If not found, value_ptr is unchanged.
|
138
|
150
|
// This allows "if (seen('A')||seen('B'))" to use the last-found value.
|
|
151
|
+ // This is volatile because its side-effects are important
|
139
|
152
|
static volatile bool seen(const char c) {
|
140
|
153
|
const char *p = strchr(command_args, c);
|
141
|
154
|
const bool b = !!p;
|
|
@@ -143,25 +156,26 @@ public:
|
143
|
156
|
return b;
|
144
|
157
|
}
|
145
|
158
|
|
146
|
|
- static volatile bool seen_any() { return *command_args == '\0'; }
|
|
159
|
+ static bool seen_any() { return *command_args == '\0'; }
|
147
|
160
|
|
148
|
161
|
#define SEEN_TEST(L) !!strchr(command_args, L)
|
149
|
162
|
|
150
|
|
- #endif // FASTER_GCODE_PARSER
|
|
163
|
+ // Seen any axis parameter
|
|
164
|
+ static bool seen_axis() {
|
|
165
|
+ return SEEN_TEST('X') || SEEN_TEST('Y') || SEEN_TEST('Z') || SEEN_TEST('E');
|
|
166
|
+ }
|
|
167
|
+
|
|
168
|
+ #endif // !FASTER_GCODE_PARSER
|
151
|
169
|
|
152
|
170
|
// Populate all fields by parsing a single line of GCode
|
153
|
171
|
// This uses 54 bytes of SRAM to speed up seen/value
|
154
|
172
|
static void parse(char * p);
|
155
|
173
|
|
156
|
|
- // Code value pointer was set
|
|
174
|
+ // The code value pointer was set
|
157
|
175
|
FORCE_INLINE static bool has_value() { return value_ptr != NULL; }
|
158
|
176
|
|
159
|
|
- // Seen and has value
|
160
|
|
- FORCE_INLINE static bool seenval(const char c) { return seen(c) && has_value(); }
|
161
|
|
-
|
162
|
|
- static volatile bool seen_axis() {
|
163
|
|
- return SEEN_TEST('X') || SEEN_TEST('Y') || SEEN_TEST('Z') || SEEN_TEST('E');
|
164
|
|
- }
|
|
177
|
+ // Seen a parameter with a value
|
|
178
|
+ inline static bool seenval(const char c) { return seen(c) && has_value(); }
|
165
|
179
|
|
166
|
180
|
// Float removes 'E' to prevent scientific notation interpretation
|
167
|
181
|
inline static float value_float() {
|
|
@@ -184,20 +198,20 @@ public:
|
184
|
198
|
}
|
185
|
199
|
|
186
|
200
|
// Code value as a long or ulong
|
187
|
|
- inline static long value_long() { return value_ptr ? strtol(value_ptr, NULL, 10) : 0L; }
|
188
|
|
- inline unsigned static long value_ulong() { return value_ptr ? strtoul(value_ptr, NULL, 10) : 0UL; }
|
|
201
|
+ inline static int32_t value_long() { return value_ptr ? strtol(value_ptr, NULL, 10) : 0L; }
|
|
202
|
+ inline static uint32_t value_ulong() { return value_ptr ? strtoul(value_ptr, NULL, 10) : 0UL; }
|
189
|
203
|
|
190
|
204
|
// Code value for use as time
|
191
|
205
|
FORCE_INLINE static millis_t value_millis() { return value_ulong(); }
|
192
|
206
|
FORCE_INLINE static millis_t value_millis_from_seconds() { return value_float() * 1000UL; }
|
193
|
207
|
|
194
|
208
|
// Reduce to fewer bits
|
195
|
|
- FORCE_INLINE static int value_int() { return (int)value_long(); }
|
196
|
|
- FORCE_INLINE uint16_t value_ushort() { return (uint16_t)value_long(); }
|
197
|
|
- inline static uint8_t value_byte() { return (uint8_t)(constrain(value_long(), 0, 255)); }
|
|
209
|
+ FORCE_INLINE static int16_t value_int() { return (int16_t)value_long(); }
|
|
210
|
+ FORCE_INLINE static uint16_t value_ushort() { return (uint16_t)value_long(); }
|
|
211
|
+ inline static uint8_t value_byte() { return (uint8_t)constrain(value_long(), 0, 255); }
|
198
|
212
|
|
199
|
213
|
// Bool is true with no value or non-zero
|
200
|
|
- inline static bool value_bool() { return !has_value() || value_byte(); }
|
|
214
|
+ inline static bool value_bool() { return !has_value() || value_byte(); }
|
201
|
215
|
|
202
|
216
|
// Units modes: Inches, Fahrenheit, Kelvin
|
203
|
217
|
|
|
@@ -282,17 +296,28 @@ public:
|
282
|
296
|
}
|
283
|
297
|
}
|
284
|
298
|
|
285
|
|
- #else
|
|
299
|
+ #else // !TEMPERATURE_UNITS_SUPPORT
|
286
|
300
|
|
287
|
301
|
FORCE_INLINE static float value_celsius() { return value_float(); }
|
288
|
302
|
FORCE_INLINE static float value_celsius_diff() { return value_float(); }
|
289
|
303
|
|
290
|
|
- #endif
|
|
304
|
+ #endif // !TEMPERATURE_UNITS_SUPPORT
|
291
|
305
|
|
292
|
306
|
FORCE_INLINE static float value_feedrate() { return value_linear_units(); }
|
293
|
307
|
|
294
|
308
|
void unknown_command_error();
|
295
|
309
|
|
|
310
|
+ // Provide simple value accessors with default option
|
|
311
|
+ FORCE_INLINE static float floatval(const char c, const float dval=0.0) { return seenval(c) ? value_float() : dval; }
|
|
312
|
+ FORCE_INLINE static bool boolval(const char c, const bool dval=false) { return seen(c) ? value_bool() : dval; }
|
|
313
|
+ FORCE_INLINE static uint8_t byteval(const char c, const uint8_t dval=0) { return seenval(c) ? value_byte() : dval; }
|
|
314
|
+ FORCE_INLINE static int16_t intval(const char c, const int16_t dval=0) { return seenval(c) ? value_int() : dval; }
|
|
315
|
+ FORCE_INLINE static uint16_t ushortval(const char c, const uint16_t dval=0) { return seenval(c) ? value_ushort() : dval; }
|
|
316
|
+ FORCE_INLINE static int32_t longval(const char c, const int32_t dval=0) { return seenval(c) ? value_long() : dval; }
|
|
317
|
+ FORCE_INLINE static uint32_t ulongval(const char c, const uint32_t dval=0) { return seenval(c) ? value_ulong() : dval; }
|
|
318
|
+ FORCE_INLINE static float linearval(const char c, const float dval=0.0) { return seenval(c) ? value_linear_units() : dval; }
|
|
319
|
+ FORCE_INLINE static float celsiusval(const char c, const float dval=0.0) { return seenval(c) ? value_celsius() : dval; }
|
|
320
|
+
|
296
|
321
|
};
|
297
|
322
|
|
298
|
323
|
extern GCodeParser parser;
|