Add g-code quoted strings, improve stream code (#16818)

This commit is contained in:
Scott Lahteine
2020-02-10 14:52:15 -06:00
committed by GitHub
parent e561f744fa
commit 3bef7a4450
6 changed files with 163 additions and 112 deletions

View File

@@ -208,6 +208,12 @@ public:
return SEEN_TEST('X') || SEEN_TEST('Y') || SEEN_TEST('Z') || SEEN_TEST('E');
}
#if ENABLED(GCODE_QUOTED_STRINGS)
static char* unescape_string(char* &src);
#else
FORCE_INLINE static char* unescape_string(char* &src) { return src; }
#endif
// Populate all fields by parsing a single line of GCode
// This uses 54 bytes of SRAM to speed up seen/value
static void parse(char * p);
@@ -223,6 +229,9 @@ public:
// Seen a parameter with a value
static inline bool seenval(const char c) { return seen(c) && has_value(); }
// Float removes 'E' to prevent scientific notation interpretation
static inline char* value_string() { return value_ptr; }
// Float removes 'E' to prevent scientific notation interpretation
static inline float value_float() {
if (value_ptr) {
@@ -369,6 +378,7 @@ 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; }