diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp index 90f567ab4..fbde923ea 100644 --- a/Marlin/configuration_store.cpp +++ b/Marlin/configuration_store.cpp @@ -1482,6 +1482,10 @@ void MarlinSettings::postprocess() { return (meshes_end - meshes_start_index()) / sizeof(ubl.z_values); } + int MarlinSettings::mesh_slot_offset(const int8_t slot) { + return meshes_end - (slot + 1) * sizeof(ubl.z_values); + } + void MarlinSettings::store_mesh(const int8_t slot) { #if ENABLED(AUTO_BED_LEVELING_UBL) @@ -1497,9 +1501,8 @@ void MarlinSettings::postprocess() { return; } + int pos = mesh_slot_offset(slot); uint16_t crc = 0; - int pos = meshes_end - (slot + 1) * sizeof(ubl.z_values); - write_data(pos, (uint8_t *)&ubl.z_values, sizeof(ubl.z_values), &crc); // Write crc to MAT along with other data, or just tack on to the beginning or end @@ -1528,8 +1531,8 @@ void MarlinSettings::postprocess() { return; } + int pos = mesh_slot_offset(slot); uint16_t crc = 0; - int pos = meshes_end - (slot + 1) * sizeof(ubl.z_values); uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&ubl.z_values; read_data(pos, dest, sizeof(ubl.z_values), &crc); diff --git a/Marlin/configuration_store.h b/Marlin/configuration_store.h index 54102807b..1f0a33c59 100644 --- a/Marlin/configuration_store.h +++ b/Marlin/configuration_store.h @@ -55,6 +55,7 @@ class MarlinSettings { static int16_t meshes_start_index(); FORCE_INLINE static int16_t meshes_end_index() { return meshes_end; } static uint16_t calc_num_meshes(); + static int mesh_slot_offset(const int8_t slot); static void store_mesh(const int8_t slot); static void load_mesh(const int8_t slot, void * const into=NULL); @@ -82,9 +83,8 @@ class MarlinSettings { #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system // That can store is enabled - static int16_t meshes_begin; - const static int16_t meshes_end = E2END - 128; // 128 is a placeholder for the size of the MAT; the MAT will always - // live at the very end of the eeprom + static constexpr int16_t meshes_end = E2END - 128; // 128 is a placeholder for the size of the MAT; the MAT will always + // live at the very end of the eeprom #endif diff --git a/Marlin/ubl_G29.cpp b/Marlin/ubl_G29.cpp index d4262ed0b..cdca64c76 100644 --- a/Marlin/ubl_G29.cpp +++ b/Marlin/ubl_G29.cpp @@ -1163,13 +1163,13 @@ SERIAL_ECHO_START(); SERIAL_ECHOLNPGM("EEPROM Dump:"); - for (uint16_t i = 0; i < E2END + 1; i += 16) { + for (uint16_t i = 0; i <= E2END; i += 16) { if (!(i & 0x3)) idle(); print_hex_word(i); SERIAL_ECHOPGM(": "); for (uint16_t j = 0; j < 16; j++) { kkkk = i + j; - eeprom_read_block(&cccc, (const void *) kkkk, sizeof(unsigned char)); + eeprom_read_block(&cccc, (const void *)kkkk, sizeof(unsigned char)); print_hex_byte(cccc); SERIAL_ECHO(' '); }