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