From 8873c583d3694c98112e88af26f6d4dd37f5fe64 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 6 Jul 2019 05:25:59 +0200 Subject: [PATCH] Prevent extra settings.load on boot (#14499) --- Marlin/src/Marlin.cpp | 2 +- Marlin/src/module/configuration_store.h | 10 ++++++++-- Marlin/src/sd/cardreader.cpp | 10 ++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp index e73066fabf..12bac48b6c 100644 --- a/Marlin/src/Marlin.cpp +++ b/Marlin/src/Marlin.cpp @@ -941,7 +941,7 @@ void setup() { // Load data from EEPROM if available (or use defaults) // This also updates variables in the planner, elsewhere - (void)settings.load(); + settings.first_load(); #if HAS_M206_COMMAND // Initialize current position based on home_offset diff --git a/Marlin/src/module/configuration_store.h b/Marlin/src/module/configuration_store.h index fc84c4005b..9e95e47525 100644 --- a/Marlin/src/module/configuration_store.h +++ b/Marlin/src/module/configuration_store.h @@ -29,8 +29,6 @@ class MarlinSettings { public: - MarlinSettings() { } - static uint16_t datasize(); static void reset(); @@ -55,9 +53,15 @@ class MarlinSettings { #endif #if ENABLED(EEPROM_SETTINGS) + static bool load(); // Return 'true' if data was loaded ok static bool validate(); // Return 'true' if EEPROM data is ok + static inline void first_load() { + static bool loaded = false; + if (!loaded && load()) loaded = true; + } + #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system // That can store is enabled static uint16_t meshes_start_index(); @@ -73,6 +77,8 @@ class MarlinSettings { #else FORCE_INLINE static bool load() { reset(); report(); return true; } + FORCE_INLINE + static void first_load() { (void)load(); } #endif #if DISABLED(DISABLE_M503) diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index efd955259d..bc67e3de4e 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -353,8 +353,8 @@ void CardReader::initsd() { else { flag.detected = true; SERIAL_ECHO_MSG(MSG_SD_CARD_OK); - #if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION) - (void)settings.load(); + #if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM) + settings.first_load(); #endif } setroot(); @@ -560,10 +560,8 @@ void CardReader::checkautostart() { if (autostart_index < 0 || flag.sdprinting) return; if (!isDetected()) initsd(); - - #if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION) - SERIAL_ECHOLNPGM("Loading settings from SD"); - (void)settings.load(); + #if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM) + else settings.first_load(); #endif if (isDetected()