UBL implementation

This commit is contained in:
Scott Lahteine
2017-03-18 10:15:54 -05:00
parent 238b8fd2a3
commit fb60aa3736
7 changed files with 268 additions and 41 deletions

View File

@ -164,6 +164,10 @@
#include "stepper_indirection.h"
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
#include "UBL.h"
#endif
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
extern void bed_level_virt_interpolate();
#endif
@ -534,6 +538,11 @@ void Config_Postprocess() {
SERIAL_ECHOPAIR("Settings Stored (", eeprom_size - (EEPROM_OFFSET));
SERIAL_ECHOLNPGM(" bytes)");
}
#if ENABLED(AUTO_BED_LEVELING_UBL)
blm.store_state();
if (blm.state.EEPROM_storage_slot >= 0)
blm.store_mesh(blm.state.EEPROM_storage_slot);
#endif
}
/**
@ -832,8 +841,45 @@ void Config_Postprocess() {
SERIAL_ERRORLNPGM("EEPROM checksum mismatch");
Config_ResetDefault();
}
}
#if ENABLED(AUTO_BED_LEVELING_UBL)
Unified_Bed_Leveling_EEPROM_start = (eeprom_index + 32) & 0xFFF8; // Pad the end of configuration data so it
// can float up or down a little bit without
// disrupting the Unified Bed Leveling data
blm.load_state();
SERIAL_ECHOPGM(" UBL ");
if (!blm.state.active) SERIAL_ECHO("not ");
SERIAL_ECHOLNPGM("active!");
if (!blm.sanity_check()) {
int tmp_mesh; // We want to preserve whether the UBL System is Active
bool tmp_active; // If it is, we want to preserve the Mesh that is being used.
tmp_mesh = blm.state.EEPROM_storage_slot;
tmp_active = blm.state.active;
SERIAL_ECHOLNPGM("\nInitializing Bed Leveling State to current firmware settings.\n");
blm.state = blm.pre_initialized; // Initialize with the pre_initialized data structure
blm.state.EEPROM_storage_slot = tmp_mesh; // But then restore some data we don't want mangled
blm.state.active = tmp_active;
}
else {
SERIAL_PROTOCOLPGM("?Unable to enable Unified Bed Leveling.\n");
blm.state = blm.pre_initialized;
blm.reset();
blm.store_state();
}
if (blm.state.EEPROM_storage_slot >= 0) {
blm.load_mesh(blm.state.EEPROM_storage_slot);
SERIAL_ECHOPAIR("Mesh ", blm.state.EEPROM_storage_slot);
SERIAL_ECHOLNPGM(" loaded from storage.");
}
else {
blm.reset();
SERIAL_ECHOPGM("UBL System reset() \n");
}
#endif
}
#if ENABLED(EEPROM_CHITCHAT)
Config_PrintSettings();
#endif
@ -1126,6 +1172,42 @@ void Config_ResetDefault() {
SERIAL_ECHOPAIR(" Z", home_offset[Z_AXIS]);
SERIAL_EOL;
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
SERIAL_ECHOLNPGM("Unified Bed Leveling:");
CONFIG_ECHO_START;
SERIAL_ECHOPGM("System is: ");
if (blm.state.active)
SERIAL_ECHOLNPGM("Active\n");
else
SERIAL_ECHOLNPGM("Deactive\n");
SERIAL_ECHOPAIR("Active Mesh Slot: ", blm.state.EEPROM_storage_slot);
SERIAL_EOL;
SERIAL_ECHOPGM("z_offset: ");
SERIAL_ECHO_F(blm.state.z_offset, 6);
SERIAL_EOL;
SERIAL_ECHOPAIR("EEPROM can hold ", (int)((E2END - sizeof(blm.state) - Unified_Bed_Leveling_EEPROM_start) / sizeof(z_values)));
SERIAL_ECHOLNPGM(" meshes. \n");
SERIAL_ECHOPAIR("\nUBL_MESH_NUM_X_POINTS ", UBL_MESH_NUM_X_POINTS);
SERIAL_ECHOPAIR("\nUBL_MESH_NUM_Y_POINTS ", UBL_MESH_NUM_Y_POINTS);
SERIAL_ECHOPAIR("\nUBL_MESH_MIN_X ", UBL_MESH_MIN_X);
SERIAL_ECHOPAIR("\nUBL_MESH_MIN_Y ", UBL_MESH_MIN_Y);
SERIAL_ECHOPAIR("\nUBL_MESH_MAX_X ", UBL_MESH_MAX_X);
SERIAL_ECHOPAIR("\nUBL_MESH_MAX_Y ", UBL_MESH_MAX_Y);
SERIAL_ECHOPGM("\nMESH_X_DIST ");
SERIAL_ECHO_F(MESH_X_DIST, 6);
SERIAL_ECHOPGM("\nMESH_Y_DIST ");
SERIAL_ECHO_F(MESH_Y_DIST, 6);
SERIAL_EOL;
SERIAL_EOL;
#endif
#if HOTENDS > 1
CONFIG_ECHO_START;