update code base to Marlin 2.0.9.2
This commit is contained in:
164
Marlin/src/gcode/parser.h
Executable file → Normal file
164
Marlin/src/gcode/parser.h
Executable file → Normal file
@@ -16,7 +16,7 @@
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
//#define DEBUG_GCODE_PARSER
|
||||
#if ENABLED(DEBUG_GCODE_PARSER)
|
||||
#include "../libs/hex_print_routines.h"
|
||||
#include "../libs/hex_print.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(TEMPERATURE_UNITS_SUPPORT)
|
||||
@@ -84,14 +84,14 @@ public:
|
||||
static char *command_ptr, // The command, so it can be echoed
|
||||
*string_arg, // string of command line
|
||||
command_letter; // G, M, or T
|
||||
static int codenum; // 123
|
||||
#if ENABLED(USE_GCODE_SUBCODES)
|
||||
static uint16_t codenum; // 123
|
||||
#if USE_GCODE_SUBCODES
|
||||
static uint8_t subcode; // .1
|
||||
#endif
|
||||
|
||||
#if ENABLED(GCODE_MOTION_MODES)
|
||||
static int16_t motion_mode_codenum;
|
||||
#if ENABLED(USE_GCODE_SUBCODES)
|
||||
#if USE_GCODE_SUBCODES
|
||||
static uint8_t motion_mode_subcode;
|
||||
#endif
|
||||
FORCE_INLINE static void cancel_motion_mode() { motion_mode_codenum = -1; }
|
||||
@@ -114,6 +114,11 @@ public:
|
||||
return valid_signless(p) || ((p[0] == '-' || p[0] == '+') && valid_signless(&p[1])); // [-+]?.?[0-9]
|
||||
}
|
||||
|
||||
FORCE_INLINE static bool valid_number(const char * const p) {
|
||||
// TODO: With MARLIN_DEV_MODE allow HEX values starting with "x"
|
||||
return valid_float(p);
|
||||
}
|
||||
|
||||
#if ENABLED(FASTER_GCODE_PARSER)
|
||||
|
||||
FORCE_INLINE static bool valid_int(const char * const p) {
|
||||
@@ -128,9 +133,9 @@ public:
|
||||
param[ind] = ptr ? ptr - command_ptr : 0; // parameter offset or 0
|
||||
#if ENABLED(DEBUG_GCODE_PARSER)
|
||||
if (codenum == 800) {
|
||||
SERIAL_ECHOPAIR("Set bit ", (int)ind, " of codebits (", hex_address((void*)(codebits >> 16)));
|
||||
SERIAL_ECHOPGM("Set bit ", ind, " of codebits (", hex_address((void*)(codebits >> 16)));
|
||||
print_hex_word((uint16_t)(codebits & 0xFFFF));
|
||||
SERIAL_ECHOLNPAIR(") | param = ", (int)param[ind]);
|
||||
SERIAL_ECHOLNPGM(") | param = ", param[ind]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -142,8 +147,12 @@ public:
|
||||
if (ind >= COUNT(param)) return false; // Only A-Z
|
||||
const bool b = TEST32(codebits, ind);
|
||||
if (b) {
|
||||
char * const ptr = command_ptr + param[ind];
|
||||
value_ptr = param[ind] && valid_float(ptr) ? ptr : nullptr;
|
||||
if (param[ind]) {
|
||||
char * const ptr = command_ptr + param[ind];
|
||||
value_ptr = valid_number(ptr) ? ptr : nullptr;
|
||||
}
|
||||
else
|
||||
value_ptr = nullptr;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
@@ -198,7 +207,7 @@ public:
|
||||
static inline bool seen(const char c) {
|
||||
char *p = strgchr(command_args, c);
|
||||
const bool b = !!p;
|
||||
if (b) value_ptr = valid_float(&p[1]) ? &p[1] : nullptr;
|
||||
if (b) value_ptr = valid_number(&p[1]) ? &p[1] : nullptr;
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -216,9 +225,7 @@ public:
|
||||
#endif // !FASTER_GCODE_PARSER
|
||||
|
||||
// Seen any axis parameter
|
||||
static inline bool seen_axis() {
|
||||
return seen_test('X') || seen_test('Y') || seen_test('Z') || seen_test('E');
|
||||
}
|
||||
static inline bool seen_axis() { return seen(LOGICAL_AXES_STRING); }
|
||||
|
||||
#if ENABLED(GCODE_QUOTED_STRINGS)
|
||||
static char* unescape_string(char* &src);
|
||||
@@ -235,8 +242,11 @@ public:
|
||||
static bool chain();
|
||||
#endif
|
||||
|
||||
// Test whether the parsed command matches the input
|
||||
static inline bool is_command(const char ltr, const uint16_t num) { return command_letter == ltr && codenum == num; }
|
||||
|
||||
// The code value pointer was set
|
||||
FORCE_INLINE static bool has_value() { return value_ptr != nullptr; }
|
||||
FORCE_INLINE static bool has_value() { return !!value_ptr; }
|
||||
|
||||
// Seen a parameter with a value
|
||||
static inline bool seenval(const char c) { return seen(c) && has_value(); }
|
||||
@@ -270,7 +280,7 @@ public:
|
||||
|
||||
// Code value for use as time
|
||||
static inline millis_t value_millis() { return value_ulong(); }
|
||||
static inline millis_t value_millis_from_seconds() { return (millis_t)(value_float() * 1000); }
|
||||
static inline millis_t value_millis_from_seconds() { return (millis_t)SEC_TO_MS(value_float()); }
|
||||
|
||||
// Reduce to fewer bits
|
||||
static inline int16_t value_int() { return (int16_t)value_long(); }
|
||||
@@ -283,8 +293,8 @@ public:
|
||||
// Units modes: Inches, Fahrenheit, Kelvin
|
||||
|
||||
#if ENABLED(INCH_MODE_SUPPORT)
|
||||
static inline float mm_to_linear_unit(const float mm) { return mm / linear_unit_factor; }
|
||||
static inline float mm_to_volumetric_unit(const float mm) { return mm / (volumetric_enabled ? volumetric_unit_factor : linear_unit_factor); }
|
||||
static inline float mm_to_linear_unit(const_float_t mm) { return mm / linear_unit_factor; }
|
||||
static inline float mm_to_volumetric_unit(const_float_t mm) { return mm / (volumetric_enabled ? volumetric_unit_factor : linear_unit_factor); }
|
||||
|
||||
// Init linear units by constructor
|
||||
GCodeParser() { set_input_linear_units(LINEARUNIT_MM); }
|
||||
@@ -299,24 +309,34 @@ public:
|
||||
}
|
||||
|
||||
static inline float axis_unit_factor(const AxisEnum axis) {
|
||||
return (axis >= E_AXIS && volumetric_enabled ? volumetric_unit_factor : linear_unit_factor);
|
||||
return (
|
||||
#if HAS_EXTRUDERS
|
||||
axis >= E_AXIS && volumetric_enabled ? volumetric_unit_factor : linear_unit_factor
|
||||
#else
|
||||
linear_unit_factor
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
static inline float linear_value_to_mm(const float v) { return v * linear_unit_factor; }
|
||||
static inline float linear_value_to_mm(const_float_t v) { return v * linear_unit_factor; }
|
||||
static inline float axis_value_to_mm(const AxisEnum axis, const float v) { return v * axis_unit_factor(axis); }
|
||||
static inline float per_axis_value(const AxisEnum axis, const float v) { return v / axis_unit_factor(axis); }
|
||||
|
||||
#else
|
||||
|
||||
static inline float mm_to_linear_unit(const float mm) { return mm; }
|
||||
static inline float mm_to_volumetric_unit(const float mm) { return mm; }
|
||||
static inline float mm_to_linear_unit(const_float_t mm) { return mm; }
|
||||
static inline float mm_to_volumetric_unit(const_float_t mm) { return mm; }
|
||||
|
||||
static inline float linear_value_to_mm(const float v) { return v; }
|
||||
static inline float linear_value_to_mm(const_float_t v) { return v; }
|
||||
static inline float axis_value_to_mm(const AxisEnum, const float v) { return v; }
|
||||
static inline float per_axis_value(const AxisEnum, const float v) { return v; }
|
||||
|
||||
#endif
|
||||
|
||||
static inline bool using_inch_units() { return mm_to_linear_unit(1.0f) != 1.0f; }
|
||||
|
||||
#define IN_TO_MM(I) ((I) * 25.4f)
|
||||
#define MM_TO_IN(M) ((M) / 25.4f)
|
||||
#define LINEAR_UNIT(V) parser.mm_to_linear_unit(V)
|
||||
#define VOLUMETRIC_UNIT(V) parser.mm_to_volumetric_unit(V)
|
||||
|
||||
@@ -328,60 +348,54 @@ public:
|
||||
|
||||
static inline void set_input_temp_units(const TempUnit units) { input_temp_units = units; }
|
||||
|
||||
static inline char temp_units_code() {
|
||||
return input_temp_units == TEMPUNIT_K ? 'K' : input_temp_units == TEMPUNIT_F ? 'F' : 'C';
|
||||
}
|
||||
static inline PGM_P temp_units_name() {
|
||||
return input_temp_units == TEMPUNIT_K ? PSTR("Kelvin") : input_temp_units == TEMPUNIT_F ? PSTR("Fahrenheit") : PSTR("Celsius");
|
||||
}
|
||||
|
||||
#if HAS_LCD_MENU && DISABLED(DISABLE_M503)
|
||||
|
||||
static inline char temp_units_code() {
|
||||
return input_temp_units == TEMPUNIT_K ? 'K' : input_temp_units == TEMPUNIT_F ? 'F' : 'C';
|
||||
}
|
||||
static inline PGM_P temp_units_name() {
|
||||
return input_temp_units == TEMPUNIT_K ? PSTR("Kelvin") : input_temp_units == TEMPUNIT_F ? PSTR("Fahrenheit") : PSTR("Celsius");
|
||||
}
|
||||
static inline float to_temp_units(const float &f) {
|
||||
static inline float to_temp_units(celsius_t c) {
|
||||
switch (input_temp_units) {
|
||||
case TEMPUNIT_F:
|
||||
return f * 0.5555555556f + 32;
|
||||
case TEMPUNIT_K:
|
||||
return f + 273.15f;
|
||||
case TEMPUNIT_C:
|
||||
default:
|
||||
return f;
|
||||
case TEMPUNIT_C: return c;
|
||||
case TEMPUNIT_K: return c + 273.15f;
|
||||
case TEMPUNIT_F: return c * 0.5555555556f + 32;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HAS_LCD_MENU && !DISABLE_M503
|
||||
|
||||
static inline float value_celsius() {
|
||||
const float f = value_float();
|
||||
static inline celsius_t value_celsius() {
|
||||
float f = value_float();
|
||||
switch (input_temp_units) {
|
||||
case TEMPUNIT_F:
|
||||
return (f - 32) * 0.5555555556f;
|
||||
case TEMPUNIT_K:
|
||||
return f - 273.15f;
|
||||
case TEMPUNIT_C:
|
||||
default:
|
||||
return f;
|
||||
case TEMPUNIT_C: break;
|
||||
case TEMPUNIT_K: f -= 273.15f;
|
||||
case TEMPUNIT_F: f = (f - 32) * 0.5555555556f;
|
||||
}
|
||||
return LROUND(f);
|
||||
}
|
||||
|
||||
static inline float value_celsius_diff() {
|
||||
static inline celsius_t value_celsius_diff() {
|
||||
float f = value_float();
|
||||
switch (input_temp_units) {
|
||||
case TEMPUNIT_F:
|
||||
return value_float() * 0.5555555556f;
|
||||
case TEMPUNIT_C:
|
||||
case TEMPUNIT_K:
|
||||
default:
|
||||
return value_float();
|
||||
case TEMPUNIT_C:
|
||||
case TEMPUNIT_K: break;
|
||||
case TEMPUNIT_F: f *= 0.5555555556f;
|
||||
}
|
||||
return LROUND(f);
|
||||
}
|
||||
|
||||
#define TEMP_UNIT(N) parser.to_temp_units(N)
|
||||
|
||||
#else // !TEMPERATURE_UNITS_SUPPORT
|
||||
|
||||
static inline float value_celsius() { return value_float(); }
|
||||
static inline float value_celsius_diff() { return value_float(); }
|
||||
static inline float to_temp_units(int16_t c) { return (float)c; }
|
||||
|
||||
#define TEMP_UNIT(N) (N)
|
||||
static inline celsius_t value_celsius() { return value_int(); }
|
||||
static inline celsius_t value_celsius_diff() { return value_int(); }
|
||||
|
||||
#endif // !TEMPERATURE_UNITS_SUPPORT
|
||||
|
||||
@@ -390,17 +404,39 @@ public:
|
||||
void unknown_command_warning();
|
||||
|
||||
// Provide simple value accessors with default option
|
||||
static inline char* stringval(const char c, char * const dval=nullptr) { return seenval(c) ? value_string() : dval; }
|
||||
static inline float floatval(const char c, const float dval=0.0) { return seenval(c) ? value_float() : dval; }
|
||||
static inline bool boolval(const char c, const bool dval=false) { return seenval(c) ? value_bool() : (seen(c) ? true : dval); }
|
||||
static inline uint8_t byteval(const char c, const uint8_t dval=0) { return seenval(c) ? value_byte() : dval; }
|
||||
static inline int16_t intval(const char c, const int16_t dval=0) { return seenval(c) ? value_int() : dval; }
|
||||
static inline uint16_t ushortval(const char c, const uint16_t dval=0) { return seenval(c) ? value_ushort() : dval; }
|
||||
static inline int32_t longval(const char c, const int32_t dval=0) { return seenval(c) ? value_long() : dval; }
|
||||
static inline uint32_t ulongval(const char c, const uint32_t dval=0) { return seenval(c) ? value_ulong() : dval; }
|
||||
static inline float linearval(const char c, const float dval=0) { return seenval(c) ? value_linear_units() : dval; }
|
||||
static inline float celsiusval(const char c, const float dval=0) { return seenval(c) ? value_celsius() : dval; }
|
||||
static inline char* stringval(const char c, char * const dval=nullptr) { return seenval(c) ? value_string() : dval; }
|
||||
static inline float floatval(const char c, const float dval=0.0) { return seenval(c) ? value_float() : dval; }
|
||||
static inline bool boolval(const char c, const bool dval=false) { return seenval(c) ? value_bool() : (seen(c) ? true : dval); }
|
||||
static inline uint8_t byteval(const char c, const uint8_t dval=0) { return seenval(c) ? value_byte() : dval; }
|
||||
static inline int16_t intval(const char c, const int16_t dval=0) { return seenval(c) ? value_int() : dval; }
|
||||
static inline uint16_t ushortval(const char c, const uint16_t dval=0) { return seenval(c) ? value_ushort() : dval; }
|
||||
static inline int32_t longval(const char c, const int32_t dval=0) { return seenval(c) ? value_long() : dval; }
|
||||
static inline uint32_t ulongval(const char c, const uint32_t dval=0) { return seenval(c) ? value_ulong() : dval; }
|
||||
static inline float linearval(const char c, const float dval=0) { return seenval(c) ? value_linear_units() : dval; }
|
||||
static inline float axisunitsval(const char c, const AxisEnum a, const float dval=0)
|
||||
{ return seenval(c) ? value_axis_units(a) : dval; }
|
||||
static inline celsius_t celsiusval(const char c, const celsius_t dval=0) { return seenval(c) ? value_celsius() : dval; }
|
||||
static inline feedRate_t feedrateval(const char c, const feedRate_t dval=0) { return seenval(c) ? value_feedrate() : dval; }
|
||||
|
||||
#if ENABLED(MARLIN_DEV_MODE)
|
||||
|
||||
static inline uint8_t* hex_adr_val(const char c, uint8_t * const dval=nullptr) {
|
||||
if (!seen(c) || *value_ptr != 'x') return dval;
|
||||
uint8_t *out = nullptr;
|
||||
for (char *vp = value_ptr + 1; HEXCHR(*vp) >= 0; vp++)
|
||||
out = (uint8_t*)((uintptr_t(out) << 8) | HEXCHR(*vp));
|
||||
return out;
|
||||
}
|
||||
|
||||
static inline uint16_t hex_val(const char c, uint16_t const dval=0) {
|
||||
if (!seen(c) || *value_ptr != 'x') return dval;
|
||||
uint16_t out = 0;
|
||||
for (char *vp = value_ptr + 1; HEXCHR(*vp) >= 0; vp++)
|
||||
out = ((out) << 8) | HEXCHR(*vp);
|
||||
return out;
|
||||
}
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
extern GCodeParser parser;
|
||||
|
Reference in New Issue
Block a user