@@ -68,26 +68,51 @@ MAP(_N_LBL, LOGICAL_AXIS_NAMES); MAP(_SP_N_LBL, LOGICAL_AXIS_NAMES);
68
68
69
69
#endif
70
70
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);
73
90
}
91
+ void SERIAL_ECHOLN_P (PGM_P pstr) { SERIAL_ECHO_P (pstr); SERIAL_EOL (); }
74
92
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:" )); }
77
95
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 (' ' ); }
79
97
80
98
void serial_offset (const_float_t v, const uint8_t sp/* =0*/ ) {
81
99
if (v == 0 && sp == 1 )
82
100
SERIAL_CHAR (' ' );
83
101
else if (v > 0 || (v == 0 && sp == 2 ))
84
102
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);
86
111
}
87
112
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)); }
89
114
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" )); }
91
116
92
117
void print_bin (uint16_t val) {
93
118
for (uint8_t i = 16 ; i--;) {
@@ -97,11 +122,11 @@ void print_bin(uint16_t val) {
97
122
}
98
123
99
124
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);
101
126
#if NUM_AXES
102
127
SERIAL_ECHOPGM_P (
103
128
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)
104
129
);
105
130
#endif
106
- if (suffix) serial_print (suffix); else SERIAL_EOL ();
131
+ if (suffix) SERIAL_ECHO (suffix); else SERIAL_EOL ();
107
132
}
0 commit comments