From 69d58e4f16a9f703e235793b5c64c6a90149a6ac Mon Sep 17 00:00:00 2001 From: vovodroid Date: Sat, 5 Jul 2025 11:22:22 +0300 Subject: [PATCH 1/2] Save ABL bilinear mesh in PLR resume data. --- Marlin/src/feature/powerloss.cpp | 13 +++++++++++++ Marlin/src/feature/powerloss.h | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/Marlin/src/feature/powerloss.cpp b/Marlin/src/feature/powerloss.cpp index d9af336d3a..b6d6bdf22f 100644 --- a/Marlin/src/feature/powerloss.cpp +++ b/Marlin/src/feature/powerloss.cpp @@ -262,6 +262,12 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW info.flag.dryrun = !!(marlin_debug_flags & MARLIN_DEBUG_DRYRUN); info.flag.allow_cold_extrusion = TERN0(PREVENT_COLD_EXTRUSION, thermalManager.allow_cold_extrude); + #if ENABLED(AUTO_BED_LEVELING_BILINEAR) + info.grid_spacing = bedlevel.grid_spacing; + info.grid_start = bedlevel.grid_start; + memcpy(info.z_values, bedlevel.z_values, sizeof(bed_mesh_t)); + #endif + write(); } } @@ -478,6 +484,13 @@ void PrintJobRecovery::resume() { set_all_homed(); #if HAS_LEVELING + #if ENABLED(AUTO_BED_LEVELING_BILINEAR) + bedlevel.set_grid(info.grid_spacing, info.grid_start); + memcpy(bedlevel.z_values, info.z_values, sizeof(bed_mesh_t)); + + TERN_(EXTENSIBLE_UI, GRID_LOOP(x, y) ExtUI::onMeshUpdate(x, y, bedlevel.z_values[x][y])); + #endif + // Restore Z fade and possibly re-enable bed leveling compensation. // Leveling may already be enabled due to the ENABLE_LEVELING_AFTER_G28 option. // TODO: Add a G28 parameter to leave leveling disabled. diff --git a/Marlin/src/feature/powerloss.h b/Marlin/src/feature/powerloss.h index 8e1e299ac0..ffc86f9918 100644 --- a/Marlin/src/feature/powerloss.h +++ b/Marlin/src/feature/powerloss.h @@ -42,6 +42,10 @@ #include "mixing.h" #endif +#if ENABLED(AUTO_BED_LEVELING_BILINEAR) + #include "bedlevel/bedlevel.h" +#endif + #if !defined(POWER_LOSS_STATE) && PIN_EXISTS(POWER_LOSS) #define POWER_LOSS_STATE HIGH #endif @@ -145,6 +149,12 @@ typedef struct { #endif } flag; + #if ENABLED(AUTO_BED_LEVELING_BILINEAR) + xy_pos_t grid_spacing; + xy_pos_t grid_start; + bed_mesh_t z_values; + #endif + uint8_t valid_foot; bool valid() { return valid_head && valid_head == valid_foot; } From c4f039eb8705807e0d6f272ee5cc9d26848890cc Mon Sep 17 00:00:00 2001 From: vovodroid Date: Sun, 6 Jul 2025 09:53:48 +0300 Subject: [PATCH 2/2] Make configurable --- Marlin/Configuration_adv.h | 4 ++++ Marlin/src/feature/powerloss.cpp | 4 ++-- Marlin/src/feature/powerloss.h | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 1cd89a9714..ad7baf5d77 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1813,6 +1813,10 @@ #if ENABLED(POWER_LOSS_RECOVER_ZHOME) //#define POWER_LOSS_ZHOME_POS { 0, 0 } // Safe XY position to home Z while avoiding objects on the bed #endif + + #if ENABLED(AUTO_BED_LEVELING_BILINEAR) + //#define POWER_LOSS_SAVE_BILINEAR_MESH // Save bilinear mesh in resume data + #endif #endif /** diff --git a/Marlin/src/feature/powerloss.cpp b/Marlin/src/feature/powerloss.cpp index b6d6bdf22f..c795eac784 100644 --- a/Marlin/src/feature/powerloss.cpp +++ b/Marlin/src/feature/powerloss.cpp @@ -262,7 +262,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW info.flag.dryrun = !!(marlin_debug_flags & MARLIN_DEBUG_DRYRUN); info.flag.allow_cold_extrusion = TERN0(PREVENT_COLD_EXTRUSION, thermalManager.allow_cold_extrude); - #if ENABLED(AUTO_BED_LEVELING_BILINEAR) + #if ENABLED(POWER_LOSS_SAVE_BILINEAR_MESH) info.grid_spacing = bedlevel.grid_spacing; info.grid_start = bedlevel.grid_start; memcpy(info.z_values, bedlevel.z_values, sizeof(bed_mesh_t)); @@ -484,7 +484,7 @@ void PrintJobRecovery::resume() { set_all_homed(); #if HAS_LEVELING - #if ENABLED(AUTO_BED_LEVELING_BILINEAR) + #if ENABLED(POWER_LOSS_SAVE_BILINEAR_MESH) bedlevel.set_grid(info.grid_spacing, info.grid_start); memcpy(bedlevel.z_values, info.z_values, sizeof(bed_mesh_t)); diff --git a/Marlin/src/feature/powerloss.h b/Marlin/src/feature/powerloss.h index ffc86f9918..dd0ee21ebd 100644 --- a/Marlin/src/feature/powerloss.h +++ b/Marlin/src/feature/powerloss.h @@ -42,7 +42,7 @@ #include "mixing.h" #endif -#if ENABLED(AUTO_BED_LEVELING_BILINEAR) +#if ENABLED(POWER_LOSS_SAVE_BILINEAR_MESH) #include "bedlevel/bedlevel.h" #endif @@ -149,7 +149,7 @@ typedef struct { #endif } flag; - #if ENABLED(AUTO_BED_LEVELING_BILINEAR) + #if ENABLED(POWER_LOSS_SAVE_BILINEAR_MESH) xy_pos_t grid_spacing; xy_pos_t grid_start; bed_mesh_t z_values;