Simplify serial port redirect (#13234)

This commit is contained in:
Scott Lahteine 2019-02-23 22:53:01 -06:00 committed by GitHub
parent 88cc1d1a31
commit e15354e387
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 575 additions and 876 deletions

View file

@ -65,9 +65,12 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
return CTRL_NO_PRESENT; return CTRL_NO_PRESENT;
#ifdef DEBUG_MMC #ifdef DEBUG_MMC
{
char buffer[80]; char buffer[80];
sprintf_P(buffer, PSTR("SDRD: %d @ 0x%08x\n"), nb_sector, addr); sprintf_P(buffer, PSTR("SDRD: %d @ 0x%08x\n"), nb_sector, addr);
SERIAL_ECHO_P(0, buffer); PORT_REDIRECT(0);
SERIAL_ECHO(buffer);
}
#endif #endif
// Start reading // Start reading
@ -99,9 +102,12 @@ Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
return CTRL_NO_PRESENT; return CTRL_NO_PRESENT;
#ifdef DEBUG_MMC #ifdef DEBUG_MMC
{
char buffer[80]; char buffer[80];
sprintf_P(buffer, PSTR("SDWR: %d @ 0x%08x\n"), nb_sector, addr); sprintf_P(buffer, PSTR("SDWR: %d @ 0x%08x\n"), nb_sector, addr);
SERIAL_ECHO_P(0, buffer); PORT_REDIRECT(0);
SERIAL_ECHO(buffer);
}
#endif #endif
if (!card.getSd2Card().writeStart(addr, nb_sector)) if (!card.getSd2Card().writeStart(addr, nb_sector))

View file

@ -29,30 +29,12 @@ static const char errormagic[] PROGMEM = "Error:";
static const char echomagic[] PROGMEM = "echo:"; static const char echomagic[] PROGMEM = "echo:";
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
void serialprintPGM_P(const int8_t p, const char * str) { int8_t serial_port_index = SERIAL_PORT;
while (char ch = pgm_read_byte(str++)) SERIAL_CHAR_P(p, ch);
}
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, const char *v) { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, char v) { serialprintPGM_P(p, s_P); SERIAL_CHAR_P(p, v); }
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, int v) { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, long v) { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, float v) { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, double v) { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, unsigned int v) { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, unsigned long v) { serialprintPGM_P(p, s_P); SERIAL_ECHO_P(p, v); }
void serial_spaces_P(const int8_t p, uint8_t count) { count *= (PROPORTIONAL_FONT_RATIO); while (count--) SERIAL_CHAR_P(p, ' '); }
void serial_echo_start_P(const int8_t p) { serialprintPGM_P(p, echomagic); }
void serial_error_start_P(const int8_t p) { serialprintPGM_P(p, errormagic); }
#endif #endif
void serialprintPGM(PGM_P str) { void serialprintPGM(PGM_P str) {
while (char ch = pgm_read_byte(str++)) SERIAL_CHAR(ch); while (const char c = pgm_read_byte(str++)) SERIAL_CHAR(c);
} }
void serial_echo_start() { serialprintPGM(echomagic); } void serial_echo_start() { serialprintPGM(echomagic); }
void serial_error_start() { serialprintPGM(errormagic); } void serial_error_start() { serialprintPGM(errormagic); }

View file

@ -43,131 +43,43 @@ extern uint8_t marlin_debug_flags;
#define DEBUGGING(F) (marlin_debug_flags & (MARLIN_DEBUG_## F)) #define DEBUGGING(F) (marlin_debug_flags & (MARLIN_DEBUG_## F))
#if TX_BUFFER_SIZE < 1 #if TX_BUFFER_SIZE < 1
#define SERIAL_FLUSHTX_P(p)
#define SERIAL_FLUSHTX() #define SERIAL_FLUSHTX()
#endif #endif
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
extern int8_t serial_port_index;
#define _PORT_REDIRECT(n,p) REMEMBER(n,serial_port_index,p)
#define _PORT_RESTORE(n) RESTORE(n)
#define SERIAL_BOTH 0x7F
#define SERIAL_OUT(WHAT, ...) do{ \
if (!serial_port_index || serial_port_index == SERIAL_BOTH) MYSERIAL0.WHAT(##__VA_ARGS__); \
if ( serial_port_index) MYSERIAL1.WHAT(##__VA_ARGS__); \
}while(0)
#else
#define _PORT_REDIRECT(n,p) NOOP
#define _PORT_RESTORE(n) NOOP
#define SERIAL_OUT(WHAT, ...) MYSERIAL0.WHAT(__VA_ARGS__)
#endif
// #define PORT_REDIRECT(p) _PORT_REDIRECT(1,p)
// Serial out to all ports #define PORT_RESTORE() _PORT_RESTORE(1)
//
#define SERIAL_CHAR(x) (MYSERIAL0.write(x), MYSERIAL1.write(x))
#define SERIAL_ECHO(x) (MYSERIAL0.print(x), MYSERIAL1.print(x))
#define SERIAL_ECHO_F(x,y) (MYSERIAL0.print(x,y), MYSERIAL1.print(x,y))
#define SERIAL_ECHOLN(x) (MYSERIAL0.println(x), MYSERIAL1.println(x))
#define SERIAL_PRINT(x,b) (MYSERIAL0.print(x,b), MYSERIAL1.print(x,b))
#define SERIAL_PRINTLN(x,b) (MYSERIAL0.println(x,b), MYSERIAL1.println(x,b))
#define SERIAL_PRINTF(args...) (MYSERIAL0.printf(args), MYSERIAL1.printf(args))
#define SERIAL_FLUSH() (MYSERIAL0.flush(), MYSERIAL1.flush())
#if TX_BUFFER_SIZE > 0
#define SERIAL_FLUSHTX() (MYSERIAL0.flushTX(), MYSERIAL1.flushTX())
#endif
// #define SERIAL_CHAR(x) SERIAL_OUT(write, x)
// Serial out with port redirect #define SERIAL_ECHO(x) SERIAL_OUT(print, x)
// #define SERIAL_ECHO_F(x,y) SERIAL_OUT(print, x, y)
#define SERIAL_CHAR_P(p,x) (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.write(x) : MYSERIAL1.write(x)) : SERIAL_CHAR(x)) #define SERIAL_ECHOLN(x) SERIAL_OUT(println, x)
#define SERIAL_ECHO_P(p,x) (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.print(x) : MYSERIAL1.print(x)) : SERIAL_ECHO(x)) #define SERIAL_PRINT(x,b) SERIAL_OUT(print, x, b)
#define SERIAL_ECHO_F_P(p,x,y) (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.print(x,y) : MYSERIAL1.print(x,y)) : SERIAL_ECHO_F(x,y)) #define SERIAL_PRINTLN(x,b) SERIAL_OUT(println, x, b)
#define SERIAL_ECHOLN_P(p,x) (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.println(x) : MYSERIAL1.println(x)) : SERIAL_ECHOLN(x)) #define SERIAL_PRINTF(args...) SERIAL_OUT(printf, args)
#define SERIAL_PRINT_P(p,x,b) (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.print(x,b) : MYSERIAL1.print(x,b)) : SERIAL_PRINT(x,b)) #define SERIAL_FLUSH() SERIAL_OUT(flush)
#define SERIAL_PRINTLN_P(p,x,b) (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.println(x,b) : MYSERIAL1.println(x,b)) : SERIAL_PRINTLN(x,b)) #if TX_BUFFER_SIZE > 0
#define SERIAL_PRINTF_P(p,args...) (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.printf(args) : MYSERIAL1.printf(args)) : SERIAL_PRINTF(args)) #define SERIAL_FLUSHTX() SERIAL_OUT(flushTX)
#define SERIAL_FLUSH_P(p) (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.flush() : MYSERIAL1.flush()) : SERIAL_FLUSH()) #endif
#if TX_BUFFER_SIZE > 0
#define SERIAL_FLUSHTX_P(p) (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.flushTX() : MYSERIAL1.flushTX()) : SERIAL_FLUSHTX())
#endif
#define SERIAL_ECHOPGM_P(p,x) (serialprintPGM_P(p,PSTR(x)))
#define SERIAL_ECHOLNPGM_P(p,x) (serialprintPGM_P(p,PSTR(x "\n")))
#define SERIAL_ECHOPAIR_P(p, pre, value) (serial_echopair_PGM_P(p,PSTR(pre),(value)))
#define SERIAL_ECHO_START_P(p) serial_echo_start_P(p)
#define SERIAL_ERROR_START_P(p) serial_error_start_P(p)
#define SERIAL_EOL_P(p) SERIAL_CHAR_P(p,'\n')
#define SERIAL_ECHOPAIR_F_P(p, pre, value, y) do{ SERIAL_ECHO_P(p, pre); SERIAL_ECHO_F_P(p, value, y); }while(0)
#define SERIAL_ECHOLNPAIR_F_P(p, pre, value, y) do{ SERIAL_ECHOPAIR_F_P(p, pre, value, y); SERIAL_EOL_P(p); }while(0)
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, const char *v);
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, char v);
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, int v);
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, long v);
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, float v);
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, double v);
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, unsigned int v);
void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, unsigned long v);
inline void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, uint8_t v) { serial_echopair_PGM_P(p, s_P, (int)v); }
inline void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, bool v) { serial_echopair_PGM_P(p, s_P, (int)v); }
inline void serial_echopair_PGM_P(const int8_t p, PGM_P const s_P, void *v) { serial_echopair_PGM_P(p, s_P, (unsigned long)v); }
void serial_spaces_P(const int8_t p, uint8_t count);
#define SERIAL_ECHO_SP_P(p,C) serial_spaces_P(p,C)
void serialprintPGM_P(const int8_t p, PGM_P str);
void serial_echo_start_P(const int8_t p);
void serial_error_start_P(const int8_t p);
#else // NUM_SERIAL <= 1
//
// Serial out to all ports
//
#define SERIAL_CHAR(x) MYSERIAL0.write(x)
#define SERIAL_ECHO(x) MYSERIAL0.print(x)
#define SERIAL_ECHO_F(x,y) MYSERIAL0.print(x,y)
#define SERIAL_ECHOLN(x) MYSERIAL0.println(x)
#define SERIAL_PRINT(x,b) MYSERIAL0.print(x,b)
#define SERIAL_PRINTLN(x,b) MYSERIAL0.println(x,b)
#define SERIAL_PRINTF(args...) MYSERIAL0.printf(args)
#define SERIAL_FLUSH() MYSERIAL0.flush()
#if TX_BUFFER_SIZE > 0
#define SERIAL_FLUSHTX() MYSERIAL0.flushTX()
#endif
//
// Serial out with port redirect
//
#define SERIAL_CHAR_P(p,x) SERIAL_CHAR(x)
#define SERIAL_ECHO_P(p,x) SERIAL_ECHO(x)
#define SERIAL_ECHO_F_P(p,x,y) SERIAL_ECHO_F(x,y)
#define SERIAL_ECHOLN_P(p,x) SERIAL_ECHOLN(x)
#define SERIAL_PRINT_P(p,x,b) SERIAL_PRINT(x,b)
#define SERIAL_PRINTLN_P(p,x,b) SERIAL_PRINTLN(x,b)
#define SERIAL_PRINTF_P(p,args...) SERIAL_PRINTF(args)
#define SERIAL_FLUSH_P(p) SERIAL_FLUSH()
#if TX_BUFFER_SIZE > 0
#define SERIAL_FLUSHTX_P(p) SERIAL_FLUSHTX()
#endif
#define SERIAL_ECHOPGM_P(p,x) SERIAL_ECHOPGM(x)
#define SERIAL_ECHOLNPGM_P(p,x) SERIAL_ECHOLNPGM(x)
#define SERIAL_ECHOPAIR_P(p, pre, value) SERIAL_ECHOPAIR(pre, value)
#define SERIAL_ECHO_P(p,x) SERIAL_ECHO(x)
#define SERIAL_ECHOLN_P(p,x) SERIAL_ECHOLN(x)
#define SERIAL_ECHO_START_P(p) SERIAL_ECHO_START()
#define SERIAL_ERROR_START_P(p) SERIAL_ERROR_START()
#define SERIAL_EOL_P(p) SERIAL_EOL()
#define SERIAL_ECHOPAIR_F_P(p, pre, value, y) SERIAL_ECHOPAIR_F(pre, value, y)
#define SERIAL_ECHOLNPAIR_F_P(p, pre, value, y) SERIAL_ECHOLNPAIR_F(pre, value, y)
#define serial_echopair_PGM_P(p,s_P,v) serial_echopair_PGM(s_P, v)
#define serial_spaces_P(p,c) serial_spaces(c)
#define SERIAL_ECHO_SP_P(p,C) SERIAL_ECHO_SP(C)
#define serialprintPGM_P(p,s) serialprintPGM(s)
#endif // NUM_SERIAL < 2
#define SERIAL_ECHOPGM(x) (serialprintPGM(PSTR(x))) #define SERIAL_ECHOPGM(x) (serialprintPGM(PSTR(x)))
#define SERIAL_ECHOLNPGM(x) (serialprintPGM(PSTR(x "\n"))) #define SERIAL_ECHOLNPGM(x) (serialprintPGM(PSTR(x "\n")))
#define SERIAL_ECHOPAIR(pre, value) (serial_echopair_PGM(PSTR(pre), value)) #define SERIAL_ECHOPAIR(pre, value) (serial_echopair_PGM(PSTR(pre), value))
#define SERIAL_ECHOLNPAIR(pre, value) do { SERIAL_ECHOPAIR(pre, value); SERIAL_EOL(); } while(0) #define SERIAL_ECHOLNPAIR(pre, value) do{ SERIAL_ECHOPAIR(pre, value); SERIAL_EOL(); }while(0)
#define SERIAL_ECHOPAIR_F(pre, value, y) do{ SERIAL_ECHO(pre); SERIAL_ECHO_F(value, y); }while(0) #define SERIAL_ECHOPAIR_F(pre, value, y) do{ SERIAL_ECHO(pre); SERIAL_ECHO_F(value, y); }while(0)
#define SERIAL_ECHOLNPAIR_F(pre, value, y) do{ SERIAL_ECHOPAIR_F(pre, value, y); SERIAL_EOL(); }while(0) #define SERIAL_ECHOLNPAIR_F(pre, value, y) do{ SERIAL_ECHOPAIR_F(pre, value, y); SERIAL_EOL(); }while(0)
@ -177,13 +89,8 @@ extern uint8_t marlin_debug_flags;
#define SERIAL_EOL() SERIAL_CHAR('\n') #define SERIAL_EOL() SERIAL_CHAR('\n')
#define SERIAL_ECHO_MSG(STR) do{ SERIAL_ECHO_START(); SERIAL_ECHOLNPGM(STR); }while(0) #define SERIAL_ECHO_MSG(STR) do{ SERIAL_ECHO_START(); SERIAL_ECHOLNPGM(STR); }while(0)
#define SERIAL_ECHO_MSG_P(p, STR) do{ SERIAL_ECHO_START_P(p); SERIAL_ECHOLNPGM_P(p, STR); }while(0)
#define SERIAL_ERROR_MSG(STR) do{ SERIAL_ERROR_START(); SERIAL_ECHOLNPGM(STR); }while(0) #define SERIAL_ERROR_MSG(STR) do{ SERIAL_ERROR_START(); SERIAL_ECHOLNPGM(STR); }while(0)
#define SERIAL_ERROR_MSG_P(p, STR) do{ SERIAL_ERROR_START_P(p); SERIAL_ECHOLNPGM_P(p, STR); }while(0)
#define SERIAL_ECHOLNPAIR_P(p, pre, value) do{ SERIAL_ECHOPAIR_P(p, pre, value); SERIAL_EOL_P(p); }while(0)
void serial_spaces(uint8_t count);
#define SERIAL_ECHO_SP(C) serial_spaces(C) #define SERIAL_ECHO_SP(C) serial_spaces(C)
// //
@ -206,6 +113,7 @@ void serial_echo_start();
void serial_error_start(); void serial_error_start();
void serialprint_onoff(const bool onoff); void serialprint_onoff(const bool onoff);
void serialprintln_onoff(const bool onoff); void serialprintln_onoff(const bool onoff);
void serial_spaces(uint8_t count);
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
void print_xyz(PGM_P const prefix, PGM_P const suffix, const float x, const float y, const float z); void print_xyz(PGM_P const prefix, PGM_P const suffix, const float x, const float y, const float z);

View file

@ -133,5 +133,5 @@ public:
inline void restore() { ref_ = val_; } inline void restore() { ref_ = val_; }
}; };
#define REMEMBER(N,X, ...) restorer<typeof(X)> N##_restorer(X, ##__VA_ARGS__) #define REMEMBER(N,X, ...) restorer<typeof(X)> restorer_##N(X, ##__VA_ARGS__)
#define RESTORE(N) N##_restorer.restore() #define RESTORE(N) restorer_##N.restore()

View file

@ -34,46 +34,30 @@
#include "math.h" #include "math.h"
void unified_bed_leveling::echo_name( void unified_bed_leveling::echo_name() {
#if NUM_SERIAL > 1 SERIAL_ECHOPGM("Unified Bed Leveling");
const int8_t port/*= -1*/
#endif
) {
SERIAL_ECHOPGM_P(port, "Unified Bed Leveling");
} }
void unified_bed_leveling::report_current_mesh( void unified_bed_leveling::report_current_mesh() {
#if NUM_SERIAL > 1
const int8_t port/*= -1*/
#endif
) {
if (!leveling_is_valid()) return; if (!leveling_is_valid()) return;
SERIAL_ECHO_MSG_P(port, " G29 I99"); SERIAL_ECHO_MSG(" G29 I99");
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
if (!isnan(z_values[x][y])) { if (!isnan(z_values[x][y])) {
SERIAL_ECHO_START_P(port); SERIAL_ECHO_START();
SERIAL_ECHOPAIR_P(port, " M421 I", x); SERIAL_ECHOPAIR(" M421 I", x);
SERIAL_ECHOPAIR_P(port, " J", y); SERIAL_ECHOPAIR(" J", y);
SERIAL_ECHOPAIR_F_P(port, " Z", z_values[x][y], 2); SERIAL_ECHOPAIR_F(" Z", z_values[x][y], 2);
SERIAL_EOL_P(port); SERIAL_EOL();
serial_delay(75); // Prevent Printrun from exploding serial_delay(75); // Prevent Printrun from exploding
} }
} }
void unified_bed_leveling::report_state( void unified_bed_leveling::report_state() {
#if NUM_SERIAL > 1 echo_name();
const int8_t port/*= -1*/ SERIAL_ECHOPGM(" System v" UBL_VERSION " ");
#endif if (!planner.leveling_active) SERIAL_ECHOPGM("in");
) { SERIAL_ECHOLNPGM("active.");
echo_name(
#if NUM_SERIAL > 1
port
#endif
);
SERIAL_ECHOPGM_P(port, " System v" UBL_VERSION " ");
if (!planner.leveling_active) SERIAL_ECHOPGM_P(port, "in");
SERIAL_ECHOLNPGM_P(port, "active.");
serial_delay(50); serial_delay(50);
} }

View file

@ -94,21 +94,9 @@ class unified_bed_leveling {
public: public:
static void echo_name( static void echo_name();
#if NUM_SERIAL > 1 static void report_current_mesh();
const int8_t port = -1 static void report_state();
#endif
);
static void report_current_mesh(
#if NUM_SERIAL > 1
const int8_t port = -1
#endif
);
static void report_state(
#if NUM_SERIAL > 1
const int8_t port = -1
#endif
);
static void save_ubl_active_state_and_disable(); static void save_ubl_active_state_and_disable();
static void restore_ubl_active_state_and_leave(); static void restore_ubl_active_state_and_leave();
static void display_map(const int) _O0; static void display_map(const int) _O0;

View file

@ -33,19 +33,15 @@
void M217_report(const bool eeprom=false) { void M217_report(const bool eeprom=false) {
#if NUM_SERIAL > 1
const int16_t port = command_queue_port[cmd_queue_index_r];
#endif
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP) #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
serialprintPGM_P(port, eeprom ? PSTR(" M217") : PSTR("Singlenozzle:")); serialprintPGM(eeprom ? PSTR(" M217") : PSTR("Singlenozzle:"));
SERIAL_ECHOPAIR_P(port, " S", LINEAR_UNIT(toolchange_settings.swap_length)); SERIAL_ECHOPAIR(" S", LINEAR_UNIT(toolchange_settings.swap_length));
SERIAL_ECHOPAIR_P(port, " P", LINEAR_UNIT(toolchange_settings.prime_speed)); SERIAL_ECHOPAIR(" P", LINEAR_UNIT(toolchange_settings.prime_speed));
SERIAL_ECHOPAIR_P(port, " R", LINEAR_UNIT(toolchange_settings.retract_speed)); SERIAL_ECHOPAIR(" R", LINEAR_UNIT(toolchange_settings.retract_speed));
#if ENABLED(TOOLCHANGE_PARK) #if ENABLED(TOOLCHANGE_PARK)
SERIAL_ECHOPAIR_P(port, " X", LINEAR_UNIT(toolchange_settings.change_point.x)); SERIAL_ECHOPAIR(" X", LINEAR_UNIT(toolchange_settings.change_point.x));
SERIAL_ECHOPAIR_P(port, " Y", LINEAR_UNIT(toolchange_settings.change_point.y)); SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(toolchange_settings.change_point.y));
#endif #endif
#else #else
@ -54,7 +50,7 @@ void M217_report(const bool eeprom=false) {
#endif #endif
SERIAL_ECHOPAIR_P(port, " Z", LINEAR_UNIT(toolchange_settings.z_raise)); SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(toolchange_settings.z_raise));
SERIAL_EOL(); SERIAL_EOL();
} }

View file

@ -23,27 +23,22 @@
#include "../gcode.h" #include "../gcode.h"
#include "../../module/planner.h" #include "../../module/planner.h"
void report_M92( void report_M92(const bool echo=true, const int8_t e=-1) {
#if NUM_SERIAL > 1 if (echo) SERIAL_ECHO_START(); else SERIAL_CHAR(' ');
const int8_t port, SERIAL_ECHOPAIR(" M92 X", LINEAR_UNIT(planner.settings.axis_steps_per_mm[X_AXIS]));
#endif SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(planner.settings.axis_steps_per_mm[Y_AXIS]));
const bool echo=true, const int8_t e=-1 SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.settings.axis_steps_per_mm[Z_AXIS]));
) {
if (echo) SERIAL_ECHO_START_P(port); else SERIAL_CHAR(' ');
SERIAL_ECHOPAIR_P(port, " M92 X", LINEAR_UNIT(planner.settings.axis_steps_per_mm[X_AXIS]));
SERIAL_ECHOPAIR_P(port, " Y", LINEAR_UNIT(planner.settings.axis_steps_per_mm[Y_AXIS]));
SERIAL_ECHOPAIR_P(port, " Z", LINEAR_UNIT(planner.settings.axis_steps_per_mm[Z_AXIS]));
#if DISABLED(DISTINCT_E_FACTORS) #if DISABLED(DISTINCT_E_FACTORS)
SERIAL_ECHOPAIR_P(port, " E", VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS])); SERIAL_ECHOPAIR(" E", VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS]));
#endif #endif
SERIAL_EOL_P(port); SERIAL_EOL();
#if ENABLED(DISTINCT_E_FACTORS) #if ENABLED(DISTINCT_E_FACTORS)
for (uint8_t i = 0; i < E_STEPPERS; i++) { for (uint8_t i = 0; i < E_STEPPERS; i++) {
if (e >= 0 && i != e) continue; if (e >= 0 && i != e) continue;
if (echo) SERIAL_ECHO_START_P(port); else SERIAL_CHAR(' '); if (echo) SERIAL_ECHO_START(); else SERIAL_CHAR(' ');
SERIAL_ECHOPAIR_P(port, " M92 T", (int)i); SERIAL_ECHOPAIR(" M92 T", (int)i);
SERIAL_ECHOLNPAIR_P(port, " E", VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS_N(i)])); SERIAL_ECHOLNPAIR(" E", VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS_N(i)]));
} }
#endif #endif
} }
@ -71,12 +66,7 @@ void GcodeSuite::M92() {
#if ENABLED(MAGIC_NUMBERS_GCODE) #if ENABLED(MAGIC_NUMBERS_GCODE)
"HL" "HL"
#endif #endif
)) return report_M92( )) return report_M92(true, target_extruder);
#if NUM_SERIAL > 1
command_queue_port[cmd_queue_index_r],
#endif
true, target_extruder
);
LOOP_XYZE(i) { LOOP_XYZE(i) {
if (parser.seenval(axis_codes[i])) { if (parser.seenval(axis_codes[i])) {

View file

@ -33,17 +33,11 @@
#include "../../gcode/queue.h" #include "../../gcode/queue.h"
#endif #endif
#if ADD_PORT_ARG
#define CHAT_PORT command_queue_port[cmd_queue_index_r]
#else
#define CHAT_PORT
#endif
/** /**
* M500: Store settings in EEPROM * M500: Store settings in EEPROM
*/ */
void GcodeSuite::M500() { void GcodeSuite::M500() {
(void)settings.save(CHAT_PORT); (void)settings.save();
#if ENABLED(EXTENSIBLE_UI) #if ENABLED(EXTENSIBLE_UI)
ExtUI::onStoreSettings(); ExtUI::onStoreSettings();
#endif #endif
@ -53,11 +47,7 @@ void GcodeSuite::M500() {
* M501: Read settings from EEPROM * M501: Read settings from EEPROM
*/ */
void GcodeSuite::M501() { void GcodeSuite::M501() {
(void)settings.load( (void)settings.load();
#if ENABLED(EEPROM_SETTINGS)
CHAT_PORT
#endif
);
#if ENABLED(EXTENSIBLE_UI) #if ENABLED(EXTENSIBLE_UI)
ExtUI::onLoadSettings(); ExtUI::onLoadSettings();
#endif #endif
@ -67,7 +57,7 @@ void GcodeSuite::M501() {
* M502: Revert to default settings * M502: Revert to default settings
*/ */
void GcodeSuite::M502() { void GcodeSuite::M502() {
(void)settings.reset(CHAT_PORT); (void)settings.reset();
#if ENABLED(EXTENSIBLE_UI) #if ENABLED(EXTENSIBLE_UI)
ExtUI::onFactoryReset(); ExtUI::onFactoryReset();
#endif #endif
@ -79,12 +69,7 @@ void GcodeSuite::M502() {
* M503: print settings currently in memory * M503: print settings currently in memory
*/ */
void GcodeSuite::M503() { void GcodeSuite::M503() {
(void)settings.report( (void)settings.report(parser.boolval('S', true));
parser.seen('S') && !parser.value_bool()
#if NUM_SERIAL > 1
, command_queue_port[cmd_queue_index_r]
#endif
);
} }
#endif // !DISABLE_M503 #endif // !DISABLE_M503
@ -94,7 +79,7 @@ void GcodeSuite::M502() {
* M504: Validate EEPROM Contents * M504: Validate EEPROM Contents
*/ */
void GcodeSuite::M504() { void GcodeSuite::M504() {
if (settings.validate(CHAT_PORT)) if (settings.validate())
SERIAL_ECHO_MSG_P(command_queue_port[cmd_queue_index_r], "EEPROM OK"); SERIAL_ECHO_MSG("EEPROM OK");
} }
#endif #endif

View file

@ -754,6 +754,8 @@ void GcodeSuite::process_parsed_command(
void GcodeSuite::process_next_command() { void GcodeSuite::process_next_command() {
char * const current_command = command_queue[cmd_queue_index_r]; char * const current_command = command_queue[cmd_queue_index_r];
PORT_REDIRECT(command_queue_port[cmd_queue_index_r]);
if (DEBUGGING(ECHO)) { if (DEBUGGING(ECHO)) {
SERIAL_ECHO_START(); SERIAL_ECHO_START();
SERIAL_ECHOLN(current_command); SERIAL_ECHOLN(current_command);

View file

@ -40,14 +40,8 @@
* M115: Capabilities string * M115: Capabilities string
*/ */
void GcodeSuite::M115() { void GcodeSuite::M115() {
#if NUM_SERIAL > 1
const int8_t port = command_queue_port[cmd_queue_index_r];
#define CAPLINE(STR,...) cap_line(PSTR(STR), port, __VA_ARGS__)
#else
#define CAPLINE(STR,...) cap_line(PSTR(STR), __VA_ARGS__)
#endif
SERIAL_ECHOLNPGM_P(port, MSG_M115_REPORT); SERIAL_ECHOLNPGM(MSG_M115_REPORT);
#if ENABLED(EXTENDED_CAPABILITIES_REPORT) #if ENABLED(EXTENDED_CAPABILITIES_REPORT)

View file

@ -328,13 +328,10 @@ void GCodeParser::parse(char *p) {
#endif // CNC_COORDINATE_SYSTEMS #endif // CNC_COORDINATE_SYSTEMS
void GCodeParser::unknown_command_error() { void GCodeParser::unknown_command_error() {
#if NUM_SERIAL > 1 SERIAL_ECHO_START();
const int16_t port = command_queue_port[cmd_queue_index_r]; SERIAL_ECHOPAIR(MSG_UNKNOWN_COMMAND, command_ptr);
#endif SERIAL_CHAR('"');
SERIAL_ECHO_START_P(port); SERIAL_EOL();
SERIAL_ECHOPAIR_P(port, MSG_UNKNOWN_COMMAND, command_ptr);
SERIAL_CHAR_P(port, '"');
SERIAL_EOL_P(port);
} }
#if ENABLED(DEBUG_GCODE_PARSER) #if ENABLED(DEBUG_GCODE_PARSER)

View file

@ -219,21 +219,22 @@ void ok_to_send() {
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
const int16_t port = command_queue_port[cmd_queue_index_r]; const int16_t port = command_queue_port[cmd_queue_index_r];
if (port < 0) return; if (port < 0) return;
PORT_REDIRECT(port);
#endif #endif
if (!send_ok[cmd_queue_index_r]) return; if (!send_ok[cmd_queue_index_r]) return;
SERIAL_ECHOPGM_P(port, MSG_OK); SERIAL_ECHOPGM(MSG_OK);
#if ENABLED(ADVANCED_OK) #if ENABLED(ADVANCED_OK)
char* p = command_queue[cmd_queue_index_r]; char* p = command_queue[cmd_queue_index_r];
if (*p == 'N') { if (*p == 'N') {
SERIAL_ECHO_P(port, ' '); SERIAL_ECHO(' ');
SERIAL_ECHO_P(port, *p++); SERIAL_ECHO(*p++);
while (NUMERIC_SIGNED(*p)) while (NUMERIC_SIGNED(*p))
SERIAL_ECHO_P(port, *p++); SERIAL_ECHO(*p++);
} }
SERIAL_ECHOPGM_P(port, " P"); SERIAL_ECHO_P(port, int(BLOCK_BUFFER_SIZE - planner.movesplanned() - 1)); SERIAL_ECHOPGM(" P"); SERIAL_ECHO(int(BLOCK_BUFFER_SIZE - planner.movesplanned() - 1));
SERIAL_ECHOPGM_P(port, " B"); SERIAL_ECHO_P(port, BUFSIZE - commands_in_queue); SERIAL_ECHOPGM(" B"); SERIAL_ECHO(BUFSIZE - commands_in_queue);
#endif #endif
SERIAL_EOL_P(port); SERIAL_EOL();
} }
/** /**
@ -244,10 +245,11 @@ void flush_and_request_resend() {
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
const int16_t port = command_queue_port[cmd_queue_index_r]; const int16_t port = command_queue_port[cmd_queue_index_r];
if (port < 0) return; if (port < 0) return;
PORT_REDIRECT(port);
#endif #endif
SERIAL_FLUSH_P(port); SERIAL_FLUSH();
SERIAL_ECHOPGM_P(port, MSG_RESEND); SERIAL_ECHOPGM(MSG_RESEND);
SERIAL_ECHOLN_P(port, gcode_LastN + 1); SERIAL_ECHOLN(gcode_LastN + 1);
ok_to_send(); ok_to_send();
} }
@ -270,10 +272,11 @@ inline int read_serial(const uint8_t index) {
} }
} }
void gcode_line_error(PGM_P err, uint8_t port) { void gcode_line_error(PGM_P const err, const int8_t port) {
SERIAL_ERROR_START_P(port); PORT_REDIRECT(port);
serialprintPGM_P(port, err); SERIAL_ERROR_START();
SERIAL_ECHOLN_P(port, gcode_LastN); serialprintPGM(err);
SERIAL_ECHOLN(gcode_LastN);
while (read_serial(port) != -1); // clear out the RX buffer while (read_serial(port) != -1); // clear out the RX buffer
flush_and_request_resend(); flush_and_request_resend();
serial_count[port] = 0; serial_count[port] = 0;
@ -281,12 +284,6 @@ void gcode_line_error(PGM_P err, uint8_t port) {
#if ENABLED(FAST_FILE_TRANSFER) #if ENABLED(FAST_FILE_TRANSFER)
#if ENABLED(SDSUPPORT)
#define CARD_CHAR_P(C) SERIAL_CHAR_P(card.transfer_port, C)
#define CARD_ECHO_P(V) SERIAL_ECHO_P(card.transfer_port, V)
#define CARD_ECHOLN_P(V) SERIAL_ECHOLN_P(card.transfer_port, V)
#endif
inline bool serial_data_available(const uint8_t index) { inline bool serial_data_available(const uint8_t index) {
switch (index) { switch (index) {
case 0: return MYSERIAL0.available(); case 0: return MYSERIAL0.available();
@ -380,6 +377,11 @@ void gcode_line_error(PGM_P err, uint8_t port) {
void receive(char (&buffer)[buffer_size]) { void receive(char (&buffer)[buffer_size]) {
uint8_t data = 0; uint8_t data = 0;
millis_t transfer_timeout = millis() + RX_TIMESLICE; millis_t transfer_timeout = millis() + RX_TIMESLICE;
#if ENABLED(SDSUPPORT)
PORT_REDIRECT(card.transfer_port);
#endif
while (PENDING(millis(), transfer_timeout)) { while (PENDING(millis(), transfer_timeout)) {
switch (stream_state) { switch (stream_state) {
case StreamState::STREAM_RESET: case StreamState::STREAM_RESET:
@ -388,24 +390,24 @@ void gcode_line_error(PGM_P err, uint8_t port) {
packet_reset(); packet_reset();
stream_state = StreamState::PACKET_HEADER; stream_state = StreamState::PACKET_HEADER;
break; break;
case StreamState::STREAM_HEADER: // we could also transfer the filename in this packet, rather than handling it in the gcode case StreamState::STREAM_HEADER: // The filename could also be in this packet, rather than handling it in the gcode
for (size_t i = 0; i < sizeof(stream_header); ++i) { for (size_t i = 0; i < sizeof(stream_header); ++i)
stream_header_bytes[i] = buffer[i]; stream_header_bytes[i] = buffer[i];
}
if (stream_header.token == 0x1234) { if (stream_header.token == 0x1234) {
stream_state = StreamState::PACKET_RESET; stream_state = StreamState::PACKET_RESET;
bytes_received = 0; bytes_received = 0;
time_stream_start = millis(); time_stream_start = millis();
CARD_ECHO_P("echo: Datastream initialized ("); SERIAL_ECHO("echo: Datastream initialized (");
CARD_ECHO_P(stream_header.filesize); SERIAL_ECHO(stream_header.filesize);
CARD_ECHOLN_P("Bytes expected)"); SERIAL_ECHOLN("Bytes expected)");
CARD_ECHO_P("so"); // confirm active stream and the maximum block size supported SERIAL_ECHO("so"); // confirm active stream and the maximum block size supported
CARD_CHAR_P(static_cast<uint8_t>(buffer_size & 0xFF)); SERIAL_CHAR(static_cast<uint8_t>(buffer_size & 0xFF));
CARD_CHAR_P(static_cast<uint8_t>((buffer_size >> 8) & 0xFF)); SERIAL_CHAR(static_cast<uint8_t>((buffer_size >> 8) & 0xFF));
CARD_CHAR_P('\n'); SERIAL_CHAR('\n');
} }
else { else {
CARD_ECHOLN_P("echo: Datastream initialization error (invalid token)"); SERIAL_ECHOLN("echo: Datastream initialization error (invalid token)");
stream_state = StreamState::STREAM_FAILED; stream_state = StreamState::STREAM_FAILED;
} }
buffer_next_index = 0; buffer_next_index = 0;
@ -421,7 +423,7 @@ void gcode_line_error(PGM_P err, uint8_t port) {
stream_state = StreamState::PACKET_DATA; stream_state = StreamState::PACKET_DATA;
} }
else { else {
CARD_ECHO_P("echo: Datastream packet out of order"); SERIAL_ECHO("echo: Datastream packet out of order");
stream_state = StreamState::PACKET_FLUSHRX; stream_state = StreamState::PACKET_FLUSHRX;
} }
} }
@ -433,7 +435,7 @@ void gcode_line_error(PGM_P err, uint8_t port) {
buffer[buffer_next_index] = data; buffer[buffer_next_index] = data;
} }
else { else {
CARD_ECHO_P("echo: Datastream packet data buffer overrun"); SERIAL_ECHO("echo: Datastream packet data buffer overrun");
stream_state = StreamState::STREAM_FAILED; stream_state = StreamState::STREAM_FAILED;
break; break;
} }
@ -458,22 +460,22 @@ void gcode_line_error(PGM_P err, uint8_t port) {
else { else {
if (bytes_received < stream_header.filesize) { if (bytes_received < stream_header.filesize) {
stream_state = StreamState::PACKET_RESET; // reset and receive next packet stream_state = StreamState::PACKET_RESET; // reset and receive next packet
CARD_ECHOLN_P("ok"); // transmit confirm packet received and valid token SERIAL_ECHOLN("ok"); // transmit confirm packet received and valid token
} }
else { else {
stream_state = StreamState::STREAM_COMPLETE; // no more data required stream_state = StreamState::STREAM_COMPLETE; // no more data required
} }
if (card.write(buffer, buffer_next_index) < 0) { if (card.write(buffer, buffer_next_index) < 0) {
stream_state = StreamState::STREAM_FAILED; stream_state = StreamState::STREAM_FAILED;
CARD_ECHO_P("echo: IO ERROR"); SERIAL_ECHO("echo: IO ERROR");
break; break;
}; };
} }
} }
else { else {
CARD_ECHO_P("echo: Block("); SERIAL_ECHO("echo: Block(");
CARD_ECHO_P(packet.header.id); SERIAL_ECHO(packet.header.id);
CARD_ECHOLN_P(") Corrupt"); SERIAL_ECHOLN(") Corrupt");
stream_state = StreamState::PACKET_FLUSHRX; stream_state = StreamState::PACKET_FLUSHRX;
} }
break; break;
@ -481,9 +483,9 @@ void gcode_line_error(PGM_P err, uint8_t port) {
if (packet_retries < MAX_RETRIES) { if (packet_retries < MAX_RETRIES) {
packet_retries ++; packet_retries ++;
stream_state = StreamState::PACKET_RESET; stream_state = StreamState::PACKET_RESET;
CARD_ECHO_P("echo: Resend request "); SERIAL_ECHO("echo: Resend request ");
CARD_ECHOLN_P(packet_retries); SERIAL_ECHOLN(packet_retries);
CARD_ECHOLN_P("rs"); // transmit resend packet token SERIAL_ECHOLN("rs"); // transmit resend packet token
} }
else { else {
stream_state = StreamState::STREAM_FAILED; stream_state = StreamState::STREAM_FAILED;
@ -499,27 +501,27 @@ void gcode_line_error(PGM_P err, uint8_t port) {
packet.timeout = millis() + STREAM_MAX_WAIT; packet.timeout = millis() + STREAM_MAX_WAIT;
break; break;
case StreamState::PACKET_TIMEOUT: case StreamState::PACKET_TIMEOUT:
CARD_ECHOLN_P("echo: Datastream timeout"); SERIAL_ECHOLN("echo: Datastream timeout");
stream_state = StreamState::PACKET_RESEND; stream_state = StreamState::PACKET_RESEND;
break; break;
case StreamState::STREAM_COMPLETE: case StreamState::STREAM_COMPLETE:
stream_state = StreamState::STREAM_RESET; stream_state = StreamState::STREAM_RESET;
card.flag.binary_mode = false; card.flag.binary_mode = false;
card.closefile(); card.closefile();
CARD_ECHO_P("echo: "); SERIAL_ECHO("echo: ");
CARD_ECHO_P(card.filename); SERIAL_ECHO(card.filename);
CARD_ECHO_P(" transfer completed @ "); SERIAL_ECHO(" transfer completed @ ");
CARD_ECHO_P(((bytes_received / (millis() - time_stream_start) * 1000) / 1024 )); SERIAL_ECHO(((bytes_received / (millis() - time_stream_start) * 1000) / 1024 ));
CARD_ECHOLN_P("KiB/s"); SERIAL_ECHOLN("KiB/s");
CARD_ECHOLN_P("sc"); // transmit stream complete token SERIAL_ECHOLN("sc"); // transmit stream complete token
return; return;
case StreamState::STREAM_FAILED: case StreamState::STREAM_FAILED:
stream_state = StreamState::STREAM_RESET; stream_state = StreamState::STREAM_RESET;
card.flag.binary_mode = false; card.flag.binary_mode = false;
card.closefile(); card.closefile();
card.removeFile(card.filename); card.removeFile(card.filename);
CARD_ECHOLN_P("echo: File transfer failed"); SERIAL_ECHOLN("echo: File transfer failed");
CARD_ECHOLN_P("sf"); // transmit stream failed token SERIAL_ECHOLN("sf"); // transmit stream failed token
return; return;
} }
} }

View file

@ -50,17 +50,13 @@
* M20: List SD card to serial output * M20: List SD card to serial output
*/ */
void GcodeSuite::M20() { void GcodeSuite::M20() {
#if NUM_SERIAL > 1 SERIAL_ECHOLNPGM(MSG_BEGIN_FILE_LIST);
const int16_t port = command_queue_port[cmd_queue_index_r];
#endif
SERIAL_ECHOLNPGM_P(port, MSG_BEGIN_FILE_LIST);
card.ls( card.ls(
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
port command_queue_port[cmd_queue_index_r]
#endif #endif
); );
SERIAL_ECHOLNPGM_P(port, MSG_END_FILE_LIST); SERIAL_ECHOLNPGM(MSG_END_FILE_LIST);
} }
/** /**
@ -165,11 +161,11 @@ void GcodeSuite::M26() {
*/ */
void GcodeSuite::M27() { void GcodeSuite::M27() {
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
const int16_t port = command_queue_port[cmd_queue_index_r]; const int16_t port = serial_port_index;
#endif #endif
if (parser.seen('C')) { if (parser.seen('C')) {
SERIAL_ECHOPGM_P(port, "Current file: "); SERIAL_ECHOPGM("Current file: ");
card.printFilename(); card.printFilename();
} }
@ -197,10 +193,6 @@ void GcodeSuite::M28() {
#if ENABLED(FAST_FILE_TRANSFER) #if ENABLED(FAST_FILE_TRANSFER)
#if NUM_SERIAL > 1
const int16_t port = command_queue_port[cmd_queue_index_r];
#endif
bool binary_mode = false; bool binary_mode = false;
char *p = parser.string_arg; char *p = parser.string_arg;
if (p[0] == 'B' && NUMERIC(p[1])) { if (p[0] == 'B' && NUMERIC(p[1])) {
@ -211,12 +203,12 @@ 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_START_P(port); SERIAL_ECHO_START();
SERIAL_ECHO_P(port, " preparing to receive: "); SERIAL_ECHO(" preparing to receive: ");
SERIAL_ECHOLN_P(port, p); SERIAL_ECHOLN(p);
card.openFile(p, false); card.openFile(p, false);
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
card.transfer_port = port; card.transfer_port = command_queue_port[cmd_queue_index_r];
#endif #endif
} }
else else

View file

@ -42,6 +42,6 @@ void GcodeSuite::M31() {
elapsed.toString(buffer); elapsed.toString(buffer);
ui.set_status(buffer); ui.set_status(buffer);
SERIAL_ECHO_START_P(port); SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR_P(port, "Print time: ", buffer); SERIAL_ECHOLNPAIR("Print time: ", buffer);
} }

View file

@ -40,15 +40,15 @@ void GcodeSuite::M105() {
#endif #endif
#if HAS_TEMP_SENSOR #if HAS_TEMP_SENSOR
SERIAL_ECHOPGM_P(port, MSG_OK); SERIAL_ECHOPGM(MSG_OK);
thermalManager.print_heater_states(target_extruder thermalManager.print_heater_states(target_extruder
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
, port , port
#endif #endif
); );
#else // !HAS_TEMP_SENSOR #else // !HAS_TEMP_SENSOR
SERIAL_ERROR_MSG_P(port, MSG_ERR_NO_THERMISTORS); SERIAL_ERROR_MSG(MSG_ERR_NO_THERMISTORS);
#endif #endif
SERIAL_EOL_P(port); SERIAL_EOL();
} }

File diff suppressed because it is too large Load diff

View file

@ -27,24 +27,14 @@
#include "../HAL/shared/persistent_store_api.h" #include "../HAL/shared/persistent_store_api.h"
#endif #endif
#define ADD_PORT_ARG ENABLED(EEPROM_CHITCHAT) && NUM_SERIAL > 1
#if ADD_PORT_ARG
#define PORTINIT_SOLO const int8_t port=-1
#define PORTINIT_AFTER ,const int8_t port=-1
#else
#define PORTINIT_SOLO
#define PORTINIT_AFTER
#endif
class MarlinSettings { class MarlinSettings {
public: public:
MarlinSettings() { } MarlinSettings() { }
static uint16_t datasize(); static uint16_t datasize();
static void reset(PORTINIT_SOLO); static void reset();
static bool save(PORTINIT_SOLO); // Return 'true' if data was saved static bool save(); // Return 'true' if data was saved
FORCE_INLINE static bool init_eeprom() { FORCE_INLINE static bool init_eeprom() {
reset(); reset();
@ -65,8 +55,8 @@ class MarlinSettings {
#endif #endif
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(EEPROM_SETTINGS)
static bool load(PORTINIT_SOLO); // Return 'true' if data was loaded ok static bool load(); // Return 'true' if data was loaded ok
static bool validate(PORTINIT_SOLO); // Return 'true' if EEPROM data is ok static bool validate(); // Return 'true' if EEPROM data is ok
#if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
// That can store is enabled // That can store is enabled
@ -86,11 +76,7 @@ class MarlinSettings {
#endif #endif
#if DISABLED(DISABLE_M503) #if DISABLED(DISABLE_M503)
static void report(const bool forReplay=false static void report(const bool forReplay=false);
#if NUM_SERIAL > 1
, const int8_t port=-1
#endif
);
#else #else
FORCE_INLINE FORCE_INLINE
static void report(const bool forReplay=false) { UNUSED(forReplay); } static void report(const bool forReplay=false) { UNUSED(forReplay); }
@ -109,12 +95,9 @@ class MarlinSettings {
// live at the very end of the eeprom // live at the very end of the eeprom
#endif #endif
static bool _load(PORTINIT_SOLO); static bool _load();
static bool size_error(const uint16_t size PORTINIT_AFTER); static bool size_error(const uint16_t size);
#endif #endif
}; };
extern MarlinSettings settings; extern MarlinSettings settings;
#undef PORTINIT_SOLO
#undef PORTINIT_AFTER

View file

@ -2500,17 +2500,14 @@ void Temperature::isr() {
#if ENABLED(SHOW_TEMP_ADC_VALUES) #if ENABLED(SHOW_TEMP_ADC_VALUES)
, const float r , const float r
#endif #endif
#if NUM_SERIAL > 1
, const int8_t port=-1
#endif
, const int8_t e=-3 , const int8_t e=-3
) { ) {
#if !(HAS_HEATED_BED && HAS_TEMP_HOTEND && HAS_TEMP_CHAMBER) && HOTENDS <= 1 #if !(HAS_HEATED_BED && HAS_TEMP_HOTEND && HAS_TEMP_CHAMBER) && HOTENDS <= 1
UNUSED(e); UNUSED(e);
#endif #endif
SERIAL_CHAR_P(port, ' '); SERIAL_CHAR(' ');
SERIAL_CHAR_P(port, SERIAL_CHAR(
#if HAS_TEMP_CHAMBER && HAS_HEATED_BED && HAS_TEMP_HOTEND #if HAS_TEMP_CHAMBER && HAS_HEATED_BED && HAS_TEMP_HOTEND
e == -2 ? 'C' : e == -1 ? 'B' : 'T' e == -2 ? 'C' : e == -1 ? 'B' : 'T'
#elif HAS_HEATED_BED && HAS_TEMP_HOTEND #elif HAS_HEATED_BED && HAS_TEMP_HOTEND
@ -2522,23 +2519,19 @@ void Temperature::isr() {
#endif #endif
); );
#if HOTENDS > 1 #if HOTENDS > 1
if (e >= 0) SERIAL_CHAR_P(port, '0' + e); if (e >= 0) SERIAL_CHAR('0' + e);
#endif #endif
SERIAL_CHAR_P(port, ':'); SERIAL_CHAR(':');
SERIAL_ECHO_P(port, c); SERIAL_ECHO(c);
SERIAL_ECHOPAIR_P(port, " /" , t); SERIAL_ECHOPAIR(" /" , t);
#if ENABLED(SHOW_TEMP_ADC_VALUES) #if ENABLED(SHOW_TEMP_ADC_VALUES)
SERIAL_ECHOPAIR_P(port, " (", r / OVERSAMPLENR); SERIAL_ECHOPAIR(" (", r / OVERSAMPLENR);
SERIAL_CHAR_P(port, ')'); SERIAL_CHAR(')');
#endif #endif
delay(2); delay(2);
} }
void Temperature::print_heater_states(const uint8_t target_extruder void Temperature::print_heater_states(const uint8_t target_extruder) {
#if NUM_SERIAL > 1
, const int8_t port
#endif
) {
#if HAS_TEMP_HOTEND #if HAS_TEMP_HOTEND
print_heater_state(degHotend(target_extruder), degTargetHotend(target_extruder) print_heater_state(degHotend(target_extruder), degTargetHotend(target_extruder)
#if ENABLED(SHOW_TEMP_ADC_VALUES) #if ENABLED(SHOW_TEMP_ADC_VALUES)
@ -2579,17 +2572,17 @@ void Temperature::isr() {
, e , e
); );
#endif #endif
SERIAL_ECHOPGM_P(port, " @:"); SERIAL_ECHOPGM(" @:");
SERIAL_ECHO_P(port, getHeaterPower(target_extruder)); SERIAL_ECHO(getHeaterPower(target_extruder));
#if HAS_HEATED_BED #if HAS_HEATED_BED
SERIAL_ECHOPGM_P(port, " B@:"); SERIAL_ECHOPGM(" B@:");
SERIAL_ECHO_P(port, getHeaterPower(-1)); SERIAL_ECHO(getHeaterPower(-1));
#endif #endif
#if HOTENDS > 1 #if HOTENDS > 1
HOTEND_LOOP() { HOTEND_LOOP() {
SERIAL_ECHOPAIR_P(port, " @", e); SERIAL_ECHOPAIR(" @", e);
SERIAL_CHAR_P(port, ':'); SERIAL_CHAR(':');
SERIAL_ECHO_P(port, getHeaterPower(e)); SERIAL_ECHO(getHeaterPower(e));
} }
#endif #endif
} }

View file

@ -672,11 +672,7 @@ class Temperature {
#endif // HEATER_IDLE_HANDLER #endif // HEATER_IDLE_HANDLER
#if HAS_TEMP_SENSOR #if HAS_TEMP_SENSOR
static void print_heater_states(const uint8_t target_extruder static void print_heater_states(const uint8_t target_extruder);
#if NUM_SERIAL > 1
, const int8_t port = -1
#endif
);
#if ENABLED(AUTO_REPORT_TEMPERATURES) #if ENABLED(AUTO_REPORT_TEMPERATURES)
static uint8_t auto_report_temp_interval; static uint8_t auto_report_temp_interval;
static millis_t next_temp_report_ms; static millis_t next_temp_report_ms;

View file

@ -51,10 +51,8 @@ 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(FAST_FILE_TRANSFER) #if ENABLED(FAST_FILE_TRANSFER) && NUM_SERIAL > 1
#if NUM_SERIAL > 1 int8_t CardReader::transfer_port;
uint8_t CardReader::transfer_port;
#endif
#endif #endif
// private: // private:
@ -160,11 +158,7 @@ char *createFilename(char *buffer, const dir_t &p) {
uint16_t nrFile_index; uint16_t nrFile_index;
void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
#if NUM_SERIAL > 1
, const int8_t port/*= -1*/
#endif
) {
dir_t p; dir_t p;
uint8_t cnt = 0; uint8_t cnt = 0;
@ -197,16 +191,12 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
SdFile dir; SdFile dir;
if (!dir.open(&parent, dosFilename, O_READ)) { if (!dir.open(&parent, dosFilename, O_READ)) {
if (lsAction == LS_SerialPrint) { if (lsAction == LS_SerialPrint) {
SERIAL_ECHO_START_P(port); SERIAL_ECHO_START();
SERIAL_ECHOPGM_P(port, MSG_SD_CANT_OPEN_SUBDIR); SERIAL_ECHOPGM(MSG_SD_CANT_OPEN_SUBDIR);
SERIAL_ECHOLN_P(port, dosFilename); SERIAL_ECHOLN(dosFilename);
} }
} }
lsDive(path, dir lsDive(path, dir);
#if NUM_SERIAL > 1
, NULL, port
#endif
);
// close() is done automatically by destructor of SdFile // close() is done automatically by destructor of SdFile
} }
else { else {
@ -228,10 +218,10 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
case LS_SerialPrint: case LS_SerialPrint:
createFilename(filename, p); createFilename(filename, p);
if (prepend) SERIAL_ECHO_P(port, prepend); if (prepend) SERIAL_ECHO(prepend);
SERIAL_ECHO_P(port, filename); SERIAL_ECHO(filename);
SERIAL_CHAR_P(port, ' '); SERIAL_CHAR(' ');
SERIAL_ECHOLN_P(port, p.fileSize); SERIAL_ECHOLN(p.fileSize);
break; break;
case LS_GetFilename: case LS_GetFilename:
@ -248,18 +238,10 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
} // while readDir } // while readDir
} }
void CardReader::ls( void CardReader::ls() {
#if NUM_SERIAL > 1
const int8_t port
#endif
) {
lsAction = LS_SerialPrint; lsAction = LS_SerialPrint;
root.rewind(); root.rewind();
lsDive(NULL, root lsDive(NULL, root);
#if NUM_SERIAL > 1
, NULL, port
#endif
);
} }
#if ENABLED(LONG_FILENAME_HOST_SUPPORT) #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
@ -267,16 +249,12 @@ void CardReader::ls(
/** /**
* Get a long pretty path based on a DOS 8.3 path * Get a long pretty path based on a DOS 8.3 path
*/ */
void CardReader::printLongPath(char *path void CardReader::printLongPath(char *path) {
#if NUM_SERIAL > 1
, const int8_t port/*= -1*/
#endif
) {
lsAction = LS_GetFilename; lsAction = LS_GetFilename;
int i, pathLen = strlen(path); int i, pathLen = strlen(path);
// SERIAL_ECHOPGM_P(port, "Full Path: "); SERIAL_ECHOLN_P(port, path); // SERIAL_ECHOPGM("Full Path: "); SERIAL_ECHOLN(path);
// Zero out slashes to make segments // Zero out slashes to make segments
for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0'; for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0';
@ -294,32 +272,28 @@ void CardReader::ls(
// Go to the next segment // Go to the next segment
while (path[++i]) { } while (path[++i]) { }
// SERIAL_ECHOPGM_P(port, "Looking for segment: "); SERIAL_ECHOLN_P(port, segment); // SERIAL_ECHOPGM("Looking for segment: "); SERIAL_ECHOLN(segment);
// Find the item, setting the long filename // Find the item, setting the long filename
diveDir.rewind(); diveDir.rewind();
lsDive(NULL, diveDir, segment lsDive(NULL, diveDir, segment);
#if NUM_SERIAL > 1
, port
#endif
);
// Print /LongNamePart to serial output // Print /LongNamePart to serial output
SERIAL_CHAR_P(port, '/'); SERIAL_CHAR('/');
SERIAL_ECHO_P(port, longFilename[0] ? longFilename : "???"); SERIAL_ECHO(longFilename[0] ? longFilename : "???");
// If the filename was printed then that's it // If the filename was printed then that's it
if (!flag.filenameIsDir) break; if (!flag.filenameIsDir) break;
// SERIAL_ECHOPGM_P(port, "Opening dir: "); SERIAL_ECHOLN_P(port, segment); // SERIAL_ECHOPGM("Opening dir: "); SERIAL_ECHOLN(segment);
// Open the sub-item as the new dive parent // Open the sub-item as the new dive parent
SdFile dir; SdFile dir;
if (!dir.open(&diveDir, segment, O_READ)) { if (!dir.open(&diveDir, segment, O_READ)) {
SERIAL_EOL_P(port); SERIAL_EOL();
SERIAL_ECHO_START_P(port); SERIAL_ECHO_START();
SERIAL_ECHOPGM_P(port, MSG_SD_CANT_OPEN_SUBDIR); SERIAL_ECHOPGM(MSG_SD_CANT_OPEN_SUBDIR);
SERIAL_ECHO_P(port, segment); SERIAL_ECHO(segment);
break; break;
} }
@ -328,7 +302,7 @@ void CardReader::ls(
} // while i<pathLen } // while i<pathLen
SERIAL_EOL_P(port); SERIAL_EOL();
} }
#endif // LONG_FILENAME_HOST_SUPPORT #endif // LONG_FILENAME_HOST_SUPPORT
@ -336,27 +310,23 @@ void CardReader::ls(
/** /**
* Echo the DOS 8.3 filename (and long filename, if any) * Echo the DOS 8.3 filename (and long filename, if any)
*/ */
void CardReader::printFilename( void CardReader::printFilename() {
#if NUM_SERIAL > 1
const int8_t port/*= -1*/
#endif
) {
if (file.isOpen()) { if (file.isOpen()) {
char dosFilename[FILENAME_LENGTH]; char dosFilename[FILENAME_LENGTH];
file.getFilename(dosFilename); file.getFilename(dosFilename);
SERIAL_ECHO_P(port, dosFilename); SERIAL_ECHO(dosFilename);
#if ENABLED(LONG_FILENAME_HOST_SUPPORT) #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
getfilename(0, dosFilename); getfilename(0, dosFilename);
if (longFilename[0]) { if (longFilename[0]) {
SERIAL_ECHO_P(port, ' '); SERIAL_ECHO(' ');
SERIAL_ECHO_P(port, longFilename); SERIAL_ECHO(longFilename);
} }
#endif #endif
} }
else else
SERIAL_ECHOPGM_P(port, "(no file)"); SERIAL_ECHOPGM("(no file)");
SERIAL_EOL_P(port); SERIAL_EOL();
} }
void CardReader::initsd() { void CardReader::initsd() {
@ -556,19 +526,15 @@ void CardReader::removeFile(const char * const name) {
} }
} }
void CardReader::report_status( void CardReader::report_status() {
#if NUM_SERIAL > 1
const int8_t port/*= -1*/
#endif
) {
if (isPrinting()) { if (isPrinting()) {
SERIAL_ECHOPGM_P(port, MSG_SD_PRINTING_BYTE); SERIAL_ECHOPGM(MSG_SD_PRINTING_BYTE);
SERIAL_ECHO_P(port, sdpos); SERIAL_ECHO(sdpos);
SERIAL_CHAR_P(port, '/'); SERIAL_CHAR('/');
SERIAL_ECHOLN_P(port, filesize); SERIAL_ECHOLN(filesize);
} }
else else
SERIAL_ECHOLNPGM_P(port, MSG_SD_NOT_PRINTING); SERIAL_ECHOLNPGM(MSG_SD_NOT_PRINTING);
} }
void CardReader::write_command(char *buf) { void CardReader::write_command(char *buf) {
@ -1038,18 +1004,15 @@ void CardReader::printingHasFinished() {
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 NUM_SERIAL > 1
int8_t CardReader::serialport; int8_t CardReader::auto_report_port;
#endif #endif
void CardReader::auto_report_sd_status() { void CardReader::auto_report_sd_status() {
millis_t current_ms = millis(); millis_t current_ms = millis();
if (auto_report_sd_interval && ELAPSED(current_ms, next_sd_report_ms)) { if (auto_report_sd_interval && ELAPSED(current_ms, next_sd_report_ms)) {
next_sd_report_ms = current_ms + 1000UL * auto_report_sd_interval; next_sd_report_ms = current_ms + 1000UL * auto_report_sd_interval;
report_status( PORT_REDIRECT(auto_report_port);
#if NUM_SERIAL > 1 report_status();
serialport
#endif
);
} }
} }
#endif // AUTO_REPORT_SD_STATUS #endif // AUTO_REPORT_SD_STATUS

View file

@ -70,24 +70,12 @@ public:
const bool re_sort=false const bool re_sort=false
#endif #endif
); );
static void report_status( static void report_status();
#if NUM_SERIAL > 1
const int8_t port = -1
#endif
);
static void printingHasFinished(); static void printingHasFinished();
static void printFilename( static void printFilename();
#if NUM_SERIAL > 1
const int8_t port = -1
#endif
);
#if ENABLED(LONG_FILENAME_HOST_SUPPORT) #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
static void printLongPath(char *path static void printLongPath(char *path);
#if NUM_SERIAL > 1
, const int8_t port = -1
#endif
);
#endif #endif
static void getfilename(uint16_t nr, const char* const match=NULL); static void getfilename(uint16_t nr, const char* const match=NULL);
@ -95,11 +83,7 @@ public:
static void getAbsFilename(char *t); static void getAbsFilename(char *t);
static void ls( static void ls();
#if NUM_SERIAL > 1
const int8_t port = -1
#endif
);
static void chdir(const char *relpath); static void chdir(const char *relpath);
static int8_t updir(); static int8_t updir();
static void setroot(); static void setroot();
@ -144,13 +128,9 @@ public:
#if ENABLED(AUTO_REPORT_SD_STATUS) #if ENABLED(AUTO_REPORT_SD_STATUS)
static void auto_report_sd_status(void); static void auto_report_sd_status(void);
static inline void set_auto_report_interval(uint8_t v static inline void set_auto_report_interval(const uint8_t v) {
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
, int8_t port auto_report_port = serial_port_index;
#endif
) {
#if NUM_SERIAL > 1
serialport = port;
#endif #endif
NOMORE(v, 60); NOMORE(v, 60);
auto_report_sd_interval = v; auto_report_sd_interval = v;
@ -167,9 +147,9 @@ public:
#if ENABLED(FAST_FILE_TRANSFER) #if ENABLED(FAST_FILE_TRANSFER)
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
static uint8_t transfer_port; static int8_t transfer_port;
#else #else
static constexpr uint8_t transfer_port = 0; static constexpr int8_t transfer_port = SERIAL_PORT;
#endif #endif
#endif #endif
@ -244,11 +224,7 @@ private:
static LsAction lsAction; //stored for recursion. static LsAction lsAction; //stored for recursion.
static uint16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory. static uint16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
static char *diveDirName; static char *diveDirName;
static void lsDive(const char *prepend, SdFile parent, const char * const match=NULL static void lsDive(const char *prepend, SdFile parent, const char * const match=NULL);
#if NUM_SERIAL > 1
, const int8_t port = -1
#endif
);
#if ENABLED(SDCARD_SORT_ALPHA) #if ENABLED(SDCARD_SORT_ALPHA)
static void flush_presort(); static void flush_presort();
@ -258,7 +234,7 @@ private:
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 NUM_SERIAL > 1
static int8_t serialport; static int8_t auto_report_port;
#endif #endif
#endif #endif
}; };