Skip to content

Commit

Permalink
🐛 Fix M105 (MString append TS) and EEPROM ver
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and EvilGremlin committed Oct 26, 2023
1 parent 88f8a8c commit 4287453
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
15 changes: 10 additions & 5 deletions Marlin/src/core/mstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ class MString {
MString& set(const char *s) { return set(const_cast<char*>(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; }
Expand All @@ -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 <int S>
MString& set(const MString<S> &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<char*>(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; }
Expand Down Expand Up @@ -157,7 +159,6 @@ class MString {
MString& append(const char *s) { return append(const_cast<char *>(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)
Expand Down Expand Up @@ -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<int S>
MString& append(const MString<S> &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<char *>(s), len); }
Expand Down Expand Up @@ -227,7 +231,7 @@ class MString {
MString(T arg1, Args... more) { set(arg1); append(more...); }

// Catch unhandled types to prevent infinite recursion
template<typename T> MString& append(T) { return append('?'); }
template<typename T> 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<typename T, typename... Args>
Expand Down Expand Up @@ -313,4 +317,5 @@ class MString {
#ifndef TS_SIZE
#define TS_SIZE 63
#endif
#define TS(V...) MString<TS_SIZE>(V)
typedef MString<TS_SIZE, DISABLED(UNSAFE_MSTRING)> TString;
#define TS(V...) TString(V)
4 changes: 2 additions & 2 deletions Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4287453

Please sign in to comment.