mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2025-02-18 15:21:25 +00:00
🩹 Fix string buffer warning (#26550)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
parent
89fdfcfaf9
commit
bb557e5195
5 changed files with 27 additions and 26 deletions
|
@ -136,7 +136,7 @@ public:
|
|||
MString& setn(FSTR_P const f, int len) { return setn_P(FTOP(f), len); }
|
||||
|
||||
// set(repchr_t('-', 10))
|
||||
MString& set(const repchr_t &s) { int c = _MIN(s.count, SIZE); memset(str, s.asc, c); str[c] = '\0'; debug(F("")); return *this; }
|
||||
MString& set(const repchr_t &s) { int c = _MIN(s.count, SIZE); if (c >= 0) { if (c > 0) memset(str, s.asc, c); str[c] = '\0'; } debug(F("repchr_t")); return *this; }
|
||||
|
||||
// set(spaces_t(10))
|
||||
MString& set(const spaces_t &s) { repchr_t r(' ', s.count); return set(r); }
|
||||
|
|
|
@ -309,10 +309,10 @@ typedef struct WFloat { float value; char width; char prec;
|
|||
typedef struct PFloat { float value; char prec;
|
||||
PFloat(float v, char p) : value(v), prec(p) {}
|
||||
} p_float_t;
|
||||
typedef struct RepChr { char asc; uint8_t count;
|
||||
typedef struct RepChr { char asc; int8_t count;
|
||||
RepChr(char a, uint8_t c) : asc(a), count(c) {}
|
||||
} repchr_t;
|
||||
typedef struct Spaces { uint8_t count;
|
||||
typedef struct Spaces { int8_t count;
|
||||
Spaces(uint8_t c) : count(c) {}
|
||||
} spaces_t;
|
||||
|
||||
|
|
|
@ -479,16 +479,16 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
|
|||
// Prepare strings for progress display
|
||||
#if ANY(HAS_EXTRA_PROGRESS, HAS_PRINT_PROGRESS)
|
||||
static MarlinUI::progress_t progress = 0;
|
||||
static MString<12> progressString;
|
||||
static MString<13> progressString;
|
||||
#endif
|
||||
|
||||
#if HAS_EXTRA_PROGRESS
|
||||
|
||||
#if HAS_TIME_DISPLAY
|
||||
static void prepare_time_string(const duration_t &time, char prefix) {
|
||||
char str[10];
|
||||
char str[13];
|
||||
const uint8_t time_len = time.toDigital(str, time.value >= 60*60*24L); // 5 to 8 chars
|
||||
progressString.set(prefix, ':', spaces_t(10 - time_len), str); // 2 to 5 spaces
|
||||
progressString.set(prefix, ':', spaces_t(10 - time_len), str); // 2 to 5 spaces
|
||||
}
|
||||
#endif
|
||||
#if ENABLED(SHOW_PROGRESS_PERCENT)
|
||||
|
|
|
@ -662,39 +662,36 @@ bool ST7920_Lite_Status_Screen::indicators_changed() {
|
|||
|
||||
// Process progress strings
|
||||
#if HAS_PRINT_PROGRESS
|
||||
static char screenstr[8];
|
||||
static MString<8> screenstr;
|
||||
|
||||
#if HAS_TIME_DISPLAY
|
||||
char * ST7920_Lite_Status_Screen::prepare_time_string(const duration_t &time, char prefix) {
|
||||
static char str[6];
|
||||
memset(&screenstr, ' ', 8); // fill with spaces to avoid artifacts, not doing right-justification to save cycles
|
||||
screenstr[0] = prefix;
|
||||
TERN_(HOTENDS == 1, screenstr[1] = 0x07;) // add bullet • separator when there is space
|
||||
int str_length = time.toDigital(str);
|
||||
memcpy(&screenstr[TERN(HOTENDS == 1, 2, 1)], str, str_length); //memcpy because we can't have terminator
|
||||
return screenstr;
|
||||
static char time_str[6];
|
||||
(void)time.toDigital(time_str); // Up to 5 chars
|
||||
screenstr = prefix;
|
||||
if (HOTENDS == 1) screenstr += char(0x07); // Add bullet • separator when there is space
|
||||
screenstr += time_str;
|
||||
screenstr += Spaces(3);
|
||||
return &screenstr;
|
||||
}
|
||||
#endif
|
||||
|
||||
void ST7920_Lite_Status_Screen::draw_progress_string(uint8_t addr, const char *str) {
|
||||
set_ddram_address(addr);
|
||||
begin_data();
|
||||
write_str(str, TERN(HOTENDS == 1, 8, 6));
|
||||
write_str(str, HOTENDS == 1 ? 8 : 6);
|
||||
}
|
||||
|
||||
#define PPOS (DDRAM_LINE_3 + TERN(HOTENDS == 1, 4, 5)) // progress string position, in 16-bit words
|
||||
constexpr uint8_t PPOS = (DDRAM_LINE_3 + (HOTENDS == 1 ? 4 : 5)); // Progress string position, in 16-bit words
|
||||
|
||||
#if ENABLED(SHOW_PROGRESS_PERCENT)
|
||||
void MarlinUI::drawPercent() { lightUI.drawPercent(); }
|
||||
void ST7920_Lite_Status_Screen::drawPercent() {
|
||||
#define LSHIFT TERN(HOTENDS == 1, 0, 1)
|
||||
const uint8_t progress = ui.get_progress_percent();
|
||||
memset(&screenstr, ' ', 8); // fill with spaces to avoid artifacts
|
||||
if (progress){
|
||||
memcpy(&screenstr[2 - LSHIFT], \
|
||||
TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(ui.get_progress_permyriad()), ui8tostr3rj(progress)), \
|
||||
TERN(PRINT_PROGRESS_SHOW_DECIMALS, 4, 3));
|
||||
screenstr[(TERN(PRINT_PROGRESS_SHOW_DECIMALS, 6, 5) - LSHIFT)] = '%';
|
||||
if (progress) {
|
||||
screenstr += Spaces(1 + (HOTENDS == 1));
|
||||
screenstr += TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(ui.get_progress_permyriad()), ui8tostr3rj(progress));
|
||||
screenstr += "% ";
|
||||
draw_progress_string(PPOS, screenstr);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1035,9 +1035,13 @@ void MarlinUI::init() {
|
|||
uint8_t abs_diff = ABS(encoderDiff);
|
||||
|
||||
#if ENCODER_PULSES_PER_STEP > 1
|
||||
static int8_t lastEncoderDiff;
|
||||
TERN_(HAS_TOUCH_SLEEP, if (lastEncoderDiff != encoderDiff) wakeup_screen());
|
||||
lastEncoderDiff = encoderDiff;
|
||||
#if HAS_TOUCH_SLEEP
|
||||
static int8_t lastEncoderDiff;
|
||||
if (lastEncoderDiff != encoderDiff) {
|
||||
wakeup_screen();
|
||||
lastEncoderDiff = encoderDiff;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
const bool encoderPastThreshold = (abs_diff >= epps);
|
||||
|
|
Loading…
Reference in a new issue