Refactor serial class with templates (#20783)
This commit is contained in:
@ -47,7 +47,8 @@ void MAC_report() {
|
||||
Ethernet.MACAddress(mac);
|
||||
SERIAL_ECHOPGM(" MAC: ");
|
||||
LOOP_L_N(i, 6) {
|
||||
SERIAL_PRINTF("%02X", mac[i]);
|
||||
if (mac[i] < 16) SERIAL_CHAR('0');
|
||||
SERIAL_PRINT(mac[i], HEX);
|
||||
if (i < 5) SERIAL_CHAR(':');
|
||||
}
|
||||
}
|
||||
|
@ -986,6 +986,8 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
|
||||
}
|
||||
|
||||
if (!no_ok) queue.ok_to_send();
|
||||
|
||||
SERIAL_OUT(msgDone); // Call the msgDone serial hook to signal command processing done
|
||||
}
|
||||
|
||||
/**
|
||||
@ -995,7 +997,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
|
||||
void GcodeSuite::process_next_command() {
|
||||
char * const current_command = queue.command_buffer[queue.index_r];
|
||||
|
||||
PORT_REDIRECT(queue.port[queue.index_r]);
|
||||
PORT_REDIRECT(SERIAL_PORTMASK(queue.port[queue.index_r]));
|
||||
|
||||
#if ENABLED(POWER_LOSS_RECOVERY)
|
||||
recovery.queue_index_r = queue.index_r;
|
||||
|
@ -53,21 +53,14 @@ void GcodeSuite::M118() {
|
||||
}
|
||||
|
||||
#if HAS_MULTI_SERIAL
|
||||
const serial_index_t old_serial = serial_port_index;
|
||||
const int8_t old_serial = multiSerial.portMask;
|
||||
if (WITHIN(port, 0, NUM_SERIAL))
|
||||
serial_port_index = (
|
||||
port == 0 ? SERIAL_BOTH
|
||||
: port == 1 ? 0
|
||||
#if HAS_MULTI_SERIAL
|
||||
: port == 2 ? 1
|
||||
#endif
|
||||
: SERIAL_PORT
|
||||
);
|
||||
multiSerial.portMask = port ? _BV(port - 1) : SERIAL_ALL;
|
||||
#endif
|
||||
|
||||
if (hasE) SERIAL_ECHO_START();
|
||||
if (hasA) SERIAL_ECHOPGM("//");
|
||||
SERIAL_ECHOLN(p);
|
||||
|
||||
TERN_(HAS_MULTI_SERIAL, serial_port_index = old_serial);
|
||||
TERN_(HAS_MULTI_SERIAL, multiSerial.portMask = old_serial);
|
||||
}
|
||||
|
@ -290,8 +290,8 @@ void GCodeQueue::enqueue_now_P(PGM_P const pgcode) {
|
||||
void GCodeQueue::ok_to_send() {
|
||||
#if HAS_MULTI_SERIAL
|
||||
const serial_index_t serial_ind = command_port();
|
||||
if (serial_ind < 0) return; // Never mind. Command came from SD or Flash Drive
|
||||
PORT_REDIRECT(serial_ind); // Reply to the serial port that sent the command
|
||||
if (serial_ind < 0) return;
|
||||
PORT_REDIRECT(SERIAL_PORTMASK(serial_ind)); // Reply to the serial port that sent the command
|
||||
#endif
|
||||
if (!send_ok[index_r]) return;
|
||||
SERIAL_ECHOPGM(STR_OK);
|
||||
@ -317,7 +317,7 @@ void GCodeQueue::flush_and_request_resend() {
|
||||
const serial_index_t serial_ind = command_port();
|
||||
#if HAS_MULTI_SERIAL
|
||||
if (serial_ind < 0) return; // Never mind. Command came from SD or Flash Drive
|
||||
PORT_REDIRECT(serial_ind); // Reply to the serial port that sent the command
|
||||
PORT_REDIRECT(SERIAL_PORTMASK(serial_ind)); // Reply to the serial port that sent the command
|
||||
#endif
|
||||
SERIAL_FLUSH();
|
||||
SERIAL_ECHOPGM(STR_RESEND);
|
||||
@ -349,11 +349,11 @@ inline int read_serial(const uint8_t index) {
|
||||
}
|
||||
|
||||
void GCodeQueue::gcode_line_error(PGM_P const err, const serial_index_t serial_ind) {
|
||||
PORT_REDIRECT(serial_ind); // Reply to the serial port that sent the command
|
||||
PORT_REDIRECT(SERIAL_PORTMASK(serial_ind)); // Reply to the serial port that sent the command
|
||||
SERIAL_ERROR_START();
|
||||
serialprintPGM(err);
|
||||
SERIAL_ECHOLN(last_N[serial_ind]);
|
||||
while (read_serial(serial_ind) != -1); // Clear out the RX buffer
|
||||
while (read_serial(serial_ind) != -1); // Clear out the RX buffer
|
||||
flush_and_request_resend();
|
||||
serial_count[serial_ind] = 0;
|
||||
}
|
||||
@ -547,7 +547,7 @@ void GCodeQueue::get_serial_commands() {
|
||||
#if ENABLED(BEZIER_CURVE_SUPPORT)
|
||||
case 5:
|
||||
#endif
|
||||
PORT_REDIRECT(p); // Reply to the serial port that sent the command
|
||||
PORT_REDIRECT(SERIAL_PORTMASK(p)); // Reply to the serial port that sent the command
|
||||
SERIAL_ECHOLNPGM(STR_ERR_STOPPED);
|
||||
LCD_MESSAGEPGM(MSG_STOPPED);
|
||||
break;
|
||||
|
@ -82,7 +82,7 @@ void GcodeSuite::M1001() {
|
||||
|
||||
// Announce SD file completion
|
||||
{
|
||||
PORT_REDIRECT(SERIAL_BOTH);
|
||||
PORT_REDIRECT(SERIAL_ALL);
|
||||
SERIAL_ECHOLNPGM(STR_FILE_PRINTED);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user