My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

serial.h 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. // Commonly-used strings in serial output
  26. extern const char NUL_STR[], SP_P_STR[], SP_T_STR[],
  27. X_STR[], Y_STR[], Z_STR[], E_STR[],
  28. X_LBL[], Y_LBL[], Z_LBL[], E_LBL[],
  29. SP_A_STR[], SP_B_STR[], SP_C_STR[],
  30. SP_X_STR[], SP_Y_STR[], SP_Z_STR[], SP_E_STR[],
  31. SP_X_LBL[], SP_Y_LBL[], SP_Z_LBL[], SP_E_LBL[];
  32. //
  33. // Debugging flags for use by M111
  34. //
  35. enum MarlinDebugFlags : uint8_t {
  36. MARLIN_DEBUG_NONE = 0,
  37. MARLIN_DEBUG_ECHO = _BV(0), ///< Echo commands in order as they are processed
  38. MARLIN_DEBUG_INFO = _BV(1), ///< Print messages for code that has debug output
  39. MARLIN_DEBUG_ERRORS = _BV(2), ///< Not implemented
  40. MARLIN_DEBUG_DRYRUN = _BV(3), ///< Ignore temperature setting and E movement commands
  41. MARLIN_DEBUG_COMMUNICATION = _BV(4), ///< Not implemented
  42. #if ENABLED(DEBUG_LEVELING_FEATURE)
  43. MARLIN_DEBUG_LEVELING = _BV(5), ///< Print detailed output for homing and leveling
  44. MARLIN_DEBUG_MESH_ADJUST = _BV(6), ///< UBL bed leveling
  45. #else
  46. MARLIN_DEBUG_LEVELING = 0,
  47. MARLIN_DEBUG_MESH_ADJUST = 0,
  48. #endif
  49. MARLIN_DEBUG_ALL = 0xFF
  50. };
  51. extern uint8_t marlin_debug_flags;
  52. #define DEBUGGING(F) (marlin_debug_flags & (MARLIN_DEBUG_## F))
  53. //
  54. // Serial redirection
  55. //
  56. typedef int8_t serial_index_t;
  57. #define SERIAL_ALL 0x7F
  58. #if HAS_MULTI_SERIAL
  59. #define _PORT_REDIRECT(n,p) REMEMBER(n,multiSerial.portMask,p)
  60. #define SERIAL_ASSERT(P) if(multiSerial.portMask!=(P)){ debugger(); }
  61. #ifdef SERIAL_CATCHALL
  62. typedef MultiSerial<decltype(MYSERIAL), decltype(SERIAL_CATCHALL), 0> SerialOutputT;
  63. #else
  64. typedef MultiSerial<decltype(MYSERIAL0), TERN(HAS_ETHERNET, ConditionalSerial<decltype(MYSERIAL1)>, decltype(MYSERIAL1)), 0> SerialOutputT;
  65. #endif
  66. extern SerialOutputT multiSerial;
  67. #define SERIAL_IMPL multiSerial
  68. #else
  69. #define _PORT_REDIRECT(n,p) NOOP
  70. #define SERIAL_ASSERT(P) NOOP
  71. #define SERIAL_IMPL MYSERIAL0
  72. #endif
  73. #define SERIAL_OUT(WHAT, V...) (void)SERIAL_IMPL.WHAT(V)
  74. #define PORT_REDIRECT(p) _PORT_REDIRECT(1,p)
  75. #define SERIAL_PORTMASK(P) _BV(P)
  76. #define SERIAL_ECHO(x) SERIAL_OUT(print, x)
  77. #define SERIAL_ECHO_F(V...) SERIAL_OUT(print, V)
  78. #define SERIAL_ECHOLN(x) SERIAL_OUT(println, x)
  79. #define SERIAL_PRINT(x,b) SERIAL_OUT(print, x, b)
  80. #define SERIAL_PRINTLN(x,b) SERIAL_OUT(println, x, b)
  81. #define SERIAL_FLUSH() SERIAL_OUT(flush)
  82. #ifdef ARDUINO_ARCH_STM32
  83. #define SERIAL_FLUSHTX() SERIAL_OUT(flush)
  84. #elif TX_BUFFER_SIZE > 0
  85. #define SERIAL_FLUSHTX() SERIAL_OUT(flushTX)
  86. #else
  87. #define SERIAL_FLUSHTX()
  88. #endif
  89. // Print up to 10 chars from a list
  90. #define __CHAR_N(N,V...) _CHAR_##N(V)
  91. #define _CHAR_N(N,V...) __CHAR_N(N,V)
  92. #define _CHAR_1(c) SERIAL_OUT(write, c)
  93. #define _CHAR_2(a,b) do{ _CHAR_1(a); _CHAR_1(b); }while(0)
  94. #define _CHAR_3(a,V...) do{ _CHAR_1(a); _CHAR_2(V); }while(0)
  95. #define _CHAR_4(a,V...) do{ _CHAR_1(a); _CHAR_3(V); }while(0)
  96. #define _CHAR_5(a,V...) do{ _CHAR_1(a); _CHAR_4(V); }while(0)
  97. #define _CHAR_6(a,V...) do{ _CHAR_1(a); _CHAR_5(V); }while(0)
  98. #define _CHAR_7(a,V...) do{ _CHAR_1(a); _CHAR_6(V); }while(0)
  99. #define _CHAR_8(a,V...) do{ _CHAR_1(a); _CHAR_7(V); }while(0)
  100. #define _CHAR_9(a,V...) do{ _CHAR_1(a); _CHAR_8(V); }while(0)
  101. #define _CHAR_10(a,V...) do{ _CHAR_1(a); _CHAR_9(V); }while(0)
  102. #define SERIAL_CHAR(V...) _CHAR_N(NUM_ARGS(V),V)
  103. // Print up to 12 pairs of values. Odd elements auto-wrapped in PSTR().
  104. #define __SEP_N(N,V...) _SEP_##N(V)
  105. #define _SEP_N(N,V...) __SEP_N(N,V)
  106. #define _SEP_1(PRE) SERIAL_ECHOPGM(PRE)
  107. #define _SEP_2(PRE,V) serial_echopair_PGM(PSTR(PRE),V)
  108. #define _SEP_3(a,b,c) do{ _SEP_2(a,b); SERIAL_ECHOPGM(c); }while(0)
  109. #define _SEP_4(a,b,V...) do{ _SEP_2(a,b); _SEP_2(V); }while(0)
  110. #define _SEP_5(a,b,V...) do{ _SEP_2(a,b); _SEP_3(V); }while(0)
  111. #define _SEP_6(a,b,V...) do{ _SEP_2(a,b); _SEP_4(V); }while(0)
  112. #define _SEP_7(a,b,V...) do{ _SEP_2(a,b); _SEP_5(V); }while(0)
  113. #define _SEP_8(a,b,V...) do{ _SEP_2(a,b); _SEP_6(V); }while(0)
  114. #define _SEP_9(a,b,V...) do{ _SEP_2(a,b); _SEP_7(V); }while(0)
  115. #define _SEP_10(a,b,V...) do{ _SEP_2(a,b); _SEP_8(V); }while(0)
  116. #define _SEP_11(a,b,V...) do{ _SEP_2(a,b); _SEP_9(V); }while(0)
  117. #define _SEP_12(a,b,V...) do{ _SEP_2(a,b); _SEP_10(V); }while(0)
  118. #define _SEP_13(a,b,V...) do{ _SEP_2(a,b); _SEP_11(V); }while(0)
  119. #define _SEP_14(a,b,V...) do{ _SEP_2(a,b); _SEP_12(V); }while(0)
  120. #define _SEP_15(a,b,V...) do{ _SEP_2(a,b); _SEP_13(V); }while(0)
  121. #define _SEP_16(a,b,V...) do{ _SEP_2(a,b); _SEP_14(V); }while(0)
  122. #define _SEP_17(a,b,V...) do{ _SEP_2(a,b); _SEP_15(V); }while(0)
  123. #define _SEP_18(a,b,V...) do{ _SEP_2(a,b); _SEP_16(V); }while(0)
  124. #define _SEP_19(a,b,V...) do{ _SEP_2(a,b); _SEP_17(V); }while(0)
  125. #define _SEP_20(a,b,V...) do{ _SEP_2(a,b); _SEP_18(V); }while(0)
  126. #define _SEP_21(a,b,V...) do{ _SEP_2(a,b); _SEP_19(V); }while(0)
  127. #define _SEP_22(a,b,V...) do{ _SEP_2(a,b); _SEP_20(V); }while(0)
  128. #define _SEP_23(a,b,V...) do{ _SEP_2(a,b); _SEP_21(V); }while(0)
  129. #define _SEP_24(a,b,V...) do{ _SEP_2(a,b); _SEP_22(V); }while(0)
  130. #define SERIAL_ECHOPAIR(V...) _SEP_N(NUM_ARGS(V),V)
  131. // Print up to 12 pairs of values. Odd elements must be PSTR pointers.
  132. #define __SEP_N_P(N,V...) _SEP_##N##_P(V)
  133. #define _SEP_N_P(N,V...) __SEP_N_P(N,V)
  134. #define _SEP_1_P(PRE) serialprintPGM(PRE)
  135. #define _SEP_2_P(PRE,V) serial_echopair_PGM(PRE,V)
  136. #define _SEP_3_P(a,b,c) do{ _SEP_2_P(a,b); serialprintPGM(c); }while(0)
  137. #define _SEP_4_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_2_P(V); }while(0)
  138. #define _SEP_5_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_3_P(V); }while(0)
  139. #define _SEP_6_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_4_P(V); }while(0)
  140. #define _SEP_7_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_5_P(V); }while(0)
  141. #define _SEP_8_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_6_P(V); }while(0)
  142. #define _SEP_9_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_7_P(V); }while(0)
  143. #define _SEP_10_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_8_P(V); }while(0)
  144. #define _SEP_11_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_9_P(V); }while(0)
  145. #define _SEP_12_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_10_P(V); }while(0)
  146. #define _SEP_13_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_11_P(V); }while(0)
  147. #define _SEP_14_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_12_P(V); }while(0)
  148. #define _SEP_15_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_13_P(V); }while(0)
  149. #define _SEP_16_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_14_P(V); }while(0)
  150. #define _SEP_17_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_15_P(V); }while(0)
  151. #define _SEP_18_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_16_P(V); }while(0)
  152. #define _SEP_19_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_17_P(V); }while(0)
  153. #define _SEP_20_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_18_P(V); }while(0)
  154. #define _SEP_21_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_19_P(V); }while(0)
  155. #define _SEP_22_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_20_P(V); }while(0)
  156. #define _SEP_23_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_21_P(V); }while(0)
  157. #define _SEP_24_P(a,b,V...) do{ _SEP_2_P(a,b); _SEP_22_P(V); }while(0)
  158. #define SERIAL_ECHOPAIR_P(V...) _SEP_N_P(NUM_ARGS(V),V)
  159. // Print up to 12 pairs of values followed by newline
  160. #define __SELP_N(N,V...) _SELP_##N(V)
  161. #define _SELP_N(N,V...) __SELP_N(N,V)
  162. #define _SELP_1(PRE) SERIAL_ECHOLNPGM(PRE)
  163. #define _SELP_2(PRE,V) do{ serial_echopair_PGM(PSTR(PRE),V); SERIAL_EOL(); }while(0)
  164. #define _SELP_3(a,b,c) do{ _SEP_2(a,b); SERIAL_ECHOLNPGM(c); }while(0)
  165. #define _SELP_4(a,b,V...) do{ _SEP_2(a,b); _SELP_2(V); }while(0)
  166. #define _SELP_5(a,b,V...) do{ _SEP_2(a,b); _SELP_3(V); }while(0)
  167. #define _SELP_6(a,b,V...) do{ _SEP_2(a,b); _SELP_4(V); }while(0)
  168. #define _SELP_7(a,b,V...) do{ _SEP_2(a,b); _SELP_5(V); }while(0)
  169. #define _SELP_8(a,b,V...) do{ _SEP_2(a,b); _SELP_6(V); }while(0)
  170. #define _SELP_9(a,b,V...) do{ _SEP_2(a,b); _SELP_7(V); }while(0)
  171. #define _SELP_10(a,b,V...) do{ _SEP_2(a,b); _SELP_8(V); }while(0)
  172. #define _SELP_11(a,b,V...) do{ _SEP_2(a,b); _SELP_9(V); }while(0)
  173. #define _SELP_12(a,b,V...) do{ _SEP_2(a,b); _SELP_10(V); }while(0)
  174. #define _SELP_13(a,b,V...) do{ _SEP_2(a,b); _SELP_11(V); }while(0)
  175. #define _SELP_14(a,b,V...) do{ _SEP_2(a,b); _SELP_12(V); }while(0)
  176. #define _SELP_15(a,b,V...) do{ _SEP_2(a,b); _SELP_13(V); }while(0)
  177. #define _SELP_16(a,b,V...) do{ _SEP_2(a,b); _SELP_14(V); }while(0)
  178. #define _SELP_17(a,b,V...) do{ _SEP_2(a,b); _SELP_15(V); }while(0)
  179. #define _SELP_18(a,b,V...) do{ _SEP_2(a,b); _SELP_16(V); }while(0)
  180. #define _SELP_19(a,b,V...) do{ _SEP_2(a,b); _SELP_17(V); }while(0)
  181. #define _SELP_20(a,b,V...) do{ _SEP_2(a,b); _SELP_18(V); }while(0)
  182. #define _SELP_21(a,b,V...) do{ _SEP_2(a,b); _SELP_19(V); }while(0)
  183. #define _SELP_22(a,b,V...) do{ _SEP_2(a,b); _SELP_20(V); }while(0)
  184. #define _SELP_23(a,b,V...) do{ _SEP_2(a,b); _SELP_21(V); }while(0)
  185. #define _SELP_24(a,b,V...) do{ _SEP_2(a,b); _SELP_22(V); }while(0)
  186. #define _SELP_25(a,b,V...) do{ _SEP_2(a,b); _SELP_23(V); }while(0)
  187. #define _SELP_26(a,b,V...) do{ _SEP_2(a,b); _SELP_24(V); }while(0)
  188. #define _SELP_27(a,b,V...) do{ _SEP_2(a,b); _SELP_25(V); }while(0)
  189. #define _SELP_28(a,b,V...) do{ _SEP_2(a,b); _SELP_26(V); }while(0)
  190. #define _SELP_29(a,b,V...) do{ _SEP_2(a,b); _SELP_27(V); }while(0)
  191. #define _SELP_30(a,b,V...) do{ _SEP_2(a,b); _SELP_28(V); }while(0) // Eat two args, pass the rest up
  192. #define SERIAL_ECHOLNPAIR(V...) _SELP_N(NUM_ARGS(V),V)
  193. // Print up to 12 pairs of values followed by newline
  194. #define __SELP_N_P(N,V...) _SELP_##N##_P(V)
  195. #define _SELP_N_P(N,V...) __SELP_N_P(N,V)
  196. #define _SELP_1_P(PRE) serialprintPGM(PRE)
  197. #define _SELP_2_P(PRE,V) do{ serial_echopair_PGM(PRE,V); SERIAL_EOL(); }while(0)
  198. #define _SELP_3_P(a,b,c) do{ _SEP_2_P(a,b); serialprintPGM(c); }while(0)
  199. #define _SELP_4_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_2_P(V); }while(0)
  200. #define _SELP_5_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_3_P(V); }while(0)
  201. #define _SELP_6_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_4_P(V); }while(0)
  202. #define _SELP_7_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_5_P(V); }while(0)
  203. #define _SELP_8_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_6_P(V); }while(0)
  204. #define _SELP_9_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_7_P(V); }while(0)
  205. #define _SELP_10_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_8_P(V); }while(0)
  206. #define _SELP_11_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_9_P(V); }while(0)
  207. #define _SELP_12_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_10_P(V); }while(0)
  208. #define _SELP_13_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_11_P(V); }while(0)
  209. #define _SELP_14_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_12_P(V); }while(0)
  210. #define _SELP_15_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_13_P(V); }while(0)
  211. #define _SELP_16_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_14_P(V); }while(0)
  212. #define _SELP_17_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_15_P(V); }while(0)
  213. #define _SELP_18_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_16_P(V); }while(0)
  214. #define _SELP_19_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_17_P(V); }while(0)
  215. #define _SELP_20_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_18_P(V); }while(0)
  216. #define _SELP_21_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_19_P(V); }while(0)
  217. #define _SELP_22_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_20_P(V); }while(0)
  218. #define _SELP_23_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_21_P(V); }while(0)
  219. #define _SELP_24_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_22_P(V); }while(0)
  220. #define _SELP_25_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_23_P(V); }while(0)
  221. #define _SELP_26_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_24_P(V); }while(0)
  222. #define _SELP_27_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_25_P(V); }while(0)
  223. #define _SELP_28_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_26_P(V); }while(0)
  224. #define _SELP_29_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_27_P(V); }while(0)
  225. #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
  226. #define SERIAL_ECHOLNPAIR_P(V...) _SELP_N_P(NUM_ARGS(V),V)
  227. // Print up to 20 comma-separated pairs of values
  228. #define __SLST_N(N,V...) _SLST_##N(V)
  229. #define _SLST_N(N,V...) __SLST_N(N,V)
  230. #define _SLST_1(a) SERIAL_ECHO(a)
  231. #define _SLST_2(a,b) do{ SERIAL_ECHO(a); SERIAL_ECHOPAIR(", ",b); }while(0)
  232. #define _SLST_3(a,b,c) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_1(c); }while(0)
  233. #define _SLST_4(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_2(V); }while(0)
  234. #define _SLST_5(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_3(V); }while(0)
  235. #define _SLST_6(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_4(V); }while(0)
  236. #define _SLST_7(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_5(V); }while(0)
  237. #define _SLST_8(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_6(V); }while(0)
  238. #define _SLST_9(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_7(V); }while(0)
  239. #define _SLST_10(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_8(V); }while(0)
  240. #define _SLST_11(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_9(V); }while(0)
  241. #define _SLST_12(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_10(V); }while(0)
  242. #define _SLST_13(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_11(V); }while(0)
  243. #define _SLST_14(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_12(V); }while(0)
  244. #define _SLST_15(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_13(V); }while(0)
  245. #define _SLST_16(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_14(V); }while(0)
  246. #define _SLST_17(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_15(V); }while(0)
  247. #define _SLST_18(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_16(V); }while(0)
  248. #define _SLST_19(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_17(V); }while(0)
  249. #define _SLST_20(a,b,V...) do{ SERIAL_ECHO(a); _SEP_2(", ",b); _SLST_18(V); }while(0) // Eat two args, pass the rest up
  250. #define SERIAL_ECHOLIST(pre,V...) do{ SERIAL_ECHOPGM(pre); _SLST_N(NUM_ARGS(V),V); }while(0)
  251. #define SERIAL_ECHOLIST_N(N,V...) _SLST_N(N,LIST_N(N,V))
  252. #define SERIAL_ECHOPGM_P(P) (serialprintPGM(P))
  253. #define SERIAL_ECHOLNPGM_P(P) (serialprintPGM(P "\n"))
  254. #define SERIAL_ECHOPGM(S) (serialprintPGM(PSTR(S)))
  255. #define SERIAL_ECHOLNPGM(S) (serialprintPGM(PSTR(S "\n")))
  256. #define SERIAL_ECHOPAIR_F_P(P,V...) do{ serialprintPGM(P); SERIAL_ECHO_F(V); }while(0)
  257. #define SERIAL_ECHOLNPAIR_F_P(V...) do{ SERIAL_ECHOPAIR_F_P(V); SERIAL_EOL(); }while(0)
  258. #define SERIAL_ECHOPAIR_F(S,V...) SERIAL_ECHOPAIR_F_P(PSTR(S),V)
  259. #define SERIAL_ECHOLNPAIR_F(V...) do{ SERIAL_ECHOPAIR_F(V); SERIAL_EOL(); }while(0)
  260. #define SERIAL_ECHO_START() serial_echo_start()
  261. #define SERIAL_ERROR_START() serial_error_start()
  262. #define SERIAL_EOL() SERIAL_CHAR('\n')
  263. #define SERIAL_ECHO_MSG(V...) do{ SERIAL_ECHO_START(); SERIAL_ECHOLNPAIR(V); }while(0)
  264. #define SERIAL_ERROR_MSG(V...) do{ SERIAL_ERROR_START(); SERIAL_ECHOLNPAIR(V); }while(0)
  265. #define SERIAL_ECHO_SP(C) serial_spaces(C)
  266. #define SERIAL_ECHO_TERNARY(TF, PRE, ON, OFF, POST) serial_ternary(TF, PSTR(PRE), PSTR(ON), PSTR(OFF), PSTR(POST))
  267. #if SERIAL_FLOAT_PRECISION
  268. #define SERIAL_DECIMAL(V) SERIAL_PRINT(V, SERIAL_FLOAT_PRECISION)
  269. #else
  270. #define SERIAL_DECIMAL(V) SERIAL_ECHO(V)
  271. #endif
  272. //
  273. // Functions for serial printing from PROGMEM. (Saves loads of SRAM.)
  274. //
  275. void serial_echopair_PGM(PGM_P const s_P, const char *v);
  276. void serial_echopair_PGM(PGM_P const s_P, char v);
  277. void serial_echopair_PGM(PGM_P const s_P, int v);
  278. void serial_echopair_PGM(PGM_P const s_P, unsigned int v);
  279. void serial_echopair_PGM(PGM_P const s_P, long v);
  280. void serial_echopair_PGM(PGM_P const s_P, unsigned long v);
  281. void serial_echopair_PGM(PGM_P const s_P, float v);
  282. void serial_echopair_PGM(PGM_P const s_P, double v);
  283. inline void serial_echopair_PGM(PGM_P const s_P, uint8_t v) { serial_echopair_PGM(s_P, (int)v); }
  284. inline void serial_echopair_PGM(PGM_P const s_P, bool v) { serial_echopair_PGM(s_P, (int)v); }
  285. inline void serial_echopair_PGM(PGM_P const s_P, void *v) { serial_echopair_PGM(s_P, (uintptr_t)v); }
  286. void serialprintPGM(PGM_P str);
  287. void serial_echo_start();
  288. void serial_error_start();
  289. void serial_ternary(const bool onoff, PGM_P const pre, PGM_P const on, PGM_P const off, PGM_P const post=nullptr);
  290. void serialprint_onoff(const bool onoff);
  291. void serialprintln_onoff(const bool onoff);
  292. void serialprint_truefalse(const bool tf);
  293. void serial_spaces(uint8_t count);
  294. void print_bin(const uint16_t val);
  295. void print_xyz(const float &x, const float &y, const float &z, PGM_P const prefix=nullptr, PGM_P const suffix=nullptr);
  296. inline void print_xyz(const xyz_pos_t &xyz, PGM_P const prefix=nullptr, PGM_P const suffix=nullptr) {
  297. print_xyz(xyz.x, xyz.y, xyz.z, prefix, suffix);
  298. }
  299. #define SERIAL_POS(SUFFIX,VAR) do { print_xyz(VAR, PSTR(" " STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n")); }while(0)
  300. #define SERIAL_XYZ(PREFIX,V...) do { print_xyz(V, PSTR(PREFIX), nullptr); }while(0)