Option to Auto-Initialize EEPROM (#13935)

This commit is contained in:
InsanityAutomation
2019-05-07 17:30:31 -04:00
committed by Scott Lahteine
parent a504366138
commit 5dcb25664f
98 changed files with 1450 additions and 1059 deletions

View File

@ -1364,17 +1364,21 @@
// @section extras
//
// EEPROM
//
// The microcontroller can store settings in the EEPROM, e.g. max velocity...
// M500 - stores parameters in EEPROM
// M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily).
// M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
//
//#define EEPROM_SETTINGS // Enable for M500 and M501 commands
//#define DISABLE_M503 // Saves ~2700 bytes of PROGMEM. Disable for release!
#define EEPROM_CHITCHAT // Give feedback on EEPROM commands. Disable to save PROGMEM.
/**
* EEPROM
*
* Persistent storage to preserve configurable settings across reboots.
*
* M500 - Store settings to EEPROM.
* M501 - Read settings from EEPROM. (i.e., Throw away unsaved changes)
* M502 - Revert settings to "factory" defaults. (Follow with M500 to init the EEPROM.)
*/
//#define EEPROM_SETTINGS // Persistent storage with M500 and M501
//#define DISABLE_M503 // Saves ~2700 bytes of PROGMEM. Disable for release!
#define EEPROM_CHITCHAT // Give feedback on EEPROM commands. Disable to save PROGMEM.
#if ENABLED(EEPROM_SETTINGS)
//#define EEPROM_AUTO_INIT // Init EEPROM automatically on any errors.
#endif
//
// Host Keepalive

View File

@ -955,7 +955,15 @@ void setup() {
// Load data from EEPROM if available (or use defaults)
// This also updates variables in the planner, elsewhere
(void)settings.load();
#if ENABLED(EEPROM_AUTO_INIT)
if (!settings.load()) {
(void)settings.reset();
(void)settings.save();
SERIAL_ECHO_MSG("EEPROM Initialized");
}
#else
(void)settings.load();
#endif
#if HAS_M206_COMMAND
// Initialize current position based on home_offset

View File

@ -401,9 +401,8 @@ void MarlinSettings::postprocess() {
report_current_position();
}
#if ENABLED(PRINTCOUNTER) && ENABLED(EEPROM_SETTINGS)
#if BOTH(PRINTCOUNTER, EEPROM_SETTINGS)
#include "printcounter.h"
static_assert(
!WITHIN(STATS_EEPROM_ADDRESS, EEPROM_OFFSET, EEPROM_OFFSET + sizeof(SettingsData)) &&
!WITHIN(STATS_EEPROM_ADDRESS + sizeof(printStatistics), EEPROM_OFFSET, EEPROM_OFFSET + sizeof(SettingsData)),