Skip to content

Commit eab5320

Browse files
committed
♻️ Simpler flexible SERIAL_ECHO
1 parent 02e4b26 commit eab5320

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+396
-603
lines changed

Marlin/src/HAL/LPC1768/eeprom_sdcard.cpp

+3-9
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,9 @@ bool PersistentStore::access_finish() {
9191
static void debug_rw(const bool write, int &pos, const uint8_t *value, const size_t size, const FRESULT s, const size_t total=0) {
9292
#if ENABLED(DEBUG_SD_EEPROM_EMULATION)
9393
FSTR_P const rw_str = write ? F("write") : F("read");
94-
SERIAL_CHAR(' ');
95-
SERIAL_ECHOF(rw_str);
96-
SERIAL_ECHOLNPGM("_data(", pos, ",", *value, ",", size, ", ...)");
97-
if (total) {
98-
SERIAL_ECHOPGM(" f_");
99-
SERIAL_ECHOF(rw_str);
100-
SERIAL_ECHOPGM("()=", s, "\n size=", size, "\n bytes_");
101-
SERIAL_ECHOLNF(write ? F("written=") : F("read="), total);
102-
}
94+
SERIAL_ECHOLN(AS_CHAR(' '), rw_str, F("_data("), pos, AS_CHAR(','), *value, AS_CHAR(','), size, F(", ...)"));
95+
if (total)
96+
SERIAL_ECHOLN(F(" f_"), rw_str, F("()="), s, F("\n size="), size, F("\n bytes_"), write ? F("written=") : F("read="), total);
10397
else
10498
SERIAL_ECHOLNPGM(" f_lseek()=", s);
10599
#endif

Marlin/src/HAL/shared/Delay.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,7 @@
109109
#if ENABLED(MARLIN_DEV_MODE)
110110
void dump_delay_accuracy_check() {
111111
auto report_call_time = [](FSTR_P const name, FSTR_P const unit, const uint32_t cycles, const uint32_t total, const bool do_flush=true) {
112-
SERIAL_ECHOPGM("Calling ");
113-
SERIAL_ECHOF(name);
114-
SERIAL_ECHOLNPGM(" for ", cycles);
115-
SERIAL_ECHOF(unit);
116-
SERIAL_ECHOLNPGM(" took: ", total);
117-
SERIAL_CHAR(' ');
118-
SERIAL_ECHOF(unit);
112+
SERIAL_ECHOLN(F("Calling "), name, F(" for "), cycles, AS_CHAR(' '), unit, F(" took: "), total, AS_CHAR(' '), unit);
119113
if (do_flush) SERIAL_FLUSHTX();
120114
};
121115

Marlin/src/MarlinCore.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ void kill(FSTR_P const lcd_error/*=nullptr*/, FSTR_P const lcd_component/*=nullp
882882
TERN_(HAS_CUTTER, cutter.kill()); // Full cutter shutdown including ISR control
883883

884884
// Echo the LCD message to serial for extra context
885-
if (lcd_error) { SERIAL_ECHO_START(); SERIAL_ECHOLNF(lcd_error); }
885+
if (lcd_error) { SERIAL_ECHO_START(); SERIAL_ECHOLN(lcd_error); }
886886

887887
#if HAS_DISPLAY
888888
ui.kill_screen(lcd_error ?: GET_TEXT_F(MSG_KILLED), lcd_component ?: FPSTR(NUL_STR));

Marlin/src/core/debug_out.h

-24
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,11 @@
3131
#undef DEBUG_ERROR_START
3232
#undef DEBUG_CHAR
3333
#undef DEBUG_ECHO
34-
#undef DEBUG_DECIMAL
35-
#undef DEBUG_ECHO_F
3634
#undef DEBUG_ECHOLN
3735
#undef DEBUG_ECHOPGM
3836
#undef DEBUG_ECHOLNPGM
39-
#undef DEBUG_ECHOF
40-
#undef DEBUG_ECHOLNF
4137
#undef DEBUG_ECHOPGM_P
4238
#undef DEBUG_ECHOLNPGM_P
43-
#undef DEBUG_ECHOPAIR_F
44-
#undef DEBUG_ECHOPAIR_F_P
45-
#undef DEBUG_ECHOLNPAIR_F
46-
#undef DEBUG_ECHOLNPAIR_F_P
4739
#undef DEBUG_ECHO_MSG
4840
#undef DEBUG_ERROR_MSG
4941
#undef DEBUG_EOL
@@ -62,21 +54,13 @@
6254
#define DEBUG_ERROR_START SERIAL_ERROR_START
6355
#define DEBUG_CHAR SERIAL_CHAR
6456
#define DEBUG_ECHO SERIAL_ECHO
65-
#define DEBUG_DECIMAL SERIAL_DECIMAL
66-
#define DEBUG_ECHO_F SERIAL_ECHO_F
6757
#define DEBUG_ECHOLN SERIAL_ECHOLN
6858
#define DEBUG_ECHOPGM SERIAL_ECHOPGM
6959
#define DEBUG_ECHOLNPGM SERIAL_ECHOLNPGM
70-
#define DEBUG_ECHOF SERIAL_ECHOF
71-
#define DEBUG_ECHOLNF SERIAL_ECHOLNF
7260
#define DEBUG_ECHOPGM SERIAL_ECHOPGM
7361
#define DEBUG_ECHOPGM_P SERIAL_ECHOPGM_P
74-
#define DEBUG_ECHOPAIR_F SERIAL_ECHOPAIR_F
75-
#define DEBUG_ECHOPAIR_F_P SERIAL_ECHOPAIR_F_P
7662
#define DEBUG_ECHOLNPGM SERIAL_ECHOLNPGM
7763
#define DEBUG_ECHOLNPGM_P SERIAL_ECHOLNPGM_P
78-
#define DEBUG_ECHOLNPAIR_F SERIAL_ECHOLNPAIR_F
79-
#define DEBUG_ECHOLNPAIR_F_P SERIAL_ECHOLNPAIR_F_P
8064
#define DEBUG_ECHO_MSG SERIAL_ECHO_MSG
8165
#define DEBUG_ERROR_MSG SERIAL_ERROR_MSG
8266
#define DEBUG_EOL SERIAL_EOL
@@ -93,19 +77,11 @@
9377
#define DEBUG_ERROR_START() NOOP
9478
#define DEBUG_CHAR(...) NOOP
9579
#define DEBUG_ECHO(...) NOOP
96-
#define DEBUG_DECIMAL(...) NOOP
97-
#define DEBUG_ECHO_F(...) NOOP
9880
#define DEBUG_ECHOLN(...) NOOP
9981
#define DEBUG_ECHOPGM(...) NOOP
10082
#define DEBUG_ECHOLNPGM(...) NOOP
101-
#define DEBUG_ECHOF(...) NOOP
102-
#define DEBUG_ECHOLNF(...) NOOP
10383
#define DEBUG_ECHOPGM_P(...) NOOP
10484
#define DEBUG_ECHOLNPGM_P(...) NOOP
105-
#define DEBUG_ECHOPAIR_F(...) NOOP
106-
#define DEBUG_ECHOPAIR_F_P(...) NOOP
107-
#define DEBUG_ECHOLNPAIR_F(...) NOOP
108-
#define DEBUG_ECHOLNPAIR_F_P(...) NOOP
10985
#define DEBUG_ECHO_MSG(...) NOOP
11086
#define DEBUG_ERROR_MSG(...) NOOP
11187
#define DEBUG_EOL() NOOP

Marlin/src/core/debug_section.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ class SectionLog {
3838
bool debug;
3939

4040
void echo_msg(FSTR_P const fpre) {
41-
SERIAL_ECHOF(fpre);
42-
if (the_msg) {
43-
SERIAL_CHAR(' ');
44-
SERIAL_ECHOF(the_msg);
45-
}
41+
SERIAL_ECHO(fpre);
42+
if (the_msg) SERIAL_ECHO(AS_CHAR(' '), the_msg);
4643
SERIAL_CHAR(' ');
4744
print_pos(current_position);
4845
}

Marlin/src/core/serial.cpp

+35-10
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,51 @@ MAP(_N_LBL, LOGICAL_AXIS_NAMES); MAP(_SP_N_LBL, LOGICAL_AXIS_NAMES);
6868

6969
#endif
7070

71-
void serial_print_P(PGM_P str) {
72-
while (const char c = pgm_read_byte(str++)) SERIAL_CHAR(c);
71+
// Specializations for float, p_float_t, w_float_t
72+
template <> void SERIAL_ECHO(const float f) { SERIAL_IMPL.print(f); }
73+
template <> void SERIAL_ECHO(const p_float_t pf) { SERIAL_IMPL.print(pf.value, pf.prec); }
74+
template <> void SERIAL_ECHO(const w_float_t wf) { char f1[20]; SERIAL_IMPL.print(dtostrf(wf.value, wf.width, wf.prec, f1)); }
75+
76+
// Specializations for F-string
77+
template <> void SERIAL_ECHO(const FSTR_P fstr) { SERIAL_ECHO_P(FTOP(fstr)); }
78+
template <> void SERIAL_ECHOLN(const FSTR_P fstr) { SERIAL_ECHOLN_P(FTOP(fstr)); }
79+
80+
void SERIAL_CHAR(char a) { SERIAL_IMPL.write(a); }
81+
void SERIAL_EOL() { SERIAL_CHAR('\n'); }
82+
83+
void SERIAL_ECHO(serial_char_t x) { SERIAL_IMPL.write(x.c); }
84+
85+
void SERIAL_FLUSH() { SERIAL_IMPL.flush(); }
86+
void SERIAL_FLUSHTX() { SERIAL_IMPL.flushTX(); }
87+
88+
void SERIAL_ECHO_P(PGM_P pstr) {
89+
while (const char c = pgm_read_byte(pstr++)) SERIAL_CHAR(c);
7390
}
91+
void SERIAL_ECHOLN_P(PGM_P pstr) { SERIAL_ECHO_P(pstr); SERIAL_EOL(); }
7492

75-
void serial_echo_start() { serial_print(F("echo:")); }
76-
void serial_error_start() { serial_print(F("Error:")); }
93+
void SERIAL_ECHO_START() { SERIAL_ECHO(F("echo:")); }
94+
void SERIAL_ERROR_START() { SERIAL_ECHO(F("Error:")); }
7795

78-
void serial_spaces(uint8_t count) { count *= (PROPORTIONAL_FONT_RATIO); while (count--) SERIAL_CHAR(' '); }
96+
void SERIAL_ECHO_SP(uint8_t count) { count *= (PROPORTIONAL_FONT_RATIO); while (count--) SERIAL_CHAR(' '); }
7997

8098
void serial_offset(const_float_t v, const uint8_t sp/*=0*/) {
8199
if (v == 0 && sp == 1)
82100
SERIAL_CHAR(' ');
83101
else if (v > 0 || (v == 0 && sp == 2))
84102
SERIAL_CHAR('+');
85-
SERIAL_DECIMAL(v);
103+
SERIAL_ECHO(v);
104+
}
105+
106+
void serial_ternary(FSTR_P const pre, const bool onoff, FSTR_P const on, FSTR_P const off, FSTR_P const post/*=nullptr*/) {
107+
if (pre) SERIAL_ECHO(pre);
108+
if (onoff && on) SERIAL_ECHO(on);
109+
if (!onoff && off) SERIAL_ECHO(off);
110+
if (post) SERIAL_ECHO(post);
86111
}
87112

88-
void serialprint_onoff(const bool onoff) { serial_print(onoff ? F(STR_ON) : F(STR_OFF)); }
113+
void serialprint_onoff(const bool onoff) { SERIAL_ECHO(onoff ? F(STR_ON) : F(STR_OFF)); }
89114
void serialprintln_onoff(const bool onoff) { serialprint_onoff(onoff); SERIAL_EOL(); }
90-
void serialprint_truefalse(const bool tf) { serial_print(tf ? F("true") : F("false")); }
115+
void serialprint_truefalse(const bool tf) { SERIAL_ECHO(tf ? F("true") : F("false")); }
91116

92117
void print_bin(uint16_t val) {
93118
for (uint8_t i = 16; i--;) {
@@ -97,11 +122,11 @@ void print_bin(uint16_t val) {
97122
}
98123

99124
void print_pos(NUM_AXIS_ARGS_(const_float_t) FSTR_P const prefix/*=nullptr*/, FSTR_P const suffix/*=nullptr*/) {
100-
if (prefix) serial_print(prefix);
125+
if (prefix) SERIAL_ECHO(prefix);
101126
#if NUM_AXES
102127
SERIAL_ECHOPGM_P(
103128
LIST_N(DOUBLE(NUM_AXES), SP_X_STR, x, SP_Y_STR, y, SP_Z_STR, z, SP_I_STR, i, SP_J_STR, j, SP_K_STR, k, SP_U_STR, u, SP_V_STR, v, SP_W_STR, w)
104129
);
105130
#endif
106-
if (suffix) serial_print(suffix); else SERIAL_EOL();
131+
if (suffix) SERIAL_ECHO(suffix); else SERIAL_EOL();
107132
}

0 commit comments

Comments
 (0)