|
@@ -167,13 +167,10 @@ inline void SERIAL_ECHO(serial_char_t x) { SERIAL_IMPL.write(x.c); }
|
167
|
167
|
#define AS_CHAR(C) serial_char_t(C)
|
168
|
168
|
#define AS_DIGIT(C) AS_CHAR('0' + (C))
|
169
|
169
|
|
170
|
|
-// SERIAL_ECHO_F prints a floating point value with optional precision
|
171
|
|
-inline void SERIAL_ECHO_F(EnsureDouble x, int digit=2) { SERIAL_IMPL.print(x, digit); }
|
172
|
|
-
|
173
|
170
|
template <typename T>
|
174
|
171
|
void SERIAL_ECHOLN(T x) { SERIAL_IMPL.println(x); }
|
175
|
172
|
|
176
|
|
-// SERIAL_PRINT works like SERIAL_ECHO but allow to specify the encoding base of the number printed
|
|
173
|
+// SERIAL_PRINT works like SERIAL_ECHO but also takes the numeric base
|
177
|
174
|
template <typename T, typename U>
|
178
|
175
|
void SERIAL_PRINT(T x, U y) { SERIAL_IMPL.print(x, y); }
|
179
|
176
|
|
|
@@ -184,8 +181,20 @@ void SERIAL_PRINTLN(T x, PrintBase y) { SERIAL_IMPL.println(x, y); }
|
184
|
181
|
inline void SERIAL_FLUSH() { SERIAL_IMPL.flush(); }
|
185
|
182
|
inline void SERIAL_FLUSHTX() { SERIAL_IMPL.flushTX(); }
|
186
|
183
|
|
187
|
|
-// Print a single PROGMEM string to serial
|
188
|
|
-void serialprintPGM(PGM_P str);
|
|
184
|
+// Serial echo and error prefixes
|
|
185
|
+#define SERIAL_ECHO_START() serial_echo_start()
|
|
186
|
+#define SERIAL_ERROR_START() serial_error_start()
|
|
187
|
+
|
|
188
|
+// Serial end-of-line
|
|
189
|
+#define SERIAL_EOL() SERIAL_CHAR('\n')
|
|
190
|
+
|
|
191
|
+// Print a single PROGMEM, PGM_P, or PSTR() string.
|
|
192
|
+void serial_print_P(PGM_P str);
|
|
193
|
+inline void serial_println_P(PGM_P str) { serial_print_P(str); SERIAL_EOL(); }
|
|
194
|
+
|
|
195
|
+// Print a single FSTR_P, F(), or FPSTR() string.
|
|
196
|
+inline void serial_print(FSTR_P const fstr) { serial_print_P(FTOP(fstr)); }
|
|
197
|
+inline void serial_println(FSTR_P const fstr) { serial_println_P(FTOP(fstr)); }
|
189
|
198
|
|
190
|
199
|
//
|
191
|
200
|
// SERIAL_ECHOPGM... macros are used to output string-value pairs.
|
|
@@ -195,8 +204,8 @@ void serialprintPGM(PGM_P str);
|
195
|
204
|
#define __SEP_N(N,V...) _SEP_##N(V)
|
196
|
205
|
#define _SEP_N(N,V...) __SEP_N(N,V)
|
197
|
206
|
#define _SEP_N_REF() _SEP_N
|
198
|
|
-#define _SEP_1(s) serialprintPGM(PSTR(s));
|
199
|
|
-#define _SEP_2(s,v) serial_echopair_PGM(PSTR(s),v);
|
|
207
|
+#define _SEP_1(s) serial_print(F(s));
|
|
208
|
+#define _SEP_2(s,v) serial_echopair(F(s),v);
|
200
|
209
|
#define _SEP_3(s,v,V...) _SEP_2(s,v); DEFER2(_SEP_N_REF)()(TWO_ARGS(V),V);
|
201
|
210
|
#define SERIAL_ECHOPGM(V...) do{ EVAL(_SEP_N(TWO_ARGS(V),V)); }while(0)
|
202
|
211
|
|
|
@@ -204,8 +213,8 @@ void serialprintPGM(PGM_P str);
|
204
|
213
|
#define __SELP_N(N,V...) _SELP_##N(V)
|
205
|
214
|
#define _SELP_N(N,V...) __SELP_N(N,V)
|
206
|
215
|
#define _SELP_N_REF() _SELP_N
|
207
|
|
-#define _SELP_1(s) serialprintPGM(PSTR(s "\n"));
|
208
|
|
-#define _SELP_2(s,v) serial_echopair_PGM(PSTR(s),v); SERIAL_EOL();
|
|
216
|
+#define _SELP_1(s) serial_print(F(s "\n"));
|
|
217
|
+#define _SELP_2(s,v) serial_echolnpair(F(s),v);
|
209
|
218
|
#define _SELP_3(s,v,V...) _SEP_2(s,v); DEFER2(_SELP_N_REF)()(TWO_ARGS(V),V);
|
210
|
219
|
#define SERIAL_ECHOLNPGM(V...) do{ EVAL(_SELP_N(TWO_ARGS(V),V)); }while(0)
|
211
|
220
|
|
|
@@ -213,8 +222,8 @@ void serialprintPGM(PGM_P str);
|
213
|
222
|
#define __SEP_N_P(N,V...) _SEP_##N##_P(V)
|
214
|
223
|
#define _SEP_N_P(N,V...) __SEP_N_P(N,V)
|
215
|
224
|
#define _SEP_N_P_REF() _SEP_N_P
|
216
|
|
-#define _SEP_1_P(p) serialprintPGM(p);
|
217
|
|
-#define _SEP_2_P(p,v) serial_echopair_PGM(p,v);
|
|
225
|
+#define _SEP_1_P(p) serial_print_P(p);
|
|
226
|
+#define _SEP_2_P(p,v) serial_echopair_P(p,v);
|
218
|
227
|
#define _SEP_3_P(p,v,V...) _SEP_2_P(p,v); DEFER2(_SEP_N_P_REF)()(TWO_ARGS(V),V);
|
219
|
228
|
#define SERIAL_ECHOPGM_P(V...) do{ EVAL(_SEP_N_P(TWO_ARGS(V),V)); }while(0)
|
220
|
229
|
|
|
@@ -222,11 +231,29 @@ void serialprintPGM(PGM_P str);
|
222
|
231
|
#define __SELP_N_P(N,V...) _SELP_##N##_P(V)
|
223
|
232
|
#define _SELP_N_P(N,V...) __SELP_N_P(N,V)
|
224
|
233
|
#define _SELP_N_P_REF() _SELP_N_P
|
225
|
|
-#define _SELP_1_P(p) { serialprintPGM(p); SERIAL_EOL(); }
|
226
|
|
-#define _SELP_2_P(p,v) { serial_echopair_PGM(p,v); SERIAL_EOL(); }
|
|
234
|
+#define _SELP_1_P(p) serial_println_P(p)
|
|
235
|
+#define _SELP_2_P(p,v) serial_echolnpair_P(p,v)
|
227
|
236
|
#define _SELP_3_P(p,v,V...) { _SEP_2_P(p,v); DEFER2(_SELP_N_P_REF)()(TWO_ARGS(V),V); }
|
228
|
237
|
#define SERIAL_ECHOLNPGM_P(V...) do{ EVAL(_SELP_N_P(TWO_ARGS(V),V)); }while(0)
|
229
|
238
|
|
|
239
|
+// Print up to 20 pairs of values. Odd elements must be FSTR_P, F(), or FPSTR().
|
|
240
|
+#define __SEP_N_F(N,V...) _SEP_##N##_F(V)
|
|
241
|
+#define _SEP_N_F(N,V...) __SEP_N_F(N,V)
|
|
242
|
+#define _SEP_N_F_REF() _SEP_N_F
|
|
243
|
+#define _SEP_1_F(p) serial_print(p);
|
|
244
|
+#define _SEP_2_F(p,v) serial_echopair(p,v);
|
|
245
|
+#define _SEP_3_F(p,v,V...) _SEP_2_F(p,v); DEFER2(_SEP_N_F_REF)()(TWO_ARGS(V),V);
|
|
246
|
+#define SERIAL_ECHOF(V...) do{ EVAL(_SEP_N_F(TWO_ARGS(V),V)); }while(0)
|
|
247
|
+
|
|
248
|
+// Print up to 20 pairs of values followed by newline. Odd elements must be FSTR_P, F(), or FPSTR().
|
|
249
|
+#define __SELP_N_F(N,V...) _SELP_##N##_F(V)
|
|
250
|
+#define _SELP_N_F(N,V...) __SELP_N_F(N,V)
|
|
251
|
+#define _SELP_N_F_REF() _SELP_N_F
|
|
252
|
+#define _SELP_1_F(p) serial_println(p)
|
|
253
|
+#define _SELP_2_F(p,v) serial_echolnpair(p,v)
|
|
254
|
+#define _SELP_3_F(p,v,V...) { _SEP_2_F(p,v); DEFER2(_SELP_N_F_REF)()(TWO_ARGS(V),V); }
|
|
255
|
+#define SERIAL_ECHOLNF(V...) do{ EVAL(_SELP_N_F(TWO_ARGS(V),V)); }while(0)
|
|
256
|
+
|
230
|
257
|
#ifdef AllowDifferentTypeInList
|
231
|
258
|
|
232
|
259
|
inline void SERIAL_ECHOLIST_IMPL() {}
|
|
@@ -236,47 +263,49 @@ void serialprintPGM(PGM_P str);
|
236
|
263
|
template <typename T, typename ... Args>
|
237
|
264
|
void SERIAL_ECHOLIST_IMPL(T && t, Args && ... args) {
|
238
|
265
|
SERIAL_IMPL.print(t);
|
239
|
|
- serialprintPGM(PSTR(", "));
|
|
266
|
+ serial_print(F(", "));
|
240
|
267
|
SERIAL_ECHOLIST_IMPL(args...);
|
241
|
268
|
}
|
242
|
269
|
|
243
|
270
|
template <typename ... Args>
|
244
|
|
- void SERIAL_ECHOLIST(PGM_P const str, Args && ... args) {
|
245
|
|
- SERIAL_IMPL.print(str);
|
|
271
|
+ void SERIAL_ECHOLIST(FSTR_P const str, Args && ... args) {
|
|
272
|
+ SERIAL_IMPL.print(FTOP(str));
|
246
|
273
|
SERIAL_ECHOLIST_IMPL(args...);
|
247
|
274
|
}
|
248
|
275
|
|
249
|
276
|
#else // Optimization if the listed type are all the same (seems to be the case in the codebase so use that instead)
|
250
|
277
|
|
251
|
278
|
template <typename ... Args>
|
252
|
|
- void SERIAL_ECHOLIST(PGM_P const str, Args && ... args) {
|
253
|
|
- serialprintPGM(str);
|
|
279
|
+ void SERIAL_ECHOLIST(FSTR_P const fstr, Args && ... args) {
|
|
280
|
+ serial_print(fstr);
|
254
|
281
|
typename Private::first_type_of<Args...>::type values[] = { args... };
|
255
|
282
|
constexpr size_t argsSize = sizeof...(args);
|
256
|
283
|
for (size_t i = 0; i < argsSize; i++) {
|
257
|
|
- if (i) serialprintPGM(PSTR(", "));
|
|
284
|
+ if (i) serial_print(F(", "));
|
258
|
285
|
SERIAL_IMPL.print(values[i]);
|
259
|
286
|
}
|
260
|
287
|
}
|
261
|
288
|
|
262
|
289
|
#endif
|
263
|
290
|
|
264
|
|
-#define SERIAL_ECHOPAIR_F_P(P,V...) do{ serialprintPGM(P); SERIAL_ECHO_F(V); }while(0)
|
265
|
|
-#define SERIAL_ECHOLNPAIR_F_P(V...) do{ SERIAL_ECHOPAIR_F_P(V); SERIAL_EOL(); }while(0)
|
|
291
|
+// SERIAL_ECHO_F prints a floating point value with optional precision
|
|
292
|
+inline void SERIAL_ECHO_F(EnsureDouble x, int digit=2) { SERIAL_IMPL.print(x, digit); }
|
|
293
|
+
|
|
294
|
+#define SERIAL_ECHOPAIR_F_P(P,V...) do{ serial_print_P(P); SERIAL_ECHO_F(V); }while(0)
|
|
295
|
+#define SERIAL_ECHOLNPAIR_F_P(P,V...) do{ SERIAL_ECHOPAIR_F_P(P,V); SERIAL_EOL(); }while(0)
|
266
|
296
|
|
267
|
|
-#define SERIAL_ECHOPAIR_F(S,V...) SERIAL_ECHOPAIR_F_P(PSTR(S),V)
|
268
|
|
-#define SERIAL_ECHOLNPAIR_F(V...) do{ SERIAL_ECHOPAIR_F(V); SERIAL_EOL(); }while(0)
|
|
297
|
+#define SERIAL_ECHOPAIR_F_F(S,V...) do{ serial_print(S); SERIAL_ECHO_F(V); }while(0)
|
|
298
|
+#define SERIAL_ECHOLNPAIR_F_F(S,V...) do{ SERIAL_ECHOPAIR_F_F(S,V); SERIAL_EOL(); }while(0)
|
269
|
299
|
|
270
|
|
-#define SERIAL_ECHO_START() serial_echo_start()
|
271
|
|
-#define SERIAL_ERROR_START() serial_error_start()
|
272
|
|
-#define SERIAL_EOL() SERIAL_CHAR('\n')
|
|
300
|
+#define SERIAL_ECHOPAIR_F(S,V...) SERIAL_ECHOPAIR_F_F(F(S),V)
|
|
301
|
+#define SERIAL_ECHOLNPAIR_F(V...) do{ SERIAL_ECHOPAIR_F(V); SERIAL_EOL(); }while(0)
|
273
|
302
|
|
274
|
|
-#define SERIAL_ECHO_MSG(V...) do{ SERIAL_ECHO_START(); SERIAL_ECHOLNPGM(V); }while(0)
|
275
|
|
-#define SERIAL_ERROR_MSG(V...) do{ SERIAL_ERROR_START(); SERIAL_ECHOLNPGM(V); }while(0)
|
|
303
|
+#define SERIAL_ECHO_MSG(V...) do{ SERIAL_ECHO_START(); SERIAL_ECHOLNPGM(V); }while(0)
|
|
304
|
+#define SERIAL_ERROR_MSG(V...) do{ SERIAL_ERROR_START(); SERIAL_ECHOLNPGM(V); }while(0)
|
276
|
305
|
|
277
|
|
-#define SERIAL_ECHO_SP(C) serial_spaces(C)
|
|
306
|
+#define SERIAL_ECHO_SP(C) serial_spaces(C)
|
278
|
307
|
|
279
|
|
-#define SERIAL_ECHO_TERNARY(TF, PRE, ON, OFF, POST) serial_ternary(TF, PSTR(PRE), PSTR(ON), PSTR(OFF), PSTR(POST))
|
|
308
|
+#define SERIAL_ECHO_TERNARY(TF, PRE, ON, OFF, POST) serial_ternary(TF, F(PRE), F(ON), F(OFF), F(POST))
|
280
|
309
|
|
281
|
310
|
#if SERIAL_FLOAT_PRECISION
|
282
|
311
|
#define SERIAL_DECIMAL(V) SERIAL_PRINT(V, SERIAL_FLOAT_PRECISION)
|
|
@@ -287,33 +316,42 @@ void serialprintPGM(PGM_P str);
|
287
|
316
|
//
|
288
|
317
|
// Functions for serial printing from PROGMEM. (Saves loads of SRAM.)
|
289
|
318
|
//
|
290
|
|
-inline void serial_echopair_PGM(PGM_P const s_P, serial_char_t v) { serialprintPGM(s_P); SERIAL_CHAR(v.c); }
|
291
|
|
-
|
292
|
|
-inline void serial_echopair_PGM(PGM_P const s_P, float v) { serialprintPGM(s_P); SERIAL_DECIMAL(v); }
|
293
|
|
-inline void serial_echopair_PGM(PGM_P const s_P, double v) { serialprintPGM(s_P); SERIAL_DECIMAL(v); }
|
294
|
|
-inline void serial_echopair_PGM(PGM_P const s_P, const char *v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
|
|
319
|
+inline void serial_echopair_P(PGM_P const pstr, serial_char_t v) { serial_print_P(pstr); SERIAL_CHAR(v.c); }
|
|
320
|
+inline void serial_echopair_P(PGM_P const pstr, float v) { serial_print_P(pstr); SERIAL_DECIMAL(v); }
|
|
321
|
+inline void serial_echopair_P(PGM_P const pstr, double v) { serial_print_P(pstr); SERIAL_DECIMAL(v); }
|
|
322
|
+//inline void serial_echopair_P(PGM_P const pstr, const char *v) { serial_print_P(pstr); SERIAL_ECHO(v); }
|
|
323
|
+inline void serial_echopair_P(PGM_P const pstr, FSTR_P v) { serial_print_P(pstr); SERIAL_ECHOF(v); }
|
295
|
324
|
|
296
|
325
|
// Default implementation for types without a specialization. Handles integers.
|
297
|
326
|
template <typename T>
|
298
|
|
-void serial_echopair_PGM(PGM_P const s_P, T v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
|
|
327
|
+inline void serial_echopair_P(PGM_P const pstr, T v) { serial_print_P(pstr); SERIAL_ECHO(v); }
|
|
328
|
+
|
|
329
|
+// Add a newline.
|
|
330
|
+template <typename T>
|
|
331
|
+inline void serial_echolnpair_P(PGM_P const pstr, T v) { serial_echopair_P(pstr, v); SERIAL_EOL(); }
|
|
332
|
+
|
|
333
|
+// Catch-all for __FlashStringHelper *
|
|
334
|
+template <typename T>
|
|
335
|
+inline void serial_echopair(FSTR_P const fstr, T v) { serial_echopair_P(FTOP(fstr), v); }
|
299
|
336
|
|
300
|
|
-inline void serial_echopair_PGM(PGM_P const s_P, bool v) { serial_echopair_PGM(s_P, (int)v); }
|
301
|
|
-inline void serial_echopair_PGM(PGM_P const s_P, void *v) { serial_echopair_PGM(s_P, (uintptr_t)v); }
|
|
337
|
+// Add a newline to the serial output
|
|
338
|
+template <typename T>
|
|
339
|
+inline void serial_echolnpair(FSTR_P const fstr, T v) { serial_echolnpair_P(FTOP(fstr), v); }
|
302
|
340
|
|
303
|
341
|
void serial_echo_start();
|
304
|
342
|
void serial_error_start();
|
305
|
|
-void serial_ternary(const bool onoff, PGM_P const pre, PGM_P const on, PGM_P const off, PGM_P const post=nullptr);
|
|
343
|
+void serial_ternary(const bool onoff, FSTR_P const pre, FSTR_P const on, FSTR_P const off, FSTR_P const post=nullptr);
|
306
|
344
|
void serialprint_onoff(const bool onoff);
|
307
|
345
|
void serialprintln_onoff(const bool onoff);
|
308
|
346
|
void serialprint_truefalse(const bool tf);
|
309
|
347
|
void serial_spaces(uint8_t count);
|
310
|
348
|
|
311
|
349
|
void print_bin(const uint16_t val);
|
312
|
|
-void print_pos(LINEAR_AXIS_ARGS(const_float_t), PGM_P const prefix=nullptr, PGM_P const suffix=nullptr);
|
|
350
|
+void print_pos(LINEAR_AXIS_ARGS(const_float_t), FSTR_P const prefix=nullptr, FSTR_P const suffix=nullptr);
|
313
|
351
|
|
314
|
|
-inline void print_pos(const xyz_pos_t &xyz, PGM_P const prefix=nullptr, PGM_P const suffix=nullptr) {
|
|
352
|
+inline void print_pos(const xyz_pos_t &xyz, FSTR_P const prefix=nullptr, FSTR_P const suffix=nullptr) {
|
315
|
353
|
print_pos(LINEAR_AXIS_ELEM(xyz), prefix, suffix);
|
316
|
354
|
}
|
317
|
355
|
|
318
|
|
-#define SERIAL_POS(SUFFIX,VAR) do { print_pos(VAR, PSTR(" " STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n")); }while(0)
|
319
|
|
-#define SERIAL_XYZ(PREFIX,V...) do { print_pos(V, PSTR(PREFIX), nullptr); }while(0)
|
|
356
|
+#define SERIAL_POS(SUFFIX,VAR) do { print_pos(VAR, F(" " STRINGIFY(VAR) "="), F(" : " SUFFIX "\n")); }while(0)
|
|
357
|
+#define SERIAL_XYZ(PREFIX,V...) do { print_pos(V, F(PREFIX)); }while(0)
|