From 5b9476fe78bc14080b0b50bed7112dccd24c549c Mon Sep 17 00:00:00 2001 From: james94jeans2 Date: Tue, 21 Feb 2017 13:49:31 +0100 Subject: [PATCH 1/2] Added z_fade_height to EEPROM-Settings Firmware was forgetting the z_fade_height in Planner, set by M420 Z, after each reset or loading settings from EEPROM. Added the float z_fade_height to EEPROM-Storage, now remembers the value. --- Marlin/Marlin.h | 4 + Marlin/configuration_store.cpp | 114 +++++++++++++----- .../delta/kossel_pro/Configuration.h | 2 +- Marlin/planner.cpp | 4 +- 4 files changed, 90 insertions(+), 34 deletions(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 5e4a278347..122a3547a4 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -307,6 +307,10 @@ float code_value_temp_diff(); void reset_bed_level(); #endif +#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) + void set_z_fade_height(const float zfh); +#endif + #if ENABLED(Z_DUAL_ENDSTOPS) extern float z_endstop_adj; #endif diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp index f83057bed6..2eda9ae473 100644 --- a/Marlin/configuration_store.cpp +++ b/Marlin/configuration_store.cpp @@ -36,13 +36,13 @@ * */ -#define EEPROM_VERSION "V32" +#define EEPROM_VERSION "V33" // Change EEPROM version if these are changed: #define EEPROM_OFFSET 100 /** - * V32 EEPROM Layout: + * V33 EEPROM Layout: * * 100 Version (char x4) * 104 EEPROM Checksum (uint16_t) @@ -64,25 +64,28 @@ * 195 M206 XYZ home_offset (float x3) * 207 M218 XYZ hotend_offset (float x3 per additional hotend) * + * Global Leveling: + * 219 z_fade_height (float) + * * Mesh bed leveling: 43 bytes - * 219 M420 S from mbl.status (bool) - * 220 mbl.z_offset (float) - * 224 GRID_MAX_POINTS_X (uint8_t) - * 225 GRID_MAX_POINTS_Y (uint8_t) - * 226 G29 S3 XYZ z_values[][] (float x9, up to float x 81) +288 + * 223 M420 S from mbl.status (bool) + * 224 mbl.z_offset (float) + * 228 GRID_MAX_POINTS_X (uint8_t) + * 229 GRID_MAX_POINTS_Y (uint8_t) + * 230 G29 S3 XYZ z_values[][] (float x9, up to float x 81) +288 * * AUTO BED LEVELING 4 bytes - * 262 M851 zprobe_zoffset (float) + * 266 M851 zprobe_zoffset (float) * * ABL_PLANAR (or placeholder): 36 bytes - * 266 planner.bed_level_matrix (matrix_3x3 = float x9) + * 270 planner.bed_level_matrix (matrix_3x3 = float x9) * * AUTO_BED_LEVELING_BILINEAR (or placeholder): 47 bytes - * 302 GRID_MAX_POINTS_X (uint8_t) - * 303 GRID_MAX_POINTS_Y (uint8_t) - * 304 bilinear_grid_spacing (int x2) - * 308 G29 L F bilinear_start (int x2) - * 312 bed_level_grid[][] (float x9, up to float x256) +988 + * 306 GRID_MAX_POINTS_X (uint8_t) + * 307 GRID_MAX_POINTS_Y (uint8_t) + * 308 bilinear_grid_spacing (int x2) + * 312 G29 L F bilinear_start (int x2) + * 316 bed_level_grid[][] (float x9, up to float x256) +988 * * DELTA (if deltabot): 48 bytes * 348 M666 XYZ endstop_adj (float x3) @@ -144,10 +147,10 @@ * 568 M906 E1 stepperE1 current (uint16_t) * 570 M906 E2 stepperE2 current (uint16_t) * 572 M906 E3 stepperE3 current (uint16_t) - * 572 M906 E4 stepperE4 current (uint16_t) + * 576 M906 E4 stepperE4 current (uint16_t) * - * 576 Minimum end-point - * 1897 (576 + 36 + 9 + 288 + 988) Maximum end-point + * 580 Minimum end-point + * 1901 (580 + 36 + 9 + 288 + 988) Maximum end-point */ #include "Marlin.h" #include "language.h" @@ -200,6 +203,16 @@ void Config_Postprocess() { // Software endstops depend on home_offset LOOP_XYZ(i) update_software_endstops((AxisEnum)i); #endif + + #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) + set_z_fade_height( + //#if ENABLED(AUTO_BED_LEVELING_UBL) + // ubl.state.g29_correction_fade_height + //#else + planner.z_fade_height + //#endif + ); + #endif } #if ENABLED(EEPROM_SETTINGS) @@ -289,6 +302,17 @@ void Config_Postprocess() { LOOP_XYZ(i) EEPROM_WRITE(hotend_offset[i][e]); #endif + // + // General Leveling + // + + #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) + EEPROM_WRITE(planner.z_fade_height); + #else + dummy = 10.0; + EEPROM_WRITE(dummy); + #endif + // // Mesh Bed Leveling // @@ -618,6 +642,16 @@ void Config_Postprocess() { LOOP_XYZ(i) EEPROM_READ(hotend_offset[i][e]); #endif + // + // General Leveling + // + + #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) + EEPROM_READ(planner.z_fade_height); + #else + EEPROM_READ(dummy); + #endif + // // Mesh (Manual) Bed Leveling // @@ -927,6 +961,11 @@ void Config_ResetDefault() { planner.max_jerk[Y_AXIS] = DEFAULT_YJERK; planner.max_jerk[Z_AXIS] = DEFAULT_ZJERK; planner.max_jerk[E_AXIS] = DEFAULT_EJERK; + + #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) + planner.z_fade_height = 0.0; + #endif + #if DISABLED(NO_WORKSPACE_OFFSETS) ZERO(home_offset); #endif @@ -968,11 +1007,13 @@ void Config_ResetDefault() { COPY(delta_diagonal_rod_trim, drt); COPY(delta_tower_angle_trim, dta); #elif ENABLED(Z_DUAL_ENDSTOPS) - #if defined(Z_DUAL_ENDSTOPS_ADJUSTMENT) - float z_endstop_adj = Z_DUAL_ENDSTOPS_ADJUSTMENT; - #else - float z_endstop_adj = 0; - #endif + float z_endstop_adj = + #ifdef Z_DUAL_ENDSTOPS_ADJUSTMENT + Z_DUAL_ENDSTOPS_ADJUSTMENT + #else + 0 + #endif + ; #endif #if ENABLED(ULTIPANEL) @@ -1027,11 +1068,11 @@ void Config_ResetDefault() { #endif volumetric_enabled = - #if ENABLED(VOLUMETRIC_DEFAULT_ON) - true - #else - false - #endif + #if ENABLED(VOLUMETRIC_DEFAULT_ON) + true + #else + false + #endif ; for (uint8_t q = 0; q < COUNT(filament_size); q++) filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA; @@ -1211,7 +1252,11 @@ void Config_ResetDefault() { SERIAL_ECHOLNPGM("Mesh Bed Leveling:"); CONFIG_ECHO_START; } - SERIAL_ECHOLNPAIR(" M420 S", mbl.has_mesh() ? 1 : 0); + SERIAL_ECHOPAIR(" M420 S", mbl.has_mesh() ? 1 : 0); + #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) + SERIAL_ECHOLNPAIR(" Z", planner.z_fade_height); + #endif + SERIAL_EOL; for (uint8_t py = 1; py <= GRID_MAX_POINTS_Y; py++) { for (uint8_t px = 1; px <= GRID_MAX_POINTS_X; px++) { CONFIG_ECHO_START; @@ -1229,8 +1274,11 @@ void Config_ResetDefault() { SERIAL_ECHOLNPGM("Unified Bed Leveling:"); CONFIG_ECHO_START; } - - SERIAL_ECHOLNPAIR(" M420 S", ubl.state.active ? 1 : 0); + SERIAL_ECHOPAIR(" M420 S", ubl.state.active ? 1 : 0); + //#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) + // SERIAL_ECHOLNPAIR(" Z", ubl.state.g29_correction_fade_height); + //#endif + SERIAL_EOL; if (!forReplay) { SERIAL_ECHOPGM("\nUBL is "); @@ -1264,7 +1312,11 @@ void Config_ResetDefault() { SERIAL_ECHOLNPGM("Auto Bed Leveling:"); CONFIG_ECHO_START; } - SERIAL_ECHOLNPAIR(" M420 S", planner.abl_enabled ? 1 : 0); + SERIAL_ECHOPAIR(" M420 S", planner.abl_enabled ? 1 : 0); + #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) + SERIAL_ECHOLNPAIR(" Z", planner.z_fade_height); + #endif + SERIAL_EOL; #endif diff --git a/Marlin/example_configurations/delta/kossel_pro/Configuration.h b/Marlin/example_configurations/delta/kossel_pro/Configuration.h index 42efb89d15..113db63bb4 100644 --- a/Marlin/example_configurations/delta/kossel_pro/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_pro/Configuration.h @@ -819,7 +819,7 @@ */ #define Z_CLEARANCE_DEPLOY_PROBE 100 // Z Clearance for Deploy/Stow #define Z_CLEARANCE_BETWEEN_PROBES 5 // Z Clearance between probe points - + // For M851 give a range for adjusting the Z probe offset #define Z_PROBE_OFFSET_RANGE_MIN -15 diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 22da7a3de0..bb7578db31 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -109,8 +109,8 @@ float Planner::min_feedrate_mm_s, #endif #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) - float Planner::z_fade_height = 0.0, - Planner::inverse_z_fade_height = 0.0; + float Planner::z_fade_height, + Planner::inverse_z_fade_height; #endif #if ENABLED(AUTOTEMP) From 786af73e24215da94cdc05c277b0ec05b7cc37d2 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 9 Apr 2017 21:47:49 -0500 Subject: [PATCH 2/2] Convert config code to a static class --- Marlin/Marlin_main.cpp | 12 +++---- Marlin/configuration_store.cpp | 58 ++++++++++++++++++++-------------- Marlin/configuration_store.h | 45 ++++++++++++++++++-------- Marlin/ultralcd.cpp | 6 ++-- 4 files changed, 75 insertions(+), 46 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 42ad37d50f..088b0d5d99 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -573,7 +573,7 @@ static uint8_t target_extruder; endstop_adj[ABC] = { 0 }; // These values are loaded or reset at boot time when setup() calls - // Config_RetrieveSettings(), which calls recalc_delta_settings(). + // settings.load(), which calls recalc_delta_settings(). float delta_radius, delta_tower_angle_trim[ABC], delta_tower[ABC][2], @@ -7898,28 +7898,28 @@ void quickstop_stepper() { * M500: Store settings in EEPROM */ inline void gcode_M500() { - (void)Config_StoreSettings(); + (void)settings.save(); } /** * M501: Read settings from EEPROM */ inline void gcode_M501() { - (void)Config_RetrieveSettings(); + (void)settings.load(); } /** * M502: Revert to default settings */ inline void gcode_M502() { - (void)Config_ResetDefault(); + (void)settings.reset(); } /** * M503: print settings currently in memory */ inline void gcode_M503() { - (void)Config_PrintSettings(code_seen('S') && !code_value_bool()); + (void)settings.report(code_seen('S') && !code_value_bool()); } #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) @@ -11343,7 +11343,7 @@ void setup() { // Load data from EEPROM if available (or use defaults) // This also updates variables in the planner, elsewhere - (void)Config_RetrieveSettings(); + (void)settings.load(); #if DISABLED(NO_WORKSPACE_OFFSETS) // Initialize current position based on home_offset diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp index 2eda9ae473..a5c47dc1d0 100644 --- a/Marlin/configuration_store.cpp +++ b/Marlin/configuration_store.cpp @@ -23,7 +23,7 @@ /** * configuration_store.cpp * - * Configuration and EEPROM storage + * Settings and EEPROM storage * * IMPORTANT: Whenever there are changes made to the variables stored in EEPROM * in the functions below, also increment the version number. This makes sure that @@ -152,13 +152,16 @@ * 580 Minimum end-point * 1901 (580 + 36 + 9 + 288 + 988) Maximum end-point */ +#include "configuration_store.h" + +MarlinSettings settings; + #include "Marlin.h" #include "language.h" #include "endstops.h" #include "planner.h" #include "temperature.h" #include "ultralcd.h" -#include "configuration_store.h" #if ENABLED(MESH_BED_LEVELING) #include "mesh_bed_leveling.h" @@ -179,7 +182,7 @@ /** * Post-process after Retrieve or Reset */ -void Config_Postprocess() { +void MarlinSettings::postprocess() { // steps per s2 needs to be updated to agree with units per s2 planner.reset_acceleration_rates(); @@ -217,12 +220,14 @@ void Config_Postprocess() { #if ENABLED(EEPROM_SETTINGS) - uint16_t eeprom_checksum; const char version[4] = EEPROM_VERSION; - bool eeprom_write_error; + uint16_t MarlinSettings::eeprom_checksum; - void _EEPROM_writeData(int &pos, const uint8_t* value, uint16_t size) { + bool MarlinSettings::eeprom_write_error, + MarlinSettings::eeprom_read_error; + + void MarlinSettings::write_data(int &pos, const uint8_t* value, uint16_t size) { if (eeprom_write_error) return; while (size--) { uint8_t * const p = (uint8_t * const)pos; @@ -243,8 +248,7 @@ void Config_Postprocess() { value++; }; } - bool eeprom_read_error; - void _EEPROM_readData(int &pos, uint8_t* value, uint16_t size) { + void MarlinSettings::read_data(int &pos, uint8_t* value, uint16_t size) { do { uint8_t c = eeprom_read_byte((unsigned char*)pos); if (!eeprom_read_error) *value = c; @@ -257,14 +261,14 @@ void Config_Postprocess() { #define DUMMY_PID_VALUE 3000.0f #define EEPROM_START() int eeprom_index = EEPROM_OFFSET #define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR) - #define EEPROM_WRITE(VAR) _EEPROM_writeData(eeprom_index, (uint8_t*)&VAR, sizeof(VAR)) - #define EEPROM_READ(VAR) _EEPROM_readData(eeprom_index, (uint8_t*)&VAR, sizeof(VAR)) - #define EEPROM_ASSERT(TST,ERR) if () do{ SERIAL_ERROR_START; SERIAL_ERRORLNPGM(ERR); eeprom_read_error |= true; }while(0) + #define EEPROM_WRITE(VAR) write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR)) + #define EEPROM_READ(VAR) read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR)) + #define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START; SERIAL_ERRORLNPGM(ERR); eeprom_read_error = true; }while(0) /** * M500 - Store Configuration */ - bool Config_StoreSettings() { + bool MarlinSettings::save() { float dummy = 0.0f; char ver[4] = "000"; @@ -576,7 +580,7 @@ void Config_Postprocess() { /** * M501 - Retrieve Configuration */ - bool Config_RetrieveSettings() { + bool MarlinSettings::load() { EEPROM_START(); eeprom_read_error = false; // If set EEPROM_READ won't write into RAM @@ -597,7 +601,7 @@ void Config_Postprocess() { SERIAL_ECHOPGM("EEPROM version mismatch "); SERIAL_ECHOPAIR("(EEPROM=", stored_ver); SERIAL_ECHOLNPGM(" Marlin=" EEPROM_VERSION ")"); - Config_ResetDefault(); + reset(); } else { float dummy = 0; @@ -747,6 +751,11 @@ void Config_Postprocess() { EEPROM_READ(lcd_preheat_bed_temp); EEPROM_READ(lcd_preheat_fan_speed); + //EEPROM_ASSERT( + // WITHIN(lcd_preheat_fan_speed, 0, 255), + // "lcd_preheat_fan_speed out of range" + //); + #if ENABLED(PIDTEMP) for (uint8_t e = 0; e < MAX_EXTRUDERS; e++) { EEPROM_READ(dummy); // Kp @@ -869,9 +878,9 @@ void Config_Postprocess() { if (eeprom_checksum == stored_checksum) { if (eeprom_read_error) - Config_ResetDefault(); + reset(); else { - Config_Postprocess(); + postprocess(); SERIAL_ECHO_START; SERIAL_ECHO(version); SERIAL_ECHOPAIR(" stored settings retrieved (", eeprom_index - (EEPROM_OFFSET)); @@ -881,7 +890,7 @@ void Config_Postprocess() { else { SERIAL_ERROR_START; SERIAL_ERRORLNPGM("EEPROM checksum mismatch"); - Config_ResetDefault(); + reset(); } #if ENABLED(AUTO_BED_LEVELING_UBL) @@ -923,7 +932,7 @@ void Config_Postprocess() { #endif } #if ENABLED(EEPROM_CHITCHAT) - Config_PrintSettings(); + report(); #endif return !eeprom_read_error; @@ -931,7 +940,7 @@ void Config_Postprocess() { #else // !EEPROM_SETTINGS - bool Config_StoreSettings() { + bool MarlinSettings::save() { SERIAL_ERROR_START; SERIAL_ERRORLNPGM("EEPROM disabled"); return false; @@ -942,7 +951,7 @@ void Config_Postprocess() { /** * M502 - Reset Configuration */ -void Config_ResetDefault() { +void MarlinSettings::reset() { const float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT, tmp2[] = DEFAULT_MAX_FEEDRATE; const uint32_t tmp3[] = DEFAULT_MAX_ACCELERATION; LOOP_XYZE_N(i) { @@ -1118,7 +1127,7 @@ void Config_ResetDefault() { #endif #endif - Config_Postprocess(); + postprocess(); SERIAL_ECHO_START; SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded"); @@ -1129,10 +1138,11 @@ void Config_ResetDefault() { #define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START; }while(0) /** - * M503 - Print Configuration + * M503 - Report current settings in RAM + * + * Unless specifically disabled, M503 is available even without EEPROM */ - void Config_PrintSettings(bool forReplay) { - // Always have this function, even with EEPROM_SETTINGS disabled, the current values will be shown + void MarlinSettings::report(bool forReplay) { CONFIG_ECHO_START; diff --git a/Marlin/configuration_store.h b/Marlin/configuration_store.h index 93dbb7404c..e31d20b5cb 100644 --- a/Marlin/configuration_store.h +++ b/Marlin/configuration_store.h @@ -25,19 +25,38 @@ #include "MarlinConfig.h" -void Config_ResetDefault(); -bool Config_StoreSettings(); +class MarlinSettings { + public: + MarlinSettings() { } -#if DISABLED(DISABLE_M503) - void Config_PrintSettings(bool forReplay=false); -#else - FORCE_INLINE void Config_PrintSettings(bool forReplay=false) {} -#endif + static void reset(); + static bool save(); -#if ENABLED(EEPROM_SETTINGS) - bool Config_RetrieveSettings(); -#else - FORCE_INLINE bool Config_RetrieveSettings() { Config_ResetDefault(); Config_PrintSettings(); return true; } -#endif + #if ENABLED(EEPROM_SETTINGS) + static bool load(); + #else + FORCE_INLINE + static bool load() { reset(); report(); return true; } + #endif -#endif //CONFIGURATION_STORE_H + #if DISABLED(DISABLE_M503) + static void report(bool forReplay=false); + #else + FORCE_INLINE + static void report(bool forReplay=false) { } + #endif + + private: + static void postprocess(); + + #if ENABLED(EEPROM_SETTINGS) + static uint16_t eeprom_checksum; + static bool eeprom_read_error, eeprom_write_error; + static void write_data(int &pos, const uint8_t* value, uint16_t size); + static void read_data(int &pos, uint8_t* value, uint16_t size); + #endif +}; + +extern MarlinSettings settings; + +#endif // CONFIGURATION_STORE_H diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index afba70a10f..7294a004d2 100755 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -2046,12 +2046,12 @@ void kill_screen(const char* lcd_msg) { */ #if ENABLED(EEPROM_SETTINGS) - static void lcd_store_settings() { lcd_completion_feedback(Config_StoreSettings()); } - static void lcd_load_settings() { lcd_completion_feedback(Config_RetrieveSettings()); } + static void lcd_store_settings() { lcd_completion_feedback(settings.save()); } + static void lcd_load_settings() { lcd_completion_feedback(settings.load()); } #endif static void lcd_factory_settings() { - Config_ResetDefault(); + settings.reset(); lcd_completion_feedback(); }