From 428745372a67760e866c6878f1f572be35050e25 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 1 Jul 2023 16:50:42 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20M105=20(MString=20append?= =?UTF-8?q?=20TS)=20and=20EEPROM=20ver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Followup to #24390 --- Marlin/src/core/mstring.h | 15 ++++++++++----- Marlin/src/module/settings.cpp | 4 ++-- Marlin/src/module/temperature.cpp | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Marlin/src/core/mstring.h b/Marlin/src/core/mstring.h index 77a03d7ff140..bdfc95f9dcda 100644 --- a/Marlin/src/core/mstring.h +++ b/Marlin/src/core/mstring.h @@ -112,10 +112,9 @@ class MString { MString& set(const char *s) { return set(const_cast(s)); } MString& set_P(PGM_P const s) { strncpy_P(str, s, SIZE); debug(F("pstring")); return *this; } MString& set(FSTR_P const f) { return set_P(FTOP(f)); } - MString& set(const MString &s) { strncpy(str, s.str, SIZE); debug(F("MString")); return *this; } MString& set(const bool &b) { return set(b ? F("true") : F("false")); } MString& set(const char c) { str[0] = c; if (1 < SIZE) str[1] = '\0'; debug(F("char")); return *this; } - MString& set(const int8_t &i) { SNPRINTF_P(str, SIZE, PSTR("%d"), i); debug(F("int8_t")); return *this; } + MString& set(const int8_t &i) { SNPRINTF_P(str, SIZE, PSTR("%d"), i); debug(F("int8_t")); return *this; } MString& set(const short &i) { SNPRINTF_P(str, SIZE, PSTR("%d"), i); debug(F("short")); return *this; } MString& set(const int &i) { SNPRINTF_P(str, SIZE, PSTR("%d"), i); debug(F("int")); return *this; } MString& set(const long &l) { SNPRINTF_P(str, SIZE, PSTR("%ld"), l); debug(F("long")); return *this; } @@ -130,6 +129,9 @@ class MString { MString& set(const xyz_pos_t &v) { set(); return append(v); } MString& set(const xyze_pos_t &v) { set(); return append(v); } + template + MString& set(const MString &m) { strncpy(str, &m, SIZE); debug(F("MString")); return *this; } + MString& setn(char *s, int len) { int c = _MIN(len, SIZE); strncpy(str, s, c); str[c] = '\0'; debug(F("string")); return *this; } MString& setn(const char *s, int len) { return setn(const_cast(s), len); } MString& setn_P(PGM_P const s, int len) { int c = _MIN(len, SIZE); strncpy_P(str, s, c); str[c] = '\0'; debug(F("pstring")); return *this; } @@ -157,7 +159,6 @@ class MString { MString& append(const char *s) { return append(const_cast(s)); } MString& append_P(PGM_P const s) { int sz = length(); if (sz < SIZE) strncpy_P(str + sz, s, SIZE - sz); debug(F("pstring")); return *this; } MString& append(FSTR_P const f) { return append_P(FTOP(f)); } - MString& append(const MString &s) { return append(s.str); } MString& append(const bool &b) { return append(b ? F("true") : F("false")); } MString& append(const char c) { int sz = length(); if (sz < SIZE) { str[sz] = c; if (sz < SIZE - 1) str[sz + 1] = '\0'; } return *this; } #if ENABLED(FASTER_APPEND) @@ -186,6 +187,9 @@ class MString { MString& append(const xyz_pos_t &v) { LOOP_NUM_AXES(i) { if (i) append(' '); append(AXIS_CHAR(i), v[i]); } debug(F("xyz")); return *this; } MString& append(const xyze_pos_t &v) { LOOP_LOGICAL_AXES(i) { if (i) append(' '); append(AXIS_CHAR(i), v[i]); } debug(F("xyze")); return *this; } + template + MString& append(const MString &m) { return append(&m); } + // Append only if the given space is available MString& appendn(char *s, int len) { int sz = length(), c = _MIN(len, SIZE - sz); if (c > 0) { strncpy(str + sz, s, c); str[sz + c] = '\0'; } debug(F("string")); return *this; } MString& appendn(const char *s, int len) { return appendn(const_cast(s), len); } @@ -227,7 +231,7 @@ class MString { MString(T arg1, Args... more) { set(arg1); append(more...); } // Catch unhandled types to prevent infinite recursion - template MString& append(T) { return append('?'); } + template MString& append(T) { return append(TERN(MSTRING_DEBUG, typeid(T).name(), '?')); } // Take a list of any number of arguments and append them to the string template @@ -313,4 +317,5 @@ class MString { #ifndef TS_SIZE #define TS_SIZE 63 #endif -#define TS(V...) MString(V) +typedef MString TString; +#define TS(V...) TString(V) diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index 479b43c4bd7d..c8ce84cd83e4 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -814,14 +814,14 @@ void MarlinSettings::postprocess() { */ bool MarlinSettings::save() { float dummyf = 0; - MString<4> ver(F("ERR")); + MString<3> ver(F("ERR")); if (!EEPROM_START(EEPROM_OFFSET)) return false; EEPROM_Error eeprom_error = ERR_EEPROM_NOERR; // Write or Skip version. (Flash doesn't allow rewrite without erase.) - TERN(FLASH_EEPROM_EMULATION, EEPROM_SKIP, EEPROM_WRITE)(&ver); + TERN(FLASH_EEPROM_EMULATION, EEPROM_SKIP, EEPROM_WRITE)(ver); #if ENABLED(EEPROM_INIT_NOW) EEPROM_SKIP(build_hash); // Skip the hash slot which will be written later diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index e209d6f83519..d7bf9c8b7936 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -4185,7 +4185,7 @@ void Temperature::isr() { SString<50> s(' ', k); if (TERN0(HAS_MULTI_HOTEND, e >= 0)) s += char('0' + e); - s += TS(':', p_float_t(c, SFP)); + s += ':'; s += p_float_t(c, SFP); if (show_t) { s += F(" /"); s += p_float_t(t, SFP); } #if ENABLED(SHOW_TEMP_ADC_VALUES) // Temperature MAX SPI boards do not have an OVERSAMPLENR defined