|
@@ -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]; }
|
|
140
|
+
|
|
141
|
+ #define SEEN_TEST(L) TEST(codebits[LETTER_IND(L)], LETTER_BIT(L))
|
132
|
142
|
|
133
|
|
- #define SEEN_TEST(L) TEST(codebits[(L - 'A') >> 3], (L - 'A') & 0x7)
|
|
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'); }
|
134
|
146
|
|
135
|
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,26 +156,27 @@ 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
|
|
|
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
|
+
|
150
|
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
|
|
177
|
+ // Seen a parameter with a value
|
160
|
178
|
inline static bool seenval(const char c) { return seen(c) && has_value(); }
|
161
|
179
|
|
162
|
|
- static volatile bool seen_axis() {
|
163
|
|
- return SEEN_TEST('X') || SEEN_TEST('Y') || SEEN_TEST('Z') || SEEN_TEST('E');
|
164
|
|
- }
|
165
|
|
-
|
166
|
180
|
// Float removes 'E' to prevent scientific notation interpretation
|
167
|
181
|
inline static float value_float() {
|
168
|
182
|
if (value_ptr) {
|