Fix MeatPack with per-serial-port instances (#21306)
This commit is contained in:
@@ -37,23 +37,22 @@ PGMSTR(SP_A_STR, " A"); PGMSTR(SP_B_STR, " B"); PGMSTR(SP_C_STR, " C");
|
||||
PGMSTR(SP_X_STR, " X"); PGMSTR(SP_Y_STR, " Y"); PGMSTR(SP_Z_STR, " Z"); PGMSTR(SP_E_STR, " E");
|
||||
PGMSTR(SP_X_LBL, " X:"); PGMSTR(SP_Y_LBL, " Y:"); PGMSTR(SP_Z_LBL, " Z:"); PGMSTR(SP_E_LBL, " E:");
|
||||
|
||||
#if HAS_MULTI_SERIAL
|
||||
#ifdef SERIAL_CATCHALL
|
||||
SerialOutputT multiSerial(MYSERIAL, SERIAL_CATCHALL);
|
||||
#else
|
||||
#if HAS_ETHERNET
|
||||
// Runtime checking of the condition variable
|
||||
ConditionalSerial<decltype(MYSERIAL2)> serialOut2(ethernet.have_telnet_client, MYSERIAL2, false); // Takes reference here
|
||||
#else
|
||||
// Don't pay for runtime checking a true variable, instead use the output directly
|
||||
#define serialOut2 MYSERIAL2
|
||||
#endif
|
||||
SerialOutputT multiSerial(MYSERIAL1, serialOut2);
|
||||
#endif
|
||||
// Hook Meatpack if it's enabled on the first leaf
|
||||
#if ENABLED(MEATPACK_ON_SERIAL_PORT_1)
|
||||
SerialLeafT1 mpSerial1(false, _SERIAL_LEAF_1);
|
||||
#endif
|
||||
#if ENABLED(MEATPACK_ON_SERIAL_PORT_2)
|
||||
SerialLeafT2 mpSerial2(false, _SERIAL_LEAF_2);
|
||||
#endif
|
||||
|
||||
#if ENABLED(MEATPACK)
|
||||
MeatpackSerial<decltype(_SERIAL_IMPL)> mpSerial(false, _SERIAL_IMPL);
|
||||
// Step 2: For multiserial, handle the second serial port as well
|
||||
#if HAS_MULTI_SERIAL
|
||||
#if HAS_ETHERNET
|
||||
// We need a definition here
|
||||
SerialLeafT2 msSerial2(ethernet.have_telnet_client, MYSERIAL2, false);
|
||||
#endif
|
||||
|
||||
SerialOutputT multiSerial(SERIAL_LEAF_1, SERIAL_LEAF_2);
|
||||
#endif
|
||||
|
||||
void serialprintPGM(PGM_P str) {
|
||||
|
@@ -24,7 +24,7 @@
|
||||
#include "../inc/MarlinConfig.h"
|
||||
#include "serial_hook.h"
|
||||
|
||||
#if ENABLED(MEATPACK)
|
||||
#if HAS_MEATPACK
|
||||
#include "../feature/meatpack.h"
|
||||
#endif
|
||||
|
||||
@@ -62,29 +62,59 @@ extern uint8_t marlin_debug_flags;
|
||||
//
|
||||
// Serial redirection
|
||||
//
|
||||
// Step 1: Find what's the first serial leaf
|
||||
#if BOTH(HAS_MULTI_SERIAL, SERIAL_CATCHALL)
|
||||
#define _SERIAL_LEAF_1 MYSERIAL
|
||||
#else
|
||||
#define _SERIAL_LEAF_1 MYSERIAL1
|
||||
#endif
|
||||
|
||||
// Hook Meatpack if it's enabled on the first leaf
|
||||
#if ENABLED(MEATPACK_ON_SERIAL_PORT_1)
|
||||
typedef MeatpackSerial<decltype(_SERIAL_LEAF_1)> SerialLeafT1;
|
||||
extern SerialLeafT1 mpSerial1;
|
||||
#define SERIAL_LEAF_1 mpSerial1
|
||||
#else
|
||||
#define SERIAL_LEAF_1 _SERIAL_LEAF_1
|
||||
#endif
|
||||
|
||||
// Step 2: For multiserial, handle the second serial port as well
|
||||
#if HAS_MULTI_SERIAL
|
||||
#define _PORT_REDIRECT(n,p) REMEMBER(n,multiSerial.portMask,p)
|
||||
#define _PORT_RESTORE(n,p) RESTORE(n)
|
||||
#define SERIAL_ASSERT(P) if(multiSerial.portMask!=(P)){ debugger(); }
|
||||
// If we have a catchall, use that directly
|
||||
#ifdef SERIAL_CATCHALL
|
||||
typedef MultiSerial<decltype(MYSERIAL), decltype(SERIAL_CATCHALL), 0> SerialOutputT;
|
||||
#define _SERIAL_LEAF_2 SERIAL_CATCHALL
|
||||
#else
|
||||
typedef MultiSerial<decltype(MYSERIAL1), TERN(HAS_ETHERNET, ConditionalSerial<decltype(MYSERIAL2)>, decltype(MYSERIAL2)), 0> SerialOutputT;
|
||||
#if HAS_ETHERNET
|
||||
// We need to create an instance here
|
||||
typedef ConditionalSerial<decltype(MYSERIAL2)> SerialLeafT2;
|
||||
extern SerialLeafT2 msSerial2;
|
||||
#define _SERIAL_LEAF_2 msSerial2
|
||||
#else
|
||||
// Don't create a useless instance here, directly use the existing instance
|
||||
#define _SERIAL_LEAF_2 MYSERIAL2
|
||||
#endif
|
||||
#endif
|
||||
extern SerialOutputT multiSerial;
|
||||
#define _SERIAL_IMPL multiSerial
|
||||
|
||||
// Hook Meatpack if it's enabled on the second leaf
|
||||
#if ENABLED(MEATPACK_ON_SERIAL_PORT_2)
|
||||
typedef MeatpackSerial<decltype(_SERIAL_LEAF_2)> SerialLeafT2;
|
||||
extern SerialLeafT2 mpSerial2;
|
||||
#define SERIAL_LEAF_2 mpSerial2
|
||||
#else
|
||||
#define SERIAL_LEAF_2 _SERIAL_LEAF_2
|
||||
#endif
|
||||
|
||||
typedef MultiSerial<decltype(SERIAL_LEAF_1), decltype(SERIAL_LEAF_2), 0> SerialOutputT;
|
||||
extern SerialOutputT multiSerial;
|
||||
#define SERIAL_IMPL multiSerial
|
||||
#else
|
||||
#define _PORT_REDIRECT(n,p) NOOP
|
||||
#define _PORT_RESTORE(n) NOOP
|
||||
#define SERIAL_ASSERT(P) NOOP
|
||||
#define _SERIAL_IMPL MYSERIAL1
|
||||
#endif
|
||||
|
||||
#if ENABLED(MEATPACK)
|
||||
extern MeatpackSerial<decltype(_SERIAL_IMPL)> mpSerial;
|
||||
#define SERIAL_IMPL mpSerial
|
||||
#else
|
||||
#define SERIAL_IMPL _SERIAL_IMPL
|
||||
#define SERIAL_IMPL SERIAL_LEAF_1
|
||||
#endif
|
||||
|
||||
#define SERIAL_OUT(WHAT, V...) (void)SERIAL_IMPL.WHAT(V)
|
||||
|
Reference in New Issue
Block a user