Add HAS_MULTI_SERIAL conditional
This commit is contained in:
parent
f350e9d0cb
commit
6371782263
@ -862,7 +862,7 @@ void setup() {
|
||||
MYSERIAL0.begin(BAUDRATE);
|
||||
uint32_t serial_connect_timeout = millis() + 1000UL;
|
||||
while (!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
MYSERIAL1.begin(BAUDRATE);
|
||||
serial_connect_timeout = millis() + 1000UL;
|
||||
while (!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
|
||||
|
@ -28,7 +28,7 @@ uint8_t marlin_debug_flags = MARLIN_DEBUG_NONE;
|
||||
static PGMSTR(errormagic, "Error:");
|
||||
static PGMSTR(echomagic, "echo:");
|
||||
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
int8_t serial_port_index = 0;
|
||||
#endif
|
||||
|
||||
|
@ -47,7 +47,7 @@ extern uint8_t marlin_debug_flags;
|
||||
#define DEBUGGING(F) (marlin_debug_flags & (MARLIN_DEBUG_## F))
|
||||
|
||||
#define SERIAL_BOTH 0x7F
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
extern int8_t serial_port_index;
|
||||
#define _PORT_REDIRECT(n,p) REMEMBER(n,serial_port_index,p)
|
||||
#define _PORT_RESTORE(n) RESTORE(n)
|
||||
|
@ -32,7 +32,7 @@
|
||||
inline bool bs_serial_data_available(const uint8_t index) {
|
||||
switch (index) {
|
||||
case 0: return MYSERIAL0.available();
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
case 1: return MYSERIAL1.available();
|
||||
#endif
|
||||
}
|
||||
@ -42,7 +42,7 @@ inline bool bs_serial_data_available(const uint8_t index) {
|
||||
inline int bs_read_serial(const uint8_t index) {
|
||||
switch (index) {
|
||||
case 0: return MYSERIAL0.read();
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
case 1: return MYSERIAL1.read();
|
||||
#endif
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ void GcodeSuite::M575() {
|
||||
if (set0) {
|
||||
SERIAL_ECHO_START();
|
||||
SERIAL_ECHOLNPAIR(" Serial "
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
, '0',
|
||||
#else
|
||||
"0"
|
||||
@ -50,7 +50,7 @@ void GcodeSuite::M575() {
|
||||
" baud rate set to ", baud
|
||||
);
|
||||
}
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
const bool set1 = (port == -99 || port == 1);
|
||||
if (set1) {
|
||||
SERIAL_ECHO_START();
|
||||
@ -62,7 +62,7 @@ void GcodeSuite::M575() {
|
||||
|
||||
if (set0) { MYSERIAL0.end(); MYSERIAL0.begin(baud); }
|
||||
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
if (set1) { MYSERIAL1.end(); MYSERIAL1.begin(baud); }
|
||||
#endif
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
*/
|
||||
void GcodeSuite::M118() {
|
||||
bool hasE = false, hasA = false;
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
int8_t port = -1; // Assume no redirect
|
||||
#endif
|
||||
char *p = parser.string_arg;
|
||||
@ -44,7 +44,7 @@ void GcodeSuite::M118() {
|
||||
switch (p[0]) {
|
||||
case 'A': hasA = true; break;
|
||||
case 'E': hasE = true; break;
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
case 'P': port = p[1] - '0'; break;
|
||||
#endif
|
||||
}
|
||||
@ -52,7 +52,7 @@ void GcodeSuite::M118() {
|
||||
while (*p == ' ') ++p;
|
||||
}
|
||||
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
const int8_t old_serial = serial_port_index;
|
||||
if (WITHIN(port, 0, NUM_SERIAL))
|
||||
serial_port_index = (
|
||||
@ -69,7 +69,5 @@ void GcodeSuite::M118() {
|
||||
if (hasA) SERIAL_ECHOPGM("// ");
|
||||
SERIAL_ECHOLN(p);
|
||||
|
||||
#if NUM_SERIAL > 1
|
||||
serial_port_index = old_serial;
|
||||
#endif
|
||||
TERN_(HAS_MULTI_SERIAL, serial_port_index = old_serial);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
#include "../MarlinCore.h"
|
||||
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
#include "queue.h"
|
||||
#endif
|
||||
|
||||
|
@ -72,7 +72,7 @@ char GCodeQueue::command_buffer[BUFSIZE][MAX_CMD_SIZE];
|
||||
/*
|
||||
* The port that the command was received on
|
||||
*/
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
int16_t GCodeQueue::port[BUFSIZE];
|
||||
#endif
|
||||
|
||||
@ -119,14 +119,12 @@ void GCodeQueue::clear() {
|
||||
* Once a new command is in the ring buffer, call this to commit it
|
||||
*/
|
||||
void GCodeQueue::_commit_command(bool say_ok
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
, int16_t p/*=-1*/
|
||||
#endif
|
||||
) {
|
||||
send_ok[index_w] = say_ok;
|
||||
#if NUM_SERIAL > 1
|
||||
port[index_w] = p;
|
||||
#endif
|
||||
TERN_(HAS_MULTI_SERIAL, port[index_w] = p);
|
||||
TERN_(POWER_LOSS_RECOVERY, recovery.commit_sdpos(index_w));
|
||||
if (++index_w >= BUFSIZE) index_w = 0;
|
||||
length++;
|
||||
@ -138,14 +136,14 @@ void GCodeQueue::_commit_command(bool say_ok
|
||||
* Return false for a full buffer, or if the 'command' is a comment.
|
||||
*/
|
||||
bool GCodeQueue::_enqueue(const char* cmd, bool say_ok/*=false*/
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
, int16_t pn/*=-1*/
|
||||
#endif
|
||||
) {
|
||||
if (*cmd == ';' || length >= BUFSIZE) return false;
|
||||
strcpy(command_buffer[index_w], cmd);
|
||||
_commit_command(say_ok
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
, pn
|
||||
#endif
|
||||
);
|
||||
@ -276,7 +274,7 @@ void GCodeQueue::enqueue_now_P(PGM_P const pgcode) {
|
||||
* B<int> Block queue space remaining
|
||||
*/
|
||||
void GCodeQueue::ok_to_send() {
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
const int16_t pn = command_port();
|
||||
if (pn < 0) return;
|
||||
PORT_REDIRECT(pn); // Reply to the serial port that sent the command
|
||||
@ -303,30 +301,24 @@ void GCodeQueue::ok_to_send() {
|
||||
*/
|
||||
void GCodeQueue::flush_and_request_resend() {
|
||||
const int16_t pn = command_port();
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
if (pn < 0) return;
|
||||
PORT_REDIRECT(pn); // Reply to the serial port that sent the command
|
||||
#endif
|
||||
SERIAL_FLUSH();
|
||||
SERIAL_ECHOPGM(STR_RESEND);
|
||||
|
||||
SERIAL_ECHOLN(last_N[pn] + 1);
|
||||
ok_to_send();
|
||||
}
|
||||
|
||||
inline bool serial_data_available() {
|
||||
return false
|
||||
|| MYSERIAL0.available()
|
||||
#if NUM_SERIAL > 1
|
||||
|| MYSERIAL1.available()
|
||||
#endif
|
||||
;
|
||||
return MYSERIAL0.available() || TERN0(HAS_MULTI_SERIAL, MYSERIAL1.available());
|
||||
}
|
||||
|
||||
inline int read_serial(const uint8_t index) {
|
||||
switch (index) {
|
||||
case 0: return MYSERIAL0.read();
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
case 1: return MYSERIAL1.read();
|
||||
#endif
|
||||
default: return -1;
|
||||
@ -538,7 +530,7 @@ void GCodeQueue::get_serial_commands() {
|
||||
|
||||
// Add the command to the queue
|
||||
_enqueue(serial_line_buffer[i], true
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
, i
|
||||
#endif
|
||||
);
|
||||
|
@ -55,16 +55,12 @@ public:
|
||||
/**
|
||||
* The port that the command was received on
|
||||
*/
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
static int16_t port[BUFSIZE];
|
||||
#endif
|
||||
|
||||
static int16_t command_port() {
|
||||
return (0
|
||||
#if NUM_SERIAL > 1
|
||||
+ port[index_r]
|
||||
#endif
|
||||
);
|
||||
return TERN0(HAS_MULTI_SERIAL, port[index_r]);
|
||||
}
|
||||
|
||||
GCodeQueue();
|
||||
@ -162,13 +158,13 @@ private:
|
||||
#endif
|
||||
|
||||
static void _commit_command(bool say_ok
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
, int16_t p=-1
|
||||
#endif
|
||||
);
|
||||
|
||||
static bool _enqueue(const char* cmd, bool say_ok=false
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
, int16_t p=-1
|
||||
#endif
|
||||
);
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "../gcode.h"
|
||||
#include "../../sd/cardreader.h"
|
||||
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
#include "../queue.h"
|
||||
#endif
|
||||
|
||||
@ -49,9 +49,7 @@ void GcodeSuite::M28() {
|
||||
// Binary transfer mode
|
||||
if ((card.flag.binary_mode = binary_mode)) {
|
||||
SERIAL_ECHO_MSG("Switching to Binary Protocol");
|
||||
#if NUM_SERIAL > 1
|
||||
card.transfer_port_index = queue.port[queue.index_r];
|
||||
#endif
|
||||
TERN_(HAS_MULTI_SERIAL, card.transfer_port_index = queue.port[queue.index_r]);
|
||||
}
|
||||
else
|
||||
card.openFileWrite(p);
|
||||
|
@ -2519,4 +2519,6 @@
|
||||
|
||||
#if !NUM_SERIAL
|
||||
#undef BAUD_RATE_GCODE
|
||||
#elif NUM_SERIAL > 1
|
||||
#define HAS_MULTI_SERIAL 1
|
||||
#endif
|
||||
|
@ -51,7 +51,7 @@ card_flags_t CardReader::flag;
|
||||
char CardReader::filename[FILENAME_LENGTH], CardReader::longFilename[LONG_FILENAME_LENGTH];
|
||||
int8_t CardReader::autostart_index;
|
||||
|
||||
#if ENABLED(BINARY_FILE_TRANSFER) && NUM_SERIAL > 1
|
||||
#if BOTH(HAS_MULTI_SERIAL, BINARY_FILE_TRANSFER)
|
||||
int8_t CardReader::transfer_port_index;
|
||||
#endif
|
||||
|
||||
@ -1095,7 +1095,7 @@ void CardReader::fileHasFinished() {
|
||||
#if ENABLED(AUTO_REPORT_SD_STATUS)
|
||||
uint8_t CardReader::auto_report_sd_interval = 0;
|
||||
millis_t CardReader::next_sd_report_ms;
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
int8_t CardReader::auto_report_port;
|
||||
#endif
|
||||
|
||||
|
@ -61,7 +61,7 @@ public:
|
||||
|
||||
// Fast! binary file transfer
|
||||
#if ENABLED(BINARY_FILE_TRANSFER)
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
static int8_t transfer_port_index;
|
||||
#else
|
||||
static constexpr int8_t transfer_port_index = 0;
|
||||
@ -164,9 +164,7 @@ public:
|
||||
#if ENABLED(AUTO_REPORT_SD_STATUS)
|
||||
static void auto_report_sd_status();
|
||||
static inline void set_auto_report_interval(uint8_t v) {
|
||||
#if NUM_SERIAL > 1
|
||||
auto_report_port = serial_port_index;
|
||||
#endif
|
||||
TERN_(HAS_MULTI_SERIAL, auto_report_port = serial_port_index);
|
||||
NOMORE(v, 60);
|
||||
auto_report_sd_interval = v;
|
||||
next_sd_report_ms = millis() + 1000UL * v;
|
||||
@ -258,7 +256,7 @@ private:
|
||||
#if ENABLED(AUTO_REPORT_SD_STATUS)
|
||||
static uint8_t auto_report_sd_interval;
|
||||
static millis_t next_sd_report_ms;
|
||||
#if NUM_SERIAL > 1
|
||||
#if HAS_MULTI_SERIAL
|
||||
static int8_t auto_report_port;
|
||||
#endif
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user