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;
#ifdef DEBUG_MMC
{
char buffer[80];
sprintf_P(buffer, PSTR("SDRD: %d @ 0x%08x\n"), nb_sector, addr);
SERIAL_ECHO_P(0, buffer);
PORT_REDIRECT(0);
SERIAL_ECHO(buffer);
}
#endif
// 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;
#ifdef DEBUG_MMC
{
char buffer[80];
sprintf_P(buffer, PSTR("SDWR: %d @ 0x%08x\n"), nb_sector, addr);
SERIAL_ECHO_P(0, buffer);
PORT_REDIRECT(0);
SERIAL_ECHO(buffer);
}
#endif
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:";
#if NUM_SERIAL > 1
void serialprintPGM_P(const int8_t p, const char * str) {
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); }
int8_t serial_port_index = SERIAL_PORT;
#endif
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_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))
#if TX_BUFFER_SIZE < 1
#define SERIAL_FLUSHTX_P(p)
#define SERIAL_FLUSHTX()
#endif
#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
//
// Serial out to all ports
//
#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 PORT_REDIRECT(p) _PORT_REDIRECT(1,p)
#define PORT_RESTORE() _PORT_RESTORE(1)
//
// Serial out with port redirect
//
#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_ECHO_P(p,x) (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.print(x) : MYSERIAL1.print(x)) : SERIAL_ECHO(x))
#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_ECHOLN_P(p,x) (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.println(x) : MYSERIAL1.println(x)) : SERIAL_ECHOLN(x))
#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_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))
#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_FLUSH_P(p) (WITHIN(p, 0, NUM_SERIAL-1) ? (p == 0 ? MYSERIAL0.flush() : MYSERIAL1.flush()) : SERIAL_FLUSH())
#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_CHAR(x) SERIAL_OUT(write, x)
#define SERIAL_ECHO(x) SERIAL_OUT(print, x)
#define SERIAL_ECHO_F(x,y) SERIAL_OUT(print, x, y)
#define SERIAL_ECHOLN(x) SERIAL_OUT(println, x)
#define SERIAL_PRINT(x,b) SERIAL_OUT(print, x, b)
#define SERIAL_PRINTLN(x,b) SERIAL_OUT(println, x, b)
#define SERIAL_PRINTF(args...) SERIAL_OUT(printf, args)
#define SERIAL_FLUSH() SERIAL_OUT(flush)
#if TX_BUFFER_SIZE > 0
#define SERIAL_FLUSHTX() SERIAL_OUT(flushTX)
#endif
#define SERIAL_ECHOPGM(x) (serialprintPGM(PSTR(x)))
#define SERIAL_ECHOLNPGM(x) (serialprintPGM(PSTR(x "\n")))
#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_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_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_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)
//
@ -206,6 +113,7 @@ void serial_echo_start();
void serial_error_start();
void serialprint_onoff(const bool onoff);
void serialprintln_onoff(const bool onoff);
void serial_spaces(uint8_t count);
#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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -40,14 +40,8 @@
* M115: Capabilities string
*/
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)

View File

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

View File

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

View File

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

View File

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

View File

@ -40,15 +40,15 @@ void GcodeSuite::M105() {
#endif
#if HAS_TEMP_SENSOR
SERIAL_ECHOPGM_P(port, MSG_OK);
SERIAL_ECHOPGM(MSG_OK);
thermalManager.print_heater_states(target_extruder
#if NUM_SERIAL > 1
, port
#endif
);
#else // !HAS_TEMP_SENSOR
SERIAL_ERROR_MSG_P(port, MSG_ERR_NO_THERMISTORS);
SERIAL_ERROR_MSG(MSG_ERR_NO_THERMISTORS);
#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"
#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 {
public:
MarlinSettings() { }
static uint16_t datasize();
static void reset(PORTINIT_SOLO);
static bool save(PORTINIT_SOLO); // Return 'true' if data was saved
static void reset();
static bool save(); // Return 'true' if data was saved
FORCE_INLINE static bool init_eeprom() {
reset();
@ -65,8 +55,8 @@ class MarlinSettings {
#endif
#if ENABLED(EEPROM_SETTINGS)
static bool load(PORTINIT_SOLO); // Return 'true' if data was loaded ok
static bool validate(PORTINIT_SOLO); // Return 'true' if EEPROM data is ok
static bool load(); // Return 'true' if data was loaded 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
// That can store is enabled
@ -86,11 +76,7 @@ class MarlinSettings {
#endif
#if DISABLED(DISABLE_M503)
static void report(const bool forReplay=false
#if NUM_SERIAL > 1
, const int8_t port=-1
#endif
);
static void report(const bool forReplay=false);
#else
FORCE_INLINE
static void report(const bool forReplay=false) { UNUSED(forReplay); }
@ -109,12 +95,9 @@ class MarlinSettings {
// live at the very end of the eeprom
#endif
static bool _load(PORTINIT_SOLO);
static bool size_error(const uint16_t size PORTINIT_AFTER);
static bool _load();
static bool size_error(const uint16_t size);
#endif
};
extern MarlinSettings settings;
#undef PORTINIT_SOLO
#undef PORTINIT_AFTER

View File

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

View File

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

View File

@ -70,24 +70,12 @@ public:
const bool re_sort=false
#endif
);
static void report_status(
#if NUM_SERIAL > 1
const int8_t port = -1
#endif
);
static void report_status();
static void printingHasFinished();
static void printFilename(
#if NUM_SERIAL > 1
const int8_t port = -1
#endif
);
static void printFilename();
#if ENABLED(LONG_FILENAME_HOST_SUPPORT)
static void printLongPath(char *path
#if NUM_SERIAL > 1
, const int8_t port = -1
#endif
);
static void printLongPath(char *path);
#endif
static void getfilename(uint16_t nr, const char* const match=NULL);
@ -95,11 +83,7 @@ public:
static void getAbsFilename(char *t);
static void ls(
#if NUM_SERIAL > 1
const int8_t port = -1
#endif
);
static void ls();
static void chdir(const char *relpath);
static int8_t updir();
static void setroot();
@ -144,13 +128,9 @@ public:
#if ENABLED(AUTO_REPORT_SD_STATUS)
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
, int8_t port
#endif
) {
#if NUM_SERIAL > 1
serialport = port;
auto_report_port = serial_port_index;
#endif
NOMORE(v, 60);
auto_report_sd_interval = v;
@ -167,9 +147,9 @@ public:
#if ENABLED(FAST_FILE_TRANSFER)
#if NUM_SERIAL > 1
static uint8_t transfer_port;
static int8_t transfer_port;
#else
static constexpr uint8_t transfer_port = 0;
static constexpr int8_t transfer_port = SERIAL_PORT;
#endif
#endif
@ -244,11 +224,7 @@ private:
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 char *diveDirName;
static void lsDive(const char *prepend, SdFile parent, const char * const match=NULL
#if NUM_SERIAL > 1
, const int8_t port = -1
#endif
);
static void lsDive(const char *prepend, SdFile parent, const char * const match=NULL);
#if ENABLED(SDCARD_SORT_ALPHA)
static void flush_presort();
@ -258,7 +234,7 @@ private:
static uint8_t auto_report_sd_interval;
static millis_t next_sd_report_ms;
#if NUM_SERIAL > 1
static int8_t serialport;
static int8_t auto_report_port;
#endif
#endif
};