Skip to content

Commit

Permalink
Export setting to file
Browse files Browse the repository at this point in the history
  • Loading branch information
vovodroid committed Apr 13, 2024
1 parent 71d9a3e commit 1e88ac8
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
Expand Down Expand Up @@ -4528,3 +4529,11 @@

// Shrink the build for smaller boards by sacrificing some serial feedback
//#define MARLIN_SMALL_BUILD

#if ALL(HAS_MEDIA, HAS_MARLINUI_MENU)
//#define EXPORT_SETTINGS // Export memory settings to file M503.gc in SD card root for replay
#endif

#if ENABLED(EXPORT_SETTINGS)
#define SERIAL_2_FILE // Dump serial output to file, needed for export settings
#endif
26 changes: 26 additions & 0 deletions Marlin/src/core/serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,29 @@ void print_xyze(LOGICAL_AXIS_ARGS_(const_float_t) FSTR_P const prefix/*=nullptr*
#endif
if (suffix) SERIAL_ECHO(suffix); else SERIAL_EOL();
}

#if ENABLED(SERIAL_2_FILE)
#include <src/sd/SdFile.h>
#include <src/sd/cardreader.h>

MediaFile sr_dump_file;
size_t sr_write_res;

bool sr_file_open(const char * filename)
{
sr_write_res = 0;
MediaFile root = card.getroot();
return sr_dump_file.open(&root, filename, O_CREAT | O_WRITE | O_TRUNC);
}

void serial2file(uint8_t c)
{
if (sr_dump_file.isOpen() && sr_write_res != -1)
sr_write_res = sr_dump_file.write(c);
}

bool sr_file_close()
{
return sr_dump_file.close();
}
#endif
4 changes: 4 additions & 0 deletions Marlin/src/core/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ inline void print_xyze(const xyze_pos_t &xyze, FSTR_P const prefix=nullptr, FSTR
print_xyze(LOGICAL_AXIS_ELEM_(xyze) prefix, suffix);
}

bool sr_file_open(const char * filename);
bool sr_file_close();
extern size_t sr_write_res;

#define SERIAL_POS(SUFFIX,VAR) do { print_xyz(VAR, F(" " STRINGIFY(VAR) "="), F(" : " SUFFIX "\n")); }while(0)
#define SERIAL_XYZ(PREFIX,V...) do { print_xyz(V, F(PREFIX)); }while(0)

Expand Down
5 changes: 5 additions & 0 deletions Marlin/src/core/serial_hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ struct RuntimeSerial : public SerialBase< RuntimeSerial<SerialT> >, public Seria
#define _S_CLASS(N) class Serial##N##T,
#define _S_NAME(N) Serial##N##T,

void serial2file(uint8_t c);

template < REPEAT(NUM_SERIAL, _S_CLASS) const uint8_t offset=0, const uint8_t step=1 >
struct MultiSerial : public SerialBase< MultiSerial< REPEAT(NUM_SERIAL, _S_NAME) offset, step > > {
typedef SerialBase< MultiSerial< REPEAT(NUM_SERIAL, _S_NAME) offset, step > > BaseClassT;
Expand Down Expand Up @@ -227,6 +229,9 @@ struct MultiSerial : public SerialBase< MultiSerial< REPEAT(NUM_SERIAL, _S_NAME)
#define _S_WRITE(N) if (portMask.enabled(output[N])) serial##N.write(c);
REPEAT(NUM_SERIAL, _S_WRITE);
#undef _S_WRITE
#if ENABLED(SERIAL_2_FILE)
serial2file(c);
#endif
}
NO_INLINE void msgDone() {
#define _S_DONE(N) if (portMask.enabled(output[N])) serial##N.msgDone();
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -1883,4 +1883,4 @@

#if ALL(SPI_FLASH, HAS_MEDIA, MARLIN_DEV_MODE)
#define SPI_FLASH_BACKUP 1
#endif
#endif
2 changes: 2 additions & 0 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -2614,6 +2614,8 @@ static_assert(NUM_SERVOS <= NUM_SERVO_PLUGS, "NUM_SERVOS (or some servo index) i
#error "Either disable SDCARD_READONLY or disable BINARY_FILE_TRANSFER."
#elif ENABLED(SDCARD_EEPROM_EMULATION)
#error "Either disable SDCARD_READONLY or disable SDCARD_EEPROM_EMULATION."
#elif ENABLED(EXPORT_SETTINGS)
#error "Either disable SDCARD_READONLY or disable EXPORT_SETTINGS."
#endif
#endif

Expand Down
1 change: 1 addition & 0 deletions Marlin/src/lcd/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ namespace LanguageNarrow_en {
LSTR MSG_LOAD_EEPROM = _UxGT("Load Settings");
LSTR MSG_RESTORE_DEFAULTS = _UxGT("Restore Defaults");
LSTR MSG_INIT_EEPROM = _UxGT("Initialize EEPROM");
LSTR MSG_EXPORT_SETTINGS = _UxGT("Export Settings");
LSTR MSG_ERR_EEPROM_CRC = _UxGT("Err: EEPROM CRC");
LSTR MSG_ERR_EEPROM_SIZE = _UxGT("Err: EEPROM Size");
LSTR MSG_ERR_EEPROM_VERSION = _UxGT("Err: EEPROM Version");
Expand Down
10 changes: 10 additions & 0 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,16 @@ void MarlinUI::host_notify(const char * const cstr) {
zoffset_overlay(dir);
}
#endif
#if ENABLED(EXPORT_SETTINGS)
void MarlinUI::export_settings() {
if (sr_file_open("M503.gc")) {
settings.report(true);
completion_feedback(sr_file_close() && sr_write_res != -1);
} else
completion_feedback(false);
}
#endif


#endif

Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,10 @@ class MarlinUI {
static void eeprom_alert(const EEPROM_Error) TERN_(EEPROM_AUTO_INIT, {});
#endif

#if ENABLED(EXPORT_SETTINGS)
static void export_settings();
#endif

//
// Special handling if a move is underway
//
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/lcd/menu/menu_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,10 @@ void menu_advanced_settings() {
);
#endif

#if ENABLED(EXPORT_SETTINGS)
ACTION_ITEM(MSG_EXPORT_SETTINGS, ui.export_settings);
#endif

END_MENU();
}

Expand Down

0 comments on commit 1e88ac8

Please sign in to comment.