My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

serial.h 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "../inc/MarlinConfig.h"
  24. #include "serial_hook.h"
  25. #if HAS_MEATPACK
  26. #include "../feature/meatpack.h"
  27. #endif
  28. // Commonly-used strings in serial output
  29. extern const char NUL_STR[], SP_P_STR[], SP_T_STR[],
  30. X_STR[], Y_STR[], Z_STR[], E_STR[],
  31. X_LBL[], Y_LBL[], Z_LBL[], E_LBL[],
  32. SP_A_STR[], SP_B_STR[], SP_C_STR[],
  33. SP_X_STR[], SP_Y_STR[], SP_Z_STR[], SP_E_STR[],
  34. SP_X_LBL[], SP_Y_LBL[], SP_Z_LBL[], SP_E_LBL[];
  35. //
  36. // Debugging flags for use by M111
  37. //
  38. enum MarlinDebugFlags : uint8_t {
  39. MARLIN_DEBUG_NONE = 0,
  40. MARLIN_DEBUG_ECHO = _BV(0), ///< Echo commands in order as they are processed
  41. MARLIN_DEBUG_INFO = _BV(1), ///< Print messages for code that has debug output
  42. MARLIN_DEBUG_ERRORS = _BV(2), ///< Not implemented
  43. MARLIN_DEBUG_DRYRUN = _BV(3), ///< Ignore temperature setting and E movement commands
  44. MARLIN_DEBUG_COMMUNICATION = _BV(4), ///< Not implemented
  45. #if ENABLED(DEBUG_LEVELING_FEATURE)
  46. MARLIN_DEBUG_LEVELING = _BV(5), ///< Print detailed output for homing and leveling
  47. MARLIN_DEBUG_MESH_ADJUST = _BV(6), ///< UBL bed leveling
  48. #else
  49. MARLIN_DEBUG_LEVELING = 0,
  50. MARLIN_DEBUG_MESH_ADJUST = 0,
  51. #endif
  52. MARLIN_DEBUG_ALL = 0xFF
  53. };
  54. extern uint8_t marlin_debug_flags;
  55. #define DEBUGGING(F) (marlin_debug_flags & (MARLIN_DEBUG_## F))
  56. //
  57. // Serial redirection
  58. //
  59. // Step 1: Find out what the first serial leaf is
  60. #if BOTH(HAS_MULTI_SERIAL, SERIAL_CATCHALL)
  61. #define _SERIAL_LEAF_1 MYSERIAL
  62. #else
  63. #define _SERIAL_LEAF_1 MYSERIAL1
  64. #endif
  65. // Hook Meatpack if it's enabled on the first leaf
  66. #if ENABLED(MEATPACK_ON_SERIAL_PORT_1)
  67. typedef MeatpackSerial<decltype(_SERIAL_LEAF_1)> SerialLeafT1;
  68. extern SerialLeafT1 mpSerial1;
  69. #define SERIAL_LEAF_1 mpSerial1
  70. #else
  71. #define SERIAL_LEAF_1 _SERIAL_LEAF_1
  72. #endif
  73. // Step 2: For multiserial wrap all serial ports in a single
  74. // interface with the ability to output to multiple serial ports.
  75. #if HAS_MULTI_SERIAL
  76. #define _PORT_REDIRECT(n,p) REMEMBER(n,multiSerial.portMask,p)
  77. #define _PORT_RESTORE(n,p) RESTORE(n)
  78. #define SERIAL_ASSERT(P) if(multiSerial.portMask!=(P)){ debugger(); }
  79. // If we have a catchall, use that directly
  80. #ifdef SERIAL_CATCHALL
  81. #define _SERIAL_LEAF_2 SERIAL_CATCHALL
  82. #else
  83. #if HAS_ETHERNET
  84. // We need to create an instance here
  85. typedef ConditionalSerial<decltype(MYSERIAL2)> SerialLeafT2;
  86. extern SerialLeafT2 msSerial2;
  87. #define _SERIAL_LEAF_2 msSerial2
  88. #else
  89. // Don't create a useless instance here, directly use the existing instance
  90. #define _SERIAL_LEAF_2 MYSERIAL2
  91. #endif
  92. #endif
  93. // Hook Meatpack if it's enabled on the second leaf
  94. #if ENABLED(MEATPACK_ON_SERIAL_PORT_2)
  95. typedef MeatpackSerial<decltype(_SERIAL_LEAF_2)> SerialLeafT2;
  96. extern SerialLeafT2 mpSerial2;
  97. #define SERIAL_LEAF_2 mpSerial2
  98. #else
  99. #define SERIAL_LEAF_2 _SERIAL_LEAF_2
  100. #endif
  101. typedef MultiSerial<decltype(SERIAL_LEAF_1), decltype(SERIAL_LEAF_2), 0> SerialOutputT;
  102. extern SerialOutputT multiSerial;
  103. #define SERIAL_IMPL multiSerial
  104. #else
  105. #define _PORT_REDIRECT(n,p) NOOP
  106. #define _PORT_RESTORE(n) NOOP
  107. #define SERIAL_ASSERT(P) NOOP
  108. #define SERIAL_IMPL SERIAL_LEAF_1
  109. #endif
  110. #define SERIAL_OUT(WHAT, V...) (void)SERIAL_IMPL.WHAT(V)
  111. #define PORT_REDIRECT(p) _PORT_REDIRECT(1,p)
  112. #define PORT_RESTORE() _PORT_RESTORE(1)
  113. #define SERIAL_PORTMASK(P) SerialMask::from(P)
  114. //
  115. // SERIAL_CHAR - Print one or more individual chars
  116. //
  117. inline void SERIAL_CHAR(char a) { SERIAL_IMPL.write(a); }
  118. template <typename ... Args>
  119. void SERIAL_CHAR(char a, Args ... args) { SERIAL_IMPL.write(a); SERIAL_CHAR(args ...); }
  120. /**
  121. * SERIAL_ECHO - Print a single string or value.
  122. * Any numeric parameter (including char) is printed as a base-10 number.
  123. * A string pointer or literal will be output as a string.
  124. *
  125. * NOTE: Use SERIAL_CHAR to print char as a single character.
  126. */
  127. template <typename T>
  128. void SERIAL_ECHO(T x) { SERIAL_IMPL.print(x); }
  129. // Wrapper for ECHO commands to interpret a char
  130. typedef struct SerialChar { char c; SerialChar(char n) : c(n) { } } serial_char_t;
  131. inline void SERIAL_ECHO(serial_char_t x) { SERIAL_IMPL.write(x.c); }
  132. #define AS_CHAR(C) serial_char_t(C)
  133. #define AS_DIGIT(C) AS_CHAR('0' + (C))
  134. // SERIAL_ECHO_F prints a floating point value with optional precision
  135. inline void SERIAL_ECHO_F(EnsureDouble x, int digit=2) { SERIAL_IMPL.print(x, digit); }
  136. template <typename T>
  137. void SERIAL_ECHOLN(T x) { SERIAL_IMPL.println(x); }
  138. // SERIAL_PRINT works like SERIAL_ECHO but allow to specify the encoding base of the number printed
  139. template <typename T, typename U>
  140. void SERIAL_PRINT(T x, U y) { SERIAL_IMPL.print(x, y); }
  141. template <typename T, typename U>
  142. void SERIAL_PRINTLN(T x, U y) { SERIAL_IMPL.println(x, y); }
  143. // Flush the serial port
  144. inline void SERIAL_FLUSH() { SERIAL_IMPL.flush(); }
  145. inline void SERIAL_FLUSHTX() { SERIAL_IMPL.flushTX(); }
  146. // Print a single PROGMEM string to serial
  147. void serialprintPGM(PGM_P str);
  148. // SERIAL_ECHOPAIR / SERIAL_ECHOPAIR_P is used to output a key value pair. The key must be a string and the value can be anything
  149. // Print up to 12 pairs of values. Odd elements auto-wrapped in PSTR().
  150. #define __SEP_N(N,V...) _SEP_##N(V)
  151. #define _SEP_N(N,V...) __SEP_N(N,V)
  152. #define _SEP_1(PRE) SERIAL_ECHOPGM(PRE)
  153. #define _SEP_2(PRE,V) serial_echopair_PGM(PSTR(PRE),V)
  154. #define _SEP_3(a,b,c) do{ _SEP_2(a,b); SERIAL_ECHOPGM(c); }while(0)
  155. #define _SEP_4(a,b,V...) do{ _SEP_2(a,b); _SEP_2(V); }while(0)
  156. #define _SEP_5(a,b,V...) do{ _SEP_2(a,b); _SEP_3(V); }while(0)
  157. #define _SEP_6(a,b,V...) do{ _SEP_2(a,b); _SEP_4(V); }while(0)
  158. #define _SEP_7(a,b,V...) do{ _SEP_2(a,b); _SEP_5(V); }while(0)
  159. #define _SEP_8(a,b,V...) do{ _SEP_2(a,b); _SEP_6(V); }while(0)
  160. #define _SEP_9(a,b,V...) do{ _SEP_2(a,b); _SEP_7(V); }while(0)
  161. #define _SEP_10(a,b,V...) do{ _SEP_2(a,b); _SEP_8(V); }while(0)
  162. #define _SEP_11(a,b,V...) do{ _SEP_2(a,b); _SEP_9(V); }while(0)
  163. #define _SEP_12(a,b,V...) do{ _SEP_2(a,b); _SEP_10(V); }while(0)
  164. #define _SEP_13(a,b,V...) do{ _SEP_2(a,b); _SEP_11(V); }while(0)
  165. #define _SEP_14(a,b,V...) do{ _SEP_2(a,b); _SEP_12(V); }while(0)
  166. #define _SEP_15(a,b,V...) do{ _SEP_2(a,b); _SEP_13(V); }while(0)
  167. #define _SEP_16(a,b,V...) do{ _SEP_2(a,b); _SEP_14(V); }while(0)
  168. #define _SEP_17(a,b,V...) do{ _SEP_2(a,b); _SEP_15(V); }while(0)
  169. #define _SEP_18(a,b,V...) do{ _SEP_2(a,b); _SEP_16(V); }while(0)
  170. #define _SEP_19(a,b,V...) do{ _SEP_2(a,b); _SEP_17(V); }while(0)
  171. #define _SEP_20(a,b,V...) do{ _SEP_2(a,b); _SEP_18(V); }while(0)
  172. #define _SEP_21(a,b,V...) do{ _SEP_2(a,b); _SEP_19(V); }while(0)
  173. #define _SEP_22(a,b,V...) do{ _SEP_2(a,b); _SEP_20(V); }while(0)
  174. #define _SEP_23(a,b,V...) do{ _SEP_2(a,b); _SEP_21(V); }while(0)
  175. #define _SEP_24(a,b,V...) do{ _SEP_2(a,b); _SEP_22(V); }while(0)
  176. #define SERIAL_ECHOPAIR(V...) _SEP_N(NUM_ARGS(V),V)
  177. // Print up to 12 pairs of values. Odd elements must be PSTR pointers.
  178. #define __SEP_N_P(N,V...) _SEP_##N##_P(V)
  179. #define _SEP_N_P(N,V...) __SEP_N_P(N,V)
  180. #define _SEP_1_P(PRE) serialprintPGM(PRE)
  181. #define _SEP_2_P(PRE,V) serial_echopair_PGM(PRE,V)
  182. #define _SEP_3_P(a,b,c) do{ _SEP_2_P(a,b); serialprintPGM(c); }while(0)
  183. #define _SEP_4_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_2_P(V); }while(0)
  184. #define _SEP_5_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_3_P(V); }while(0)
  185. #define _SEP_6_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_4_P(V); }while(0)
  186. #define _SEP_7_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_5_P(V); }while(0)
  187. #define _SEP_8_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_6_P(V); }while(0)
  188. #define _SEP_9_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_7_P(V); }while(0)
  189. #define _SEP_10_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_8_P(V); }while(0)
  190. #define _SEP_11_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_9_P(V); }while(0)
  191. #define _SEP_12_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_10_P(V); }while(0)
  192. #define _SEP_13_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_11_P(V); }while(0)
  193. #define _SEP_14_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_12_P(V); }while(0)
  194. #define _SEP_15_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_13_P(V); }while(0)
  195. #define _SEP_16_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_14_P(V); }while(0)
  196. #define _SEP_17_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_15_P(V); }while(0)
  197. #define _SEP_18_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_16_P(V); }while(0)
  198. #define _SEP_19_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_17_P(V); }while(0)
  199. #define _SEP_20_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_18_P(V); }while(0)
  200. #define _SEP_21_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_19_P(V); }while(0)
  201. #define _SEP_22_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_20_P(V); }while(0)
  202. #define _SEP_23_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_21_P(V); }while(0)
  203. #define _SEP_24_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_22_P(V); }while(0)
  204. // SERIAL_ECHOPAIR_P is used to output a key value pair. Unlike SERIAL_ECHOPAIR, the key must be a PGM string already and the value can be anything
  205. #define SERIAL_ECHOPAIR_P(V...) _SEP_N_P(NUM_ARGS(V),V)
  206. // Print up to 12 pairs of values followed by newline
  207. #define __SELP_N(N,V...) _SELP_##N(V)
  208. #define _SELP_N(N,V...) __SELP_N(N,V)
  209. #define _SELP_1(PRE) SERIAL_ECHOLNPGM(PRE)
  210. #define _SELP_2(PRE,V) do{ serial_echopair_PGM(PSTR(PRE),V); SERIAL_EOL(); }while(0)
  211. #define _SELP_3(a,b,c) do{ _SEP_2(a,b); SERIAL_ECHOLNPGM(c); }while(0)
  212. #define _SELP_4(a,b,V...) do{ _SEP_2(a,b); _SELP_2(V); }while(0)
  213. #define _SELP_5(a,b,V...) do{ _SEP_2(a,b); _SELP_3(V); }while(0)
  214. #define _SELP_6(a,b,V...) do{ _SEP_2(a,b); _SELP_4(V); }while(0)
  215. #define _SELP_7(a,b,V...) do{ _SEP_2(a,b); _SELP_5(V); }while(0)
  216. #define _SELP_8(a,b,V...) do{ _SEP_2(a,b); _SELP_6(V); }while(0)
  217. #define _SELP_9(a,b,V...) do{ _SEP_2(a,b); _SELP_7(V); }while(0)
  218. #define _SELP_10(a,b,V...) do{ _SEP_2(a,b); _SELP_8(V); }while(0)
  219. #define _SELP_11(a,b,V...) do{ _SEP_2(a,b); _SELP_9(V); }while(0)
  220. #define _SELP_12(a,b,V...) do{ _SEP_2(a,b); _SELP_10(V); }while(0)
  221. #define _SELP_13(a,b,V...) do{ _SEP_2(a,b); _SELP_11(V); }while(0)
  222. #define _SELP_14(a,b,V...) do{ _SEP_2(a,b); _SELP_12(V); }while(0)
  223. #define _SELP_15(a,b,V...) do{ _SEP_2(a,b); _SELP_13(V); }while(0)
  224. #define _SELP_16(a,b,V...) do{ _SEP_2(a,b); _SELP_14(V); }while(0)
  225. #define _SELP_17(a,b,V...) do{ _SEP_2(a,b); _SELP_15(V); }while(0)
  226. #define _SELP_18(a,b,V...) do{ _SEP_2(a,b); _SELP_16(V); }while(0)
  227. #define _SELP_19(a,b,V...) do{ _SEP_2(a,b); _SELP_17(V); }while(0)
  228. #define _SELP_20(a,b,V...) do{ _SEP_2(a,b); _SELP_18(V); }while(0)
  229. #define _SELP_21(a,b,V...) do{ _SEP_2(a,b); _SELP_19(V); }while(0)
  230. #define _SELP_22(a,b,V...) do{ _SEP_2(a,b); _SELP_20(V); }while(0)
  231. #define _SELP_23(a,b,V...) do{ _SEP_2(a,b); _SELP_21(V); }while(0)
  232. #define _SELP_24(a,b,V...) do{ _SEP_2(a,b); _SELP_22(V); }while(0)
  233. #define _SELP_25(a,b,V...) do{ _SEP_2(a,b); _SELP_23(V); }while(0)
  234. #define _SELP_26(a,b,V...) do{ _SEP_2(a,b); _SELP_24(V); }while(0)
  235. #define _SELP_27(a,b,V...) do{ _SEP_2(a,b); _SELP_25(V); }while(0)
  236. #define _SELP_28(a,b,V...) do{ _SEP_2(a,b); _SELP_26(V); }while(0)
  237. #define _SELP_29(a,b,V...) do{ _SEP_2(a,b); _SELP_27(V); }while(0)
  238. #define _SELP_30(a,b,V...) do{ _SEP_2(a,b); _SELP_28(V); }while(0) // Eat two args, pass the rest up
  239. #define SERIAL_ECHOLNPAIR(V...) _SELP_N(NUM_ARGS(V),V)
  240. // Print up to 12 pairs of values followed by newline
  241. #define __SELP_N_P(N,V...) _SELP_##N##_P(V)
  242. #define _SELP_N_P(N,V...) __SELP_N_P(N,V)
  243. #define _SELP_1_P(PRE) serialprintPGM(PRE)
  244. #define _SELP_2_P(PRE,V) do{ serial_echopair_PGM(PRE,V); SERIAL_EOL(); }while(0)
  245. #define _SELP_3_P(a,b,c) do{ _SEP_2_P(a,b); serialprintPGM(c); }while(0)
  246. #define _SELP_4_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_2_P(V); }while(0)
  247. #define _SELP_5_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_3_P(V); }while(0)
  248. #define _SELP_6_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_4_P(V); }while(0)
  249. #define _SELP_7_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_5_P(V); }while(0)
  250. #define _SELP_8_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_6_P(V); }while(0)
  251. #define _SELP_9_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_7_P(V); }while(0)
  252. #define _SELP_10_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_8_P(V); }while(0)
  253. #define _SELP_11_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_9_P(V); }while(0)
  254. #define _SELP_12_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_10_P(V); }while(0)
  255. #define _SELP_13_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_11_P(V); }while(0)
  256. #define _SELP_14_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_12_P(V); }while(0)
  257. #define _SELP_15_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_13_P(V); }while(0)
  258. #define _SELP_16_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_14_P(V); }while(0)
  259. #define _SELP_17_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_15_P(V); }while(0)
  260. #define _SELP_18_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_16_P(V); }while(0)
  261. #define _SELP_19_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_17_P(V); }while(0)
  262. #define _SELP_20_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_18_P(V); }while(0)
  263. #define _SELP_21_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_19_P(V); }while(0)
  264. #define _SELP_22_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_20_P(V); }while(0)
  265. #define _SELP_23_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_21_P(V); }while(0)
  266. #define _SELP_24_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_22_P(V); }while(0)
  267. #define _SELP_25_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_23_P(V); }while(0)
  268. #define _SELP_26_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_24_P(V); }while(0)
  269. #define _SELP_27_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_25_P(V); }while(0)
  270. #define _SELP_28_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_26_P(V); }while(0)
  271. #define _SELP_29_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_27_P(V); }while(0)
  272. #define _SELP_30_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_28_P(V); }while(0) // Eat two args, pass the rest up
  273. #define SERIAL_ECHOLNPAIR_P(V...) _SELP_N_P(NUM_ARGS(V),V)
  274. #ifdef AllowDifferentTypeInList
  275. inline void SERIAL_ECHOLIST_IMPL() {}
  276. template <typename T>
  277. void SERIAL_ECHOLIST_IMPL(T && t) { SERIAL_IMPL.print(t); }
  278. template <typename T, typename ... Args>
  279. void SERIAL_ECHOLIST_IMPL(T && t, Args && ... args) {
  280. SERIAL_IMPL.print(t);
  281. serialprintPGM(PSTR(", "));
  282. SERIAL_ECHOLIST_IMPL(args...);
  283. }
  284. template <typename ... Args>
  285. void SERIAL_ECHOLIST(PGM_P const str, Args && ... args) {
  286. SERIAL_IMPL.print(str);
  287. SERIAL_ECHOLIST_IMPL(args...);
  288. }
  289. #else // Optimization if the listed type are all the same (seems to be the case in the codebase so use that instead)
  290. template <typename ... Args>
  291. void SERIAL_ECHOLIST(PGM_P const str, Args && ... args) {
  292. serialprintPGM(str);
  293. typename Private::first_type_of<Args...>::type values[] = { args... };
  294. constexpr size_t argsSize = sizeof...(args);
  295. for (size_t i = 0; i < argsSize; i++) {
  296. if (i) serialprintPGM(PSTR(", "));
  297. SERIAL_IMPL.print(values[i]);
  298. }
  299. }
  300. #endif
  301. #define SERIAL_ECHOPGM_P(P) (serialprintPGM(P))
  302. #define SERIAL_ECHOLNPGM_P(P) do{ serialprintPGM(P); SERIAL_EOL(); }while(0)
  303. #define SERIAL_ECHOPGM(S) (serialprintPGM(PSTR(S)))
  304. #define SERIAL_ECHOLNPGM(S) (serialprintPGM(PSTR(S "\n")))
  305. #define SERIAL_ECHOPAIR_F_P(P,V...) do{ serialprintPGM(P); SERIAL_ECHO_F(V); }while(0)
  306. #define SERIAL_ECHOLNPAIR_F_P(V...) do{ SERIAL_ECHOPAIR_F_P(V); SERIAL_EOL(); }while(0)
  307. #define SERIAL_ECHOPAIR_F(S,V...) SERIAL_ECHOPAIR_F_P(PSTR(S),V)
  308. #define SERIAL_ECHOLNPAIR_F(V...) do{ SERIAL_ECHOPAIR_F(V); SERIAL_EOL(); }while(0)
  309. #define SERIAL_ECHO_START() serial_echo_start()
  310. #define SERIAL_ERROR_START() serial_error_start()
  311. #define SERIAL_EOL() SERIAL_CHAR('\n')
  312. #define SERIAL_ECHO_MSG(V...) do{ SERIAL_ECHO_START(); SERIAL_ECHOLNPAIR(V); }while(0)
  313. #define SERIAL_ERROR_MSG(V...) do{ SERIAL_ERROR_START(); SERIAL_ECHOLNPAIR(V); }while(0)
  314. #define SERIAL_ECHO_SP(C) serial_spaces(C)
  315. #define SERIAL_ECHO_TERNARY(TF, PRE, ON, OFF, POST) serial_ternary(TF, PSTR(PRE), PSTR(ON), PSTR(OFF), PSTR(POST))
  316. #if SERIAL_FLOAT_PRECISION
  317. #define SERIAL_DECIMAL(V) SERIAL_PRINT(V, SERIAL_FLOAT_PRECISION)
  318. #else
  319. #define SERIAL_DECIMAL(V) SERIAL_ECHO(V)
  320. #endif
  321. //
  322. // Functions for serial printing from PROGMEM. (Saves loads of SRAM.)
  323. //
  324. void serial_echopair_PGM(PGM_P const s_P, serial_char_t v);
  325. void serial_echopair_PGM(PGM_P const s_P, const char *v);
  326. void serial_echopair_PGM(PGM_P const s_P, char v);
  327. void serial_echopair_PGM(PGM_P const s_P, int v);
  328. void serial_echopair_PGM(PGM_P const s_P, long v);
  329. void serial_echopair_PGM(PGM_P const s_P, float v);
  330. void serial_echopair_PGM(PGM_P const s_P, double v);
  331. void serial_echopair_PGM(PGM_P const s_P, unsigned char v);
  332. void serial_echopair_PGM(PGM_P const s_P, unsigned int v);
  333. void serial_echopair_PGM(PGM_P const s_P, unsigned long v);
  334. inline void serial_echopair_PGM(PGM_P const s_P, bool v) { serial_echopair_PGM(s_P, (int)v); }
  335. inline void serial_echopair_PGM(PGM_P const s_P, void *v) { serial_echopair_PGM(s_P, (uintptr_t)v); }
  336. void serial_echo_start();
  337. void serial_error_start();
  338. void serial_ternary(const bool onoff, PGM_P const pre, PGM_P const on, PGM_P const off, PGM_P const post=nullptr);
  339. void serialprint_onoff(const bool onoff);
  340. void serialprintln_onoff(const bool onoff);
  341. void serialprint_truefalse(const bool tf);
  342. void serial_spaces(uint8_t count);
  343. void print_bin(const uint16_t val);
  344. void print_xyz(const_float_t x, const_float_t y, const_float_t z, PGM_P const prefix=nullptr, PGM_P const suffix=nullptr);
  345. inline void print_xyz(const xyz_pos_t &xyz, PGM_P const prefix=nullptr, PGM_P const suffix=nullptr) {
  346. print_xyz(xyz.x, xyz.y, xyz.z, prefix, suffix);
  347. }
  348. #define SERIAL_POS(SUFFIX,VAR) do { print_xyz(VAR, PSTR(" " STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n")); }while(0)
  349. #define SERIAL_XYZ(PREFIX,V...) do { print_xyz(V, PSTR(PREFIX), nullptr); }while(0)